Mesen/Core/Bmc64in1NoRepeat.h

68 lines
1.4 KiB
C
Raw Normal View History

2016-11-11 23:36:20 +00:00
#pragma once
#include "stdafx.h"
#include "BaseMapper.h"
class Bmc64in1NoRepeat : public BaseMapper
{
private:
uint8_t _regs[4];
protected:
uint16_t GetPRGPageSize() override { return 0x4000; }
uint16_t GetCHRPageSize() override { return 0x2000; }
void InitMapper() override
{
2023-05-13 01:39:46 +00:00
AddRegisterRange(0x5000, 0x5FFF, MemoryOperation::Write);
2016-11-11 23:36:20 +00:00
}
2016-12-18 04:14:47 +00:00
void Reset(bool softReset) override
2016-11-11 23:36:20 +00:00
{
BaseMapper::Reset(softReset);
_regs[0] = 0x80;
_regs[1] = 0x43;
_regs[2] = _regs[3] = 0;
UpdateState();
}
2016-12-18 04:14:47 +00:00
void StreamState(bool saving) override
2016-11-11 23:36:20 +00:00
{
BaseMapper::StreamState(saving);
Stream(_regs[0], _regs[1], _regs[2], _regs[3]);
}
void UpdateState()
{
if(_regs[0] & 0x80) {
if(_regs[1] & 0x80) {
2023-05-13 01:39:46 +00:00
SelectPrgPage2x(0, (_regs[1] & 0x3F) << 1);
2016-11-11 23:36:20 +00:00
} else {
2023-05-13 01:39:46 +00:00
int bank = ((_regs[1] & 0x3F) << 1) | ((_regs[1] >> 6) & 0x01);
2016-11-11 23:36:20 +00:00
SelectPRGPage(0, bank);
SelectPRGPage(1, bank);
}
} else {
2023-05-13 01:39:46 +00:00
SelectPRGPage(0, ((_regs[1] & 0x3F) << 1) | (_regs[3] & 0x07));
SelectPRGPage(1, ((_regs[1] & 0x3F) << 1) | 0x07);
2016-11-11 23:36:20 +00:00
}
SetMirroringType(_regs[0] & 0x20 ? MirroringType::Horizontal : MirroringType::Vertical);
SelectCHRPage(0, (_regs[2] << 2) | ((_regs[0] >> 1) & 0x03));
}
void WriteRegister(uint16_t addr, uint8_t value) override
{
if(addr < 0x8000) {
2023-05-13 01:39:46 +00:00
if(HasChrRom() == false) {
_regs[addr & 0x01] = value;
} else {
_regs[addr & 0x03] = value;
}
2016-11-11 23:36:20 +00:00
} else {
_regs[3] = value;
}
UpdateState();
}
};