From ae3e6c4978559b41fbc0bc088219dbbdea09420a Mon Sep 17 00:00:00 2001 From: Souryo Date: Wed, 30 Dec 2015 19:41:01 -0500 Subject: [PATCH] CNROM w/ copy protection (Mapper 185) support --- Core/BaseMapper.h | 12 +++++++++++- Core/CNROM.h | 38 ++++++++++++++++++++++++++++---------- Core/MapperFactory.cpp | 3 ++- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/Core/BaseMapper.h b/Core/BaseMapper.h index 67d04b46..d2259c39 100644 --- a/Core/BaseMapper.h +++ b/Core/BaseMapper.h @@ -143,6 +143,7 @@ class BaseMapper : public IMemoryHandler, public Snapshotable, public INotificat for(uint16_t i = startAddr; i <= endAddr; i++) { _prgPages[i] = source; _prgPageAccessType[i] = accessType != -1 ? accessType : defaultAccessType; + source += 0x100; } } @@ -166,10 +167,19 @@ class BaseMapper : public IMemoryHandler, public Snapshotable, public INotificat for(uint16_t i = startAddr; i <= endAddr; i++) { _chrPages[i] = sourceMemory; _chrPageAccessType[i] = accessType != -1 ? accessType : MemoryAccessType::ReadWrite; - sourceMemory += 0x100; + + if(sourceMemory != nullptr) { + sourceMemory += 0x100; + } } } + void RemovePpuMemoryMapping(uint16_t startAddr, uint16_t endAddr) + { + //Unmap this section of memory (causing open bus behavior) + SetPpuMemoryMapping(startAddr, endAddr, nullptr, MemoryAccessType::NoAccess); + } + uint8_t InternalReadRam(uint16_t addr) { return _prgPages[addr >> 8] ? _prgPages[addr >> 8][addr & 0xFF] : 0; diff --git a/Core/CNROM.h b/Core/CNROM.h index ea9b08b0..a828faac 100644 --- a/Core/CNROM.h +++ b/Core/CNROM.h @@ -4,18 +4,36 @@ class CNROM : public BaseMapper { - protected: - virtual uint16_t GetPRGPageSize() { return 0x8000; } - virtual uint16_t GetCHRPageSize() { return 0x2000; } +private: + bool _enableCopyProtection; - void InitMapper() - { - SelectPRGPage(0, 0); - SelectCHRPage(0, 0); - } +protected: + virtual uint16_t GetPRGPageSize() { return 0x8000; } + virtual uint16_t GetCHRPageSize() { return 0x2000; } - void WriteRegister(uint16_t addr, uint8_t value) - { + void InitMapper() + { + SelectPRGPage(0, 0); + SelectCHRPage(0, 0); + } + + void WriteRegister(uint16_t addr, uint8_t value) + { + if(_enableCopyProtection) { + //"if C AND $0F is nonzero, and if C does not equal $13: CHR is enabled" + //This means Seicross (mapper 185 version) will not work (to allow Spy vs Spy (J) to work + if((value & 0x0F) != 0 && value != 0x13) { + SelectCHRPage(0, 0); + } else { + RemovePpuMemoryMapping(0x0000, 0x1FFF); + } + } else { SelectCHRPage(0, value); } + } + +public: + CNROM(bool enableCopyProtection) : _enableCopyProtection(enableCopyProtection) + { + } }; \ No newline at end of file diff --git a/Core/MapperFactory.cpp b/Core/MapperFactory.cpp index 0b9f2db8..cb266d4d 100644 --- a/Core/MapperFactory.cpp +++ b/Core/MapperFactory.cpp @@ -37,7 +37,7 @@ BaseMapper* MapperFactory::GetMapperFromID(uint8_t mapperID) case 0: return new NROM(); case 1: return new MMC1(); case 2: return new UNROM(); - case 3: return new CNROM(); + case 3: return new CNROM(false); case 4: return new MMC3(); case 5: return new MMC5(); case 7: return new AXROM(); @@ -67,6 +67,7 @@ BaseMapper* MapperFactory::GetMapperFromID(uint8_t mapperID) case 101: return new JalecoJfxx(true); case 152: return new Bandai74161_7432(true); case 163: return new Nanjing(); + case 185: return new CNROM(true); case 189: return new MMC3_189(); }