Add toggle logic to all sprites.

This commit is contained in:
Christian Speckner 2016-12-02 08:58:19 +01:00
parent 920787aa9f
commit a1eb8fd9ab
8 changed files with 124 additions and 24 deletions

View File

@ -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);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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;

View File

@ -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;

View File

@ -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)

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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);