Adding PEA

This commit is contained in:
Anonymus Raccoon
2020-05-13 18:19:21 +02:00
parent fea20fee70
commit 051d1d7596
3 changed files with 20 additions and 2 deletions
+3 -1
View File
@@ -437,6 +437,8 @@ namespace ComSquare::CPU
int PER(uint24_t, AddressingMode);
//! @brief Push Effective Indirect Address
int PEI(uint24_t, AddressingMode);
//! @brief Push Effective Absolute Address
int PEA(uint24_t, AddressingMode);
//! @brief All the instructions of the CPU.
//! @info Instructions are indexed by their opcode
@@ -685,7 +687,7 @@ namespace ComSquare::CPU
{&CPU::SBC, 5, "sbc", AddressingMode::DirectPageIndirectIndexedByY, 2}, // F1
{&CPU::SBC, 5, "sbc", AddressingMode::DirectPageIndirect, 2}, // F2
{&CPU::SBC, 7, "sbc", AddressingMode::StackRelativeIndirectIndexedByY, 2}, // F3
{&CPU::BRK, 7, "pea #-#", AddressingMode::Implied, 2}, // F4
{&CPU::PEA, 5, "pea", AddressingMode::Immediate16bits, 3}, // F4
{&CPU::SBC, 4, "sbc", AddressingMode::DirectPageIndexedByX, 2}, // F5
{&CPU::INC, 6, "inc", AddressingMode::DirectPageIndexedByX, 2}, // F6
{&CPU::SBC, 6, "sbc", AddressingMode::DirectPageIndirectIndexedByYLong, 2}, // F7
@@ -193,6 +193,12 @@ namespace ComSquare::CPU
return 0;
}
int CPU::PEA(uint24_t value, AddressingMode)
{
this->_push(static_cast<uint16_t>(value));
return 0;
}
int CPU::PEI(uint24_t value, AddressingMode)
{
this->_push(static_cast<uint16_t>(value));
+11 -1
View File
@@ -930,12 +930,22 @@ Test(PER, simple)
}
Test(PEI, simple)
{
Init()
snes.cpu->_registers.s = 0x1FFF;
snes.cpu->PEI(0xFFFF, ComSquare::CPU::AddressingMode::Implied);
cr_assert_eq(snes.cpu->_registers.s, 0x1FFD, "The stack pointer should be equal to 0x1FFD but it was 0x%x.", snes.cpu->_registers.s);
uint16_t value = snes.cpu->_pop16();
cr_assert_eq(value, 0xFFFF, "The pushed value should be equal to 0xFFFF but it was 0x%x.", value);
}
Test(PEA, simple)
{
Init()
snes.cpu->_registers.s = 0x1FFF;
snes.wram->_data[0x0] = 0xFF;
snes.wram->_data[0x1] = 0xFF;
snes.cpu->PER(0x0, ComSquare::CPU::AddressingMode::Implied);
snes.cpu->PEA(0xFFFF, ComSquare::CPU::AddressingMode::Implied);
cr_assert_eq(snes.cpu->_registers.s, 0x1FFD, "The stack pointer should be equal to 0x1FFD but it was 0x%x.", snes.cpu->_registers.s);
uint16_t value = snes.cpu->_pop16();
cr_assert_eq(value, 0xFFFF, "The pushed value should be equal to 0xFFFF but it was 0x%x.", value);