From 7d7c0f6c9ea52921e7711f9a12c75727d6c4dcf7 Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Sun, 18 Dec 2016 22:47:24 +0100 Subject: [PATCH] Refine and unify late RESx during hblank, comments. --- src/emucore/tia/Ball.cxx | 4 ++-- src/emucore/tia/Ball.hxx | 2 +- src/emucore/tia/Missile.cxx | 4 ++-- src/emucore/tia/Missile.hxx | 2 +- src/emucore/tia/Player.cxx | 8 ++++++-- src/emucore/tia/Player.hxx | 2 +- src/emucore/tia/TIA.cxx | 28 +++++++++++++++++++++++----- src/emucore/tia/TIA.hxx | 2 ++ 8 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/emucore/tia/Ball.cxx b/src/emucore/tia/Ball.cxx index 7cd37d694..3f6a1b0d1 100644 --- a/src/emucore/tia/Ball.cxx +++ b/src/emucore/tia/Ball.cxx @@ -69,9 +69,9 @@ void Ball::hmbl(uInt8 value) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Ball::resbl(bool hblank, bool extendedHblank) +void Ball::resbl(uInt8 counter) { - myCounter = hblank ? (extendedHblank ? 158 : 159) : 157; + myCounter = counter; myIsRendering = true; myRenderCounter = Count::renderCounterOffset; diff --git a/src/emucore/tia/Ball.hxx b/src/emucore/tia/Ball.hxx index 7f9468445..9c3b1c724 100644 --- a/src/emucore/tia/Ball.hxx +++ b/src/emucore/tia/Ball.hxx @@ -39,7 +39,7 @@ class Ball : public Serializable void hmbl(uInt8 value); uInt8 hmbl() const { return myHmmClocks; } - void resbl(bool hblank, bool extendedHblank); + void resbl(uInt8 counter); void ctrlpf(uInt8 value); diff --git a/src/emucore/tia/Missile.cxx b/src/emucore/tia/Missile.cxx index 4c7cff39a..d08a1da05 100644 --- a/src/emucore/tia/Missile.cxx +++ b/src/emucore/tia/Missile.cxx @@ -69,9 +69,9 @@ void Missile::hmm(uInt8 value) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Missile::resm(bool hblank, bool extendedHblank) +void Missile::resm(uInt8 counter) { - myCounter = hblank ? (extendedHblank ? 158 : 159) : 157; + myCounter = counter; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/tia/Missile.hxx b/src/emucore/tia/Missile.hxx index c8ea58c0d..ca828f8b5 100644 --- a/src/emucore/tia/Missile.hxx +++ b/src/emucore/tia/Missile.hxx @@ -39,7 +39,7 @@ class Missile : public Serializable void hmm(uInt8 value); uInt32 hmm() const { return myHmmClocks; } - void resm(bool hblank, bool extendHblank); + void resm(uInt8 counter); void resmp(uInt8 value, const Player& player); bool resmp() const { return bool(myResmp); } diff --git a/src/emucore/tia/Player.cxx b/src/emucore/tia/Player.cxx index 005e9d7ca..cd45e0b06 100644 --- a/src/emucore/tia/Player.cxx +++ b/src/emucore/tia/Player.cxx @@ -88,6 +88,8 @@ void Player::nusiz(uInt8 value) if (myIsRendering && myRenderCounter >= myWidth) myIsRendering = false; + // NUSIZ during decode seems to affect the decoding logic. The rods in Meltdown + // are highly sensitive to this effect, and this seems to model it adequately. if (myIsRendering && myRenderCounter < 0 && myWidth > 8 && oldWidth == 8) myRenderCounter += (myRenderCounter < -2 ? -1 : 1); @@ -95,12 +97,14 @@ void Player::nusiz(uInt8 value) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -void Player::resp(bool hblank, bool extendedHblank) +void Player::resp(uInt8 counter) { - myCounter = hblank ? (extendedHblank ? 158 : 159) : 157; + myCounter = counter; const Int8 renderCounterOffset = myWidth > 8 ? Count::renderCounterOffsetWide : Count::renderCounterOffset; + // This tries to account for the effects of RESP during draw counter decode as + // described in Andrew Towers' notes. Still room for tuning.' if (myIsRendering && (myRenderCounter - renderCounterOffset) < 4) myRenderCounter = renderCounterOffset; } diff --git a/src/emucore/tia/Player.hxx b/src/emucore/tia/Player.hxx index 2883d6ba7..6f82b4a6e 100644 --- a/src/emucore/tia/Player.hxx +++ b/src/emucore/tia/Player.hxx @@ -40,7 +40,7 @@ class Player : public Serializable void nusiz(uInt8 value); - void resp(bool hblank, bool extendedHblank); + void resp(uInt8 counter); void refp(uInt8 value); bool refp() const { return myIsReflected; } diff --git a/src/emucore/tia/TIA.cxx b/src/emucore/tia/TIA.cxx index aa2b74d9c..423fe3063 100644 --- a/src/emucore/tia/TIA.cxx +++ b/src/emucore/tia/TIA.cxx @@ -57,6 +57,17 @@ enum DummyRegisters: uInt8 { shuffleBL = 0xF2 }; +enum ResxCounter: uInt8 { + hblank = 159, + lateHblank = 158, + frame = 157 +}; + +// This parameter still has room for tuning. If we go lower than 73, long005 will show +// a slight artifact (still have to crosscheck on real hardware), if we go lower than +// 70, the G.I. Joe will show an artifact (hole in roof). +static constexpr uInt8 resxLateHblankThreshold = 73; + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TIA::TIA(Console& console, Sound& sound, Settings& settings) : myConsole(console), @@ -451,12 +462,12 @@ bool TIA::poke(uInt16 address, uInt8 value) case RESM0: myLinesSinceChange = 0; - myMissile0.resm(myHstate == HState::blank, myHctr >= 68); + myMissile0.resm(resxCounter()); break; case RESM1: myLinesSinceChange = 0; - myMissile1.resm(myHstate == HState::blank, myHctr >= 68); + myMissile1.resm(resxCounter()); break; case RESMP0: @@ -520,12 +531,12 @@ bool TIA::poke(uInt16 address, uInt8 value) case RESP0: myLinesSinceChange = 0; - myPlayer0.resp(myHstate == HState::blank, myHctr >= 68); + myPlayer0.resp(resxCounter()); break; case RESP1: myLinesSinceChange = 0; - myPlayer1.resp(myHstate == HState::blank, myHctr >= 68); + myPlayer1.resp(resxCounter()); break; case REFP0: @@ -560,7 +571,7 @@ bool TIA::poke(uInt16 address, uInt8 value) case RESBL: myLinesSinceChange = 0; - myBall.resbl(myHstate == HState::blank, myHctr >= 68); + myBall.resbl(resxCounter()); break; case VDELBL: @@ -1235,6 +1246,13 @@ void TIA::updatePaddle(uInt8 idx) myTimestamp, myFrameManager.tvMode()); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt8 TIA::resxCounter() +{ + return myHstate == HState::blank ? + (myHctr >= resxLateHblankThreshold ? ResxCounter::lateHblank : ResxCounter::hblank) : ResxCounter::frame; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt8 TIA::collCXM0P() const { diff --git a/src/emucore/tia/TIA.hxx b/src/emucore/tia/TIA.hxx index 32c59488a..10866b86d 100644 --- a/src/emucore/tia/TIA.hxx +++ b/src/emucore/tia/TIA.hxx @@ -380,6 +380,8 @@ class TIA : public Device void updatePaddle(uInt8 idx); + uInt8 resxCounter(); + /** Get the result of the specified collision register. */