diff --git a/src/emucore/tia/Ball.hxx b/src/emucore/tia/Ball.hxx index 654f08b06..274206827 100644 --- a/src/emucore/tia/Ball.hxx +++ b/src/emucore/tia/Ball.hxx @@ -82,60 +82,9 @@ class Ball : public Serializable bool save(Serializer& out) const override; bool load(Serializer& in) override; - void movementTick(uInt32 clock, bool hblank) - { - myLastMovementTick = myCounter; + inline void movementTick(uInt32 clock, bool hblank); - if (clock == myHmmClocks) - isMoving = false; - - if(isMoving) - { - if (hblank) tick(false); - myInvertedPhaseClock = !hblank; - } - } - - void tick(bool isReceivingMclock = true) - { - if(myUseInvertedPhaseClock && myInvertedPhaseClock) - { - myInvertedPhaseClock = false; - return; - } - - myIsVisible = myIsRendering && myRenderCounter >= 0; - collision = (myIsVisible && myIsEnabled) ? myCollisionMaskEnabled : myCollisionMaskDisabled; - - bool starfieldEffect = isMoving && isReceivingMclock; - - if (myCounter == 156) { - myIsRendering = true; - myRenderCounter = renderCounterOffset; - - uInt8 starfieldDelta = (myCounter + TIAConstants::H_PIXEL - myLastMovementTick) % 4; - if (starfieldEffect && starfieldDelta == 3 && myWidth < 4) ++myRenderCounter; - - switch (starfieldDelta) { - case 3: - myEffectiveWidth = myWidth == 1 ? 2 : myWidth; - break; - - case 2: - myEffectiveWidth = 0; - break; - - default: - myEffectiveWidth = myWidth; - break; - } - - } else if (myIsRendering && ++myRenderCounter >= (starfieldEffect ? myEffectiveWidth : myWidth)) - myIsRendering = false; - - if (++myCounter >= TIAConstants::H_PIXEL) - myCounter = 0; - } + inline void tick(bool isReceivingMclock = true); public: @@ -191,4 +140,65 @@ class Ball : public Serializable Ball& operator=(Ball&&); }; +// ############################################################################ +// Implementation +// ############################################################################ + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Ball::movementTick(uInt32 clock, bool hblank) +{ + myLastMovementTick = myCounter; + + if (clock == myHmmClocks) + isMoving = false; + + if(isMoving) + { + if (hblank) tick(false); + myInvertedPhaseClock = !hblank; + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Ball::tick(bool isReceivingMclock) +{ + if(myUseInvertedPhaseClock && myInvertedPhaseClock) + { + myInvertedPhaseClock = false; + return; + } + + myIsVisible = myIsRendering && myRenderCounter >= 0; + collision = (myIsVisible && myIsEnabled) ? myCollisionMaskEnabled : myCollisionMaskDisabled; + + bool starfieldEffect = isMoving && isReceivingMclock; + + if (myCounter == 156) { + myIsRendering = true; + myRenderCounter = renderCounterOffset; + + uInt8 starfieldDelta = (myCounter + TIAConstants::H_PIXEL - myLastMovementTick) % 4; + if (starfieldEffect && starfieldDelta == 3 && myWidth < 4) ++myRenderCounter; + + switch (starfieldDelta) { + case 3: + myEffectiveWidth = myWidth == 1 ? 2 : myWidth; + break; + + case 2: + myEffectiveWidth = 0; + break; + + default: + myEffectiveWidth = myWidth; + break; + } + + } else if (myIsRendering && ++myRenderCounter >= (starfieldEffect ? myEffectiveWidth : myWidth)) + myIsRendering = false; + + if (++myCounter >= TIAConstants::H_PIXEL) + myCounter = 0; +} + #endif // TIA_BALL diff --git a/src/emucore/tia/Missile.hxx b/src/emucore/tia/Missile.hxx index 2cfc0408b..0edf68e2a 100644 --- a/src/emucore/tia/Missile.hxx +++ b/src/emucore/tia/Missile.hxx @@ -76,62 +76,9 @@ class Missile : public Serializable bool save(Serializer& out) const override; bool load(Serializer& in) override; - void movementTick(uInt8 clock, uInt8 hclock, bool hblank) - { - if(clock == myHmmClocks) isMoving = false; + inline void movementTick(uInt8 clock, uInt8 hclock, bool hblank); - if (isMoving) - { - if (hblank) tick(hclock, false); - myInvertedPhaseClock = !hblank; - } - } - - void tick(uInt8 hclock, bool isReceivingMclock = true) - { - if(myUseInvertedPhaseClock && myInvertedPhaseClock) - { - myInvertedPhaseClock = false; - return; - } - - myIsVisible = - myIsRendering && - (myRenderCounter >= 0 || (isMoving && isReceivingMclock && myRenderCounter == -1 && myWidth < 4 && ((hclock + 1) % 4 == 3))); - - collision = (myIsVisible && myIsEnabled) ? myCollisionMaskEnabled : myCollisionMaskDisabled; - - if (myDecodes[myCounter] && !myResmp) { - myIsRendering = true; - myRenderCounter = renderCounterOffset; - } else if (myIsRendering) { - - if (myRenderCounter == -1) { - if (isMoving && isReceivingMclock) { - switch ((hclock + 1) % 4) { - case 3: - myEffectiveWidth = myWidth == 1 ? 2 : myWidth; - if (myWidth < 4) ++myRenderCounter; - break; - - case 2: - myEffectiveWidth = 0; - break; - - default: - myEffectiveWidth = myWidth; - break; - } - } else { - myEffectiveWidth = myWidth; - } - } - - if (++myRenderCounter >= (isMoving ? myEffectiveWidth : myWidth)) myIsRendering = false; - } - - if (++myCounter >= TIAConstants::H_PIXEL) myCounter = 0; - } + inline void tick(uInt8 hclock, bool isReceivingMclock = true); public: @@ -188,4 +135,67 @@ class Missile : public Serializable Missile& operator=(Missile&&) = delete; }; +// ############################################################################ +// Implementation +// ############################################################################ + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Missile::movementTick(uInt8 clock, uInt8 hclock, bool hblank) +{ + if(clock == myHmmClocks) isMoving = false; + + if (isMoving) + { + if (hblank) tick(hclock, false); + myInvertedPhaseClock = !hblank; + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Missile::tick(uInt8 hclock, bool isReceivingMclock) +{ + if(myUseInvertedPhaseClock && myInvertedPhaseClock) + { + myInvertedPhaseClock = false; + return; + } + + myIsVisible = + myIsRendering && + (myRenderCounter >= 0 || (isMoving && isReceivingMclock && myRenderCounter == -1 && myWidth < 4 && ((hclock + 1) % 4 == 3))); + + collision = (myIsVisible && myIsEnabled) ? myCollisionMaskEnabled : myCollisionMaskDisabled; + + if (myDecodes[myCounter] && !myResmp) { + myIsRendering = true; + myRenderCounter = renderCounterOffset; + } else if (myIsRendering) { + + if (myRenderCounter == -1) { + if (isMoving && isReceivingMclock) { + switch ((hclock + 1) % 4) { + case 3: + myEffectiveWidth = myWidth == 1 ? 2 : myWidth; + if (myWidth < 4) ++myRenderCounter; + break; + + case 2: + myEffectiveWidth = 0; + break; + + default: + myEffectiveWidth = myWidth; + break; + } + } else { + myEffectiveWidth = myWidth; + } + } + + if (++myRenderCounter >= (isMoving ? myEffectiveWidth : myWidth)) myIsRendering = false; + } + + if (++myCounter >= TIAConstants::H_PIXEL) myCounter = 0; +} + #endif // TIA_MISSILE diff --git a/src/emucore/tia/Player.hxx b/src/emucore/tia/Player.hxx index dab8fe9f2..d44432f64 100644 --- a/src/emucore/tia/Player.hxx +++ b/src/emucore/tia/Player.hxx @@ -87,63 +87,9 @@ class Player : public Serializable bool save(Serializer& out) const override; bool load(Serializer& in) override; - void movementTick(uInt32 clock, bool hblank) - { - if (clock == myHmmClocks) - isMoving = false; + inline void movementTick(uInt32 clock, bool hblank); - if(isMoving) - { - if (hblank) tick(); - myInvertedPhaseClock = !hblank; - } - } - - void tick() - { - if(myUseInvertedPhaseClock && myInvertedPhaseClock) - { - myInvertedPhaseClock = false; - return; - } - - if (!myIsRendering || myRenderCounter < myRenderCounterTripPoint) - collision = myCollisionMaskDisabled; - else - collision = (myPattern & (1 << mySampleCounter)) ? myCollisionMaskEnabled : myCollisionMaskDisabled; - - if (myDecodes[myCounter]) { - myIsRendering = true; - mySampleCounter = 0; - myRenderCounter = renderCounterOffset; - } else if (myIsRendering) { - ++myRenderCounter; - - switch (myDivider) { - case 1: - if (myRenderCounter > 0) - ++mySampleCounter; - - if (myRenderCounter >= 0 && myDividerChangeCounter >= 0 && myDividerChangeCounter-- == 0) - setDivider(myDividerPending); - - break; - - default: - if (myRenderCounter > 1 && (((myRenderCounter - 1) % myDivider) == 0)) - ++mySampleCounter; - - if (myRenderCounter > 0 && myDividerChangeCounter >= 0 && myDividerChangeCounter-- == 0) - setDivider(myDividerPending); - - break; - } - - if (mySampleCounter > 7) myIsRendering = false; - } - - if (++myCounter >= TIAConstants::H_PIXEL) myCounter = 0; - } + inline void tick(); public: @@ -205,4 +151,68 @@ class Player : public Serializable Player& operator=(Player&&) = delete; }; +// ############################################################################ +// Implementation +// ############################################################################ + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Player::movementTick(uInt32 clock, bool hblank) +{ + if (clock == myHmmClocks) + isMoving = false; + + if(isMoving) + { + if (hblank) tick(); + myInvertedPhaseClock = !hblank; + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Player::tick() +{ + if(myUseInvertedPhaseClock && myInvertedPhaseClock) + { + myInvertedPhaseClock = false; + return; + } + + if (!myIsRendering || myRenderCounter < myRenderCounterTripPoint) + collision = myCollisionMaskDisabled; + else + collision = (myPattern & (1 << mySampleCounter)) ? myCollisionMaskEnabled : myCollisionMaskDisabled; + + if (myDecodes[myCounter]) { + myIsRendering = true; + mySampleCounter = 0; + myRenderCounter = renderCounterOffset; + } else if (myIsRendering) { + ++myRenderCounter; + + switch (myDivider) { + case 1: + if (myRenderCounter > 0) + ++mySampleCounter; + + if (myRenderCounter >= 0 && myDividerChangeCounter >= 0 && myDividerChangeCounter-- == 0) + setDivider(myDividerPending); + + break; + + default: + if (myRenderCounter > 1 && (((myRenderCounter - 1) % myDivider) == 0)) + ++mySampleCounter; + + if (myRenderCounter > 0 && myDividerChangeCounter >= 0 && myDividerChangeCounter-- == 0) + setDivider(myDividerPending); + + break; + } + + if (mySampleCounter > 7) myIsRendering = false; + } + + if (++myCounter >= TIAConstants::H_PIXEL) myCounter = 0; +} + #endif // TIA_PLAYER diff --git a/src/emucore/tia/Playfield.hxx b/src/emucore/tia/Playfield.hxx index 945139bd0..5bc0b547b 100644 --- a/src/emucore/tia/Playfield.hxx +++ b/src/emucore/tia/Playfield.hxx @@ -127,31 +127,9 @@ class Playfield : public Serializable bool load(Serializer& in) override; /** - Tick one color clock. Inline for performance. + Tick one color clock. Inline for performance (implementation below). */ - void tick(uInt32 x) - { - myX = x; - - // Reflected flag is updated only at x = 0 or x = 79 - if (myX == TIAConstants::H_PIXEL / 2 || myX == 0) myRefp = myReflected; - - if (x & 0x03) return; - - uInt32 currentPixel; - - if (myEffectivePattern == 0) { - currentPixel = 0; - } else if (x < TIAConstants::H_PIXEL / 2) { - currentPixel = myEffectivePattern & (1 << (x >> 2)); - } else if (myRefp) { - currentPixel = myEffectivePattern & (1 << (39 - (x >> 2))); - } else { - currentPixel = myEffectivePattern & (1 << ((x >> 2) - 20)); - } - - collision = currentPixel ? myCollisionMaskEnabled : myCollisionMaskDisabled; - } + inline void tick(uInt32 x); public: @@ -268,4 +246,33 @@ class Playfield : public Serializable Playfield& operator=(Playfield&&) = delete; }; +// ############################################################################ +// Implementation +// ############################################################################ + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Playfield::tick(uInt32 x) +{ + myX = x; + + // Reflected flag is updated only at x = 0 or x = 79 + if (myX == TIAConstants::H_PIXEL / 2 || myX == 0) myRefp = myReflected; + + if (x & 0x03) return; + + uInt32 currentPixel; + + if (myEffectivePattern == 0) { + currentPixel = 0; + } else if (x < TIAConstants::H_PIXEL / 2) { + currentPixel = myEffectivePattern & (1 << (x >> 2)); + } else if (myRefp) { + currentPixel = myEffectivePattern & (1 << (39 - (x >> 2))); + } else { + currentPixel = myEffectivePattern & (1 << ((x >> 2) - 20)); + } + + collision = currentPixel ? myCollisionMaskEnabled : myCollisionMaskDisabled; +} + #endif // TIA_PLAYFIELD