From 7e5029063470c957a1da7d2d860d40756fe32516 Mon Sep 17 00:00:00 2001 From: Lauchmelder Date: Mon, 28 Feb 2022 17:05:50 +0100 Subject: [PATCH] documented cpu --- src/CPU.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/CPU.cpp b/src/CPU.cpp index adf31eb..d5596b4 100644 --- a/src/CPU.cpp +++ b/src/CPU.cpp @@ -44,6 +44,7 @@ uint8_t CPU::Tick() if (halted) return 0; + // If there are still cycles left from last instruction, dont do anything totalCycles++; if (remainingCycles) { @@ -53,13 +54,16 @@ uint8_t CPU::Tick() RESET_DEBUG_STRING(); APPEND_DEBUG_STRING(std::setw(4) << pc.Raw << " "); + // Get current opcode and instruction Byte opcode = Read(pc.Raw++); currentInstruction = &(InstructionTable[opcode]); + // Add this instruction to the past instruction list pastInstructions.push_back(std::make_pair(pc.Raw - 1, currentInstruction)); if (pastInstructions.size() > 50) pastInstructions.pop_front(); + // If the instruction is not set in the lookup table, abort if (currentInstruction->Operation == nullptr || currentInstruction->Mode == nullptr) { 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 << " "); + // Invoke addressing mode and instruction accumulatorAddressing = false; currentInstruction->Mode(); currentInstruction->Operation(); @@ -83,6 +88,7 @@ uint8_t CPU::Tick() LOG(); + // Set remaining cycles remainingCycles = currentInstruction->Cycles + additionalCycles; additionalCycles = 0; remainingCycles--;