From 467c45e7b28d221f3fbdb37db5af9ad278186d9b Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Tue, 4 Apr 2017 00:38:44 +0200 Subject: [PATCH] Delay queue widget: replace mock. * Add an iterator for interating over delay queue entries * Dynamically build delay queue widget content from iterator * Refactor shadow registers to reflect a possible delay --- src/debugger/TIADebug.cxx | 108 ++++++++------- src/debugger/TIADebug.hxx | 4 + src/debugger/gui/DelayQueueWidget.cxx | 179 ++++++++++++++++++++++++- src/debugger/gui/DelayQueueWidget.hxx | 7 +- src/debugger/gui/TiaWidget.cxx | 2 + src/emucore/tia/DelayQueue.hxx | 3 + src/emucore/tia/DelayQueueIterator.cxx | 94 +++++++++++++ src/emucore/tia/DelayQueueIterator.hxx | 56 ++++++++ src/emucore/tia/DelayQueueMember.hxx | 8 +- src/emucore/tia/TIA.cxx | 33 ++++- src/emucore/tia/TIA.hxx | 2 +- src/emucore/tia/module.mk | 4 +- 12 files changed, 438 insertions(+), 62 deletions(-) create mode 100644 src/emucore/tia/DelayQueueIterator.cxx create mode 100644 src/emucore/tia/DelayQueueIterator.hxx diff --git a/src/debugger/TIADebug.cxx b/src/debugger/TIADebug.cxx index 046c64865..cd71c6408 100644 --- a/src/debugger/TIADebug.cxx +++ b/src/debugger/TIADebug.cxx @@ -185,7 +185,7 @@ bool TIADebug::vdelP0(int newVal) if(newVal > -1) mySystem.poke(VDELP0, bool(newVal)); - return myTIA.lastValueWrittenToRegister(VDELP0) & 0x01; + return myTIA.registerValue(VDELP0) & 0x01; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -194,7 +194,7 @@ bool TIADebug::vdelP1(int newVal) if(newVal > -1) mySystem.poke(VDELP1, bool(newVal)); - return myTIA.lastValueWrittenToRegister(VDELP1) & 0x01; + return myTIA.registerValue(VDELP1) & 0x01; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -203,7 +203,7 @@ bool TIADebug::vdelBL(int newVal) if(newVal > -1) mySystem.poke(VDELBL, bool(newVal)); - return myTIA.lastValueWrittenToRegister(VDELBL) & 0x01; + return myTIA.registerValue(VDELBL) & 0x01; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -212,7 +212,7 @@ bool TIADebug::enaM0(int newVal) if(newVal > -1) mySystem.poke(ENAM0, bool(newVal) << 1); - return myTIA.lastValueWrittenToRegister(ENAM0) & 0x02; + return myTIA.registerValue(ENAM0) & 0x02; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -221,7 +221,7 @@ bool TIADebug::enaM1(int newVal) if(newVal > -1) mySystem.poke(ENAM1, bool(newVal) << 1); - return myTIA.lastValueWrittenToRegister(ENAM1) & 0x02; + return myTIA.registerValue(ENAM1) & 0x02; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -230,7 +230,7 @@ bool TIADebug::enaBL(int newVal) if(newVal > -1) mySystem.poke(ENABL, bool(newVal) << 1); - return myTIA.lastValueWrittenToRegister(ENABL) & 0x02; + return myTIA.registerValue(ENABL) & 0x02; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -239,7 +239,7 @@ bool TIADebug::resMP0(int newVal) if(newVal > -1) mySystem.poke(RESMP0, bool(newVal) << 1); - return myTIA.lastValueWrittenToRegister(RESMP0) & 0x02; + return myTIA.registerValue(RESMP0) & 0x02; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -248,7 +248,7 @@ bool TIADebug::resMP1(int newVal) if(newVal > -1) mySystem.poke(RESMP1, bool(newVal) << 1); - return myTIA.lastValueWrittenToRegister(RESMP1) & 0x02;; + return myTIA.registerValue(RESMP1) & 0x02;; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -257,7 +257,7 @@ bool TIADebug::refP0(int newVal) if(newVal > -1) mySystem.poke(REFP0, bool(newVal) << 3); - return myTIA.lastValueWrittenToRegister(REFP0) & 0x08; + return myTIA.registerValue(REFP0) & 0x08; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -266,7 +266,7 @@ bool TIADebug::refP1(int newVal) if(newVal > -1) mySystem.poke(REFP1, bool(newVal) << 3); - return myTIA.lastValueWrittenToRegister(REFP1) & 0x08; + return myTIA.registerValue(REFP1) & 0x08; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -274,7 +274,7 @@ bool TIADebug::refPF(int newVal) { if(newVal > -1) { - int tmp = myTIA.lastValueWrittenToRegister(CTRLPF); + int tmp = myTIA.registerValue(CTRLPF); if(newVal) tmp |= 0x01; else @@ -282,7 +282,7 @@ bool TIADebug::refPF(int newVal) mySystem.poke(CTRLPF, tmp); } - return myTIA.lastValueWrittenToRegister(CTRLPF) & 0x01; + return myTIA.registerValue(CTRLPF) & 0x01; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -290,7 +290,7 @@ bool TIADebug::scorePF(int newVal) { if(newVal > -1) { - int tmp = myTIA.lastValueWrittenToRegister(CTRLPF); + int tmp = myTIA.registerValue(CTRLPF); if(newVal) tmp |= 0x02; else @@ -298,7 +298,7 @@ bool TIADebug::scorePF(int newVal) mySystem.poke(CTRLPF, tmp); } - return myTIA.lastValueWrittenToRegister(CTRLPF) & 0x02; + return myTIA.registerValue(CTRLPF) & 0x02; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -306,7 +306,7 @@ bool TIADebug::priorityPF(int newVal) { if(newVal > -1) { - int tmp = myTIA.lastValueWrittenToRegister(CTRLPF); + int tmp = myTIA.registerValue(CTRLPF); if(newVal) tmp |= 0x04; else @@ -314,7 +314,7 @@ bool TIADebug::priorityPF(int newVal) mySystem.poke(CTRLPF, tmp); } - return myTIA.lastValueWrittenToRegister(CTRLPF) & 0x04; + return myTIA.registerValue(CTRLPF) & 0x04; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -347,7 +347,7 @@ uInt8 TIADebug::audC0(int newVal) if(newVal > -1) mySystem.poke(AUDC0, newVal); - return myTIA.lastValueWrittenToRegister(AUDC0) & 0x0f; + return myTIA.registerValue(AUDC0) & 0x0f; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -356,7 +356,7 @@ uInt8 TIADebug::audC1(int newVal) if(newVal > -1) mySystem.poke(AUDC1, newVal); - return myTIA.lastValueWrittenToRegister(AUDC1) & 0x0f; + return myTIA.registerValue(AUDC1) & 0x0f; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -365,7 +365,7 @@ uInt8 TIADebug::audV0(int newVal) if(newVal > -1) mySystem.poke(AUDV0, newVal); - return myTIA.lastValueWrittenToRegister(AUDV0) & 0x0f; + return myTIA.registerValue(AUDV0) & 0x0f; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -374,7 +374,7 @@ uInt8 TIADebug::audV1(int newVal) if(newVal > -1) mySystem.poke(AUDV1, newVal); - return myTIA.lastValueWrittenToRegister(AUDV1) & 0x0f; + return myTIA.registerValue(AUDV1) & 0x0f; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -383,7 +383,7 @@ uInt8 TIADebug::audF0(int newVal) if(newVal > -1) mySystem.poke(AUDF0, newVal); - return myTIA.lastValueWrittenToRegister(AUDF0) & 0x1f; + return myTIA.registerValue(AUDF0) & 0x1f; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -392,7 +392,7 @@ uInt8 TIADebug::audF1(int newVal) if(newVal > -1) mySystem.poke(AUDF1, newVal); - return myTIA.lastValueWrittenToRegister(AUDF1) & 0x1f; + return myTIA.registerValue(AUDF1) & 0x1f; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -401,7 +401,7 @@ uInt8 TIADebug::pf0(int newVal) if(newVal > -1) mySystem.poke(PF0, newVal << 4); - return myTIA.lastValueWrittenToRegister(PF0) >> 4; + return myTIA.registerValue(PF0) >> 4; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -410,7 +410,7 @@ uInt8 TIADebug::pf1(int newVal) if(newVal > -1) mySystem.poke(PF1, newVal); - return myTIA.lastValueWrittenToRegister(PF1); + return myTIA.registerValue(PF1); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -419,7 +419,7 @@ uInt8 TIADebug::pf2(int newVal) if(newVal > -1) mySystem.poke(PF2, newVal); - return myTIA.lastValueWrittenToRegister(PF1); + return myTIA.registerValue(PF1); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -428,7 +428,7 @@ uInt8 TIADebug::coluP0(int newVal) if(newVal > -1) mySystem.poke(COLUP0, newVal); - return myTIA.lastValueWrittenToRegister(COLUP0); + return myTIA.registerValue(COLUP0); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -437,7 +437,7 @@ uInt8 TIADebug::coluP1(int newVal) if(newVal > -1) mySystem.poke(COLUP1, newVal); - return myTIA.lastValueWrittenToRegister(COLUP1); + return myTIA.registerValue(COLUP1); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -446,7 +446,7 @@ uInt8 TIADebug::coluPF(int newVal) if(newVal > -1) mySystem.poke(COLUPF, newVal); - return myTIA.lastValueWrittenToRegister(COLUPF); + return myTIA.registerValue(COLUPF); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -455,7 +455,7 @@ uInt8 TIADebug::coluBK(int newVal) if(newVal > -1) mySystem.poke(COLUBK, newVal); - return myTIA.lastValueWrittenToRegister(COLUBK); + return myTIA.registerValue(COLUBK); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -464,7 +464,7 @@ uInt8 TIADebug::nusiz0(int newVal) if(newVal > -1) mySystem.poke(NUSIZ0, newVal); - return myTIA.lastValueWrittenToRegister(NUSIZ0); + return myTIA.registerValue(NUSIZ0); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -473,7 +473,7 @@ uInt8 TIADebug::nusiz1(int newVal) if(newVal > -1) mySystem.poke(NUSIZ1, newVal); - return myTIA.lastValueWrittenToRegister(NUSIZ1); + return myTIA.registerValue(NUSIZ1); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -481,12 +481,12 @@ uInt8 TIADebug::nusizP0(int newVal) { if(newVal > -1) { - uInt8 tmp = myTIA.lastValueWrittenToRegister(NUSIZ0) & ~0x07; + uInt8 tmp = myTIA.registerValue(NUSIZ0) & ~0x07; tmp |= (newVal & 0x07); mySystem.poke(NUSIZ0, tmp); } - return myTIA.lastValueWrittenToRegister(NUSIZ0) & 0x07; + return myTIA.registerValue(NUSIZ0) & 0x07; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -494,12 +494,12 @@ uInt8 TIADebug::nusizP1(int newVal) { if(newVal > -1) { - uInt8 tmp = myTIA.lastValueWrittenToRegister(NUSIZ1) & ~0x07; + uInt8 tmp = myTIA.registerValue(NUSIZ1) & ~0x07; tmp |= newVal & 0x07; mySystem.poke(NUSIZ1, tmp); } - return myTIA.lastValueWrittenToRegister(NUSIZ1) & 0x07; + return myTIA.registerValue(NUSIZ1) & 0x07; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -507,12 +507,12 @@ uInt8 TIADebug::nusizM0(int newVal) { if(newVal > -1) { - uInt8 tmp = myTIA.lastValueWrittenToRegister(NUSIZ0) & ~0x30; + uInt8 tmp = myTIA.registerValue(NUSIZ0) & ~0x30; tmp |= (newVal & 0x04) << 4; mySystem.poke(NUSIZ0, tmp); } - return (myTIA.lastValueWrittenToRegister(NUSIZ0) & 0x30) >> 4; + return (myTIA.registerValue(NUSIZ0) & 0x30) >> 4; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -520,12 +520,12 @@ uInt8 TIADebug::nusizM1(int newVal) { if(newVal > -1) { - uInt8 tmp = myTIA.lastValueWrittenToRegister(NUSIZ1) & ~0x30; + uInt8 tmp = myTIA.registerValue(NUSIZ1) & ~0x30; tmp |= (newVal & 0x04) << 4; mySystem.poke(NUSIZ1, tmp); } - return (myTIA.lastValueWrittenToRegister(NUSIZ1) & 0x30) >> 4; + return (myTIA.registerValue(NUSIZ1) & 0x30) >> 4; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -534,7 +534,7 @@ uInt8 TIADebug::grP0(int newVal) if(newVal > -1) mySystem.poke(GRP0, newVal); - return myTIA.lastValueWrittenToRegister(GRP0); + return myTIA.registerValue(GRP0); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -543,7 +543,7 @@ uInt8 TIADebug::grP1(int newVal) if(newVal > -1) mySystem.poke(GRP1, newVal); - return myTIA.lastValueWrittenToRegister(GRP1); + return myTIA.registerValue(GRP1); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -597,7 +597,7 @@ uInt8 TIADebug::ctrlPF(int newVal) if(newVal > -1) mySystem.poke(CTRLPF, newVal); - return myTIA.lastValueWrittenToRegister(CTRLPF); + return myTIA.registerValue(CTRLPF); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -605,12 +605,12 @@ uInt8 TIADebug::sizeBL(int newVal) { if(newVal > -1) { - uInt8 tmp = myTIA.lastValueWrittenToRegister(CTRLPF) & ~0x30; + uInt8 tmp = myTIA.registerValue(CTRLPF) & ~0x30; tmp |= (newVal & 0x04) << 4; mySystem.poke(CTRLPF, tmp); } - return (myTIA.lastValueWrittenToRegister(CTRLPF) & 0x30) >> 4; + return (myTIA.registerValue(CTRLPF) & 0x30) >> 4; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -619,7 +619,7 @@ uInt8 TIADebug::hmP0(int newVal) if(newVal > -1) mySystem.poke(HMP0, newVal << 4); - return myTIA.lastValueWrittenToRegister(HMP0) >> 4; + return myTIA.registerValue(HMP0) >> 4; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -628,7 +628,7 @@ uInt8 TIADebug::hmP1(int newVal) if(newVal > -1) mySystem.poke(HMP1, newVal << 4); - return myTIA.lastValueWrittenToRegister(HMP1) >> 4; + return myTIA.registerValue(HMP1) >> 4; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -637,7 +637,7 @@ uInt8 TIADebug::hmM0(int newVal) if(newVal > -1) mySystem.poke(HMM0, newVal << 4); - return myTIA.lastValueWrittenToRegister(HMM0) >> 4; + return myTIA.registerValue(HMM0) >> 4; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -646,7 +646,7 @@ uInt8 TIADebug::hmM1(int newVal) if(newVal > -1) mySystem.poke(HMM1, newVal << 4); - return myTIA.lastValueWrittenToRegister(HMM1) >> 4; + return myTIA.registerValue(HMM1) >> 4; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -655,7 +655,7 @@ uInt8 TIADebug::hmBL(int newVal) if(newVal > -1) mySystem.poke(HMBL, newVal << 4); - return myTIA.lastValueWrittenToRegister(HMBL) >> 4; + return myTIA.registerValue(HMBL) >> 4; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -679,13 +679,19 @@ int TIADebug::clocksThisLine() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool TIADebug::vsync() const { - return myTIA.lastValueWrittenToRegister(VSYNC) & 0x02; + return myTIA.registerValue(VSYNC) & 0x02; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool TIADebug::vblank() const { - return myTIA.lastValueWrittenToRegister(VBLANK) & 0x02; + return myTIA.registerValue(VBLANK) & 0x02; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +shared_ptr TIADebug::delayQueueIterator() const +{ + return shared_ptr(new DelayQueueIterator(myTIA.myDelayQueue)); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/debugger/TIADebug.hxx b/src/debugger/TIADebug.hxx index d8594e2de..0885601d2 100644 --- a/src/debugger/TIADebug.hxx +++ b/src/debugger/TIADebug.hxx @@ -23,6 +23,8 @@ class TiaDebug; class TIA; #include "DebuggerSystem.hxx" +#include "DelayQueueIterator.hxx" +#include "bspf.hxx" // Function type for TIADebug instance methods class TIADebug; @@ -156,6 +158,8 @@ class TIADebug : public DebuggerSystem int vsyncAsInt() const { return int(vsync()); } // so we can use _vsync pseudo-register int vblankAsInt() const { return int(vblank()); } // so we can use _vblank pseudo-register + shared_ptr delayQueueIterator() const; + private: /** Display a color patch for color at given index in the palette */ string colorSwatch(uInt8 c); diff --git a/src/debugger/gui/DelayQueueWidget.cxx b/src/debugger/gui/DelayQueueWidget.cxx index 88bc5f39f..e1446f22f 100644 --- a/src/debugger/gui/DelayQueueWidget.cxx +++ b/src/debugger/gui/DelayQueueWidget.cxx @@ -16,6 +16,154 @@ //============================================================================ #include "DelayQueueWidget.hxx" +#include "DelayQueueIterator.hxx" +#include "OSystem.hxx" +#include "TIATypes.hxx" +#include "Debugger.hxx" +#include "Base.hxx" + +static const string formatRegister(uInt8 address) +{ + switch (address) { + case WSYNC: + return "WSYNC"; + + case RSYNC: + return "RSYNC"; + + case VSYNC: + return "VSYNC"; + + case VBLANK: + return "VBLANK"; + + case AUDV0: + return "AUDV0"; + + case AUDV1: + return "AUDV1"; + + case AUDF0: + return "AUDF0"; + + case AUDF1: + return "AUDF1"; + + case AUDC0: + return "AUDC0"; + + case AUDC1: + return "AUDC1"; + + case HMOVE: + return "HMOVE"; + + case COLUBK: + return "COLUBK"; + + case COLUP0: + return "COLUP0"; + + case COLUP1: + return "COLUP1"; + + case COLUPF: + return "COLUPF"; + + case CTRLPF: + return "CTRLPF"; + + case PF0: + return "PF0"; + + case PF1: + return "PF1"; + + case PF2: + return "PF2"; + + case ENAM0: + return "ENAM0"; + + case ENAM1: + return "ENAM1"; + + case RESM0: + return "RESM0"; + + case RESM1: + return "RESM1"; + + case RESMP0: + return "RESMP0"; + + case RESMP1: + return "RESMP1"; + + case RESP0: + return "RESP0"; + + case RESP1: + return "RESP1"; + + case RESBL: + return "RESBL"; + + case NUSIZ0: + return "NUSIZ0"; + + case NUSIZ1: + return "NUSIZ1"; + + case HMM0: + return "HMM0"; + + case HMM1: + return "HMM1"; + + case HMP0: + return "HMP0"; + + case HMP1: + return "HMP1"; + + case HMBL: + return "HMBL"; + + case HMCLR: + return "HMCLR"; + + case GRP0: + return "GRP0"; + + case GRP1: + return "GRP1"; + + case REFP0: + return "REFP0"; + + case REFP1: + return "REFP1"; + + case VDELP0: + return "VDELP0"; + + case VDELP1: + return "VDELP1"; + + case VDELBL: + return "VDELBL"; + + case ENABL: + return "ENABL"; + + case CXCLR: + return "CXCLR"; + + default: + return Common::Base::toString(address, Common::Base::Format::F_16_2); + } +} // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - DelayQueueWidget::DelayQueueWidget( @@ -28,6 +176,31 @@ DelayQueueWidget::DelayQueueWidget( _w = 300; _h = 3 * font.getLineHeight() + 6; + + myLines[0] = myLines[1] = myLines[2]; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void DelayQueueWidget::loadConfig() { + shared_ptr delayQueueIterator = instance().debugger().tiaDebug().delayQueueIterator(); + + for (uInt8 i = 0; i < 3; i++) { + if (delayQueueIterator->isValid() && delayQueueIterator->address() < 64) { + stringstream ss; + + ss + << int(delayQueueIterator->delay()) + << " clk, " + << Common::Base::toString(delayQueueIterator->value(), Common::Base::Format::F_16_2) + << " -> " + << formatRegister(delayQueueIterator->address()); + + myLines[i] = ss.str(); + delayQueueIterator->next(); + } + else + myLines[i] = ""; + } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -50,11 +223,11 @@ void DelayQueueWidget::drawWidget(bool hilite) y += 2; x += 2; w -= 3; - surface.drawString(_font, "1 clk, 40 -> GRP0", x, y, w, _textcolor); + surface.drawString(_font, myLines[0], x, y, w, _textcolor); y += lineHeight; - surface.drawString(_font, "3 clk, 02 -> VSYNC", x, y, w, _textcolor); + surface.drawString(_font, myLines[1], x, y, w, _textcolor); y += lineHeight; - surface.drawString(_font, "6 clk, 02 -> HMOVE", x, y, w, _textcolor); + surface.drawString(_font, myLines[2], x, y, w, _textcolor); } \ No newline at end of file diff --git a/src/debugger/gui/DelayQueueWidget.hxx b/src/debugger/gui/DelayQueueWidget.hxx index d4878f7a9..98cad3273 100644 --- a/src/debugger/gui/DelayQueueWidget.hxx +++ b/src/debugger/gui/DelayQueueWidget.hxx @@ -24,18 +24,23 @@ class DelayQueueWidget : public Widget { public: + DelayQueueWidget( GuiObject* boss, const GUI::Font& font, int x, int y ); - virtual ~DelayQueueWidget() = default; + void loadConfig() override; protected: void drawWidget(bool hilite) override; + private: + + string myLines[3]; + private: DelayQueueWidget() = delete; diff --git a/src/debugger/gui/TiaWidget.cxx b/src/debugger/gui/TiaWidget.cxx index 0aa5d8750..5cff1731f 100644 --- a/src/debugger/gui/TiaWidget.cxx +++ b/src/debugger/gui/TiaWidget.cxx @@ -915,6 +915,8 @@ void TiaWidget::loadConfig() // Undriven pins myUndrivenPins->setState(tia.tia().driveUnusedPinsRandom()); + + myDelayQueueWidget->loadConfig(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/tia/DelayQueue.hxx b/src/emucore/tia/DelayQueue.hxx index c01c66b53..27408f9fd 100644 --- a/src/emucore/tia/DelayQueue.hxx +++ b/src/emucore/tia/DelayQueue.hxx @@ -24,6 +24,9 @@ class DelayQueue : public Serializable { + public: + friend class DelayQueueIterator; + public: DelayQueue(uInt8 length, uInt8 size); diff --git a/src/emucore/tia/DelayQueueIterator.cxx b/src/emucore/tia/DelayQueueIterator.cxx new file mode 100644 index 000000000..522a6f023 --- /dev/null +++ b/src/emucore/tia/DelayQueueIterator.cxx @@ -0,0 +1,94 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2017 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#include "DelayQueueIterator.hxx" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +DelayQueueIterator::DelayQueueIterator(const DelayQueue& delayQueue) + : myDelayQueue(delayQueue), + myDelayCycle(0) +{ + while (isValid()) { + const DelayQueueMember& currentMember = myDelayQueue.myMembers.at(currentIndex()); + myCurrentIterator = currentMember.begin(); + + if (myCurrentIterator == currentMember.end()) + myDelayCycle++; + else + break; + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool DelayQueueIterator::isValid() const +{ + return myDelayCycle < myDelayQueue.myMembers.size(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt8 DelayQueueIterator::delay() const +{ + if (!isValid()) { + throw runtime_error("delay called on invalid DelayQueueInterator"); + } + + return myDelayCycle; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt8 DelayQueueIterator::address() const +{ + if (!isValid()) { + throw runtime_error("address called on invalid DelayQueueInterator"); + } + + return myCurrentIterator->address; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt8 DelayQueueIterator::value() const +{ + if (!isValid()) { + throw runtime_error("value called on invalid DelayQueueIterator"); + } + + return myCurrentIterator->value; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool DelayQueueIterator::next() +{ + if (!isValid()) { + return false; + } + + if (++myCurrentIterator == myDelayQueue.myMembers.at(currentIndex()).end()) { + myDelayCycle++; + + while (isValid()) { + const DelayQueueMember& currentMember = myDelayQueue.myMembers.at(currentIndex()); + myCurrentIterator = currentMember.begin(); + + if (myCurrentIterator == currentMember.end()) + myDelayCycle++; + else + break; + } + + return isValid(); + } +} \ No newline at end of file diff --git a/src/emucore/tia/DelayQueueIterator.hxx b/src/emucore/tia/DelayQueueIterator.hxx new file mode 100644 index 000000000..5b72c4f6a --- /dev/null +++ b/src/emucore/tia/DelayQueueIterator.hxx @@ -0,0 +1,56 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2017 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#ifndef TIA_DELAY_QUEUE_ITERATOR +#define TIA_DELAY_QUEUE_ITERATOR + +#include "bspf.hxx" +#include "DelayQueue.hxx" +#include "DelayQueueMember.hxx" + +class DelayQueueIterator +{ + public: + + DelayQueueIterator(const DelayQueue&); + + bool isValid() const; + + uInt8 delay() const; + + uInt8 address() const; + + uInt8 value() const; + + bool next(); + + private: + + uInt8 currentIndex() const { + return (myDelayQueue.myIndex + myDelayCycle) % myDelayQueue.myMembers.size(); + } + + private: + + const DelayQueue& myDelayQueue; + + uInt8 myDelayCycle; + + DelayQueueMember::iterator myCurrentIterator; +}; + +#endif // TIA_DELAY_QUEUE_ITERATOR \ No newline at end of file diff --git a/src/emucore/tia/DelayQueueMember.hxx b/src/emucore/tia/DelayQueueMember.hxx index a729f2881..56f8aa0bb 100644 --- a/src/emucore/tia/DelayQueueMember.hxx +++ b/src/emucore/tia/DelayQueueMember.hxx @@ -35,17 +35,21 @@ class DelayQueueMember : public Serializable DelayQueueMember(DelayQueueMember&&) = default; DelayQueueMember& operator=(DelayQueueMember&&) = default; + public: + + typedef vector::const_iterator iterator; + public: void push(uInt8 address, uInt8 value); void remove(uInt8 address); - vector::const_iterator begin() const { + iterator begin() const { return myEntries.begin(); } - vector::const_iterator end() const { + iterator end() const { return (mySize < myEntries.size()) ? (myEntries.begin() + mySize) : myEntries.end(); } diff --git a/src/emucore/tia/TIA.cxx b/src/emucore/tia/TIA.cxx index 62f77ad4f..93bda91ef 100644 --- a/src/emucore/tia/TIA.cxx +++ b/src/emucore/tia/TIA.cxx @@ -425,7 +425,6 @@ bool TIA::poke(uInt16 address, uInt8 value) updateEmulation(); address &= 0x3F; - myShadowRegisters[address] = value; switch (address) { @@ -440,14 +439,17 @@ bool TIA::poke(uInt16 address, uInt8 value) mySystem->incrementCycles(mySubClock / 3); mySubClock %= 3; } + myShadowRegisters[address] = value; break; case RSYNC: applyRsync(); + myShadowRegisters[address] = value; break; case VSYNC: myFrameManager.setVsync(value & 0x02); + myShadowRegisters[address] = value; break; case VBLANK: @@ -465,21 +467,27 @@ bool TIA::poke(uInt16 address, uInt8 value) // FIXME - rework this when we add the new sound core case AUDV0: mySound.set(address, value, mySystem->cycles()); + myShadowRegisters[address] = value; break; case AUDV1: mySound.set(address, value, mySystem->cycles()); + myShadowRegisters[address] = value; break; case AUDF0: mySound.set(address, value, mySystem->cycles()); + myShadowRegisters[address] = value; break; case AUDF1: mySound.set(address, value, mySystem->cycles()); + myShadowRegisters[address] = value; break; case AUDC0: mySound.set(address, value, mySystem->cycles()); + myShadowRegisters[address] = value; break; case AUDC1: mySound.set(address, value, mySystem->cycles()); + myShadowRegisters[address] = value; break; //////////////////////////////////////////////////////////// @@ -490,6 +498,7 @@ bool TIA::poke(uInt16 address, uInt8 value) case COLUBK: myLinesSinceChange = 0; myBackground.setColor(value & 0xFE); + myShadowRegisters[address] = value; break; case COLUP0: @@ -498,6 +507,7 @@ bool TIA::poke(uInt16 address, uInt8 value) myPlayfield.setColorP0(value); myMissile0.setColor(value); myPlayer0.setColor(value); + myShadowRegisters[address] = value; break; case COLUP1: @@ -506,6 +516,7 @@ bool TIA::poke(uInt16 address, uInt8 value) myPlayfield.setColorP1(value); myMissile1.setColor(value); myPlayer1.setColor(value); + myShadowRegisters[address] = value; break; case CTRLPF: @@ -514,6 +525,7 @@ bool TIA::poke(uInt16 address, uInt8 value) (value & 0x02) ? Priority::score : Priority::normal; myPlayfield.ctrlpf(value); myBall.ctrlpf(value); + myShadowRegisters[address] = value; break; case COLUPF: @@ -521,6 +533,7 @@ bool TIA::poke(uInt16 address, uInt8 value) value &= 0xFE; myPlayfield.setColor(value); myBall.setColor(value); + myShadowRegisters[address] = value; break; case PF0: @@ -567,33 +580,39 @@ bool TIA::poke(uInt16 address, uInt8 value) case RESM0: myLinesSinceChange = 0; myMissile0.resm(resxCounter(), myHstate == HState::blank); + myShadowRegisters[address] = value; break; case RESM1: myLinesSinceChange = 0; myMissile1.resm(resxCounter(), myHstate == HState::blank); + myShadowRegisters[address] = value; break; case RESMP0: myLinesSinceChange = 0; myMissile0.resmp(value, myPlayer0); + myShadowRegisters[address] = value; break; case RESMP1: myLinesSinceChange = 0; myMissile1.resmp(value, myPlayer1); + myShadowRegisters[address] = value; break; case NUSIZ0: myLinesSinceChange = 0; myMissile0.nusiz(value); myPlayer0.nusiz(value, myHstate == HState::blank); + myShadowRegisters[address] = value; break; case NUSIZ1: myLinesSinceChange = 0; myMissile1.nusiz(value); myPlayer1.nusiz(value, myHstate == HState::blank); + myShadowRegisters[address] = value; break; case HMM0: @@ -636,11 +655,13 @@ bool TIA::poke(uInt16 address, uInt8 value) case RESP0: myLinesSinceChange = 0; myPlayer0.resp(resxCounter()); + myShadowRegisters[address] = value; break; case RESP1: myLinesSinceChange = 0; myPlayer1.resp(resxCounter()); + myShadowRegisters[address] = value; break; case REFP0: @@ -654,11 +675,13 @@ bool TIA::poke(uInt16 address, uInt8 value) case VDELP0: myLinesSinceChange = 0; myPlayer0.vdelp(value); + myShadowRegisters[address] = value; break; case VDELP1: myLinesSinceChange = 0; myPlayer1.vdelp(value); + myShadowRegisters[address] = value; break; case HMP0: @@ -676,11 +699,13 @@ bool TIA::poke(uInt16 address, uInt8 value) case RESBL: myLinesSinceChange = 0; myBall.resbl(resxCounter()); + myShadowRegisters[address] = value; break; case VDELBL: myLinesSinceChange = 0; myBall.vdelbl(value); + myShadowRegisters[address] = value; break; case HMBL: @@ -690,6 +715,7 @@ bool TIA::poke(uInt16 address, uInt8 value) case CXCLR: myLinesSinceChange = 0; myCollisionMask = 0; + myShadowRegisters[address] = value; break; } @@ -911,7 +937,7 @@ void TIA::updateScanlineByTrace(int target) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt8 TIA::lastValueWrittenToRegister(uInt8 reg) const +uInt8 TIA::registerValue(uInt8 reg) const { return reg < 64 ? myShadowRegisters[reg] : 0; } @@ -1169,6 +1195,9 @@ void TIA::clearHmoveComb() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TIA::delayedWrite(uInt8 address, uInt8 value) { + if (address < 64) + myShadowRegisters[address] = value; + switch (address) { case VBLANK: diff --git a/src/emucore/tia/TIA.hxx b/src/emucore/tia/TIA.hxx index 4a2a279fc..5cdfd8d82 100644 --- a/src/emucore/tia/TIA.hxx +++ b/src/emucore/tia/TIA.hxx @@ -312,7 +312,7 @@ class TIA : public Device, public PlayfieldPositionProvider /** Retrieve the last value written to a certain register */ - uInt8 lastValueWrittenToRegister(uInt8 reg) const; + uInt8 registerValue(uInt8 reg) const; /** Get the current x value diff --git a/src/emucore/tia/module.mk b/src/emucore/tia/module.mk index b62b8c13f..43c317bf5 100644 --- a/src/emucore/tia/module.mk +++ b/src/emucore/tia/module.mk @@ -13,8 +13,8 @@ MODULE_OBJS := \ src/emucore/tia/Background.o \ src/emucore/tia/LatchedInput.o \ src/emucore/tia/PaddleReader.o \ - src/emucore/tia/VblankManager.o - + src/emucore/tia/VblankManager.o \ + src/emucore/tia/DelayQueueIterator.o MODULE_DIRS += \ src/emucore/tia