From bd46bb417477435eb2a205a0fc5dcacdad14093a Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Mon, 9 Jan 2017 00:10:55 +0100 Subject: [PATCH] Implement RSYNC. --- src/emucore/tia/TIA.cxx | 30 +++++++++++++++++++++++++----- src/emucore/tia/TIA.hxx | 3 +++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/emucore/tia/TIA.cxx b/src/emucore/tia/TIA.cxx index 534fd72d6..7365efc5e 100644 --- a/src/emucore/tia/TIA.cxx +++ b/src/emucore/tia/TIA.cxx @@ -116,6 +116,7 @@ void TIA::reset() myColorHBlank = 0; myLastCycle = 0; mySubClock = 0; + myXDelta = 0; myBackground.reset(); myPlayfield.reset(); @@ -348,6 +349,10 @@ bool TIA::poke(uInt16 address, uInt8 value) } break; + case RSYNC: + applyRsync(); + break; + case VSYNC: myFrameManager.setVsync(value & 0x02); break; @@ -942,6 +947,9 @@ void TIA::cycle(uInt32 colorClocks) else tickHframe(); + if (++myHctr >= 228) + nextLine(); + if (myCollisionUpdateRequired) updateCollision(); myTimestamp++; @@ -982,8 +990,6 @@ void TIA::tickHblank() } if (++myHblankCtr >= 68) myHstate = HState::frame; - - myHctr++; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -991,7 +997,7 @@ void TIA::tickHframe() { const uInt32 y = myFrameManager.currentLine(); const bool lineNotCached = myLinesSinceChange < 2 || y == 0; - const uInt32 x = myHctr - 68; + const uInt32 x = myHctr - 68 + myXDelta; myCollisionUpdateRequired = lineNotCached; @@ -1004,9 +1010,20 @@ void TIA::tickHframe() if (myFrameManager.isRendering()) renderPixel(x, y, lineNotCached); +} - if (++myHctr >= 228) - nextLine(); +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void TIA::applyRsync() +{ + const Int32 x = myHctr - 68; + + if (x > 0 && myFrameManager.isRendering()) { + myXDelta = x - 157; + memset(myCurrentFrameBuffer.get() + myFrameManager.currentLine() * 160 + x, 0, 160 - x); + } + + myLinesSinceChange = 0; + myHctr = 225; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1038,6 +1055,7 @@ void TIA::nextLine() myHstate = HState::blank; myIsFreshLine = true; myExtendedHblank = false; + myXDelta = 0; myFrameManager.nextLine(); } @@ -1058,6 +1076,8 @@ void TIA::updateCollision() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void TIA::renderPixel(uInt32 x, uInt32 y, bool lineNotCached) { + if (x >= 160) return; + if (lineNotCached) { uInt8 color = myBackground.getColor(); diff --git a/src/emucore/tia/TIA.hxx b/src/emucore/tia/TIA.hxx index 7dc14e9ad..45c924e8f 100644 --- a/src/emucore/tia/TIA.hxx +++ b/src/emucore/tia/TIA.hxx @@ -365,6 +365,8 @@ class TIA : public Device void tickHframe(); + void applyRsync(); + void updateCollision(); void renderSprites(); @@ -411,6 +413,7 @@ class TIA : public Device Int32 myHblankCtr; Int32 myHctr; + Int32 myXDelta; bool myCollisionUpdateRequired; uInt32 myCollisionMask;