2018-06-17 21:04:11 +00:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "MMC3.h"
|
|
|
|
|
|
|
|
class MMC3_208 : public MMC3
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
const uint8_t _protectionLut[256] = {
|
|
|
|
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09,
|
|
|
|
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01,
|
|
|
|
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09,
|
|
|
|
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01,
|
|
|
|
0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08,
|
|
|
|
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00,
|
|
|
|
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08,
|
|
|
|
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00,
|
|
|
|
0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
};
|
|
|
|
|
2023-05-13 01:37:50 +00:00
|
|
|
uint8_t _exRegs[7];
|
2018-06-17 21:04:11 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
uint16_t RegisterStartAddress() override { return 0x8000; }
|
|
|
|
uint16_t RegisterEndAddress() override { return 0xFFFF; }
|
|
|
|
bool AllowRegisterRead() override { return true; }
|
|
|
|
|
|
|
|
void InitMapper() override
|
|
|
|
{
|
|
|
|
_exRegs[5] = 3;
|
|
|
|
MMC3::InitMapper();
|
2023-05-13 01:37:50 +00:00
|
|
|
if(_romInfo.SubMapperID == 0) {
|
|
|
|
AddRegisterRange(0x4800, 0x4FFF, MemoryOperation::Write);
|
|
|
|
AddRegisterRange(0x6800, 0x6FFF, MemoryOperation::Write);
|
|
|
|
AddRegisterRange(0x5000, 0x5FFF, MemoryOperation::Write);
|
|
|
|
AddRegisterRange(0x5800, 0x5FFF, MemoryOperation::Read);
|
|
|
|
}
|
2018-06-17 21:04:11 +00:00
|
|
|
RemoveRegisterRange(0x8000, 0xFFFF, MemoryOperation::Read);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StreamState(bool saving) override
|
|
|
|
{
|
|
|
|
MMC3::StreamState(saving);
|
2023-05-13 01:37:50 +00:00
|
|
|
ArrayInfo<uint8_t> exRegs { _exRegs, 7 };
|
2018-06-17 21:04:11 +00:00
|
|
|
Stream(exRegs);
|
|
|
|
}
|
|
|
|
|
2018-06-20 00:48:57 +00:00
|
|
|
void UpdatePrgMapping() override
|
2018-06-17 21:04:11 +00:00
|
|
|
{
|
2023-05-13 01:37:50 +00:00
|
|
|
if(_romInfo.SubMapperID == 1) {
|
|
|
|
SelectPrgPage4x(0, MMC3::_registers[6]);
|
|
|
|
} else {
|
|
|
|
SelectPrgPage4x(0, _exRegs[5] << 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateMirroring() override
|
|
|
|
{
|
|
|
|
if(_romInfo.SubMapperID == 1) {
|
|
|
|
MMC3::UpdateMirroring();
|
|
|
|
} else {
|
|
|
|
SetMirroringType(_exRegs[6] ? MirroringType::Horizontal : MirroringType::Vertical);
|
|
|
|
}
|
2018-06-17 21:04:11 +00:00
|
|
|
}
|
|
|
|
|
2018-06-20 00:48:57 +00:00
|
|
|
uint8_t ReadRegister(uint16_t addr) override
|
2018-06-17 21:04:11 +00:00
|
|
|
{
|
|
|
|
return _exRegs[addr & 0x03];
|
|
|
|
}
|
|
|
|
|
|
|
|
void WriteRegister(uint16_t addr, uint8_t value) override
|
|
|
|
{
|
|
|
|
if(addr >= 0x5000 && addr <= 0x5FFF) {
|
|
|
|
if(addr <= 0x57FF) {
|
|
|
|
_exRegs[4] = value;
|
|
|
|
} else {
|
|
|
|
_exRegs[addr & 0x03] = value ^ _protectionLut[_exRegs[4]];
|
|
|
|
}
|
|
|
|
} else if(addr < 0x8000) {
|
|
|
|
_exRegs[5] = (value & 0x01) | ((value >> 3) & 0x02);
|
2023-05-13 01:37:50 +00:00
|
|
|
_exRegs[6] = (value >> 5) & 0x01;
|
2018-06-17 21:04:11 +00:00
|
|
|
UpdatePrgMapping();
|
|
|
|
} else {
|
|
|
|
MMC3::WriteRegister(addr, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|