mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-05-22 22:45:52 +00:00
Adding the program counter relative addressing mode
This commit is contained in:
@@ -318,4 +318,11 @@ namespace ComSquare::CPU
|
||||
lng += this->_bus->read(this->_registers.pac++) << 16u;
|
||||
return lng + this->_registers.x;
|
||||
}
|
||||
|
||||
uint24_t CPU::_getProgramCounterRelativeAddr()
|
||||
{
|
||||
uint24_t pc = this->_registers.pac;
|
||||
int8_t mod = this->_bus->read(this->_registers.pac++);
|
||||
return pc + mod;
|
||||
}
|
||||
}
|
||||
@@ -218,6 +218,8 @@ namespace ComSquare::CPU
|
||||
uint24_t _getAbsoluteIndexedByYAddr();
|
||||
//! @brief The effective address is formed by adding the <long exp> with X.
|
||||
uint24_t _getAbsoluteLongIndexedByXAddr();
|
||||
//! @brief The <8-bit signed exp> is added to PC (program counter) to form the new location.
|
||||
uint24_t _getProgramCounterRelativeAddr();
|
||||
|
||||
|
||||
//! @brief Execute a single instruction.
|
||||
|
||||
@@ -162,4 +162,22 @@ Test(AddrMode, AbsoluteLongIndexByX)
|
||||
pair.second.cpu->_registers.x = 0x0005;
|
||||
cr_assert_eq(pair.second.cpu->_getAbsoluteLongIndexedByXAddr(), 0xEFAC15, "Returned address was %x but was expecting 0xEFAC15.", pair.second.cpu->_getAbsoluteLongIndexedByXAddr());
|
||||
cr_assert_eq(pair.second.cpu->_registers.pac, 0x808003);
|
||||
}
|
||||
|
||||
Test(AddrMode, ProgramCounterRelativePositive)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.cpu->_registers.pac = 0x808010;
|
||||
pair.second.cartridge->_data[0x10] = 0x15;
|
||||
cr_assert_eq(pair.second.cpu->_getProgramCounterRelativeAddr(), 0x808025, "Returned address was %x but was expecting 0x808025.", pair.second.cpu->_getProgramCounterRelativeAddr());
|
||||
cr_assert_eq(pair.second.cpu->_registers.pac, 0x808011);
|
||||
}
|
||||
|
||||
Test(AddrMode, ProgramCounterRelativeNegative)
|
||||
{
|
||||
auto pair = Init();
|
||||
pair.second.cpu->_registers.pac = 0x808010;
|
||||
pair.second.cartridge->_data[0x10] = -0x15;
|
||||
cr_assert_eq(pair.second.cpu->_getProgramCounterRelativeAddr(), 0x807FFB, "Returned address was %x but was expecting 0x807FFB.", pair.second.cpu->_getProgramCounterRelativeAddr());
|
||||
cr_assert_eq(pair.second.cpu->_registers.pac, 0x808011);
|
||||
}
|
||||
Reference in New Issue
Block a user