mirror of
https://github.com/libretro/Mesen.git
synced 2024-11-23 09:09:45 +00:00
93 lines
3.3 KiB
C++
93 lines
3.3 KiB
C++
#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,
|
|
};
|
|
|
|
uint8_t _exRegs[7];
|
|
|
|
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();
|
|
if(_romInfo.SubMapperID == 0) {
|
|
AddRegisterRange(0x4800, 0x4FFF, MemoryOperation::Write);
|
|
AddRegisterRange(0x6800, 0x6FFF, MemoryOperation::Write);
|
|
AddRegisterRange(0x5000, 0x5FFF, MemoryOperation::Write);
|
|
AddRegisterRange(0x5800, 0x5FFF, MemoryOperation::Read);
|
|
}
|
|
RemoveRegisterRange(0x8000, 0xFFFF, MemoryOperation::Read);
|
|
}
|
|
|
|
void StreamState(bool saving) override
|
|
{
|
|
MMC3::StreamState(saving);
|
|
ArrayInfo<uint8_t> exRegs { _exRegs, 7 };
|
|
Stream(exRegs);
|
|
}
|
|
|
|
void UpdatePrgMapping() override
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
|
|
uint8_t ReadRegister(uint16_t addr) override
|
|
{
|
|
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);
|
|
_exRegs[6] = (value >> 5) & 0x01;
|
|
UpdatePrgMapping();
|
|
} else {
|
|
MMC3::WriteRegister(addr, value);
|
|
}
|
|
}
|
|
}; |