diff --git a/sources/CPU/CPU.hpp b/sources/CPU/CPU.hpp index 364fc81..a4746a3 100644 --- a/sources/CPU/CPU.hpp +++ b/sources/CPU/CPU.hpp @@ -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 diff --git a/sources/CPU/Instructions/InternalInstruction.cpp b/sources/CPU/Instructions/InternalInstruction.cpp index 0f01df9..bb06b87 100644 --- a/sources/CPU/Instructions/InternalInstruction.cpp +++ b/sources/CPU/Instructions/InternalInstruction.cpp @@ -193,6 +193,12 @@ namespace ComSquare::CPU return 0; } + int CPU::PEA(uint24_t value, AddressingMode) + { + this->_push(static_cast(value)); + return 0; + } + int CPU::PEI(uint24_t value, AddressingMode) { this->_push(static_cast(value)); diff --git a/tests/CPU/testInternal.cpp b/tests/CPU/testInternal.cpp index 3eabc41..63f6f5c 100644 --- a/tests/CPU/testInternal.cpp +++ b/tests/CPU/testInternal.cpp @@ -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);