Finishing addressing modes

This commit is contained in:
AnonymusRaccoon
2020-02-11 13:52:44 +01:00
parent fe04834731
commit 40d7ef1c39
3 changed files with 40 additions and 0 deletions
+12
View File
@@ -371,4 +371,16 @@ namespace ComSquare::CPU
effective += this->_bus->read(++dp) << 16u;
return effective;
}
uint24_t CPU::_getStackRelativeAddr()
{
return this->_bus->read(this->_registers.pac++) + this->_registers.s;
}
uint24_t CPU::_getStackRelativeIndirectIndexedAddr()
{
uint24_t base = this->_bus->read(this->_registers.pac++) + this->_registers.s;
base += this->_registers.dbr << 16u;
return base + this->_registers.y;
}
}
+4
View File
@@ -230,6 +230,10 @@ namespace ComSquare::CPU
uint24_t _getDirectIndirectAddr();
//! @brief 3 bytes are pulled from the direct page address to form an effective address.
uint24_t _getDirectIndirectLongAddr();
//! @brief The stack register is added to the <8-bit exp> to form the effective address.
uint24_t _getStackRelativeAddr();
//! @brief The <8-bit exp> is added to S and combined with DBR to form the base address. Y is added to the base address to form the effective address.
uint24_t _getStackRelativeIndirectIndexedAddr();
//! @brief Execute a single instruction.
+24
View File
@@ -257,4 +257,28 @@ Test(AddrMode, DirectIndirectLong)
auto addr = pair.second.cpu->_getDirectIndirectLongAddr();
cr_assert_eq(addr, 0x8801EF, "Returned address was %x but was expecting 0x8801EF.", addr);
cr_assert_eq(pair.second.cpu->_registers.pac, 0x808001);
}
Test(AddrMode, StackRelative)
{
auto pair = Init();
pair.second.cpu->_registers.pac = 0x808000;
pair.second.cartridge->_data[0] = 0x06;
pair.second.cpu->_registers.s = 0x1010;
auto addr = pair.second.cpu->_getStackRelativeAddr();
cr_assert_eq(addr, 0x1016, "Returned address was %x but was expecting 0x1016.", addr);
cr_assert_eq(pair.second.cpu->_registers.pac, 0x808001);
}
Test(AddrMode, StackRelativeIndirectIndexed)
{
auto pair = Init();
pair.second.cpu->_registers.pac = 0x808000;
pair.second.cartridge->_data[0] = 0x06;
pair.second.cpu->_registers.s = 0x1010;
pair.second.cpu->_registers.y = 0x5;
pair.second.cpu->_registers.dbr = 0x88;
auto addr = pair.second.cpu->_getStackRelativeIndirectIndexedAddr();
cr_assert_eq(addr, 0x88101B, "Returned address was %x but was expecting 0x88101B.", addr);
cr_assert_eq(pair.second.cpu->_registers.pac, 0x808001);
}