From a1eb8fd9abb96e0dfff8074858f17f9d3074a10f Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Fri, 2 Dec 2016 08:58:19 +0100 Subject: [PATCH] Add toggle logic to all sprites. --- src/emucore/tia/core_6502ts/Ball.cxx | 28 +++++++++++++--- src/emucore/tia/core_6502ts/Ball.hxx | 10 ++++-- src/emucore/tia/core_6502ts/Missile.cxx | 3 ++ src/emucore/tia/core_6502ts/Player.cxx | 28 ++++++++++++++-- src/emucore/tia/core_6502ts/Player.hxx | 11 ++++-- src/emucore/tia/core_6502ts/Playfield.cxx | 41 +++++++++++++++++++---- src/emucore/tia/core_6502ts/Playfield.hxx | 15 +++++++-- src/emucore/tia/core_6502ts/TIA.cxx | 12 ++++--- 8 files changed, 124 insertions(+), 24 deletions(-) diff --git a/src/emucore/tia/core_6502ts/Ball.cxx b/src/emucore/tia/core_6502ts/Ball.cxx index 588b8e829..02267909a 100644 --- a/src/emucore/tia/core_6502ts/Ball.cxx +++ b/src/emucore/tia/core_6502ts/Ball.cxx @@ -26,7 +26,9 @@ namespace TIA6502tsCore { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Ball::Ball(uInt32 collisionMask) - : myCollisionMask(collisionMask) + : myCollisionMaskDisabled(collisionMask), + myCollisionMaskEnabled(0x8000), + mySupressed(false) { reset(); } @@ -35,7 +37,7 @@ Ball::Ball(uInt32 collisionMask) void Ball::reset() { myColor = 0; - collision = myCollisionMask; + collision = myCollisionMaskDisabled; myEnabledOld = false; myEnabledNew = false; myEnabled = false; @@ -46,6 +48,8 @@ void Ball::reset() myWidth = 1; myIsRendering = false; myRenderCounter = 0; + + updateEnabled(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -85,6 +89,20 @@ void Ball::vdelbl(uInt8 value) updateEnabled(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Ball::toggleCollisions(bool enabled) +{ + myCollisionMaskEnabled = enabled ? 0x8000 : (0x8000 | myCollisionMaskDisabled); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Ball::toggleEnabled(bool enabled) +{ + mySupressed = !enabled; + + updateEnabled(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Ball::setColor(uInt8 color) { @@ -113,7 +131,9 @@ bool Ball::movementTick(uInt32 clock, bool apply) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Ball::render() { - collision = (myIsRendering && myRenderCounter >= 0 && myEnabled) ? 0 : myCollisionMask; + collision = (myIsRendering && myRenderCounter >= 0 && myEnabled) ? + myCollisionMaskEnabled : + myCollisionMaskDisabled; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -140,7 +160,7 @@ void Ball::shuffleStatus() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Ball::updateEnabled() { - myEnabled = myIsDelaying ? myEnabledOld : myEnabledNew; + myEnabled = !mySupressed && (myIsDelaying ? myEnabledOld : myEnabledNew); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/tia/core_6502ts/Ball.hxx b/src/emucore/tia/core_6502ts/Ball.hxx index aee1aadc9..b3932360b 100644 --- a/src/emucore/tia/core_6502ts/Ball.hxx +++ b/src/emucore/tia/core_6502ts/Ball.hxx @@ -45,6 +45,10 @@ class Ball : public Serializable void vdelbl(uInt8 value); + void toggleCollisions(bool enabled); + + void toggleEnabled(bool enabled); + void setColor(uInt8 color); void startMovement(); @@ -56,7 +60,7 @@ class Ball : public Serializable void tick(); uInt8 getPixel(uInt8 colorIn) const { - return collision > 0 ? colorIn : myColor; + return (collision & 0x8000) ? myColor : colorIn; } void shuffleStatus(); @@ -78,13 +82,15 @@ class Ball : public Serializable private: - uInt32 myCollisionMask; + uInt32 myCollisionMaskDisabled; + uInt32 myCollisionMaskEnabled; uInt8 myColor; bool myEnabledOld; bool myEnabledNew; bool myEnabled; + bool mySupressed; bool myIsDelaying; uInt8 myHmmClocks; diff --git a/src/emucore/tia/core_6502ts/Missile.cxx b/src/emucore/tia/core_6502ts/Missile.cxx index 05b96df69..6559648f2 100644 --- a/src/emucore/tia/core_6502ts/Missile.cxx +++ b/src/emucore/tia/core_6502ts/Missile.cxx @@ -50,6 +50,8 @@ void Missile::reset() myRenderCounter = 0; myColor = 0; collision = myCollisionMaskDisabled; + + updateEnabled(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -91,6 +93,7 @@ void Missile::toggleCollisions(bool enabled) myCollisionMaskEnabled = enabled ? 0x8000 : (0x8000 | myCollisionMaskDisabled); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Missile::toggleEnabled(bool enabled) { mySupressed = !enabled; diff --git a/src/emucore/tia/core_6502ts/Player.cxx b/src/emucore/tia/core_6502ts/Player.cxx index 59409c163..0fd6d199e 100644 --- a/src/emucore/tia/core_6502ts/Player.cxx +++ b/src/emucore/tia/core_6502ts/Player.cxx @@ -28,7 +28,9 @@ namespace TIA6502tsCore { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Player::Player(uInt32 collisionMask) - : myCollisionMask(collisionMask) + : myCollisionMaskDisabled(collisionMask), + myCollisionMaskEnabled(0x8000), + mySupressed(false) { reset(); } @@ -48,7 +50,9 @@ void Player::reset() myPattern = 0; myIsReflected = 0; myIsDelaying = false; - collision = myCollisionMask; + collision = myCollisionMaskDisabled; + + updatePattern(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -112,6 +116,19 @@ void Player::vdelp(uInt8 value) if (myIsDelaying != oldIsDelaying) updatePattern(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Player::toggleEnabled(bool enabled) +{ + mySupressed = !enabled; + updatePattern(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Player::toggleCollisions(bool enabled) +{ + myCollisionMaskEnabled = enabled ? 0x8000 : (0x8000 | myCollisionMaskDisabled); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Player::setColor(uInt8 color) { @@ -146,7 +163,7 @@ void Player::render() myIsRendering && myRenderCounter >= 0 && (myPattern & (1 << (myWidth - myRenderCounter - 1))) - ) ? 0 : myCollisionMask; + ) ? myCollisionMaskEnabled : myCollisionMaskDisabled; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -194,6 +211,11 @@ uInt8 Player::getRespClock() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Player::updatePattern() { + if (mySupressed) { + myPattern = 0; + return; +} + const uInt32 pattern = myIsDelaying ? myPatternOld : myPatternNew; switch (myWidth) diff --git a/src/emucore/tia/core_6502ts/Player.hxx b/src/emucore/tia/core_6502ts/Player.hxx index ba16026fc..ca38c637a 100644 --- a/src/emucore/tia/core_6502ts/Player.hxx +++ b/src/emucore/tia/core_6502ts/Player.hxx @@ -46,6 +46,10 @@ class Player : public Serializable void vdelp(uInt8 value); + void toggleEnabled(bool enabled); + + void toggleCollisions(bool enabled); + void setColor(uInt8 color); void startMovement(); @@ -57,7 +61,7 @@ class Player : public Serializable void tick(); uInt8 getPixel(uInt8 colorIn) const { - return collision ? colorIn : myColor; + return (collision & 0x8000) ? myColor : colorIn; } void shufflePatterns(); @@ -81,9 +85,12 @@ class Player : public Serializable private: - uInt32 myCollisionMask; + uInt32 myCollisionMaskDisabled; + uInt32 myCollisionMaskEnabled; uInt8 myColor; + bool mySupressed; + uInt8 myHmmClocks; uInt8 myCounter; bool myIsMoving; diff --git a/src/emucore/tia/core_6502ts/Playfield.cxx b/src/emucore/tia/core_6502ts/Playfield.cxx index 9fad3b1c3..9a8cb8d5a 100644 --- a/src/emucore/tia/core_6502ts/Playfield.cxx +++ b/src/emucore/tia/core_6502ts/Playfield.cxx @@ -23,7 +23,9 @@ namespace TIA6502tsCore { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Playfield::Playfield(uInt32 collisionMask) - : myCollisionMask(collisionMask) + : myCollisionMaskDisabled(collisionMask), + myCollisionMaskEnabled(0x8000), + mySupressed(false) { reset(); } @@ -47,12 +49,15 @@ void Playfield::reset() collision = 0; applyColors(); + updatePattern(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Playfield::pf0(uInt8 value) { myPattern = (myPattern & 0x000FFFF0) | (value >> 4); + + updatePattern(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -67,12 +72,16 @@ void Playfield::pf1(uInt8 value) | ((value & 0x04) << 7) | ((value & 0x02) << 9) | ((value & 0x01) << 11); + + updatePattern(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Playfield::pf2(uInt8 value) { myPattern = (myPattern & 0x00000FFF) | (value << 12); + + updatePattern(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -83,6 +92,20 @@ void Playfield::ctrlpf(uInt8 value) applyColors(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Playfield::toggleEnabled(bool enabled) +{ + mySupressed = !enabled; + + updatePattern(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Playfield::toggleCollisions(bool enabled) +{ + myCollisionMaskEnabled = enabled ? 0x8000 : (0x8000 | myCollisionMaskDisabled); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Playfield::setColor(uInt8 color) { @@ -115,17 +138,17 @@ void Playfield::tick(uInt32 x) uInt32 currentPixel; - if (myPattern == 0) { + if (myEffectivePattern == 0) { currentPixel = 0; } else if (x < 80) { - currentPixel = myPattern & (1 << (x >> 2)); + currentPixel = myEffectivePattern & (1 << (x >> 2)); } else if (myRefp) { - currentPixel = myPattern & (1 << (39 - (x >> 2))); + currentPixel = myEffectivePattern & (1 << (39 - (x >> 2))); } else { - currentPixel = myPattern & (1 << ((x >> 2) - 20)); + currentPixel = myEffectivePattern & (1 << ((x >> 2) - 20)); } - collision = currentPixel ? 0 : myCollisionMask; + collision = currentPixel ? myCollisionMaskEnabled : myCollisionMaskDisabled; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -144,6 +167,12 @@ void Playfield::applyColors() } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Playfield::updatePattern() +{ + myEffectivePattern = mySupressed ? 0 : myPattern; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // TODO: implement this once the class is finalized bool Playfield::save(Serializer& out) const diff --git a/src/emucore/tia/core_6502ts/Playfield.hxx b/src/emucore/tia/core_6502ts/Playfield.hxx index de95b6903..e8efd3f4b 100644 --- a/src/emucore/tia/core_6502ts/Playfield.hxx +++ b/src/emucore/tia/core_6502ts/Playfield.hxx @@ -42,6 +42,10 @@ class Playfield : public Serializable void ctrlpf(uInt8 value); + void toggleEnabled(bool enabled); + + void toggleCollisions(bool enabled); + void setColor(uInt8 color); void setColorP0(uInt8 color); @@ -51,7 +55,7 @@ class Playfield : public Serializable void tick(uInt32 x); uInt8 getPixel(uInt8 colorIn) const { - if (!collision) return myX < 80 ? myColorLeft : myColorRight; + if (collision & 0x8000) return myX < 80 ? myColorLeft : myColorRight; return colorIn; } @@ -73,9 +77,15 @@ class Playfield : public Serializable private: void applyColors(); + void updatePattern(); private: + uInt32 myCollisionMaskDisabled; + uInt32 myCollisionMaskEnabled; + + bool mySupressed; + uInt8 myColorLeft; uInt8 myColorRight; uInt8 myColorP0; @@ -84,6 +94,7 @@ class Playfield : public Serializable ColorMode myColorMode; uInt32 myPattern; + uInt32 myEffectivePattern; bool myRefp; bool myReflected; @@ -93,8 +104,6 @@ class Playfield : public Serializable uInt32 myX; - uInt32 myCollisionMask; - private: Playfield() = delete; Playfield(const Playfield&) = delete; diff --git a/src/emucore/tia/core_6502ts/TIA.cxx b/src/emucore/tia/core_6502ts/TIA.cxx index 13aaa7128..003baa042 100644 --- a/src/emucore/tia/core_6502ts/TIA.cxx +++ b/src/emucore/tia/core_6502ts/TIA.cxx @@ -649,7 +649,6 @@ bool TIA::scanlinePos(uInt16& x, uInt16& y) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// TODO: stub bool TIA::toggleBit(TIABit b, uInt8 mode) { uInt8 mask; @@ -672,12 +671,15 @@ bool TIA::toggleBit(TIABit b, uInt8 mode) myMissile0.toggleEnabled(mySpriteEnabledBits & TIABit::M0Bit); myMissile1.toggleEnabled(mySpriteEnabledBits & TIABit::M1Bit); + myPlayer0.toggleEnabled(mySpriteEnabledBits & TIABit::P0Bit); + myPlayer1.toggleEnabled(mySpriteEnabledBits & TIABit::P1Bit); + myBall.toggleEnabled(mySpriteEnabledBits & TIABit::BLBit); + myPlayfield.toggleEnabled(mySpriteEnabledBits & TIABit::PFBit); return mask; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// TODO: stub bool TIA::toggleBits() { toggleBit(TIABit(0xFF), mySpriteEnabledBits > 0 ? 0 : 1); @@ -686,7 +688,6 @@ bool TIA::toggleBits() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// TODO: stub bool TIA::toggleCollision(TIABit b, uInt8 mode) { uInt8 mask; @@ -709,12 +710,15 @@ bool TIA::toggleCollision(TIABit b, uInt8 mode) myMissile0.toggleCollisions(myCollisionsEnabledBits & TIABit::M0Bit); myMissile1.toggleCollisions(myCollisionsEnabledBits & TIABit::M1Bit); + myPlayer0.toggleCollisions(myCollisionsEnabledBits & TIABit::P0Bit); + myPlayer1.toggleCollisions(myCollisionsEnabledBits & TIABit::P1Bit); + myBall.toggleCollisions(myCollisionsEnabledBits & TIABit::BLBit); + myPlayfield.toggleCollisions(myCollisionsEnabledBits & TIABit::PFBit); return mask; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// TODO: stub bool TIA::toggleCollisions() { toggleCollision(TIABit(0xFF), myCollisionsEnabledBits > 0 ? 0 : 1);