diff --git a/sources/CPU/CPU.cpp b/sources/CPU/CPU.cpp index e7f0903..ffc2647 100644 --- a/sources/CPU/CPU.cpp +++ b/sources/CPU/CPU.cpp @@ -197,6 +197,7 @@ namespace ComSquare::CPU unsigned CPU::_executeInstruction(uint8_t opcode) { this->_hasIndexCrossedPageBoundary = false; + uint24_t addr; switch (opcode) { case Instructions::BRK: this->BRK(); return 7 + !this->_isEmulationMode; @@ -370,11 +371,11 @@ namespace ComSquare::CPU case Instructions::BRA: this->BRA(this->_registers.pc++); return 3 + this->_isEmulationMode; case Instructions::BRL: this->BRL(this->_registers.pc); this->_registers.pc += 2; return 4; - case Instructions::JMP_ABS: this->JMP(this->_getAbsoluteAddr()); return 3; - case Instructions::JMP_ABSi: this->JMP(this->_getAbsoluteIndirectAddr()); return 3; - case Instructions::JMP_ABSXi: this->JMP(this->_getAbsoluteIndexedByXAddr()); return 3; + case Instructions::JMP_ABS: addr = this->_getAbsoluteAddr(); this->JMP(addr); return 3; + case Instructions::JMP_ABSi: addr = this->_getAbsoluteIndirectAddr(); this->JMP(addr); return 3; + case Instructions::JMP_ABSXi: addr = this->_getAbsoluteIndexedByXAddr(); this->JMP(addr); return 3; - case Instructions::JML_ABSl: this->JML(this->_getAbsoluteLongAddr()); return 3; + case Instructions::JML_ABSl: addr = this->_getAbsoluteLongAddr(); this->JML(addr); return 3; //case Instructions::JML_ABSil: this->JML(this->_getAbsoluteLong()); return 3; default: diff --git a/sources/CPU/Instructions/InternalInstruction.cpp b/sources/CPU/Instructions/InternalInstruction.cpp index 16b426b..6c16c0c 100644 --- a/sources/CPU/Instructions/InternalInstruction.cpp +++ b/sources/CPU/Instructions/InternalInstruction.cpp @@ -298,20 +298,13 @@ namespace ComSquare::CPU return this->_registers.p.v; } - void CPU::JMP(uint24_t valueAddr) + void CPU::JMP(uint24_t value) { - unsigned value = this->_bus->read(valueAddr); - value += this->_bus->read(valueAddr + 1) << 8u; - this->_registers.pc = value; } - void CPU::JML(uint24_t valueAddr) + void CPU::JML(uint24_t value) { - unsigned value = this->_bus->read(valueAddr); - value += this->_bus->read(valueAddr + 1) << 8u; - value += this->_bus->read(valueAddr + 2) << 16u; - this->_registers.pac = value; } } \ No newline at end of file diff --git a/sources/Memory/IMemory.hpp b/sources/Memory/IMemory.hpp index 6f7d33b..78aa385 100644 --- a/sources/Memory/IMemory.hpp +++ b/sources/Memory/IMemory.hpp @@ -49,6 +49,9 @@ namespace ComSquare::Memory //! @brief Return the memory accessor this accessor mirror if any //! @return nullptr if isMirror is false, the source otherwise. virtual std::shared_ptr getMirrored(); + // TODO add destructors everywhere + // TODO rename this as an abstract. + virtual ~IMemory() = default; }; }; diff --git a/sources/Memory/MemoryBus.hpp b/sources/Memory/MemoryBus.hpp index 1bd4844..3274807 100644 --- a/sources/Memory/MemoryBus.hpp +++ b/sources/Memory/MemoryBus.hpp @@ -28,7 +28,7 @@ namespace ComSquare //! @brief WRam, CPU, PPU & APU registers are mirrored to all banks of Q1 & Q3. This function is used for the mirroring. //! @param console All the components. //! @param i Base address for the mirrors. - inline void _mirrorComponents(SNES &console, unsigned i); + void _mirrorComponents(SNES &console, unsigned i); public: MemoryBus() = default; diff --git a/tests/CPU/testInternal.cpp b/tests/CPU/testInternal.cpp index e4b7bf6..888caf4 100644 --- a/tests/CPU/testInternal.cpp +++ b/tests/CPU/testInternal.cpp @@ -889,9 +889,7 @@ Test(JMP, simpleJump) { auto pair = Init(); pair.second.cpu->_registers.pc = 0x8000; - pair.second.wram->_data[0] = 0x00; - pair.second.wram->_data[1] = 0x10; - pair.second.cpu->JMP(0x0); + pair.second.cpu->JMP(0x1000); cr_assert_eq(pair.second.cpu->_registers.pc, 0x1000, "The program counter should be equal to 0x9000 but it was 0x%x.", pair.second.cpu->_registers.pc); } @@ -899,9 +897,6 @@ Test(JML, simpleJump) { auto pair = Init(); pair.second.cpu->_registers.pc = 0x8000; - pair.second.wram->_data[0] = 0x00; - pair.second.wram->_data[1] = 0xAB; - pair.second.wram->_data[2] = 0x10; - pair.second.cpu->JML(0x0); + pair.second.cpu->JML(0x10AB00); cr_assert_eq(pair.second.cpu->_registers.pac, 0x10AB00, "The program counter should be equal to 0x10AB00 but it was 0x%x.", pair.second.cpu->_registers.pac); } \ No newline at end of file