From c5850f7946426b6d98d980c9a14c2b5ce54d3d31 Mon Sep 17 00:00:00 2001 From: Souryo Date: Tue, 8 Nov 2016 17:18:36 -0500 Subject: [PATCH] UNIF AX5705 board support --- Core/Ax5705.h | 65 +++++++++++++++++++++++++++++++++++++++ Core/Core.vcxproj | 1 + Core/Core.vcxproj.filters | 3 ++ Core/MapperFactory.cpp | 3 ++ Core/MapperFactory.h | 1 + Core/UnifLoader.h | 2 +- 6 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 Core/Ax5705.h diff --git a/Core/Ax5705.h b/Core/Ax5705.h new file mode 100644 index 00000000..5d52e3db --- /dev/null +++ b/Core/Ax5705.h @@ -0,0 +1,65 @@ +#pragma once +#include "stdafx.h" +#include "BaseMapper.h" + +class Ax5705 : public BaseMapper +{ +private: + uint8_t _chrReg[8]; + +protected: + uint16_t GetPRGPageSize() { return 0x2000; } + uint16_t GetCHRPageSize() { return 0x400; } + + void InitMapper() override + { + memset(_chrReg, 0, sizeof(_chrReg)); + + SelectPRGPage(2, -2); + SelectPRGPage(3, -1); + + for(int i = 0; i < 8; i++) { + SelectCHRPage(i, _chrReg[i]); + } + } + + void StreamState(bool saving) override + { + BaseMapper::StreamState(saving); + ArrayInfo chrReg{ _chrReg, 8 }; + Stream(chrReg); + } + + void UpdateChrReg(int index, uint8_t value, bool low) + { + if(low) { + _chrReg[index] = (_chrReg[index] & 0xF0) | (value & 0x0F); + } else { + _chrReg[index] = (_chrReg[index] & 0x0F) | ((((value & 0x04) >> 1) | ((value & 0x02) << 1) | (value & 0x09)) << 4); + } + SelectCHRPage(index, _chrReg[index]); + } + + void WriteRegister(uint16_t addr, uint8_t value) override + { + if(addr >= 0xA008) { + bool low = (addr & 0x01) == 0x00; + switch(addr & 0xF00E) { + case 0xA008: UpdateChrReg(0, value, low); break; + case 0xA00A: UpdateChrReg(1, value, low); break; + case 0xC000: UpdateChrReg(2, value, low); break; + case 0xC002: UpdateChrReg(3, value, low); break; + case 0xC008: UpdateChrReg(4, value, low); break; + case 0xC00A: UpdateChrReg(5, value, low); break; + case 0xE000: UpdateChrReg(6, value, low); break; + case 0xE002: UpdateChrReg(7, value, low); break; + } + } else { + switch(addr & 0xF00F) { + case 0x8000: SelectPRGPage(0, ((value & 0x02) << 2) | ((value & 0x08) >> 2) | (value & 0x05)); break; // EPROM dump have mixed PRG and CHR banks, data lines to mapper seems to be mixed + case 0x8008: SetMirroringType(value & 0x01 ? MirroringType::Horizontal : MirroringType::Vertical); break; + case 0xA000: SelectPRGPage(1, ((value & 0x02) << 2) | ((value & 0x08) >> 2) | (value & 0x05)); break; + } + } + } +}; \ No newline at end of file diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 994ae6a2..c182ac9d 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -405,6 +405,7 @@ + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index 66a06304..80d41a9a 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -1006,6 +1006,9 @@ Nes\Mappers\Unif + + Nes\Mappers\Unif + diff --git a/Core/MapperFactory.cpp b/Core/MapperFactory.cpp index cdf5874a..4c328f16 100644 --- a/Core/MapperFactory.cpp +++ b/Core/MapperFactory.cpp @@ -5,6 +5,7 @@ #include "A65AS.h" #include "Action53.h" #include "ActionEnterprises.h" +#include "Ax5705.h" #include "AXROM.h" #include "Bandai74161_7432.h" #include "BandaiFcg.h" @@ -233,6 +234,7 @@ const uint16_t MapperFactory::FdsMapperID; const uint16_t MapperFactory::NsfMapperID; const uint16_t MapperFactory::UnknownBoard; const uint16_t MapperFactory::UnifA65AS; +const uint16_t MapperFactory::UnifAx5705; const uint16_t MapperFactory::UnifBmc70in1; const uint16_t MapperFactory::UnifBmc70in1B; const uint16_t MapperFactory::UnifBmc190in1; @@ -478,6 +480,7 @@ BaseMapper* MapperFactory::GetMapperFromID(RomData &romData) case 255: return new Bmc255(); case MapperFactory::UnifA65AS: return new A65AS(); + case MapperFactory::UnifAx5705: return new Ax5705(); case MapperFactory::UnifBmc70in1: return new Bmc70in1(); case MapperFactory::UnifBmc70in1B: return new Bmc70in1(); case MapperFactory::UnifBmc190in1: return new Bmc190in1(); diff --git a/Core/MapperFactory.h b/Core/MapperFactory.h index 0eb96acd..59cbab93 100644 --- a/Core/MapperFactory.h +++ b/Core/MapperFactory.h @@ -30,6 +30,7 @@ class MapperFactory static const uint16_t UnifGhostbusters63in1 = 65517; static const uint16_t UnifBmc70in1 = 65516; static const uint16_t UnifBmc70in1B = 65515; + static const uint16_t UnifAx5705 = 65514; static shared_ptr InitializeFromFile(string romFilename, stringstream *filestream, string ipsFilename, int32_t archiveFileIndex); }; diff --git a/Core/UnifLoader.h b/Core/UnifLoader.h index 3b3f8dc7..28410851 100644 --- a/Core/UnifLoader.h +++ b/Core/UnifLoader.h @@ -29,7 +29,7 @@ private: { "A65AS", MapperFactory::UnifA65AS }, { "AC08", MapperFactory::UnknownBoard }, { "ANROM", 7 }, - { "AX5705", MapperFactory::UnknownBoard }, + { "AX5705", MapperFactory::UnifAx5705 }, { "BB", MapperFactory::UnknownBoard }, { "BS-5", MapperFactory::UnifBs5 }, { "CC-21", MapperFactory::UnknownBoard },