Reworking the instruction history

This commit is contained in:
Anonymus Raccoon
2020-04-04 23:17:31 +02:00
parent 84f964111c
commit 218935b5bb
8 changed files with 252 additions and 118 deletions
+59 -76
View File
@@ -211,86 +211,69 @@ namespace ComSquare::CPU
return cycles;
}
uint24_t CPU::_getValueAddr(Instruction &instruction)
{
switch (instruction.addressingMode) {
case Implied:
return 0;
case Immediate8bits:
return this->_getImmediateAddr8Bits();
case ImmediateForA:
return this->_getImmediateAddrForA();
case ImmediateForX:
return this->_getImmediateAddrForX();
case Absolute:
return this->_getAbsoluteAddr();
case AbsoluteLong:
return this->_getAbsoluteLongAddr();
case AbsoluteIndirect:
return this->_getAbsoluteIndirectAddr();
case AbsoluteIndirectLong:
return this->_getAbsoluteIndirectLongAddr();
case DirectPage:
return this->_getDirectAddr();
case DirectPageIndirect:
return this->_getDirectIndirectAddr();
case DirectPageIndirectLong:
return this->_getDirectIndirectLongAddr();
case DirectPageIndexedByX:
return this->_getDirectIndexedByXAddr();
case DirectPageIndexedByY:
return this->_getDirectIndexedByYAddr();
case DirectPageIndirectIndexedByX:
return this->_getDirectIndirectIndexedXAddr();
case DirectPageIndirectIndexedByY:
return this->_getDirectIndirectIndexedYAddr();
case DirectPageIndirectIndexedByYLong:
return this->_getDirectIndirectIndexedYLongAddr();
case AbsoluteIndexedByX:
return this->_getAbsoluteIndexedByXAddr();
case AbsoluteIndexedByXLong:
return this->_getAbsoluteIndexedByXLongAddr();
case AbsoluteIndexedByY:
return this->_getAbsoluteIndexedByYAddr();
case StackRelative:
return this->_getStackRelativeAddr();
case StackRelativeIndirectIndexedByY:
return this->_getStackRelativeIndirectIndexedYAddr();
case AbsoluteIndirectIndexedByX:
return this->_getAbsoluteIndirectIndexedByXAddr();
default:
return 0;
}
}
unsigned CPU::_executeInstruction(uint8_t opcode)
{
Instruction instruction = this->_instructions[opcode];
uint24_t valueAddr = 0;
this->_hasIndexCrossedPageBoundary = false;
switch (instruction.addressingMode) {
case Implied:
break;
case Immediate8bits:
valueAddr = this->_getImmediateAddr8Bits();
break;
case ImmediateForA:
valueAddr = this->_getImmediateAddrForA();
break;
case ImmediateForX:
valueAddr = this->_getImmediateAddrForX();
break;
case Absolute:
valueAddr = this->_getAbsoluteAddr();
break;
case AbsoluteLong:
valueAddr = this->_getAbsoluteLongAddr();
break;
case AbsoluteIndirect:
valueAddr = this->_getAbsoluteIndirectAddr();
break;
case AbsoluteIndirectLong:
valueAddr = this->_getAbsoluteIndirectLongAddr();
break;
case DirectPage:
valueAddr = this->_getDirectAddr();
break;
case DirectPageIndirect:
valueAddr = this->_getDirectIndirectAddr();
break;
case DirectPageIndirectLong:
valueAddr = this->_getDirectIndirectLongAddr();
break;
case DirectPageIndexedByX:
valueAddr = this->_getDirectIndexedByXAddr();
break;
case DirectPageIndexedByY:
valueAddr = this->_getDirectIndexedByYAddr();
break;
case DirectPageIndirectIndexedByX:
valueAddr = this->_getDirectIndirectIndexedXAddr();
break;
case DirectPageIndirectIndexedByY:
valueAddr = this->_getDirectIndirectIndexedYAddr();
break;
case DirectPageIndirectIndexedByYLong:
valueAddr = this->_getDirectIndirectIndexedYLongAddr();
break;
case AbsoluteIndexedByX:
valueAddr = this->_getAbsoluteIndexedByXAddr();
break;
case AbsoluteIndexedByXLong:
valueAddr = this->_getAbsoluteIndexedByXLongAddr();
break;
case AbsoluteIndexedByY:
valueAddr = this->_getAbsoluteIndexedByYAddr();
break;
case StackRelative:
valueAddr = this->_getStackRelativeAddr();
break;
case StackRelativeIndirectIndexedByY:
valueAddr = this->_getStackRelativeIndirectIndexedYAddr();
break;
case AbsoluteIndirectIndexedByX:
valueAddr = this->_getAbsoluteIndirectIndexedByXAddr();
break;
}
uint24_t valueAddr = this->_getValueAddr(instruction);
return instruction.cycleCount + (this->*instruction.call)(valueAddr, instruction.addressingMode);
}
+5
View File
@@ -258,6 +258,11 @@ namespace ComSquare::CPU
//! @return The number of CPU cycles that the instruction took.
virtual unsigned _executeInstruction(uint8_t opcode);
//! @brief Get the parameter address of an instruction from it's addressing mode.
//! @info The current program counter should point to the instruction's opcode + 1.
//! @return The address of the data to read on the instruction.
uint24_t _getValueAddr(Instruction &instruction);
//! @brief Break instruction - Causes a software break. The PC is loaded from a vector table.
int BRK(uint24_t, AddressingMode);
//! @brief Co-Processor Enable instruction - Causes a software break. The PC is loaded from a vector table.