Mesen/Core/Mapper42.h

77 lines
1.5 KiB
C
Raw Normal View History

2016-07-17 02:17:21 +00:00
#pragma once
#include "stdafx.h"
#include "BaseMapper.h"
#include "CPU.h"
class Mapper42 : public BaseMapper
{
private:
uint16_t _irqCounter;
bool _irqEnabled;
protected:
2016-12-18 04:14:47 +00:00
virtual uint16_t GetPRGPageSize() override { return 0x2000; }
virtual uint16_t GetCHRPageSize() override { return 0x2000; }
2016-07-17 02:17:21 +00:00
2016-12-18 04:14:47 +00:00
void InitMapper() override
2016-07-17 02:17:21 +00:00
{
_irqCounter = 0;
_irqEnabled = false;
SelectPRGPage(0, 0x0C);
SelectPRGPage(1, 0x0D);
SelectPRGPage(2, 0x0E);
SelectPRGPage(3, 0x0F);
SelectCHRPage(0, 0);
}
2016-12-18 04:14:47 +00:00
void StreamState(bool saving) override
2016-07-17 02:17:21 +00:00
{
BaseMapper::StreamState(saving);
Stream(_irqCounter, _irqEnabled);
}
2016-12-18 04:14:47 +00:00
void ProcessCpuClock() override
2016-07-17 02:17:21 +00:00
{
if(_irqEnabled) {
_irqCounter++;
if(_irqCounter >= 0x8000) {
_irqCounter -= 0x8000;
}
if(_irqCounter >= 0x6000) {
CPU::SetIRQSource(IRQSource::External);
} else {
CPU::ClearIRQSource(IRQSource::External);
}
}
}
2016-12-18 04:14:47 +00:00
void WriteRegister(uint16_t addr, uint8_t value) override
2016-07-17 02:17:21 +00:00
{
switch(addr & 0xE003) {
case 0x8000:
if(_chrRomSize > 0) {
SelectCHRPage(0, value & 0x0F);
}
break;
case 0xE000:
SetCpuMemoryMapping(0x6000, 0x7FFF, value & 0x0F, PrgMemoryType::PrgRom);
break;
case 0xE001:
SetMirroringType(value & 0x08 ? MirroringType::Horizontal : MirroringType::Vertical);
break;
case 0xE002:
_irqEnabled = (value == 0x02);
if(!_irqEnabled) {
CPU::ClearIRQSource(IRQSource::External);
_irqCounter = 0;
}
break;
}
}
};