From 20c126adfc015fec86894558570081751358b2ad Mon Sep 17 00:00:00 2001 From: "Adrian.Conlon" Date: Thu, 31 Aug 2017 01:19:51 +0100 Subject: [PATCH] Correct a couple of cycle counting issues. Signed-off-by: Adrian.Conlon --- LR35902/src/LR35902.cpp | 12 ++++++------ M6502/src/mos6502.cpp | 16 +++++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/LR35902/src/LR35902.cpp b/LR35902/src/LR35902.cpp index c74e9ca..28e717d 100644 --- a/LR35902/src/LR35902.cpp +++ b/LR35902/src/LR35902.cpp @@ -335,10 +335,10 @@ void EightBit::LR35902::ccf(uint8_t& a, uint8_t& f) { int EightBit::LR35902::runRasterLines() { m_bus.resetLY(); - int cycles = 0; + int count = 0; for (int line = 0; line < Display::RasterHeight; ++line) - cycles += runRasterLine(); - return cycles; + count += runRasterLine(); + return count; } int EightBit::LR35902::runRasterLine() { @@ -351,10 +351,10 @@ int EightBit::LR35902::runRasterLine() { int EightBit::LR35902::runVerticalBlankLines() { m_bus.triggerInterrupt(Bus::Interrupts::VerticalBlank); - int cycles = 0; + int count = 0; for (int line = 0; line < (Bus::TotalLineCount - Display::RasterHeight); ++line) - cycles += runRasterLine(); - return cycles; + count += runRasterLine(); + return count; } int EightBit::LR35902::singleStep() { diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index 13e5759..cac272e 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -33,13 +33,11 @@ void EightBit::MOS6502::initialise() { } PC().word = 0; + X() = Bit7; Y() = 0; A() = 0; - - P() = 0; - setFlag(P(), RF); - + P() = RF; S() = Mask8; MEMPTR().word = 0; @@ -47,7 +45,8 @@ void EightBit::MOS6502::initialise() { int EightBit::MOS6502::step() { ExecutingInstruction.fire(*this); - auto returned = execute(fetchByte()); + cycles = 0; + auto returned = fetchExecute(); ExecutedInstruction.fire(*this); return returned; } @@ -344,6 +343,9 @@ int EightBit::MOS6502::execute(uint8_t cell) { __assume(0); } + if (cycles == 0) + throw std::logic_error("Unhandled opcode"); + return cycles; } @@ -483,7 +485,7 @@ void EightBit::MOS6502::ADC_d(uint8_t data) { //// void EightBit::MOS6502::Branch(int8_t displacement) { - auto page = PC().high; + const auto page = PC().high; PC().word += displacement; if (PC().high != page) cycles++; @@ -491,7 +493,7 @@ void EightBit::MOS6502::Branch(int8_t displacement) { } void EightBit::MOS6502::Branch(bool flag) { - int8_t displacement = AM_Immediate(); + const int8_t displacement = AM_Immediate(); if (flag) Branch(displacement); }