diff --git a/src/emucore/tia/Audio.cxx b/src/emucore/tia/Audio.cxx index 0e6d4b03b..e2620879c 100644 --- a/src/emucore/tia/Audio.cxx +++ b/src/emucore/tia/Audio.cxx @@ -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; +} diff --git a/src/emucore/tia/Audio.hxx b/src/emucore/tia/Audio.hxx index b4a59dfc4..968c30a9a 100644 --- a/src/emucore/tia/Audio.hxx +++ b/src/emucore/tia/Audio.hxx @@ -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(); diff --git a/src/emucore/tia/AudioChannel.cxx b/src/emucore/tia/AudioChannel.cxx index a9fe49a5c..81b16d020 100644 --- a/src/emucore/tia/AudioChannel.cxx +++ b/src/emucore/tia/AudioChannel.cxx @@ -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; +} diff --git a/src/emucore/tia/AudioChannel.hxx b/src/emucore/tia/AudioChannel.hxx index de596edbd..f72372a86 100644 --- a/src/emucore/tia/AudioChannel.hxx +++ b/src/emucore/tia/AudioChannel.hxx @@ -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; diff --git a/src/emucore/tia/TIA.cxx b/src/emucore/tia/TIA.cxx index bc79b5ede..53edcb0aa 100644 --- a/src/emucore/tia/TIA.cxx +++ b/src/emucore/tia/TIA.cxx @@ -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;