diff --git a/sources/CPU/CPU.cpp b/sources/CPU/CPU.cpp index f1c3e4f..aeeefa0 100644 --- a/sources/CPU/CPU.cpp +++ b/sources/CPU/CPU.cpp @@ -203,6 +203,8 @@ namespace ComSquare::CPU switch (opcode) { case Instructions::BRK: return 7 + this->BRK(); + case Instructions::RTI: return 6 + this->RTI(); + case Instructions::ADC_IM: return 2 + this->ADC(this->_getImmediateAddr()); case Instructions::ADC_ABS: return 4 + this->ADC(this->_getAbsoluteAddr()); case Instructions::ADC_ABSl: return 5 + this->ADC(this->_getAbsoluteLongAddr()); diff --git a/sources/CPU/CPU.hpp b/sources/CPU/CPU.hpp index c864ee8..960dbae 100644 --- a/sources/CPU/CPU.hpp +++ b/sources/CPU/CPU.hpp @@ -187,6 +187,7 @@ namespace ComSquare::CPU enum Instructions { BRK = 0x00, + RTI = 0x40, ADC_DPXi = 0x61, ADC_SR = 0x63, @@ -282,6 +283,8 @@ namespace ComSquare::CPU unsigned RESB(); //! @brief Break instruction - Causes a software break. The PC is loaded from a vector table. unsigned BRK(); + //! @brief Return from Interrupt - Used to return from a interrupt handler. + unsigned RTI(); //! @brief Add with carry - Adds operand to the Accumulator; adds an additional 1 if carry is set. //! @return The number of extra cycles that this operation took. unsigned ADC(uint24_t valueAddr); diff --git a/sources/CPU/Instructions/Interrupts.cpp b/sources/CPU/Instructions/Interrupts.cpp index 8136db9..b175048 100644 --- a/sources/CPU/Instructions/Interrupts.cpp +++ b/sources/CPU/Instructions/Interrupts.cpp @@ -35,4 +35,16 @@ namespace ComSquare::CPU this->_registers.p.d = false; return !this->_isEmulationMode; } + + unsigned CPU::RTI() + { + this->_registers.p.flags = this->pop(); + this->_registers.pc = this->pop16(); + + if (!this->_isEmulationMode) { + this->_registers.pbr = this->pop16(); + return 1; + } + return 0; + } } \ No newline at end of file