From 07f1051be0669fd7a8c470310e9aa892fc13d532 Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Tue, 6 Feb 2018 23:31:34 +0100 Subject: [PATCH] Tentative fixes for collisions during HBLANK. --- src/emucore/tia/Ball.cxx | 17 ++++++++++++++--- src/emucore/tia/Ball.hxx | 3 +++ src/emucore/tia/Missile.cxx | 24 ++++++++++++++++++------ src/emucore/tia/Missile.hxx | 3 +++ src/emucore/tia/Player.cxx | 14 ++++++++++++++ src/emucore/tia/Player.hxx | 3 +++ src/emucore/tia/TIA.cxx | 5 +++++ src/emucore/tia/TIA.hxx | 10 +++++----- 8 files changed, 65 insertions(+), 14 deletions(-) diff --git a/src/emucore/tia/Ball.cxx b/src/emucore/tia/Ball.cxx index c44301064..36cda80bd 100644 --- a/src/emucore/tia/Ball.cxx +++ b/src/emucore/tia/Ball.cxx @@ -40,6 +40,7 @@ void Ball::reset() myIsEnabledNew = false; myIsEnabled = false; myIsDelaying = false; + myIsVisible = false; myHmmClocks = 0; myCounter = 0; myIsMoving = false; @@ -62,7 +63,11 @@ void Ball::enabl(uInt8 value) if (myIsEnabledNew != enabledNewOldValue && !myIsDelaying) { myTIA->flushLineCache(); + updateEnabled(); + + collision = (myIsVisible && myIsEnabled) ? myCollisionMaskEnabled : myCollisionMaskDisabled; + myTIA->updateCollision(); } } @@ -173,9 +178,8 @@ bool Ball::movementTick(uInt32 clock, bool apply) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Ball::tick(bool isReceivingMclock) { - collision = (myIsRendering && myRenderCounter >= 0 && myIsEnabled) ? - myCollisionMaskEnabled : - myCollisionMaskDisabled; + myIsVisible = myIsRendering && myRenderCounter >= 0; + collision = (myIsVisible && myIsEnabled) ? myCollisionMaskEnabled : myCollisionMaskDisabled; bool starfieldEffect = myIsMoving && isReceivingMclock; @@ -207,6 +211,13 @@ void Ball::tick(bool isReceivingMclock) myCounter = 0; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Ball::nextLine() +{ + myIsVisible = myIsRendering && myRenderCounter >= 0; + collision = (myIsVisible && myIsEnabled) ? myCollisionMaskEnabled : myCollisionMaskDisabled; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Ball::setENABLOld(bool enabled) { diff --git a/src/emucore/tia/Ball.hxx b/src/emucore/tia/Ball.hxx index 7ee6bdb24..f6807e792 100644 --- a/src/emucore/tia/Ball.hxx +++ b/src/emucore/tia/Ball.hxx @@ -62,6 +62,8 @@ class Ball : public Serializable void tick(bool isReceivingMclock = true); + void nextLine(); + bool isOn() const { return (collision & 0x8000); } uInt8 getColor() const { return myColor; } @@ -105,6 +107,7 @@ class Ball : public Serializable bool myIsEnabled; bool myIsSuppressed; bool myIsDelaying; + bool myIsVisible; uInt8 myHmmClocks; uInt8 myCounter; diff --git a/src/emucore/tia/Missile.cxx b/src/emucore/tia/Missile.cxx index 9ad2a49d2..ea73a06de 100644 --- a/src/emucore/tia/Missile.cxx +++ b/src/emucore/tia/Missile.cxx @@ -47,6 +47,7 @@ void Missile::reset() myWidth = 1; myEffectiveWidth = 1; myIsRendering = false; + myIsVisible = false; myRenderCounter = 0; myColor = myObjectColor = myDebugColor = 0; myDebugEnabled = false; @@ -62,9 +63,14 @@ void Missile::enam(uInt8 value) myEnam = (value & 0x02) > 0; - if (oldEnam != myEnam) myTIA->flushLineCache(); + if (oldEnam != myEnam) { + myTIA->flushLineCache(); - updateEnabled(); + updateEnabled(); + + collision = (myIsVisible && myIsEnabled) ? myCollisionMaskEnabled : myCollisionMaskDisabled; + myTIA->updateCollision(); + } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -174,12 +180,11 @@ bool Missile::movementTick(uInt8 clock, uInt8 hclock, bool apply) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Missile::tick(uInt8 hclock) { - const bool render = + myIsVisible = myIsRendering && - (myRenderCounter >= 0 || (myIsMoving && myRenderCounter == -1 && myWidth < 4 && ((hclock + 1) % 4 == 3))) && - myIsEnabled; + (myRenderCounter >= 0 || (myIsMoving && myRenderCounter == -1 && myWidth < 4 && ((hclock + 1) % 4 == 3))); - collision = render ? myCollisionMaskEnabled : myCollisionMaskDisabled; + collision = (myIsVisible && myIsEnabled) ? myCollisionMaskEnabled : myCollisionMaskDisabled; if (myDecodes[myCounter] && !myResmp) { myIsRendering = true; @@ -210,6 +215,13 @@ void Missile::tick(uInt8 hclock) if (++myCounter >= 160) myCounter = 0; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Missile::nextLine() +{ + myIsVisible = myIsRendering && (myRenderCounter >= 0); + collision = (myIsVisible && myIsEnabled) ? myCollisionMaskEnabled : myCollisionMaskDisabled; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Missile::setColor(uInt8 color) { diff --git a/src/emucore/tia/Missile.hxx b/src/emucore/tia/Missile.hxx index c89b9f40a..36886845c 100644 --- a/src/emucore/tia/Missile.hxx +++ b/src/emucore/tia/Missile.hxx @@ -52,6 +52,8 @@ class Missile : public Serializable void tick(uInt8 hclock); + void nextLine(); + void setColor(uInt8 color); void setDebugColor(uInt8 color); @@ -103,6 +105,7 @@ class Missile : public Serializable uInt8 myLastMovementTick; bool myIsRendering; + bool myIsVisible; Int8 myRenderCounter; const uInt8* myDecodes; diff --git a/src/emucore/tia/Player.cxx b/src/emucore/tia/Player.cxx index 480707f1f..9b137a433 100644 --- a/src/emucore/tia/Player.cxx +++ b/src/emucore/tia/Player.cxx @@ -67,6 +67,11 @@ void Player::grp(uInt8 pattern) if (!myIsDelaying && myPatternNew != oldPatternNew) { myTIA->flushLineCache(); updatePattern(); + + if (myIsRendering && myRenderCounter >= myRenderCounterTripPoint) { + collision = (myPattern & (1 << mySampleCounter)) ? myCollisionMaskEnabled : myCollisionMaskDisabled; + myTIA->updateCollision(); + } } } @@ -309,6 +314,15 @@ void Player::tick() if (++myCounter >= 160) myCounter = 0; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Player::nextLine() +{ + if (!myIsRendering || myRenderCounter < myRenderCounterTripPoint) + collision = myCollisionMaskDisabled; + else + collision = (myPattern & (1 << mySampleCounter)) ? myCollisionMaskEnabled : myCollisionMaskDisabled; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Player::shufflePatterns() { diff --git a/src/emucore/tia/Player.hxx b/src/emucore/tia/Player.hxx index 60b025e31..78a59e37a 100644 --- a/src/emucore/tia/Player.hxx +++ b/src/emucore/tia/Player.hxx @@ -62,6 +62,9 @@ class Player : public Serializable bool movementTick(uInt32 clock, bool apply); void tick(); + + void nextLine(); + uInt8 getClock() const { return myCounter; } bool isOn() const { return (collision & 0x8000); } diff --git a/src/emucore/tia/TIA.cxx b/src/emucore/tia/TIA.cxx index 889524697..da5fbba28 100644 --- a/src/emucore/tia/TIA.cxx +++ b/src/emucore/tia/TIA.cxx @@ -1280,6 +1280,11 @@ void TIA::nextLine() myHctrDelta = 0; myFrameManager->nextLine(); + myMissile0.nextLine(); + myMissile1.nextLine(); + myPlayer0.nextLine(); + myPlayer1.nextLine(); + myBall.nextLine(); if (myFrameManager->isRendering() && myFrameManager->getY() == 0) flushLineCache(); diff --git a/src/emucore/tia/TIA.hxx b/src/emucore/tia/TIA.hxx index 84e2b8a06..37e3af293 100644 --- a/src/emucore/tia/TIA.hxx +++ b/src/emucore/tia/TIA.hxx @@ -414,6 +414,11 @@ class TIA : public Device */ void flushLineCache(); + /** + * Update the collision bitfield. + */ + void updateCollision(); + /** Create a new delayQueueIterator for the debugger. */ @@ -510,11 +515,6 @@ class TIA : public Device */ void applyRsync(); - /** - * Update the collision bitfield. - */ - void updateCollision(); - /** * Render the current pixel into the framebuffer. */