mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-12 05:54:03 +00:00
Implementing DEX & DEY
This commit is contained in:
+6
-2
@@ -374,6 +374,10 @@ namespace ComSquare::CPU
|
||||
int JML(uint24_t valueAddr, AddressingMode);
|
||||
//! @brief No OP.
|
||||
int NOP(uint24_t, AddressingMode);
|
||||
//! @brief Decrement the X register.
|
||||
int DEX(uint24_t, AddressingMode);
|
||||
//! @brief Decrement the Y register.
|
||||
int DEY(uint24_t, AddressingMode);
|
||||
|
||||
//! @brief All the instructions of the CPU.
|
||||
//! @info Instructions are indexed by their opcode
|
||||
@@ -514,7 +518,7 @@ namespace ComSquare::CPU
|
||||
{&CPU::STA, 3, "sta", AddressingMode::DirectPage, 2}, // 85
|
||||
{&CPU::STX, 3, "stx", AddressingMode::DirectPage, 2}, // 86
|
||||
{&CPU::STA, 6, "sta", AddressingMode::DirectPageIndirectLong, 2}, // 87
|
||||
{&CPU::BRK, 7, "dey #-#", AddressingMode::Implied, 2}, // 88
|
||||
{&CPU::DEY, 2, "dey", AddressingMode::Implied, 1}, // 88
|
||||
{&CPU::BRK, 7, "bit #-#", AddressingMode::Implied, 2}, // 89
|
||||
{&CPU::BRK, 7, "txa #-#", AddressingMode::Implied, 2}, // 8A
|
||||
{&CPU::PHB, 3, "phb", AddressingMode::Implied, 1}, // 8B
|
||||
@@ -580,7 +584,7 @@ namespace ComSquare::CPU
|
||||
{&CPU::BRK, 7, "cmp #-#", AddressingMode::Implied, 2}, // C7
|
||||
{&CPU::INY, 2, "iny", AddressingMode::Implied, 1}, // C8
|
||||
{&CPU::BRK, 7, "cmp #-#", AddressingMode::Implied, 2}, // C9
|
||||
{&CPU::BRK, 7, "dex #-#", AddressingMode::Implied, 2}, // CA
|
||||
{&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::BRK, 7, "cmp #-#", AddressingMode::Implied, 2}, // CD
|
||||
|
||||
@@ -12,8 +12,8 @@ namespace ComSquare::CPU
|
||||
unsigned value = this->_bus->read(valueAddr) + this->_registers.p.c;
|
||||
if (!this->_registers.p.m)
|
||||
value += this->_bus->read(valueAddr + 1) << 8u;
|
||||
unsigned negativeMask = this->_isEmulationMode ? 0x80u : 0x8000u;
|
||||
unsigned maxValue = this->_isEmulationMode ? UINT8_MAX : UINT16_MAX;
|
||||
unsigned negativeMask = this->_registers.p.m ? 0x80u : 0x8000u;
|
||||
unsigned maxValue = this->_registers.p.m ? UINT8_MAX : UINT16_MAX;
|
||||
|
||||
this->_registers.p.c = static_cast<unsigned>(this->_registers.a) + value > maxValue;
|
||||
if ((this->_registers.a & negativeMask) == (value & negativeMask))
|
||||
@@ -21,7 +21,7 @@ namespace ComSquare::CPU
|
||||
else
|
||||
this->_registers.p.v = false;
|
||||
this->_registers.a += value;
|
||||
if (this->_isEmulationMode)
|
||||
if (this->_registers.p.m)
|
||||
this->_registers.a %= 0x100;
|
||||
this->_registers.p.z = this->_registers.a == 0;
|
||||
this->_registers.p.n = this->_registers.a & negativeMask;
|
||||
@@ -51,7 +51,7 @@ namespace ComSquare::CPU
|
||||
|
||||
int CPU::SBC(uint24_t valueAddr, AddressingMode mode)
|
||||
{
|
||||
unsigned negativeMask = this->_isEmulationMode ? 0x80u : 0x8000u;
|
||||
unsigned negativeMask = this->_registers.p.m ? 0x80u : 0x8000u;
|
||||
unsigned value = this->_bus->read(valueAddr);
|
||||
if (!this->_registers.p.m)
|
||||
value += this->_bus->read(valueAddr + 1) << 8u;
|
||||
@@ -63,7 +63,7 @@ namespace ComSquare::CPU
|
||||
else
|
||||
this->_registers.p.v = false;
|
||||
this->_registers.a += ~value + oldCarry;
|
||||
if (this->_isEmulationMode)
|
||||
if (this->_registers.p.m)
|
||||
this->_registers.a %= 0x100;
|
||||
this->_registers.p.z = this->_registers.a == 0;
|
||||
this->_registers.p.n = this->_registers.a & negativeMask;
|
||||
@@ -90,4 +90,28 @@ namespace ComSquare::CPU
|
||||
}
|
||||
return cycles;
|
||||
}
|
||||
|
||||
int CPU::DEX(uint24_t, AddressingMode)
|
||||
{
|
||||
unsigned negativeMask = this->_registers.p.x_b ? UINT8_MAX : UINT16_MAX;
|
||||
|
||||
this->_registers.x--;
|
||||
if (this->_registers.p.x_b)
|
||||
this->_registers.xh = 0;
|
||||
this->_registers.p.z = this->_registers.x == 0;
|
||||
this->_registers.p.n = this->_registers.x & negativeMask;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CPU::DEY(uint24_t, AddressingMode)
|
||||
{
|
||||
unsigned negativeMask = this->_registers.p.x_b ? UINT8_MAX : UINT16_MAX;
|
||||
|
||||
this->_registers.y--;
|
||||
if (this->_registers.p.x_b)
|
||||
this->_registers.yh = 0;
|
||||
this->_registers.p.z = this->_registers.y == 0;
|
||||
this->_registers.p.n = this->_registers.y & negativeMask;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ Test(ADC, overflowEmulation)
|
||||
Test(ADC, signedOverflow)
|
||||
{
|
||||
Init()
|
||||
snes.cpu->_isEmulationMode = false;
|
||||
snes.cpu->_registers.p.m = false;
|
||||
snes.cpu->_registers.a = 0x7FFF;
|
||||
snes.wram->_data[0] = 0x1;
|
||||
snes.cpu->ADC(0x0, ComSquare::CPU::AddressingMode::Implied);
|
||||
@@ -81,7 +81,7 @@ Test(ADC, signedOverflow)
|
||||
Test(ADC, signedOverflowEmulated)
|
||||
{
|
||||
Init()
|
||||
snes.cpu->_isEmulationMode = true;
|
||||
snes.cpu->_registers.p.m = true;
|
||||
snes.cpu->_registers.a = 0x007F;
|
||||
snes.wram->_data[0] = 0x1;
|
||||
snes.cpu->ADC(0x0, ComSquare::CPU::AddressingMode::Implied);
|
||||
@@ -95,7 +95,7 @@ Test(ADC, signedOverflowEmulated)
|
||||
Test(ADC, negative)
|
||||
{
|
||||
Init()
|
||||
snes.cpu->_isEmulationMode = false;
|
||||
snes.cpu->_registers.p.m = false;
|
||||
snes.cpu->_registers.a = 0x8FFF;
|
||||
snes.wram->_data[0] = 0x1;
|
||||
snes.cpu->ADC(0x0, ComSquare::CPU::AddressingMode::Implied);
|
||||
|
||||
@@ -62,7 +62,7 @@ Test(SBC, overflowEmulation)
|
||||
Init()
|
||||
snes.cpu->_isEmulationMode = true;
|
||||
snes.cpu->_registers.a = 0x1;
|
||||
snes.cpu->_registers.p.m = false;
|
||||
snes.cpu->_registers.p.m = true;
|
||||
snes.cpu->_registers.p.c = false;
|
||||
snes.wram->_data[0] = 0x02;
|
||||
snes.cpu->SBC(0x0, ComSquare::CPU::AddressingMode::Implied);
|
||||
|
||||
Reference in New Issue
Block a user