From 627fac8f2df00e2a8478762e310e5943b674808e Mon Sep 17 00:00:00 2001 From: Anonymus Raccoon Date: Thu, 28 May 2020 03:45:37 +0200 Subject: [PATCH] Fixing the PHA --- sources/CPU/CPU.hpp | 2 +- sources/CPU/Instructions/InternalInstruction.cpp | 5 ++++- sources/PPU/PPU.cpp | 4 ++-- tests/CPU/testInternal.cpp | 12 ++++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/sources/CPU/CPU.hpp b/sources/CPU/CPU.hpp index 8aec2fa..f2afc1b 100644 --- a/sources/CPU/CPU.hpp +++ b/sources/CPU/CPU.hpp @@ -478,7 +478,7 @@ namespace ComSquare::CPU {&CPU::ORA, 3, "ora", AddressingMode::DirectPage, 2}, // 05 {&CPU::ASL, 5, "asl", AddressingMode::DirectPage, 2}, // 06 {&CPU::ORA, 6, "ora", AddressingMode::DirectPageIndirectLong, 2}, // 07 - {&CPU::PHP, 3, "php", AddressingMode::Implied, 3}, // 08 + {&CPU::PHP, 3, "php", AddressingMode::Implied, 1}, // 08 {&CPU::ORA, 2, "ora", AddressingMode::ImmediateForA, 2}, // 09 {&CPU::ASL, 2, "asl", AddressingMode::Implied, 1}, // 0A {&CPU::PHD, 4, "phd", AddressingMode::Implied, 1}, // 0B diff --git a/sources/CPU/Instructions/InternalInstruction.cpp b/sources/CPU/Instructions/InternalInstruction.cpp index 8430522..03fb101 100644 --- a/sources/CPU/Instructions/InternalInstruction.cpp +++ b/sources/CPU/Instructions/InternalInstruction.cpp @@ -82,7 +82,10 @@ namespace ComSquare::CPU int CPU::PHA(uint24_t, AddressingMode) { - this->_push(this->_registers.a); + if (this->_registers.p.m) + this->_push(this->_registers.al); + else + this->_push(this->_registers.a); return !this->_registers.p.m; } diff --git a/sources/PPU/PPU.cpp b/sources/PPU/PPU.cpp index c0a5661..9075adc 100644 --- a/sources/PPU/PPU.cpp +++ b/sources/PPU/PPU.cpp @@ -45,7 +45,7 @@ namespace ComSquare::PPU case ppuRegisters::stat78: return 0; default: - throw InvalidAddress("PPU Internal Registers read ", addr); + throw InvalidAddress("PPU Internal Registers read ", addr + this->getStart()); } } @@ -215,7 +215,7 @@ namespace ComSquare::PPU break; //TODO adding the rest of the registers. oaf ! default: - throw InvalidAddress("PPU Internal Registers write", addr); + throw InvalidAddress("PPU Internal Registers write", addr + this->getStart()); } } diff --git a/tests/CPU/testInternal.cpp b/tests/CPU/testInternal.cpp index 63f6f5c..5b38be7 100644 --- a/tests/CPU/testInternal.cpp +++ b/tests/CPU/testInternal.cpp @@ -105,12 +105,24 @@ Test(PHA, basic) Init() snes.cpu->_registers.a = 0xABCD; snes.cpu->_registers.s = 0x02; + snes.cpu->_registers.p.m = false; snes.cpu->PHA(0x0, ComSquare::CPU::AddressingMode::Implied); cr_assert_eq(snes.wram->_data[1], 0xCD, "The second value pushed to the stack should be 0xCD but it was %x", snes.wram->_data[1]); cr_assert_eq(snes.wram->_data[2], 0xAB, "The first value pushed to the stack should be 0xAB but it was %x", snes.wram->_data[2]); cr_assert_eq(snes.cpu->_registers.s, 0x0, "The Stack pointer should be equal to 0x0 but it was %x", snes.cpu->_registers.s); } +Test(PHA, 8bits) +{ + Init() + snes.cpu->_registers.a = 0xCD; + snes.cpu->_registers.s = 0x02; + snes.cpu->_registers.p.m = false; + snes.cpu->PHA(0x0, ComSquare::CPU::AddressingMode::Implied); + cr_assert_eq(snes.wram->_data[1], 0xCD, "The second value pushed to the stack should be 0xCD but it was %x", snes.wram->_data[1]); + cr_assert_eq(snes.cpu->_registers.s, 0x0, "The Stack pointer should be equal to 0x0 but it was %x", snes.cpu->_registers.s); +} + Test(PHB, basic) { Init()