mirror of
https://github.com/zoriya/ComSquare.git
synced 2026-06-05 10:59:38 +00:00
Implementing the COP instruction
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user