Mesen/Core/Mapper50.h

67 lines
1.4 KiB
C
Raw Normal View History

2016-07-17 00:39:48 +00:00
#pragma once
#include "stdafx.h"
#include "BaseMapper.h"
#include "CPU.h"
class Mapper50 : public BaseMapper
{
private:
uint16_t _irqCounter;
bool _irqEnabled;
protected:
2016-12-18 04:14:47 +00:00
virtual uint16_t RegisterStartAddress() override { return 0x4020; }
virtual uint16_t RegisterEndAddress() override { return 0x5FFF; }
virtual uint16_t GetPRGPageSize() override { return 0x2000; }
virtual uint16_t GetCHRPageSize() override { return 0x2000; }
2016-07-17 00:39:48 +00:00
2016-12-18 04:14:47 +00:00
void InitMapper() override
2016-07-17 00:39:48 +00:00
{
_irqCounter = 0;
_irqEnabled = false;
SetCpuMemoryMapping(0x6000, 0x7FFF, 0x0F, PrgMemoryType::PrgRom);
SelectPRGPage(0, 0x08);
SelectPRGPage(1, 0x09);
SelectPRGPage(3, 0x0B);
SelectCHRPage(0, 0);
}
2016-12-18 04:14:47 +00:00
void StreamState(bool saving) override
2016-07-17 00:39:48 +00:00
{
BaseMapper::StreamState(saving);
Stream(_irqCounter, _irqEnabled);
}
2016-12-18 04:14:47 +00:00
void ProcessCpuClock() override
2016-07-17 00:39:48 +00:00
{
if(_irqEnabled) {
_irqCounter++;
if(_irqCounter == 0x1000) {
CPU::SetIRQSource(IRQSource::External);
_irqEnabled = false;
}
}
}
2016-12-18 04:14:47 +00:00
void WriteRegister(uint16_t addr, uint8_t value) override
2016-07-17 00:39:48 +00:00
{
switch(addr & 0x4120) {
case 0x4020:
SelectPRGPage(2, (value & 0x08) | ((value & 0x01) << 2) | ((value & 0x06) >> 1));
break;
case 0x4120:
if(value & 0x01) {
_irqEnabled = true;
} else {
CPU::ClearIRQSource(IRQSource::External);
_irqCounter = 0;
_irqEnabled = false;
}
break;
}
}
};