VRC4: Added IRQ support

This commit is contained in:
Souryo 2016-01-24 15:17:25 -05:00
parent 4d8a007e5f
commit 742d76c2f2
2 changed files with 25 additions and 8 deletions

View file

@ -1,6 +1,7 @@
#pragma once
#include "stdafx.h"
#include "BaseMapper.h"
#include "VrcIrq.h"
enum class VRCVariant
{
@ -20,6 +21,7 @@ enum class VRCVariant
class VRC2_4 : public BaseMapper
{
private:
VrcIrq _irq;
VRCVariant _variant;
uint8_t _prgReg0;
@ -40,13 +42,18 @@ class VRC2_4 : public BaseMapper
_prgMode = 0;
_prgReg0 = 0;
_prgReg1 = 0;
_hasIRQ = 0;
_hasIRQ = false;
memset(_loCHRRegs, 0, sizeof(_loCHRRegs));
memset(_hiCHRRegs, 0, sizeof(_hiCHRRegs));
UpdateState();
}
void ProcessCpuClock()
{
_irq.ProcessCpuClock();
}
void UpdateState()
{
for(int i = 0; i < 8; i++) {
@ -99,15 +106,14 @@ class VRC2_4 : public BaseMapper
//One reg contains the high 5 bits
_hiCHRRegs[regNumber] = value & 0x1F;
}
} else if(addr == 0xF000 || addr == 0xF001) {
//IRQ Reload Value
_hasIRQ = true;
} else if(addr == 0xF000) {
_irq.SetReloadValueNibble(value, false);
} else if(addr == 0xF001) {
_irq.SetReloadValueNibble(value, true);
} else if(addr == 0xF002) {
//IRQ Control
_hasIRQ = true;
_irq.SetControlValue(value);
} else if(addr == 0xF003) {
//IRQ Acknowledge
_hasIRQ = true;
_irq.AcknowledgeIrq();
}
UpdateState();
@ -186,6 +192,8 @@ class VRC2_4 : public BaseMapper
Stream<bool>(_hasIRQ);
Stream(_irq);
BaseMapper::StreamState(saving);
}
};

View file

@ -56,6 +56,15 @@ public:
_irqReloadValue = value;
}
void SetReloadValueNibble(uint8_t value, bool highBits)
{
if(highBits) {
_irqReloadValue = (_irqReloadValue & 0x0F) | ((value & 0x0F) << 4);
} else {
_irqReloadValue = (_irqReloadValue & 0xF0) | (value & 0x0F);
}
}
void SetControlValue(uint8_t value)
{
_irqEnabledAfterAck = (value & 0x01) == 0x01;