From 520478972dd3fb1bdb24d28372c3207a18acc212 Mon Sep 17 00:00:00 2001 From: Souryo Date: Sat, 23 Jul 2016 12:26:02 -0400 Subject: [PATCH] Mapper 234 support --- Core/Core.vcxproj | 1 + Core/Core.vcxproj.filters | 3 ++ Core/Mapper234.h | 68 +++++++++++++++++++++++++++++++++++++++ Core/MapperFactory.cpp | 4 ++- 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 Core/Mapper234.h diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 68e7d9a3..04752c11 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -456,6 +456,7 @@ + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index af81d34e..5f205177 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -799,6 +799,9 @@ Nes\Mappers\Txc + + Nes\Mappers\Unnamed + diff --git a/Core/Mapper234.h b/Core/Mapper234.h new file mode 100644 index 00000000..22569461 --- /dev/null +++ b/Core/Mapper234.h @@ -0,0 +1,68 @@ +#pragma once +#include "stdafx.h" +#include "BaseMapper.h" + +class Mapper234 : public BaseMapper +{ +private: + uint8_t _regs[2]; + +protected: + virtual uint16_t RegisterStartAddress() { return 0xFF80; } + virtual uint16_t RegisterEndAddress() { return 0xFF9F; } + virtual uint16_t GetPRGPageSize() { return 0x8000; } + virtual uint16_t GetCHRPageSize() { return 0x2000; } + virtual bool AllowRegisterRead() { return true; } + virtual bool HasBusConflicts() { return true; } + + void InitMapper() + { + AddRegisterRange(0xFFE8, 0xFFF8, MemoryOperation::Any); + memset(_regs, 0, sizeof(_regs)); + UpdateState(); + } + + void UpdateState() + { + if(_regs[0] & 0x40) { + //NINA-03 mode + SelectPRGPage(0, (_regs[0] & 0x0E) | (_regs[1] & 0x01)); + SelectCHRPage(0, ((_regs[0] << 2) & 0x38) | (_regs[1] >> 4) & 0x07); + } else { + //CNROM mode + SelectPRGPage(0, _regs[0] & 0x0F); + SelectCHRPage(0, ((_regs[0] << 2) & 0x3C) | (_regs[1] >> 4) & 0x03); + } + + SetMirroringType(_regs[0] & 0x80 ? MirroringType::Horizontal : MirroringType::Vertical); + } + + uint8_t ReadRegister(uint16_t addr) + { + uint8_t value = InternalReadRam(addr); + if(addr <= 0xFF9F) { + if(!(_regs[0] & 0x3F)) { + _regs[0] = value; + UpdateState(); + } + } else { + _regs[1] = value & 0x71; + UpdateState(); + } + + return value; + } + + void WriteRegister(uint16_t addr, uint8_t value) + { + if(addr <= 0xFF9F) { + if(!(_regs[0] & 0x3F)) { + _regs[0] = value; + UpdateState(); + } + } else { + _regs[1] = value & 0x71; + UpdateState(); + } + } +}; \ No newline at end of file diff --git a/Core/MapperFactory.cpp b/Core/MapperFactory.cpp index a0f8e652..20952424 100644 --- a/Core/MapperFactory.cpp +++ b/Core/MapperFactory.cpp @@ -62,6 +62,7 @@ #include "Mapper227.h" #include "Mapper230.h" #include "Mapper231.h" +#include "Mapper234.h" #include "Mapper240.h" #include "Mapper241.h" #include "Mapper242.h" @@ -160,7 +161,7 @@ Supported mappers: |176|177|178|179|180| |182| |184|185| | | |189| |191| |192|193|194|195| | | | |200|201|202|203| |205|206|207| | |209|210|211| | | | | | |218| | | | | | -| |225|226|227|228| |230|231|232| | |235| | | | | +| |225|226|227|228| |230|231|232| |234|235| | | | | |240|241|242|243| |245|246| | | | | |252| | | | ----------------------------------------------------------------- */ @@ -340,6 +341,7 @@ BaseMapper* MapperFactory::GetMapperFromID(RomData &romData) case 230: return new Mapper230(); case 231: return new Mapper231(); case 232: return new BF9096(); + case 234: return new Mapper234(); case 235: return new Bmc235(); case 240: return new Mapper240(); case 241: return new Mapper241();