diff --git a/MC6809/src/mc6809.cpp b/MC6809/src/mc6809.cpp index b0a0272..53d9f77 100644 --- a/MC6809/src/mc6809.cpp +++ b/MC6809/src/mc6809.cpp @@ -15,9 +15,9 @@ void EightBit::mc6809::powerOn() { int EightBit::mc6809::step() { resetCycles(); + ExecutingInstruction.fire(*this); if (LIKELY(powered())) { m_prefix10 = m_prefix11 = false; - ExecutingInstruction.fire(*this); if (UNLIKELY(lowered(HALT()))) handleHALT(); else if (UNLIKELY(lowered(RESET()))) @@ -30,8 +30,8 @@ int EightBit::mc6809::step() { handleIRQ(); else execute(fetchByte()); - ExecutedInstruction.fire(*this); } + ExecutedInstruction.fire(*this); return cycles(); } @@ -51,6 +51,7 @@ void EightBit::mc6809::handleRESET() { setFlag(CC(), IF); // Disable IRQ setFlag(CC(), FF); // Disable FIRQ jump(getWordPaged(0xff, RESETvector)); + addCycles(10); } void EightBit::mc6809::handleNMI() { diff --git a/MC6809/test/Board.cpp b/MC6809/test/Board.cpp index 5b11644..46b094b 100644 --- a/MC6809/test/Board.cpp +++ b/MC6809/test/Board.cpp @@ -44,7 +44,7 @@ void Board::initialise() { CPU().ExecutedInstruction.connect(std::bind(&Board::Cpu_ExecutedInstruction_Debug, this, std::placeholders::_1)); } if (m_configuration.terminatesEarly()) - CPU().ExecutingInstruction.connect(std::bind(&Board::Cpu_ExecutedInstruction_Terminator, this, std::placeholders::_1)); + CPU().ExecutedInstruction.connect(std::bind(&Board::Cpu_ExecutedInstruction_Terminator, this, std::placeholders::_1)); } void Board::Cpu_ExecutingInstruction_Debug(EightBit::mc6809&) { @@ -95,14 +95,15 @@ void Board::updateAciaPins(const EightBit::Chip::PinLevel rw) { } void Board::Cpu_ExecutedInstruction_Terminator(EightBit::mc6809&) { + assert(CPU().cycles() > 0); + m_totalCycleCount += CPU().cycles(); if (m_totalCycleCount > Configuration::TerminationCycles) CPU().powerOff(); } void Board::Cpu_ExecutedInstruction_Acia(EightBit::mc6809&) { - const auto cycles = CPU().cycles(); - m_totalCycleCount += cycles; - m_frameCycleCount -= cycles; + assert(CPU().cycles() > 0); + m_frameCycleCount -= CPU().cycles(); if (m_frameCycleCount < 0) { if (_kbhit()) { ACIA().RDR() = _getch();