Adding the RTI

This commit is contained in:
AnonymusRaccoon
2020-02-12 16:51:13 +01:00
parent 17c0cb8660
commit b1a2222b55
3 changed files with 17 additions and 0 deletions

View File

@@ -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());

View File

@@ -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);

View File

@@ -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;
}
}