Mesen/Core/Lh10.h

53 lines
1.1 KiB
C
Raw Normal View History

2016-11-12 14:18:52 +00:00
#pragma once
#include "stdafx.h"
#include "BaseMapper.h"
class Lh10 : public BaseMapper
{
private:
uint8_t _currentRegister;
uint8_t _regs[8];
protected:
2016-12-18 04:14:47 +00:00
uint16_t GetPRGPageSize() override { return 0x2000; }
uint16_t GetCHRPageSize() override { return 0x2000; }
2016-11-12 14:18:52 +00:00
void InitMapper() override
{
memset(_regs, 0, sizeof(_regs));
_currentRegister = 0;
SelectCHRPage(0, 0);
RemoveRegisterRange(0xC000, 0xDFFF);
UpdateState();
}
2016-12-18 04:14:47 +00:00
void StreamState(bool saving) override
2016-11-12 14:18:52 +00:00
{
BaseMapper::StreamState(saving);
ArrayInfo<uint8_t> regs{ _regs, 8 };
Stream(_currentRegister, regs);
if(!saving) {
UpdateState();
}
}
void UpdateState()
{
SetCpuMemoryMapping(0x6000, 0x7FFF, -2, PrgMemoryType::PrgRom);
SelectPRGPage(0, _regs[6]);
SelectPRGPage(1, _regs[7]);
SelectPRGPage(2, 0, PrgMemoryType::WorkRam);
SelectPRGPage(3, -1);
}
void WriteRegister(uint16_t addr, uint8_t value) override
{
switch(addr & 0xE001) {
case 0x8000: _currentRegister = value & 0x07; break;
case 0x8001: _regs[_currentRegister] = value; UpdateState(); break;
}
}
};