From d8178f546bef24a70e026d5ad0e39e71423adf21 Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Tue, 13 Mar 2018 22:12:57 +0100 Subject: [PATCH] Make sure that the hardware state is up to date before entering the debugger. --- src/emucore/M6502.cxx | 29 ++++++++++++++++++++--------- src/emucore/M6502.hxx | 6 ++++++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/emucore/M6502.cxx b/src/emucore/M6502.cxx index be39a27e6..24f2316a1 100644 --- a/src/emucore/M6502.cxx +++ b/src/emucore/M6502.cxx @@ -237,6 +237,21 @@ bool M6502::execute(uInt32 number) return status; } +bool M6502::startDebugger(const string& message, int address, bool read) { + handleHalt(); + + mySystem->tia().updateEmulation(); + mySystem->m6532().updateEmulation(); + + #ifndef DEBUGGER_SUPPORT + return false; + #endif + + if (!myDebugger) return false; + + return myDebugger->start(message, address, read); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - inline bool M6502::_execute(uInt32 number) { @@ -258,23 +273,19 @@ inline bool M6502::_execute(uInt32 number) { bool read = myJustHitReadTrapFlag; myJustHitReadTrapFlag = myJustHitWriteTrapFlag = false; - if(myDebugger && myDebugger->start(myHitTrapInfo.message, myHitTrapInfo.address, read)) - { - return true; - } + + if (startDebugger(myHitTrapInfo.message, myHitTrapInfo.address, read)) return true; } - if(myBreakPoints.isInitialized() && myBreakPoints.isSet(PC)) - if(myDebugger && myDebugger->start("BP: ", PC)) - return true; + if(myBreakPoints.isInitialized() && myBreakPoints.isSet(PC) && startDebugger("BP: ", PC)) + return true; int cond = evalCondBreaks(); if(cond > -1) { stringstream msg; msg << "CBP[" << Common::Base::HEX2 << cond << "]: " << myCondBreakNames[cond]; - if(myDebugger && myDebugger->start(msg.str())) - return true; + if (startDebugger(msg.str())) return true; } cond = evalCondSaveStates(); diff --git a/src/emucore/M6502.hxx b/src/emucore/M6502.hxx index 3c88674ac..5786b938a 100644 --- a/src/emucore/M6502.hxx +++ b/src/emucore/M6502.hxx @@ -326,6 +326,12 @@ class M6502 : public Serializable */ bool _execute(uInt32 number); + /** + Make sure that the current hardware state is up to date (TIA & RIOT) and dispatch + debugger. + */ + bool startDebugger(const string& message = "", int address = -1, bool read = true); + private: /** Bit fields used to indicate that certain conditions need to be