From 920787aa9fb4e12bf271c8be6c6911fe38679465 Mon Sep 17 00:00:00 2001 From: Christian Speckner Date: Fri, 2 Dec 2016 01:11:54 +0100 Subject: [PATCH] Sprite toggeling for missiles. --- src/emucore/tia/core_6502ts/Missile.cxx | 39 ++++++++++++----- src/emucore/tia/core_6502ts/Missile.hxx | 14 ++++++- src/emucore/tia/core_6502ts/TIA.cxx | 56 +++++++++++++++++++++++-- src/emucore/tia/core_6502ts/TIA.hxx | 3 ++ 4 files changed, 96 insertions(+), 16 deletions(-) diff --git a/src/emucore/tia/core_6502ts/Missile.cxx b/src/emucore/tia/core_6502ts/Missile.cxx index 4dbbb1c48..05b96df69 100644 --- a/src/emucore/tia/core_6502ts/Missile.cxx +++ b/src/emucore/tia/core_6502ts/Missile.cxx @@ -28,7 +28,9 @@ namespace TIA6502tsCore { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Missile::Missile(uInt32 collisionMask) - : myCollisionMask(collisionMask) + : myCollisionMaskDisabled(collisionMask), + myCollisionMaskEnabled(0x8000), + mySupressed(false) { reset(); } @@ -47,14 +49,14 @@ void Missile::reset() myIsRendering = false; myRenderCounter = 0; myColor = 0; - collision = myCollisionMask; + collision = myCollisionMaskDisabled; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Missile::enam(uInt8 value) { myEnam = (value & 0x02) > 0; - myEnabled = myEnam && (myResmp == 0); + updateEnabled(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -78,12 +80,21 @@ void Missile::resmp(uInt8 value, const Player& player) myResmp = resmp; - if (myResmp) { - myEnabled = false; - } else { - myEnabled = myEnam; - myCounter = player.getRespClock(); - } + if (!myResmp) myCounter = player.getRespClock(); + + updateEnabled(); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Missile::toggleCollisions(bool enabled) +{ + myCollisionMaskEnabled = enabled ? 0x8000 : (0x8000 | myCollisionMaskDisabled); +} + +void Missile::toggleEnabled(bool enabled) +{ + mySupressed = !enabled; + updateEnabled(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -120,7 +131,9 @@ bool Missile::movementTick(uInt32 clock, bool apply) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Missile::render() { - collision = (myIsRendering && myRenderCounter >= 0 && myEnabled) ? 0 : myCollisionMask; + collision = (myIsRendering && myRenderCounter >= 0 && myEnabled) ? + myCollisionMaskEnabled : + myCollisionMaskDisabled; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -142,6 +155,12 @@ void Missile::setColor(uInt8 color) myColor = color; } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void Missile::updateEnabled() +{ + myEnabled = !mySupressed && myEnam && !myResmp; +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // TODO: implement this once the class is finalized bool Missile::save(Serializer& out) const diff --git a/src/emucore/tia/core_6502ts/Missile.hxx b/src/emucore/tia/core_6502ts/Missile.hxx index b05fde2b4..67abb55ca 100644 --- a/src/emucore/tia/core_6502ts/Missile.hxx +++ b/src/emucore/tia/core_6502ts/Missile.hxx @@ -55,8 +55,12 @@ class Missile : public Serializable void setColor(uInt8 color); + void toggleCollisions(bool enabled); + + void toggleEnabled(bool enabled); + uInt8 getPixel(uInt8 colorIn) const { - return collision ? colorIn : myColor; + return (collision & 0x8000) ? myColor : colorIn; } /** @@ -72,9 +76,15 @@ class Missile : public Serializable private: - uInt32 myCollisionMask; + void updateEnabled(); + + private: + + uInt32 myCollisionMaskDisabled; + uInt32 myCollisionMaskEnabled; bool myEnabled; + bool mySupressed; bool myEnam; uInt8 myResmp; diff --git a/src/emucore/tia/core_6502ts/TIA.cxx b/src/emucore/tia/core_6502ts/TIA.cxx index 4b50b849b..13aaa7128 100644 --- a/src/emucore/tia/core_6502ts/TIA.cxx +++ b/src/emucore/tia/core_6502ts/TIA.cxx @@ -56,6 +56,8 @@ TIA::TIA(Console& console, Sound& sound, Settings& settings) mySound(sound), mySettings(settings), myDelayQueue(10, 20), + mySpriteEnabledBits(0xFF), + myCollisionsEnabledBits(0xFF), myPlayfield(CollisionMask::playfield), myMissile0(CollisionMask::missile0), myMissile1(CollisionMask::missile1), @@ -650,28 +652,74 @@ bool TIA::scanlinePos(uInt16& x, uInt16& y) const // TODO: stub bool TIA::toggleBit(TIABit b, uInt8 mode) { - return false; + uInt8 mask; + + switch (mode) { + case 0: + mask = 0; + break; + + case 1: + mask = b; + break; + + default: + mask = (~mySpriteEnabledBits & b); + break; + } + + mySpriteEnabledBits = (mySpriteEnabledBits & ~b) | mask; + + myMissile0.toggleEnabled(mySpriteEnabledBits & TIABit::M0Bit); + myMissile1.toggleEnabled(mySpriteEnabledBits & TIABit::M1Bit); + + return mask; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // TODO: stub bool TIA::toggleBits() { - return false; + toggleBit(TIABit(0xFF), mySpriteEnabledBits > 0 ? 0 : 1); + + return mySpriteEnabledBits; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // TODO: stub bool TIA::toggleCollision(TIABit b, uInt8 mode) { - return false; + uInt8 mask; + + switch (mode) { + case 0: + mask = 0; + break; + + case 1: + mask = b; + break; + + default: + mask = (~myCollisionsEnabledBits & b); + break; + } + + myCollisionsEnabledBits = (myCollisionsEnabledBits & ~b) | mask; + + myMissile0.toggleCollisions(myCollisionsEnabledBits & TIABit::M0Bit); + myMissile1.toggleCollisions(myCollisionsEnabledBits & TIABit::M1Bit); + + return mask; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // TODO: stub bool TIA::toggleCollisions() { - return false; + toggleCollision(TIABit(0xFF), myCollisionsEnabledBits > 0 ? 0 : 1); + + return myCollisionsEnabledBits; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/tia/core_6502ts/TIA.hxx b/src/emucore/tia/core_6502ts/TIA.hxx index 5311f360b..b7f0014bd 100644 --- a/src/emucore/tia/core_6502ts/TIA.hxx +++ b/src/emucore/tia/core_6502ts/TIA.hxx @@ -210,6 +210,9 @@ class TIA : public AbstractTIA uInt8 mySubClock; uInt32 myLastCycle; + uInt8 mySpriteEnabledBits; + uInt8 myCollisionsEnabledBits; + uInt8 myColorBk; double myTimestamp;