From fa76042790ea544d880a3b654c70e796454eb6a7 Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Sat, 24 Jun 2017 00:35:17 +0200 Subject: [PATCH] Make sure that pending RDY is handled after stepping the CPU. Closes #155. --- src/emucore/M6502.cxx | 23 +++++++++++++++++++---- src/emucore/M6502.hxx | 5 +++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/emucore/M6502.cxx b/src/emucore/M6502.cxx index 4a44fe7be..20bacfa69 100644 --- a/src/emucore/M6502.cxx +++ b/src/emucore/M6502.cxx @@ -111,10 +111,7 @@ void M6502::reset() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - inline uInt8 M6502::peek(uInt16 address, uInt8 flags) { - if (myHaltRequested) { - myOnHaltCallback(); - myHaltRequested = false; - } + handleHalt(); //////////////////////////////////////////////// // TODO - move this logic directly into CartAR @@ -175,6 +172,15 @@ void M6502::requestHalt() myHaltRequested = true; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +inline void M6502::handleHalt() +{ + if (myHaltRequested) { + myOnHaltCallback(); + myHaltRequested = false; + } +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool M6502::execute(uInt32 number) { @@ -241,6 +247,12 @@ bool M6502::execute(uInt32 number) // See if execution has been stopped if(myExecutionStatus & StopExecutionBit) { + // Debugger hack: this ensures that stepping a "STA WSYNC" will actually end at the + // beginning of the next line (otherwise, the next instruction would be stepped in order for + // the halt to take effect). This is safe because as we know that the next cycle will be a read + // cycle anyway. + handleHalt(); + // Yes, so answer that everything finished fine return true; } @@ -255,6 +267,9 @@ bool M6502::execute(uInt32 number) // See if we've executed the specified number of instructions if(number == 0) { + // See above + handleHalt(); + // Yes, so answer that everything finished fine return true; } diff --git a/src/emucore/M6502.hxx b/src/emucore/M6502.hxx index ba6a74ef5..a03631337 100644 --- a/src/emucore/M6502.hxx +++ b/src/emucore/M6502.hxx @@ -286,6 +286,11 @@ class M6502 : public Serializable */ void interruptHandler(); + /** + Check whether halt was requested (RDY low) and notify + */ + void handleHalt(); + private: /** Bit fields used to indicate that certain conditions need to be