diff --git a/Changes.txt b/Changes.txt index 87670ce4e..f1bcadfe1 100644 --- a/Changes.txt +++ b/Changes.txt @@ -53,6 +53,10 @@ * Fixed regression in RIOT INTIM reads; at least one known ROM (Mr. Roboto Berzerk hack) wasn't working properly. + * Fixed bug in the debugger with RIOT INTIM/TIMINT display; reads + were being done multiple times, changing the state of the + registers and resulting in incorrect emulation. + * Added support for different directories for saving/loading PNG files. These are set with the 'snapsavedir' and 'snaploaddir' commandline arguments (which replace the old 'snapdir'), and are diff --git a/src/debugger/RiotDebug.cxx b/src/debugger/RiotDebug.cxx index 1cea82bd4..e7aa5e86b 100644 --- a/src/debugger/RiotDebug.cxx +++ b/src/debugger/RiotDebug.cxx @@ -20,7 +20,6 @@ #include #include "System.hxx" -#include "M6532.hxx" #include "TIA.hxx" #include "Debugger.hxx" #include "Switches.hxx" @@ -129,7 +128,7 @@ uInt8 RiotDebug::swacnt(int newVal) if(newVal > -1) mySystem.poke(0x281, newVal); - return mySystem.peek(0x281); + return mySystem.m6532().myDDRA; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -138,7 +137,7 @@ uInt8 RiotDebug::swbcnt(int newVal) if(newVal > -1) mySystem.poke(0x283, newVal); - return mySystem.peek(0x283); + return mySystem.m6532().myDDRB; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -196,24 +195,6 @@ uInt8 RiotDebug::tim1024T(int newVal) return mySystem.m6532().myOutTimer[3]; } -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt8 RiotDebug::intim() -{ - return mySystem.peek(0x284); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt8 RiotDebug::timint() -{ - return mySystem.peek(0x285); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Int32 RiotDebug::timClocks() -{ - return mySystem.m6532().timerClocks(); -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Controller& RiotDebug::controller(Controller::Jack jack) const { diff --git a/src/debugger/RiotDebug.hxx b/src/debugger/RiotDebug.hxx index 7996d74cd..8b2306a32 100644 --- a/src/debugger/RiotDebug.hxx +++ b/src/debugger/RiotDebug.hxx @@ -24,6 +24,7 @@ class Debugger; class RiotDebug; #include "Array.hxx" +#include "M6532.hxx" #include "DebuggerSystem.hxx" class RiotState : public DebuggerState @@ -71,9 +72,9 @@ class RiotDebug : public DebuggerSystem uInt8 tim8T(int newVal = -1); uInt8 tim64T(int newVal = -1); uInt8 tim1024T(int newVal = -1); - uInt8 intim(); - uInt8 timint(); - Int32 timClocks(); + uInt8 intim() const { return mySystem.m6532().intim(); } + uInt8 timint() const { return mySystem.m6532().timint(); } + Int32 timClocks() const { return mySystem.m6532().timerClocks(); } /* Controller ports */ Controller& controller(Controller::Jack jack) const; diff --git a/src/emucore/M6532.cxx b/src/emucore/M6532.cxx index e38fd61b5..799aa458c 100644 --- a/src/emucore/M6532.cxx +++ b/src/emucore/M6532.cxx @@ -401,6 +401,34 @@ bool M6532::load(Serializer& in) return true; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt8 M6532::intim() const +{ + // This method is documented in ::peek(0x284), and exists so that the + // debugger can read INTIM without changing the state of the system + + // Get number of clocks since timer was set + Int32 timer = timerClocks(); + if(!(timer & 0x40000)) + return (timer >> myIntervalShift) & 0xff; + else + return timer & 0xff; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt8 M6532::timint() const +{ + // This method is documented in ::peek(0x285), and exists so that the + // debugger can read TIMINT without changing the state of the system + + // Update timer flag if it is invalid and timer has expired + uInt8 interrupt = myInterruptFlag; + if(timerClocks() < 0) + interrupt |= TimerBit; + + return interrupt; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - M6532::M6532(const M6532& c) : myConsole(c.myConsole), diff --git a/src/emucore/M6532.hxx b/src/emucore/M6532.hxx index b8c91e427..d7a6f8287 100644 --- a/src/emucore/M6532.hxx +++ b/src/emucore/M6532.hxx @@ -140,12 +140,18 @@ class M6532 : public Device bool poke(uInt16 address, uInt8 value); private: - Int32 timerClocks() + Int32 timerClocks() const { return myTimer - (mySystem->cycles() - myCyclesWhenTimerSet); } void setTimerRegister(uInt8 data, uInt8 interval); void setPinState(bool shcha); + // The following are used by the debugger to read INTIM/TIMINT + // We need separate methods to do this, so the state of the system + // isn't changed + uInt8 intim() const; + uInt8 timint() const; + private: // Accessible bits in the interrupt flag register // All other bits are always zeroed