Commit 2e2b3739 authored by Christian Speckner's avatar Christian Speckner
Browse files

Playfield comments.

parent 0d34de26
......@@ -125,6 +125,7 @@ void Playfield::toggleEnabled(bool enabled)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Playfield::toggleCollisions(bool enabled)
{
// Only keep bit 15 active if collisions are disabled.
myCollisionMaskEnabled = enabled ? 0xFFFF : (0x8000 | myCollisionMaskDisabled);
}
......
......@@ -27,40 +27,97 @@ class TIA;
class Playfield : public Serializable
{
public:
/**
The collision mask is injected at construction
*/
explicit Playfield(uInt32 collisionMask);
public:
/**
Set the TIA instance
*/
void setTIA(TIA* tia) { myTIA = tia; }
/**
Reset to initial state.
*/
void reset();
/**
PF0 write.
*/
void pf0(uInt8 value);
/**
PF1 write.
*/
void pf1(uInt8 value);
/**
PF2 write.
*/
void pf2(uInt8 value);
/**
CTRLPF write.
*/
void ctrlpf(uInt8 value);
/**
Enable / disable PF display (debugging only, not used during normal emulation).
*/
void toggleEnabled(bool enabled);
/**
Enable / disable PF collisions (debugging only, not used during normal emulation).
*/
void toggleCollisions(bool enabled);
/**
Set color PF.
*/
void setColor(uInt8 color);
/**
Set color P0.
*/
void setColorP0(uInt8 color);
/**
Set color P1.
*/
void setColorP1(uInt8 color);
/**
Set the color used in "debug colors" mode.
*/
void setDebugColor(uInt8 color);
/**
Enable "debug colors" mode.
*/
void enableDebugColors(bool enabled);
/**
Update internal state to use the color loss palette.
*/
void applyColorLoss();
/**
Notify playfield of line change,
*/
void nextLine();
/**
Is the playfield signal active? This is determined by looking at bit 8
of the collision mask.
*/
bool isOn() const { return (collision & 0x8000); }
/**
Get the current color.
*/
uInt8 getColor() const;
/**
......@@ -69,10 +126,14 @@ class Playfield : public Serializable
bool save(Serializer& out) const override;
bool load(Serializer& in) override;
/**
Tick one color clock. Inline for performance.
*/
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;
......@@ -94,44 +155,109 @@ class Playfield : public Serializable
public:
/**
16 bit Collision mask. Each sprite is represented by a single bit in the mask
(1 = active, 0 = inactive). All other bits are always 1. The highest bit is
abused to store the active / inactive state (as the actual collision bit will
always be zero if collisions are disabled).
*/
uInt32 collision;
private:
/**
Playfield mode.
*/
enum class ColorMode: uInt8 {normal, score};
private:
/**
Recalculate playfield color based on COLUPF, debug colors, color loss, etc.
*/
void applyColors();
/**
Recalculate the playfield pattern from PF0, PF1 and PF2.
*/
void updatePattern();
private:
/**
Collision mask values for active / inactive states. Disabling collisions
will change those.
*/
uInt32 myCollisionMaskDisabled;
uInt32 myCollisionMaskEnabled;
/**
Enable / disable PF (debugging).
*/
bool myIsSuppressed;
/**
Left / right PF colors. Derifed from P0 / P1 color, COLUPF and playfield mode.
*/
uInt8 myColorLeft;
uInt8 myColorRight;
/**
P0 / P1 colors
*/
uInt8 myColorP0;
uInt8 myColorP1;
/**
COLUPF and debug colors
*/
uInt8 myObjectColor, myDebugColor;
/**
Debug colors enabled?
*/
bool myDebugEnabled;
/**
* Plafield mode.
*/
ColorMode myColorMode;
/**
Pattern derifed from PF0, PF1, PF2
*/
uInt32 myPattern;
/**
"Effective pattern". Will be 0 if playfield is disabled (debug), otherwise the same as myPattern.
*/
uInt32 myEffectivePattern;
bool myRefp;
/**
Reflected mode on / off.
*/
bool myReflected;
/**
* Are we currently drawing the reflected PF?
*/
bool myRefp;
/**
PF registers.
*/
uInt8 myPf0;
uInt8 myPf1;
uInt8 myPf2;
/**
The current scanline position (0 .. 159).
*/
uInt32 myX;
/**
TIA instance.
*/
TIA* myTIA;
private:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment