Implementing the COP instruction

This commit is contained in:
AnonymusRaccoon
2020-02-19 18:44:45 +01:00
parent 27f755e315
commit 52b5a6ba23
5 changed files with 83 additions and 6 deletions
+2
View File
@@ -201,6 +201,8 @@ namespace ComSquare::CPU
switch (opcode) {
case Instructions::BRK: this->BRK(); return 7 + !this->_isEmulationMode;
case Instructions::COP: this->COP(); return 7 + !this->_isEmulationMode;
case Instructions::RTI: this->RTI(); return 6 + !this->_isEmulationMode;
case Instructions::ADC_IM: this->ADC(this->_getImmediateAddr()); return 2 + !this->_registers.p.m;
+3
View File
@@ -186,6 +186,7 @@ namespace ComSquare::CPU
enum Instructions
{
BRK = 0x00,
COP = 0x02,
RTI = 0x40,
ADC_DPXi = 0x61,
@@ -365,6 +366,8 @@ namespace ComSquare::CPU
//! @brief Break instruction - Causes a software break. The PC is loaded from a vector table.
void BRK();
//! @brief Co-Processor Enable instruction - Causes a software break. The PC is loaded from a vector table.
void COP();
//! @brief Return from Interrupt - Used to return from a interrupt handler.
void RTI();
//! @brief Add with carry - Adds operand to the Accumulator; adds an additional 1 if carry is set.
+22
View File
@@ -43,6 +43,28 @@ namespace ComSquare::CPU
}
}
void CPU::COP()
{
if (this->_isEmulationMode) {
this->_registers.pc += 2;
this->_push(this->_registers.pc);
this->_push(this->_registers.p.flags);
this->_registers.p.i = true;
this->_registers.p.d = false;
this->_registers.pc = this->_cartridgeHeader.emulationInterrupts.cop;
} else {
this->_push(this->_registers.pbr);
this->_registers.pc += 2;
this->_push(this->_registers.pc);
this->_push(this->_registers.p.flags);
this->_registers.p.i = true;
this->_registers.p.d = false;
this->_registers.pbr = 0x0;
this->_registers.pc = this->_cartridgeHeader.nativeInterrupts.cop;
}
}
void CPU::RTI()
{
this->_registers.p.flags = this->_pop();