Cleaning up the CPX/CPY/INX/INY

This commit is contained in:
Anonymus Raccoon
2020-04-06 17:19:04 +02:00
parent 83b8c83e6e
commit 055e7d29bd
3 changed files with 74 additions and 73 deletions
+7 -7
View File
@@ -587,19 +587,19 @@ namespace ComSquare::CPU
{&CPU::LDA, 4, "lda", AddressingMode::AbsoluteIndexedByX, 3}, // BD
{&CPU::LDX, 4, "ldx", AddressingMode::AbsoluteIndexedByY, 3}, // BE
{&CPU::LDA, 5, "lda", AddressingMode::AbsoluteIndexedByXLong, 4}, // BF
{&CPU::BRK, 7, "cpy #-#", AddressingMode::Implied, 2}, // C0
{&CPU::CPY, 2, "cpy", AddressingMode::ImmediateForX, 2}, // C0
{&CPU::CMP, 6, "cmp", AddressingMode::DirectPageIndirectIndexedByX, 2}, // C1
{&CPU::REP, 3, "rep", AddressingMode::Immediate8bits, 2}, // C2
{&CPU::CMP, 4, "cmp", AddressingMode::StackRelative, 2}, // C3
{&CPU::BRK, 7, "cpy #-#", AddressingMode::Implied, 2}, // C4
{&CPU::CPY, 3, "cpy", AddressingMode::DirectPage, 2}, // C4
{&CPU::CMP, 3, "cmp", AddressingMode::DirectPage, 2}, // C5
{&CPU::BRK, 7, "dec #-#", AddressingMode::Implied, 2}, // C6
{&CPU::CMP, 6, "cmp", AddressingMode::DirectPageIndirectLong, 2}, // C7
{&CPU::INY, 2, "iny", AddressingMode::Implied, 1}, // C8
{&CPU::CMP, 2, "cmp", AddressingMode::Implied, 2}, // C9
{&CPU::CMP, 2, "cmp", AddressingMode::ImmediateForA, 2}, // C9
{&CPU::DEX, 2, "dex", AddressingMode::Implied, 1}, // CA
{&CPU::BRK, 7, "wai #-#", AddressingMode::Implied, 2}, // CB
{&CPU::BRK, 7, "cpy #-#", AddressingMode::Implied, 2}, // CC
{&CPU::CPY, 4, "cpy", AddressingMode::Absolute, 3}, // CC
{&CPU::CMP, 4, "cmp", AddressingMode::Absolute, 3}, // CD
{&CPU::BRK, 7, "dec #-#", AddressingMode::Implied, 2}, // CE
{&CPU::CMP, 6, "cmp", AddressingMode::AbsoluteLong, 4}, // CF
@@ -619,11 +619,11 @@ namespace ComSquare::CPU
{&CPU::CMP, 4, "cmp", AddressingMode::AbsoluteIndexedByX, 3}, // DD
{&CPU::BRK, 7, "dec #-#", AddressingMode::Implied, 2}, // DE
{&CPU::CMP, 5, "cmp", AddressingMode::AbsoluteIndexedByXLong, 4}, // DF
{&CPU::BRK, 7, "cpx #-#", AddressingMode::Implied, 2}, // E0
{&CPU::CPX, 2, "cpx", AddressingMode::ImmediateForX, 2}, // E0
{&CPU::SBC, 6, "sbc", AddressingMode::DirectPageIndirectIndexedByX, 2}, // E1
{&CPU::SEP, 3, "sep", AddressingMode::Immediate8bits, 2}, // E2
{&CPU::SBC, 4, "sbc", AddressingMode::StackRelative, 2}, // E3
{&CPU::BRK, 7, "cpx #-#", AddressingMode::Implied, 2}, // E4
{&CPU::CPX, 3, "cpx", AddressingMode::DirectPage, 2}, // E4
{&CPU::SBC, 3, "sbc", AddressingMode::DirectPage, 2}, // E5
{&CPU::BRK, 7, "inc #-#", AddressingMode::Implied, 2}, // E6
{&CPU::SBC, 6, "sbc", AddressingMode::DirectPageIndirectLong, 2}, // E7
@@ -631,7 +631,7 @@ namespace ComSquare::CPU
{&CPU::SBC, 2, "sbc", AddressingMode::ImmediateForA, 2}, // E9
{&CPU::NOP, 2, "nop", AddressingMode::Implied, 1}, // EA
{&CPU::BRK, 7, "xba #-#", AddressingMode::Implied, 2}, // EB
{&CPU::BRK, 7, "cpx #-#", AddressingMode::Implied, 2}, // EC
{&CPU::CPX, 4, "cpx", AddressingMode::Absolute, 3}, // EC
{&CPU::SBC, 4, "sbc", AddressingMode::Absolute, 3}, // ED
{&CPU::BRK, 7, "inc #-#", AddressingMode::Implied, 2}, // EE
{&CPU::SBC, 5, "sbc", AddressingMode::AbsoluteLong, 4}, // EF
@@ -199,72 +199,6 @@ namespace ComSquare::CPU
return 0;
}
int CPU::INX(uint24_t, AddressingMode)
{
this->_registers.x++;
if (this->_registers.p.x_b)
this->_registers.x %= 0x100;
unsigned negativeFlag = this->_registers.p.x_b ? 0x80u : 0x8000u;
this->_registers.p.z = this->_registers.x == 0;
this->_registers.p.n = this->_registers.x & negativeFlag;
return 0;
}
int CPU::INY(uint24_t, AddressingMode)
{
this->_registers.y++;
if (this->_registers.p.x_b)
this->_registers.y %= 0x100;
unsigned negativeFlag = this->_registers.p.x_b ? 0x80u : 0x8000u;
this->_registers.p.z = this->_registers.y == 0;
this->_registers.p.n = this->_registers.y & negativeFlag;
return 0;
}
int CPU::CPX(uint24_t valueAddr, AddressingMode mode)
{
unsigned value = this->_bus->read(valueAddr++);
if (this->_registers.p.x_b) {
uint8_t x = this->_registers.x;
x -= value;
this->_registers.p.z = x == 0;
this->_registers.p.n = x & 0x80u;
} else {
value += this->_bus->read(valueAddr) << 8u;
uint16_t x = this->_registers.x;
x -= value;
this->_registers.p.z = x == 0;
this->_registers.p.n = x & 0x8000u;
}
this->_registers.p.c = this->_registers.x >= value;
return !this->_registers.p.x_b + (mode == DirectPage && this->_registers.dl != 0);
}
int CPU::CPY(uint24_t valueAddr, AddressingMode mode)
{
unsigned value = this->_bus->read(valueAddr++);
this->_registers.p.c = this->_registers.y >= value;
if (this->_registers.p.x_b) {
uint8_t y = this->_registers.y;
y -= value;
this->_registers.p.z = y == 0;
this->_registers.p.n = y & 0x80u;
} else {
value += this->_bus->read(valueAddr) << 8u;
uint16_t y = this->_registers.y;
y -= value;
this->_registers.p.z = y == 0;
this->_registers.p.n = y & 0x8000u;
}
return !this->_registers.p.x_b + (mode == DirectPage && this->_registers.dl != 0);
}
int CPU::BCC(uint24_t valueAddr, AddressingMode)
{
if (!this->_registers.p.c)
@@ -184,4 +184,71 @@ namespace ComSquare::CPU
}
return cycles;
}
int CPU::INX(uint24_t, AddressingMode)
{
this->_registers.x++;
if (this->_registers.p.x_b)
this->_registers.x %= 0x100;
unsigned negativeFlag = this->_registers.p.x_b ? 0x80u : 0x8000u;
this->_registers.p.z = this->_registers.x == 0;
this->_registers.p.n = this->_registers.x & negativeFlag;
return 0;
}
int CPU::INY(uint24_t, AddressingMode)
{
this->_registers.y++;
if (this->_registers.p.x_b)
this->_registers.y %= 0x100;
unsigned negativeFlag = this->_registers.p.x_b ? 0x80u : 0x8000u;
this->_registers.p.z = this->_registers.y == 0;
this->_registers.p.n = this->_registers.y & negativeFlag;
return 0;
}
int CPU::CPX(uint24_t valueAddr, AddressingMode mode)
{
unsigned value = this->_bus->read(valueAddr++);
if (this->_registers.p.x_b) {
uint8_t x = this->_registers.x;
x -= value;
this->_registers.p.z = x == 0;
this->_registers.p.n = x & 0x80u;
} else {
value += this->_bus->read(valueAddr) << 8u;
uint16_t x = this->_registers.x;
x -= value;
this->_registers.p.z = x == 0;
this->_registers.p.n = x & 0x8000u;
}
this->_registers.p.c = this->_registers.x >= value;
return !this->_registers.p.x_b + (mode == DirectPage && this->_registers.dl != 0);
}
int CPU::CPY(uint24_t valueAddr, AddressingMode mode)
{
unsigned value = this->_bus->read(valueAddr++);
this->_registers.p.c = this->_registers.y >= value;
if (this->_registers.p.x_b) {
uint8_t y = this->_registers.y;
y -= value;
this->_registers.p.z = y == 0;
this->_registers.p.n = y & 0x80u;
} else {
value += this->_bus->read(valueAddr) << 8u;
uint16_t y = this->_registers.y;
y -= value;
this->_registers.p.z = y == 0;
this->_registers.p.n = y & 0x8000u;
}
return !this->_registers.p.x_b + (mode == DirectPage && this->_registers.dl != 0);
}
}