Audio state serialization.

This commit is contained in:
Christian Speckner 2018-01-29 22:44:06 +01:00
parent 025adc59aa
commit d70b0d8c40
5 changed files with 132 additions and 2 deletions

View File

@ -114,3 +114,51 @@ AudioChannel& Audio::channel1()
{
return myChannel1;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string Audio::name() const
{
return "TIA_Audio";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Audio::save(Serializer& out) const
{
try
{
out.putString(name());
out.putInt(myCounter);
if (!myChannel0.save(out)) return false;
if (!myChannel1.save(out)) return false;
}
catch(...)
{
cerr << "ERROR: TIA_Audio::save" << endl;
return false;
}
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool Audio::load(Serializer& in)
{
try
{
if (in.getString() != name()) return false;
myCounter = in.getInt();
if (!myChannel0.load(in)) return false;
if (!myChannel1.load(in)) return false;
}
catch(...)
{
cerr << "ERROR: TIA_Audio::load" << endl;
return false;
}
return true;
}

View File

@ -20,10 +20,11 @@
#include "bspf.hxx"
#include "AudioChannel.hxx"
#include "Serializable.hxx"
class AudioQueue;
class Audio
class Audio : public Serializable
{
public:
Audio();
@ -38,6 +39,13 @@ class Audio
AudioChannel& channel1();
/**
Serializable methods (see that class for more information).
*/
bool save(Serializer& out) const override;
bool load(Serializer& in) override;
string name() const override;
private:
void phase1();

View File

@ -141,3 +141,67 @@ void AudioChannel::audf(uInt8 value)
{
myAudf = value & 0x1f;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string AudioChannel::name() const
{
return "TIA_AudioChannel";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool AudioChannel::save(Serializer& out) const
{
try
{
out.putString(name());
out.putInt(myAudc);
out.putInt(myAudv);
out.putInt(myAudf);
out.putBool(myClockEnable);
out.putBool(myNoiseFeedback);
out.putBool(myNoiseCounterBit4);
out.putBool(myPulseCounterHold);
out.putInt(myDivCounter);
out.putInt(myPulseCounter);
out.putInt(myNoiseCounter);
}
catch(...)
{
cerr << "ERROR: TIA_AudioChannel::save" << endl;
return false;
}
return true;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool AudioChannel::load(Serializer& in)
{
try
{
if (in.getString() != name()) return false;
myAudc = in.getInt();
myAudv = in.getInt();
myAudf = in.getInt();
myClockEnable = in.getBool();
myNoiseFeedback = in.getBool();
myNoiseCounterBit4 = in.getBool();
myPulseCounterHold = in.getBool();
myDivCounter = in.getInt();
myPulseCounter = in.getInt();
myNoiseCounter = in.getInt();
}
catch(...)
{
cerr << "ERROR: TIA_AudioChannel::load" << endl;
return false;
}
return true;
}

View File

@ -19,8 +19,9 @@
#define TIA_AUDIO_CHANNEL_HXX
#include "bspf.hxx"
#include "Serializable.hxx"
class AudioChannel
class AudioChannel : public Serializable
{
public:
AudioChannel();
@ -37,6 +38,13 @@ class AudioChannel
void audv(uInt8 value);
/**
Serializable methods (see that class for more information).
*/
bool save(Serializer& out) const override;
bool load(Serializer& in) override;
string name() const override;
private:
uInt8 myAudc;
uInt8 myAudv;

View File

@ -240,6 +240,7 @@ bool TIA::save(Serializer& out) const
if(!myPlayer0.save(out)) return false;
if(!myPlayer1.save(out)) return false;
if(!myBall.save(out)) return false;
if(!myAudio.save(out)) return false;
for (const PaddleReader& paddleReader : myPaddleReaders)
if(!paddleReader.save(out)) return false;
@ -309,6 +310,7 @@ bool TIA::load(Serializer& in)
if(!myPlayer0.load(in)) return false;
if(!myPlayer1.load(in)) return false;
if(!myBall.load(in)) return false;
if(!myAudio.load(in)) return false;
for (PaddleReader& paddleReader : myPaddleReaders)
if(!paddleReader.load(in)) return false;