documented cpu

This commit is contained in:
Lauchmelder 2022-02-28 17:05:50 +01:00
parent 71b524519d
commit 7e50290634
No known key found for this signature in database
GPG key ID: C2403C69D78F011D

View file

@ -44,6 +44,7 @@ uint8_t CPU::Tick()
if (halted) if (halted)
return 0; return 0;
// If there are still cycles left from last instruction, dont do anything
totalCycles++; totalCycles++;
if (remainingCycles) if (remainingCycles)
{ {
@ -53,13 +54,16 @@ uint8_t CPU::Tick()
RESET_DEBUG_STRING(); RESET_DEBUG_STRING();
APPEND_DEBUG_STRING(std::setw(4) << pc.Raw << " "); APPEND_DEBUG_STRING(std::setw(4) << pc.Raw << " ");
// Get current opcode and instruction
Byte opcode = Read(pc.Raw++); Byte opcode = Read(pc.Raw++);
currentInstruction = &(InstructionTable[opcode]); currentInstruction = &(InstructionTable[opcode]);
// Add this instruction to the past instruction list
pastInstructions.push_back(std::make_pair(pc.Raw - 1, currentInstruction)); pastInstructions.push_back(std::make_pair(pc.Raw - 1, currentInstruction));
if (pastInstructions.size() > 50) if (pastInstructions.size() > 50)
pastInstructions.pop_front(); pastInstructions.pop_front();
// If the instruction is not set in the lookup table, abort
if (currentInstruction->Operation == nullptr || currentInstruction->Mode == nullptr) if (currentInstruction->Operation == nullptr || currentInstruction->Mode == nullptr)
{ {
LOG_DEBUG_ERROR("Unknown instruction {0:02X} at ${1:04X}", opcode, pc.Raw); LOG_DEBUG_ERROR("Unknown instruction {0:02X} at ${1:04X}", opcode, pc.Raw);
@ -68,6 +72,7 @@ uint8_t CPU::Tick()
APPEND_DEBUG_STRING((Word)opcode << " "); APPEND_DEBUG_STRING((Word)opcode << " ");
// Invoke addressing mode and instruction
accumulatorAddressing = false; accumulatorAddressing = false;
currentInstruction->Mode(); currentInstruction->Mode();
currentInstruction->Operation(); currentInstruction->Operation();
@ -83,6 +88,7 @@ uint8_t CPU::Tick()
LOG(); LOG();
// Set remaining cycles
remainingCycles = currentInstruction->Cycles + additionalCycles; remainingCycles = currentInstruction->Cycles + additionalCycles;
additionalCycles = 0; additionalCycles = 0;
remainingCycles--; remainingCycles--;