1 #pragma once 2 3 #include "stdafx.h" 4 #include "MMC3.h" 5 6 class MMC3_115 : public MMC3 7 { 8 private: 9 uint8_t _prgReg = 0; 10 uint8_t _chrReg = 0; 11 uint8_t _protectionReg = 0; 12 13 protected: AllowRegisterRead()14 bool AllowRegisterRead() override { return true; } 15 InitMapper()16 void InitMapper() override 17 { 18 AddRegisterRange(0x4100, 0x7FFF, MemoryOperation::Write); 19 AddRegisterRange(0x5000, 0x5FFF, MemoryOperation::Read); 20 RemoveRegisterRange(0x8000, 0xFFFF, MemoryOperation::Read); 21 22 MMC3::InitMapper(); 23 } 24 25 void SelectCHRPage(uint16_t slot, uint16_t page, ChrMemoryType memoryType = ChrMemoryType::Default) override 26 { 27 page |= (_chrReg << 8); 28 BaseMapper::SelectCHRPage(slot, page); 29 } 30 UpdateState()31 void UpdateState() override 32 { 33 MMC3::UpdateState(); 34 35 if(_prgReg & 0x80) { 36 if(_prgReg & 0x20) { 37 SelectPrgPage4x(0, ((_prgReg & 0x0F) >> 1) << 2); 38 } else { 39 SelectPrgPage2x(0, (_prgReg & 0x0F) << 1); 40 SelectPrgPage2x(1, (_prgReg & 0x0F) << 1); 41 } 42 } 43 } 44 ReadRegister(uint16_t addr)45 uint8_t ReadRegister(uint16_t addr) override 46 { 47 return _protectionReg; 48 } 49 WriteRegister(uint16_t addr,uint8_t value)50 void WriteRegister(uint16_t addr, uint8_t value) override 51 { 52 if(addr < 0x8000) { 53 if(addr == 0x5080) { 54 _protectionReg = value; 55 } else { 56 if(addr & 0x01) { 57 _chrReg = value & 0x01; 58 } else { 59 _prgReg = value; 60 } 61 UpdateState(); 62 } 63 } else { 64 MMC3::WriteRegister(addr, value); 65 } 66 } 67 StreamState(bool saving)68 void StreamState(bool saving) override 69 { 70 MMC3::StreamState(saving); 71 Stream(_prgReg, _chrReg); 72 } 73 };