Implementing the RTS/RTL

This commit is contained in:
Anonymus Raccoon
2020-04-03 22:32:39 +02:00
parent 1feab12fec
commit 84f964111c
2 changed files with 19 additions and 2 deletions
+6 -2
View File
@@ -380,6 +380,10 @@ namespace ComSquare::CPU
int DEY(uint24_t, AddressingMode);
//! @brief Or accumulator with memory.
int ORA(uint24_t valueAddr, AddressingMode mode);
//! @brief Return from subroutine.
int RTS(uint24_t, AddressingMode);
//! @brief Return from subroutine long.
int RTL(uint24_t, AddressingMode);
//! @brief All the instructions of the CPU.
//! @info Instructions are indexed by their opcode
@@ -480,7 +484,7 @@ namespace ComSquare::CPU
{&CPU::BRK, 7, "eor #-#", AddressingMode::Implied, 2}, // 5D
{&CPU::BRK, 7, "lsr #-#", AddressingMode::Implied, 2}, // 5E
{&CPU::BRK, 7, "eor #-#", AddressingMode::Implied, 2}, // 5F
{&CPU::BRK, 7, "rtl #-#", AddressingMode::Implied, 1}, // 60
{&CPU::RTL, 6, "rtl", AddressingMode::Implied, 1}, // 60
{&CPU::ADC, 6, "adc", AddressingMode::DirectPageIndirectIndexedByX, 2}, // 61
{&CPU::BRK, 7, "per #-#", AddressingMode::Implied, 2}, // 62
{&CPU::ADC, 4, "adc", AddressingMode::StackRelative, 2}, // 63
@@ -491,7 +495,7 @@ namespace ComSquare::CPU
{&CPU::PLA, 4, "pla", AddressingMode::Implied, 1}, // 68
{&CPU::ADC, 2, "adc", AddressingMode::ImmediateForA, 2}, // 69
{&CPU::BRK, 7, "ror #-#", AddressingMode::Implied, 2}, // 6A
{&CPU::BRK, 7, "rts #-#", AddressingMode::Implied, 1}, // 6B
{&CPU::RTS, 6, "rts", AddressingMode::Implied, 1}, // 6B
{&CPU::JMP, 5, "jmp", AddressingMode::AbsoluteIndirect, 3}, // 6C
{&CPU::ADC, 4, "adc", AddressingMode::Absolute, 3}, // 6D
{&CPU::BRK, 7, "ror #-#", AddressingMode::Implied, 2}, // 6E
@@ -352,4 +352,17 @@ namespace ComSquare::CPU
{
return 0;
}
int CPU::RTS(uint24_t, AddressingMode)
{
this->_registers.pc = this->_pop16() + 1;
return 0;
}
int CPU::RTL(uint24_t, AddressingMode)
{
this->_registers.pc = this->_pop16() + 1;
this->_registers.dbr = this->_pop();
return 0;
}
}