#include "Processor.h"
#include "CVMemory.h"
#include "opcode_timing.h"
#include "opcode_daa.h"
void Processor::OPCode0x00()
{
}
void Processor::OPCode0x01()
{
OPCodes_LD(BC.GetLowRegister(), PC.GetValue());
PC.Increment();
OPCodes_LD(BC.GetHighRegister(), PC.GetValue());
PC.Increment();
}
void Processor::OPCode0x02()
{
OPCodes_LD(BC.GetValue(), AF.GetHigh());
WZ.SetLow((BC.GetValue() + 1) & 0xFF);
WZ.SetHigh(AF.GetHigh());
}
void Processor::OPCode0x03()
{
BC.Increment();
}
void Processor::OPCode0x04()
{
OPCodes_INC(BC.GetHighRegister());
}
void Processor::OPCode0x05()
{
OPCodes_DEC(BC.GetHighRegister());
}
void Processor::OPCode0x06()
{
OPCodes_LD(BC.GetHighRegister(), PC.GetValue());
PC.Increment();
}
void Processor::OPCode0x07()
{
OPCodes_RLC(AF.GetHighRegister(), true);
}
void Processor::OPCode0x08()
{
OPCodes_EX(&AF, &AF2);
}
void Processor::OPCode0x09()
{
OPCodes_ADD_HL(BC.GetValue());
}
void Processor::OPCode0x0A()
{
OPCodes_LD(AF.GetHighRegister(), BC.GetValue());
WZ.SetValue(BC.GetValue() + 1);
}
void Processor::OPCode0x0B()
{
BC.Decrement();
}
void Processor::OPCode0x0C()
{
OPCodes_INC(BC.GetLowRegister());
}
void Processor::OPCode0x0D()
{
OPCodes_DEC(BC.GetLowRegister());
}
void Processor::OPCode0x0E()
{
OPCodes_LD(BC.GetLowRegister(), PC.GetValue());
PC.Increment();
}
void Processor::OPCode0x0F()
{
OPCodes_RRC(AF.GetHighRegister(), true);
}
void Processor::OPCode0x10()
{
u8* b = BC.GetHighRegister();
*b = *b - 1;
OPCodes_JR_n_conditional(BC.GetHigh() != 0);
}
void Processor::OPCode0x11()
{
OPCodes_LD(DE.GetLowRegister(), PC.GetValue());
PC.Increment();
OPCodes_LD(DE.GetHighRegister(), PC.GetValue());
PC.Increment();
}
void Processor::OPCode0x12()
{
OPCodes_LD(DE.GetValue(), AF.GetHigh());
WZ.SetLow((DE.GetValue() + 1) & 0xFF);
WZ.SetHigh(AF.GetHigh());
}
void Processor::OPCode0x13()
{
DE.Increment();
}
void Processor::OPCode0x14()
{
OPCodes_INC(DE.GetHighRegister());
}
void Processor::OPCode0x15()
{
OPCodes_DEC(DE.GetHighRegister());
}
void Processor::OPCode0x16()
{
OPCodes_LD(DE.GetHighRegister(), PC.GetValue());
PC.Increment();
}
void Processor::OPCode0x17()
{
OPCodes_RL(AF.GetHighRegister(), true);
}
void Processor::OPCode0x18()
{
OPCodes_JR_n();
}
void Processor::OPCode0x19()
{
OPCodes_ADD_HL(DE.GetValue());
}
void Processor::OPCode0x1A()
{
OPCodes_LD(AF.GetHighRegister(), DE.GetValue());
WZ.SetValue(DE.GetValue() + 1);
}
void Processor::OPCode0x1B()
{
DE.Decrement();
}
void Processor::OPCode0x1C()
{
OPCodes_INC(DE.GetLowRegister());
}
void Processor::OPCode0x1D()
{
OPCodes_DEC(DE.GetLowRegister());
}
void Processor::OPCode0x1E()
{
OPCodes_LD(DE.GetLowRegister(), PC.GetValue());
PC.Increment();
}
void Processor::OPCode0x1F()
{
OPCodes_RR(AF.GetHighRegister(), true);
}
void Processor::OPCode0x20()
{
OPCodes_JR_n_conditional(!IsSetFlag(FLAG_ZERO));
}
void Processor::OPCode0x21()
{
SixteenBitRegister* reg = GetPrefixedRegister();
OPCodes_LD(reg->GetLowRegister(), PC.GetValue());
PC.Increment();
OPCodes_LD(reg->GetHighRegister(), PC.GetValue());
PC.Increment();
}
void Processor::OPCode0x22()
{
OPCodes_LD_nn_dd(GetPrefixedRegister());
}
void Processor::OPCode0x23()
{
GetPrefixedRegister()->Increment();
}
void Processor::OPCode0x24()
{
OPCodes_INC(GetPrefixedRegister()->GetHighRegister());
}
void Processor::OPCode0x25()
{
OPCodes_DEC(GetPrefixedRegister()->GetHighRegister());
}
void Processor::OPCode0x26()
{
OPCodes_LD(GetPrefixedRegister()->GetHighRegister(), PC.GetValue());
PC.Increment();
}
void Processor::OPCode0x27()
{
int idx = AF.GetHigh();
if (IsSetFlag(FLAG_CARRY))
idx |= 0x100;
if (IsSetFlag(FLAG_HALF))
idx |= 0x200;
if (IsSetFlag(FLAG_NEGATIVE))
idx |= 0x400;
AF.SetValue(kOPCodeDAATable[idx]);
}
void Processor::OPCode0x28()
{
OPCodes_JR_n_conditional(IsSetFlag(FLAG_ZERO));
}
void Processor::OPCode0x29()
{
SixteenBitRegister* reg = GetPrefixedRegister();
OPCodes_ADD_HL(reg->GetValue());
}
void Processor::OPCode0x2A()
{
OPCodes_LD_dd_nn(GetPrefixedRegister());
}
void Processor::OPCode0x2B()
{
GetPrefixedRegister()->Decrement();
}
void Processor::OPCode0x2C()
{
OPCodes_INC(GetPrefixedRegister()->GetLowRegister());
}
void Processor::OPCode0x2D()
{
OPCodes_DEC(GetPrefixedRegister()->GetLowRegister());
}
void Processor::OPCode0x2E()
{
OPCodes_LD(GetPrefixedRegister()->GetLowRegister(), PC.GetValue());
PC.Increment();
}
void Processor::OPCode0x2F()
{
AF.SetHigh(~AF.GetHigh());
ToggleFlag(FLAG_HALF);
ToggleFlag(FLAG_NEGATIVE);
ToggleXYFlagsFromResult(AF.GetHigh());
}
void Processor::OPCode0x30()
{
OPCodes_JR_n_conditional(!IsSetFlag(FLAG_CARRY));
}
void Processor::OPCode0x31()
{
SP.SetLow(m_pMemory->Read(PC.GetValue()));
PC.Increment();
SP.SetHigh(m_pMemory->Read(PC.GetValue()));
PC.Increment();
}
void Processor::OPCode0x32()
{
u16 address = FetchArg16();
m_pMemory->Write(address, AF.GetHigh());
WZ.SetLow((address + 1) & 0xFF);
WZ.SetHigh(AF.GetHigh());
}
void Processor::OPCode0x33()
{
SP.Increment();
}
void Processor::OPCode0x34()
{
OPCodes_INC_HL();
}
void Processor::OPCode0x35()
{
OPCodes_DEC_HL();
}
void Processor::OPCode0x36()
{
if (m_CurrentPrefix == 0xDD)
{
u8 d = m_pMemory->Read(PC.GetValue());
u8 n = m_pMemory->Read(PC.GetValue() + 1);
u16 address = IX.GetValue() + static_cast<s8> (d);
m_pMemory->Write(address, n);
PC.Increment();
}
else if (m_CurrentPrefix == 0xFD)
{
u8 d = m_pMemory->Read(PC.GetValue());
u8 n = m_pMemory->Read(PC.GetValue() + 1);
u16 address = IY.GetValue() + static_cast<s8> (d);
m_pMemory->Write(address, n);
PC.Increment();
}
else
m_pMemory->Write(HL.GetValue(), m_pMemory->Read(PC.GetValue()));
PC.Increment();
}
void Processor::OPCode0x37()
{
ToggleFlag(FLAG_CARRY);
ClearFlag(FLAG_HALF);
ClearFlag(FLAG_NEGATIVE);
ToggleXYFlagsFromResult(AF.GetHigh());
}
void Processor::OPCode0x38()
{
OPCodes_JR_n_conditional(IsSetFlag(FLAG_CARRY));
}
void Processor::OPCode0x39()
{
OPCodes_ADD_HL(SP.GetValue());
}
void Processor::OPCode0x3A()
{
u16 address = FetchArg16();
*(AF.GetHighRegister()) = m_pMemory->Read(address);
WZ.SetValue(address + 1);
}
void Processor::OPCode0x3B()
{
SP.Decrement();
}
void Processor::OPCode0x3C()
{
OPCodes_INC(AF.GetHighRegister());
}
void Processor::OPCode0x3D()
{
OPCodes_DEC(AF.GetHighRegister());
}
void Processor::OPCode0x3E()
{
OPCodes_LD(AF.GetHighRegister(), PC.GetValue());
PC.Increment();
}
void Processor::OPCode0x3F()
{
bool half = IsSetFlag(FLAG_CARRY);
FlipFlag(FLAG_CARRY);
if (half)
ToggleFlag(FLAG_HALF);
else
ClearFlag(FLAG_HALF);
ClearFlag(FLAG_NEGATIVE);
ToggleXYFlagsFromResult(AF.GetHigh());
}
void Processor::OPCode0x40()
{
OPCodes_LD(BC.GetHighRegister(), BC.GetHigh());
}
void Processor::OPCode0x41()
{
OPCodes_LD(BC.GetHighRegister(), BC.GetLow());
}
void Processor::OPCode0x42()
{
OPCodes_LD(BC.GetHighRegister(), DE.GetHigh());
}
void Processor::OPCode0x43()
{
OPCodes_LD(BC.GetHighRegister(), DE.GetLow());
}
void Processor::OPCode0x44()
{
OPCodes_LD(BC.GetHighRegister(), GetPrefixedRegister()->GetHigh());
}
void Processor::OPCode0x45()
{
OPCodes_LD(BC.GetHighRegister(), GetPrefixedRegister()->GetLow());
}
void Processor::OPCode0x46()
{
OPCodes_LD(BC.GetHighRegister(), GetEffectiveAddress());
}
void Processor::OPCode0x47()
{
OPCodes_LD(BC.GetHighRegister(), AF.GetHigh());
}
void Processor::OPCode0x48()
{
OPCodes_LD(BC.GetLowRegister(), BC.GetHigh());
}
void Processor::OPCode0x49()
{
OPCodes_LD(BC.GetLowRegister(), BC.GetLow());
}
void Processor::OPCode0x4A()
{
OPCodes_LD(BC.GetLowRegister(), DE.GetHigh());
}
void Processor::OPCode0x4B()
{
OPCodes_LD(BC.GetLowRegister(), DE.GetLow());
}
void Processor::OPCode0x4C()
{
OPCodes_LD(BC.GetLowRegister(), GetPrefixedRegister()->GetHigh());
}
void Processor::OPCode0x4D()
{
OPCodes_LD(BC.GetLowRegister(), GetPrefixedRegister()->GetLow());
}
void Processor::OPCode0x4E()
{
OPCodes_LD(BC.GetLowRegister(), GetEffectiveAddress());
}
void Processor::OPCode0x4F()
{
OPCodes_LD(BC.GetLowRegister(), AF.GetHigh());
}
void Processor::OPCode0x50()
{
OPCodes_LD(DE.GetHighRegister(), BC.GetHigh());
}
void Processor::OPCode0x51()
{
OPCodes_LD(DE.GetHighRegister(), BC.GetLow());
}
void Processor::OPCode0x52()
{
OPCodes_LD(DE.GetHighRegister(), DE.GetHigh());
}
void Processor::OPCode0x53()
{
OPCodes_LD(DE.GetHighRegister(), DE.GetLow());
}
void Processor::OPCode0x54()
{
OPCodes_LD(DE.GetHighRegister(), GetPrefixedRegister()->GetHigh());
}
void Processor::OPCode0x55()
{
OPCodes_LD(DE.GetHighRegister(), GetPrefixedRegister()->GetLow());
}
void Processor::OPCode0x56()
{
OPCodes_LD(DE.GetHighRegister(), GetEffectiveAddress());
}
void Processor::OPCode0x57()
{
OPCodes_LD(DE.GetHighRegister(), AF.GetHigh());
}
void Processor::OPCode0x58()
{
OPCodes_LD(DE.GetLowRegister(), BC.GetHigh());
}
void Processor::OPCode0x59()
{
OPCodes_LD(DE.GetLowRegister(), BC.GetLow());
}
void Processor::OPCode0x5A()
{
OPCodes_LD(DE.GetLowRegister(), DE.GetHigh());
}
void Processor::OPCode0x5B()
{
OPCodes_LD(DE.GetLowRegister(), DE.GetLow());
}
void Processor::OPCode0x5C()
{
OPCodes_LD(DE.GetLowRegister(), GetPrefixedRegister()->GetHigh());
}
void Processor::OPCode0x5D()
{
OPCodes_LD(DE.GetLowRegister(), GetPrefixedRegister()->GetLow());
}
void Processor::OPCode0x5E()
{
OPCodes_LD(DE.GetLowRegister(), GetEffectiveAddress());
}
void Processor::OPCode0x5F()
{
OPCodes_LD(DE.GetLowRegister(), AF.GetHigh());
}
void Processor::OPCode0x60()
{
OPCodes_LD(GetPrefixedRegister()->GetHighRegister(), BC.GetHigh());
}
void Processor::OPCode0x61()
{
OPCodes_LD(GetPrefixedRegister()->GetHighRegister(), BC.GetLow());
}
void Processor::OPCode0x62()
{
OPCodes_LD(GetPrefixedRegister()->GetHighRegister(), DE.GetHigh());
}
void Processor::OPCode0x63()
{
OPCodes_LD(GetPrefixedRegister()->GetHighRegister(), DE.GetLow());
}
void Processor::OPCode0x64()
{
OPCodes_LD(GetPrefixedRegister()->GetHighRegister(), GetPrefixedRegister()->GetHigh());
}
void Processor::OPCode0x65()
{
OPCodes_LD(GetPrefixedRegister()->GetHighRegister(), GetPrefixedRegister()->GetLow());
}
void Processor::OPCode0x66()
{
OPCodes_LD(HL.GetHighRegister(), GetEffectiveAddress());
}
void Processor::OPCode0x67()
{
OPCodes_LD(GetPrefixedRegister()->GetHighRegister(), AF.GetHigh());
}
void Processor::OPCode0x68()
{
OPCodes_LD(GetPrefixedRegister()->GetLowRegister(), BC.GetHigh());
}
void Processor::OPCode0x69()
{
OPCodes_LD(GetPrefixedRegister()->GetLowRegister(), BC.GetLow());
}
void Processor::OPCode0x6A()
{
OPCodes_LD(GetPrefixedRegister()->GetLowRegister(), DE.GetHigh());
}
void Processor::OPCode0x6B()
{
OPCodes_LD(GetPrefixedRegister()->GetLowRegister(), DE.GetLow());
}
void Processor::OPCode0x6C()
{
OPCodes_LD(GetPrefixedRegister()->GetLowRegister(), GetPrefixedRegister()->GetHigh());
}
void Processor::OPCode0x6D()
{
OPCodes_LD(GetPrefixedRegister()->GetLowRegister(), GetPrefixedRegister()->GetLow());
}
void Processor::OPCode0x6E()
{
OPCodes_LD(HL.GetLowRegister(), GetEffectiveAddress());
}
void Processor::OPCode0x6F()
{
OPCodes_LD(GetPrefixedRegister()->GetLowRegister(), AF.GetHigh());
}
void Processor::OPCode0x70()
{
OPCodes_LD(GetEffectiveAddress(), BC.GetHigh());
}
void Processor::OPCode0x71()
{
OPCodes_LD(GetEffectiveAddress(), BC.GetLow());
}
void Processor::OPCode0x72()
{
OPCodes_LD(GetEffectiveAddress(), DE.GetHigh());
}
void Processor::OPCode0x73()
{
OPCodes_LD(GetEffectiveAddress(), DE.GetLow());
}
void Processor::OPCode0x74()
{
OPCodes_LD(GetEffectiveAddress(), HL.GetHigh());
}
void Processor::OPCode0x75()
{
OPCodes_LD(GetEffectiveAddress(), HL.GetLow());
}
void Processor::OPCode0x76()
{
m_bHalt = true;
PC.Decrement();
}
void Processor::OPCode0x77()
{
OPCodes_LD(GetEffectiveAddress(), AF.GetHigh());
}
void Processor::OPCode0x78()
{
OPCodes_LD(AF.GetHighRegister(), BC.GetHigh());
}
void Processor::OPCode0x79()
{
OPCodes_LD(AF.GetHighRegister(), BC.GetLow());
}
void Processor::OPCode0x7A()
{
OPCodes_LD(AF.GetHighRegister(), DE.GetHigh());
}
void Processor::OPCode0x7B()
{
OPCodes_LD(AF.GetHighRegister(), DE.GetLow());
}
void Processor::OPCode0x7C()
{
OPCodes_LD(AF.GetHighRegister(), GetPrefixedRegister()->GetHigh());
}
void Processor::OPCode0x7D()
{
OPCodes_LD(AF.GetHighRegister(), GetPrefixedRegister()->GetLow());
}
void Processor::OPCode0x7E()
{
OPCodes_LD(AF.GetHighRegister(), GetEffectiveAddress());
}
void Processor::OPCode0x7F()
{
OPCodes_LD(AF.GetHighRegister(), AF.GetHigh());
}
void Processor::OPCode0x80()
{
OPCodes_ADD(BC.GetHigh());
}
void Processor::OPCode0x81()
{
OPCodes_ADD(BC.GetLow());
}
void Processor::OPCode0x82()
{
OPCodes_ADD(DE.GetHigh());
}
void Processor::OPCode0x83()
{
OPCodes_ADD(DE.GetLow());
}
void Processor::OPCode0x84()
{
OPCodes_ADD(GetPrefixedRegister()->GetHigh());
}
void Processor::OPCode0x85()
{
OPCodes_ADD(GetPrefixedRegister()->GetLow());
}
void Processor::OPCode0x86()
{
OPCodes_ADD(m_pMemory->Read(GetEffectiveAddress()));
}
void Processor::OPCode0x87()
{
OPCodes_ADD(AF.GetHigh());
}
void Processor::OPCode0x88()
{
OPCodes_ADC(BC.GetHigh());
}
void Processor::OPCode0x89()
{
OPCodes_ADC(BC.GetLow());
}
void Processor::OPCode0x8A()
{
OPCodes_ADC(DE.GetHigh());
}
void Processor::OPCode0x8B()
{
OPCodes_ADC(DE.GetLow());
}
void Processor::OPCode0x8C()
{
OPCodes_ADC(GetPrefixedRegister()->GetHigh());
}
void Processor::OPCode0x8D()
{
OPCodes_ADC(GetPrefixedRegister()->GetLow());
}
void Processor::OPCode0x8E()
{
OPCodes_ADC(m_pMemory->Read(GetEffectiveAddress()));
}
void Processor::OPCode0x8F()
{
OPCodes_ADC(AF.GetHigh());
}
void Processor::OPCode0x90()
{
OPCodes_SUB(BC.GetHigh());
}
void Processor::OPCode0x91()
{
OPCodes_SUB(BC.GetLow());
}
void Processor::OPCode0x92()
{
OPCodes_SUB(DE.GetHigh());
}
void Processor::OPCode0x93()
{
OPCodes_SUB(DE.GetLow());
}
void Processor::OPCode0x94()
{
OPCodes_SUB(GetPrefixedRegister()->GetHigh());
}
void Processor::OPCode0x95()
{
OPCodes_SUB(GetPrefixedRegister()->GetLow());
}
void Processor::OPCode0x96()
{
OPCodes_SUB(m_pMemory->Read(GetEffectiveAddress()));
}
void Processor::OPCode0x97()
{
OPCodes_SUB(AF.GetHigh());
}
void Processor::OPCode0x98()
{
OPCodes_SBC(BC.GetHigh());
}
void Processor::OPCode0x99()
{
OPCodes_SBC(BC.GetLow());
}
void Processor::OPCode0x9A()
{
OPCodes_SBC(DE.GetHigh());
}
void Processor::OPCode0x9B()
{
OPCodes_SBC(DE.GetLow());
}
void Processor::OPCode0x9C()
{
OPCodes_SBC(GetPrefixedRegister()->GetHigh());
}
void Processor::OPCode0x9D()
{
OPCodes_SBC(GetPrefixedRegister()->GetLow());
}
void Processor::OPCode0x9E()
{
OPCodes_SBC(m_pMemory->Read(GetEffectiveAddress()));
}
void Processor::OPCode0x9F()
{
OPCodes_SBC(AF.GetHigh());
}
void Processor::OPCode0xA0()
{
OPCodes_AND(BC.GetHigh());
}
void Processor::OPCode0xA1()
{
OPCodes_AND(BC.GetLow());
}
void Processor::OPCode0xA2()
{
OPCodes_AND(DE.GetHigh());
}
void Processor::OPCode0xA3()
{
OPCodes_AND(DE.GetLow());
}
void Processor::OPCode0xA4()
{
OPCodes_AND(GetPrefixedRegister()->GetHigh());
}
void Processor::OPCode0xA5()
{
OPCodes_AND(GetPrefixedRegister()->GetLow());
}
void Processor::OPCode0xA6()
{
OPCodes_AND(m_pMemory->Read(GetEffectiveAddress()));
}
void Processor::OPCode0xA7()
{
OPCodes_AND(AF.GetHigh());
}
void Processor::OPCode0xA8()
{
OPCodes_XOR(BC.GetHigh());
}
void Processor::OPCode0xA9()
{
OPCodes_XOR(BC.GetLow());
}
void Processor::OPCode0xAA()
{
OPCodes_XOR(DE.GetHigh());
}
void Processor::OPCode0xAB()
{
OPCodes_XOR(DE.GetLow());
}
void Processor::OPCode0xAC()
{
OPCodes_XOR(GetPrefixedRegister()->GetHigh());
}
void Processor::OPCode0xAD()
{
OPCodes_XOR(GetPrefixedRegister()->GetLow());
}
void Processor::OPCode0xAE()
{
OPCodes_XOR(m_pMemory->Read(GetEffectiveAddress()));
}
void Processor::OPCode0xAF()
{
OPCodes_XOR(AF.GetHigh());
}
void Processor::OPCode0xB0()
{
OPCodes_OR(BC.GetHigh());
}
void Processor::OPCode0xB1()
{
OPCodes_OR(BC.GetLow());
}
void Processor::OPCode0xB2()
{
OPCodes_OR(DE.GetHigh());
}
void Processor::OPCode0xB3()
{
OPCodes_OR(DE.GetLow());
}
void Processor::OPCode0xB4()
{
OPCodes_OR(GetPrefixedRegister()->GetHigh());
}
void Processor::OPCode0xB5()
{
OPCodes_OR(GetPrefixedRegister()->GetLow());
}
void Processor::OPCode0xB6()
{
OPCodes_OR(m_pMemory->Read(GetEffectiveAddress()));
}
void Processor::OPCode0xB7()
{
OPCodes_OR(AF.GetHigh());
}
void Processor::OPCode0xB8()
{
OPCodes_CP(BC.GetHigh());
}
void Processor::OPCode0xB9()
{
OPCodes_CP(BC.GetLow());
}
void Processor::OPCode0xBA()
{
OPCodes_CP(DE.GetHigh());
}
void Processor::OPCode0xBB()
{
OPCodes_CP(DE.GetLow());
}
void Processor::OPCode0xBC()
{
OPCodes_CP(GetPrefixedRegister()->GetHigh());
}
void Processor::OPCode0xBD()
{
OPCodes_CP(GetPrefixedRegister()->GetLow());
}
void Processor::OPCode0xBE()
{
OPCodes_CP(m_pMemory->Read(GetEffectiveAddress()));
}
void Processor::OPCode0xBF()
{
OPCodes_CP(AF.GetHigh());
}
void Processor::OPCode0xC0()
{
OPCodes_RET_Conditional(!IsSetFlag(FLAG_ZERO));
}
void Processor::OPCode0xC1()
{
StackPop(&BC);
}
void Processor::OPCode0xC2()
{
OPCodes_JP_nn_Conditional(!IsSetFlag(FLAG_ZERO));
}
void Processor::OPCode0xC3()
{
OPCodes_JP_nn();
}
void Processor::OPCode0xC4()
{
OPCodes_CALL_nn_Conditional(!IsSetFlag(FLAG_ZERO));
}
void Processor::OPCode0xC5()
{
StackPush(&BC);
}
void Processor::OPCode0xC6()
{
OPCodes_ADD(m_pMemory->Read(PC.GetValue()));
PC.Increment();
}
void Processor::OPCode0xC7()
{
OPCodes_RST(0x0000);
}
void Processor::OPCode0xC8()
{
OPCodes_RET_Conditional(IsSetFlag(FLAG_ZERO));
}
void Processor::OPCode0xC9()
{
OPCodes_RET();
}
void Processor::OPCode0xCA()
{
OPCodes_JP_nn_Conditional(IsSetFlag(FLAG_ZERO));
}
void Processor::OPCode0xCB()
{
InvalidOPCode();
}
void Processor::OPCode0xCC()
{
OPCodes_CALL_nn_Conditional(IsSetFlag(FLAG_ZERO));
}
void Processor::OPCode0xCD()
{
OPCodes_CALL_nn();
}
void Processor::OPCode0xCE()
{
OPCodes_ADC(m_pMemory->Read(PC.GetValue()));
PC.Increment();
}
void Processor::OPCode0xCF()
{
OPCodes_RST(0x0008);
}
void Processor::OPCode0xD0()
{
OPCodes_RET_Conditional(!IsSetFlag(FLAG_CARRY));
}
void Processor::OPCode0xD1()
{
StackPop(&DE);
}
void Processor::OPCode0xD2()
{
OPCodes_JP_nn_Conditional(!IsSetFlag(FLAG_CARRY));
}
void Processor::OPCode0xD3()
{
u8 port = m_pMemory->Read(PC.GetValue());
PC.Increment();
m_pIOPorts->Out(port, AF.GetHigh());
WZ.SetLow((port + 1) & 0xFF);
WZ.SetHigh(AF.GetHigh());
}
void Processor::OPCode0xD4()
{
OPCodes_CALL_nn_Conditional(!IsSetFlag(FLAG_CARRY));
}
void Processor::OPCode0xD5()
{
StackPush(&DE);
}
void Processor::OPCode0xD6()
{
OPCodes_SUB(m_pMemory->Read(PC.GetValue()));
PC.Increment();
}
void Processor::OPCode0xD7()
{
OPCodes_RST(0x0010);
}
void Processor::OPCode0xD8()
{
OPCodes_RET_Conditional(IsSetFlag(FLAG_CARRY));
}
void Processor::OPCode0xD9()
{
OPCodes_EX(&BC, &BC2);
OPCodes_EX(&DE, &DE2);
OPCodes_EX(&HL, &HL2);
}
void Processor::OPCode0xDA()
{
OPCodes_JP_nn_Conditional(IsSetFlag(FLAG_CARRY));
}
void Processor::OPCode0xDB()
{
if (m_bInputLastCycle)
{
u8 a = AF.GetHigh();
u8 port = m_pMemory->Read(PC.GetValue());
PC.Increment();
AF.SetHigh(m_pIOPorts->In(port));
WZ.SetValue((a << 8) | (port + 1));
m_iTStates -= 10;
m_bInputLastCycle = false;
}
else
{
PC.Decrement();
m_iTStates -= 1;
m_bInputLastCycle = true;
}
}
void Processor::OPCode0xDC()
{
OPCodes_CALL_nn_Conditional(IsSetFlag(FLAG_CARRY));
}
void Processor::OPCode0xDD()
{
InvalidOPCode();
}
void Processor::OPCode0xDE()
{
OPCodes_SBC(m_pMemory->Read(PC.GetValue()));
PC.Increment();
}
void Processor::OPCode0xDF()
{
OPCodes_RST(0x0018);
}
void Processor::OPCode0xE0()
{
OPCodes_RET_Conditional(!IsSetFlag(FLAG_PARITY));
}
void Processor::OPCode0xE1()
{
StackPop(GetPrefixedRegister());
}
void Processor::OPCode0xE2()
{
OPCodes_JP_nn_Conditional(!IsSetFlag(FLAG_PARITY));
}
void Processor::OPCode0xE3()
{
SixteenBitRegister* reg = GetPrefixedRegister();
u8 l = reg->GetLow();
u8 h = reg->GetHigh();
reg->SetLow(m_pMemory->Read(SP.GetValue()));
reg->SetHigh(m_pMemory->Read(SP.GetValue() + 1));
m_pMemory->Write(SP.GetValue(), l);
m_pMemory->Write(SP.GetValue() + 1, h);
WZ.SetValue(reg->GetValue());
}
void Processor::OPCode0xE4()
{
OPCodes_CALL_nn_Conditional(!IsSetFlag(FLAG_PARITY));
}
void Processor::OPCode0xE5()
{
StackPush(GetPrefixedRegister());
}
void Processor::OPCode0xE6()
{
OPCodes_AND(m_pMemory->Read(PC.GetValue()));
PC.Increment();
}
void Processor::OPCode0xE7()
{
OPCodes_RST(0x0020);
}
void Processor::OPCode0xE8()
{
OPCodes_RET_Conditional(IsSetFlag(FLAG_PARITY));
}
void Processor::OPCode0xE9()
{
PC.SetValue(GetPrefixedRegister()->GetValue());
}
void Processor::OPCode0xEA()
{
OPCodes_JP_nn_Conditional(IsSetFlag(FLAG_PARITY));
}
void Processor::OPCode0xEB()
{
OPCodes_EX(&DE, &HL);
}
void Processor::OPCode0xEC()
{
OPCodes_CALL_nn_Conditional(IsSetFlag(FLAG_PARITY));
}
void Processor::OPCode0xED()
{
InvalidOPCode();
}
void Processor::OPCode0xEE()
{
OPCodes_XOR(m_pMemory->Read(PC.GetValue()));
PC.Increment();
}
void Processor::OPCode0xEF()
{
OPCodes_RST(0x28);
}
void Processor::OPCode0xF0()
{
OPCodes_RET_Conditional(!IsSetFlag(FLAG_SIGN));
}
void Processor::OPCode0xF1()
{
StackPop(&AF);
}
void Processor::OPCode0xF2()
{
OPCodes_JP_nn_Conditional(!IsSetFlag(FLAG_SIGN));
}
void Processor::OPCode0xF3()
{
m_bIFF1 = false;
m_bIFF2 = false;
}
void Processor::OPCode0xF4()
{
OPCodes_CALL_nn_Conditional(!IsSetFlag(FLAG_SIGN));
}
void Processor::OPCode0xF5()
{
StackPush(&AF);
}
void Processor::OPCode0xF6()
{
OPCodes_OR(m_pMemory->Read(PC.GetValue()));
PC.Increment();
}
void Processor::OPCode0xF7()
{
OPCodes_RST(0x0030);
}
void Processor::OPCode0xF8()
{
OPCodes_RET_Conditional(IsSetFlag(FLAG_SIGN));
}
void Processor::OPCode0xF9()
{
SP.SetValue(GetPrefixedRegister()->GetValue());
}
void Processor::OPCode0xFA()
{
OPCodes_JP_nn_Conditional(IsSetFlag(FLAG_SIGN));
}
void Processor::OPCode0xFB()
{
m_bIFF1 = true;
m_bIFF2 = true;
m_bAfterEI = true;
}
void Processor::OPCode0xFC()
{
OPCodes_CALL_nn_Conditional(IsSetFlag(FLAG_SIGN));
}
void Processor::OPCode0xFD()
{
InvalidOPCode();
}
void Processor::OPCode0xFE()
{
OPCodes_CP(m_pMemory->Read(PC.GetValue()));
PC.Increment();
}
void Processor::OPCode0xFF()
{
OPCodes_RST(0x0038);
}