Implemented Serializable for TIA inptx registers (LatchedInput

and PaddleReader).  For now, PaddleReader is stubbed out, since
it needs to save double values and Serializer can't do that yet.

Fixed bug in Ball, Background and Playfield serialization; they
were correctly saving data, but returning false (indicating failure).
This commit is contained in:
Stephen Anthony 2017-02-20 21:05:54 -03:30
parent 30e1996d5b
commit 8263eb1e7c
9 changed files with 119 additions and 10 deletions

View File

@ -28,7 +28,7 @@
#include "StateManager.hxx"
#define STATE_HEADER "04090100state"
#define STATE_HEADER "04090200state"
#define MOVIE_HEADER "03030000movie"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -75,7 +75,7 @@ bool Background::save(Serializer& out) const
return false;
}
return false;
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -99,5 +99,5 @@ bool Background::load(Serializer& in)
return false;
}
return false;
return true;
}

View File

@ -243,7 +243,7 @@ bool Ball::save(Serializer& out) const
return false;
}
return false;
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -288,5 +288,5 @@ bool Ball::load(Serializer& in)
return false;
}
return false;
return true;
}

View File

@ -53,3 +53,42 @@ uInt8 LatchedInput::inpt(bool pinState)
return value;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool LatchedInput::save(Serializer& out) const
{
try
{
out.putString(name());
out.putBool(myModeLatched);
out.putByte(myLatchedValue);
}
catch(...)
{
cerr << "ERROR: TIA_LatchedInput::save" << endl;
return false;
}
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool LatchedInput::load(Serializer& in)
{
try
{
if(in.getString() != name())
return false;
myModeLatched = in.getBool();
myLatchedValue = in.getByte();
}
catch(...)
{
cerr << "ERROR: TIA_LatchedInput::load" << endl;
return false;
}
return true;
}

View File

@ -19,8 +19,9 @@
#define TIA_LATCHED_INPUT
#include "bspf.hxx"
#include "Serializable.hxx"
class LatchedInput
class LatchedInput : public Serializable
{
public:
LatchedInput();
@ -34,6 +35,13 @@ class LatchedInput
uInt8 inpt(bool pinState);
/**
Serializable methods (see that class for more information).
*/
bool save(Serializer& out) const override;
bool load(Serializer& in) override;
string name() const override { return "TIA_PADDLE_READER"; }
private:
bool myModeLatched;

View File

@ -103,3 +103,42 @@ void PaddleReader::updateCharge(double timestamp)
myTimestamp = timestamp;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// TODO: implement this once the class is finalized
bool PaddleReader::save(Serializer& out) const
{
try
{
out.putString(name());
// TODO - save instance variables
}
catch(...)
{
cerr << "ERROR: TIA_PaddleReader::save" << endl;
return false;
}
return false;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// TODO: implement this once the class is finalized
bool PaddleReader::load(Serializer& in)
{
try
{
if(in.getString() != name())
return false;
// TODO - load instance variables
}
catch(...)
{
cerr << "ERROR: TIA_PaddleReader::load" << endl;
return false;
}
return false;
}

View File

@ -20,8 +20,9 @@
#include "bspf.hxx"
#include "TvMode.hxx"
#include "Serializable.hxx"
class PaddleReader
class PaddleReader : public Serializable
{
public:
@ -38,6 +39,13 @@ class PaddleReader
void update(double value, double timestamp, TvMode tvMode);
/**
Serializable methods (see that class for more information).
*/
bool save(Serializer& out) const override;
bool load(Serializer& in) override;
string name() const override { return "TIA_PADDLE_READER"; }
private:
void setTvMode(TvMode mode);
@ -58,7 +66,6 @@ class PaddleReader
bool myIsDumped;
private:
PaddleReader(const PaddleReader&) = delete;
PaddleReader(PaddleReader&&) = delete;
PaddleReader& operator=(const PaddleReader&) = delete;

View File

@ -232,7 +232,7 @@ bool Playfield::save(Serializer& out) const
return false;
}
return false;
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -279,5 +279,5 @@ bool Playfield::load(Serializer& in)
return false;
}
return false;
return true;
}

View File

@ -207,6 +207,14 @@ bool TIA::save(Serializer& out) const
if(!myPlayer1.save(out)) return false;
if(!myBall.save(out)) return false;
// Save dumped input ports
for (const PaddleReader& paddleReader : myPaddleReaders)
if(!paddleReader.save(out)) return false;
// Save latched input ports
if(!myInput0.save(out)) return false;
if(!myInput1.save(out)) return false;
// Save the sound sample stuff ...
mySound.save(out);
}
@ -237,6 +245,14 @@ bool TIA::load(Serializer& in)
if(!myPlayer0.load(in)) return false;
if(!myPlayer1.load(in)) return false;
if(!myBall.load(in)) return false;
// Load dumped input ports
for (PaddleReader& paddleReader : myPaddleReaders)
if(!paddleReader.load(in)) return false;
// Load latched input ports
if(!myInput0.load(in)) return false;
if(!myInput1.load(in)) return false;
}
catch(...)
{