Skip to content

Commit

Permalink
Final state load/save updates for DelayQueue.
Browse files Browse the repository at this point in the history
  • Loading branch information
sa666666 committed Mar 25, 2017
1 parent 73beb8c commit 94cd456
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/emucore/CartBUS.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class System;
1K C Varaible and Stack, and the BUS chip.
BUS chip access is mapped to $1000 - $103F.
Authors: Darrell Spice Jr, Chris Walton, Fred Quimby,
@authors: Darrell Spice Jr, Chris Walton, Fred Quimby,
Stephen Anthony, Bradford W. Mott
*/
class CartridgeBUS : public Cartridge
Expand Down
2 changes: 1 addition & 1 deletion src/emucore/CartCDF.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class System;
1K C Varaible and Stack, and the CDF chip.
CDF chip access is mapped to $1000 - $103F.
Authors: Darrell Spice Jr, Chris Walton, Fred Quimby,
@authors: Darrell Spice Jr, Chris Walton, Fred Quimby,
Stephen Anthony, Bradford W. Mott
*/
class CartridgeCDF : public Cartridge
Expand Down
12 changes: 5 additions & 7 deletions src/emucore/Serializable.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class Serializable
Serializable() = default;
virtual ~Serializable() = default;

Serializable(const Serializable&) = default;
Serializable(Serializable&&) = default;
Serializable& operator=(const Serializable&) = default;
Serializable& operator=(Serializable&&) = default;

/**
Save the current state of the object to the given Serializer.
Expand All @@ -55,13 +60,6 @@ class Serializable
@return The name of the object
*/
virtual string name() const = 0;

private:
// Following constructors and assignment operators not supported
Serializable(const Serializable&) = delete;
Serializable(Serializable&&) = delete;
Serializable& operator=(const Serializable&) = delete;
Serializable& operator=(Serializable&&) = delete;
};

#endif
2 changes: 1 addition & 1 deletion src/emucore/StateManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include "StateManager.hxx"

#define STATE_HEADER "04090300state"
#define STATE_HEADER "04090400state"
#define MOVIE_HEADER "03030000movie"

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
10 changes: 8 additions & 2 deletions src/emucore/tia/DelayQueue.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ bool DelayQueue::save(Serializer& out) const
{
try
{
// FIXME out.putVector(myMembers);
out.putInt(myMembers.size());
for(const DelayQueueMember& m: myMembers)
m.save(out);

out.putByte(myIndex);
out.putByteArray(myIndices, 0xFF);
}
Expand All @@ -80,7 +83,10 @@ bool DelayQueue::load(Serializer& in)
{
try
{
// FIXME in.getVector(myMembers);
myMembers.resize(in.getInt());
for(DelayQueueMember& m: myMembers)
m.load(in);

myIndex = in.getByte();
in.getByteArray(myIndices, 0xFF);
}
Expand Down
50 changes: 47 additions & 3 deletions src/emucore/tia/DelayQueueMember.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,56 @@ void DelayQueueMember::remove(uInt8 address)
{
size_t index;

for (index = 0; index < mySize; index++) {
if (myEntries.at(index).address == address) break;
}
for (index = 0; index < mySize; index++)
if (myEntries.at(index).address == address)
break;

if (index < mySize) {
myEntries.at(index) = myEntries.at(mySize - 1);
mySize--;
}
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool DelayQueueMember::save(Serializer& out) const
{
try
{
out.putInt(mySize);
for(size_t i = 0; i < mySize; ++i)
{
const Entry& e = myEntries[i];
out.putByte(e.address);
out.putByte(e.value);
}
}
catch(...)
{
cerr << "ERROR: TIA_DelayQueueMember::save" << endl;
return false;
}

return true;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool DelayQueueMember::load(Serializer& in)
{
try
{
mySize = size_t(in.getInt());
for(size_t i = 0; i < mySize; ++i)
{
Entry& e = myEntries[i];
e.address = in.getByte();
e.value = in.getByte();
}
}
catch(...)
{
cerr << "ERROR: TIA_DelayQueueMember::load" << endl;
return false;
}

return true;
}
19 changes: 10 additions & 9 deletions src/emucore/tia/DelayQueueMember.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,21 @@
#ifndef TIA_DELAY_QUEUE_MEMBER
#define TIA_DELAY_QUEUE_MEMBER

#include "Serializable.hxx"
#include "bspf.hxx"

class DelayQueueMember
class DelayQueueMember : public Serializable
{
public:

struct Entry {
uInt8 address;
uInt8 value;
};

public:

DelayQueueMember(uInt8 size);
DelayQueueMember(uInt8 size = 0);

DelayQueueMember(DelayQueueMember&&) = default;

DelayQueueMember& operator=(DelayQueueMember&&) = default;

public:
Expand All @@ -55,17 +53,20 @@ class DelayQueueMember
mySize = 0;
}

private:
/**
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_DelayQueueMember"; }

private:
vector<Entry> myEntries;

size_t mySize;

private:
DelayQueueMember() = delete;
DelayQueueMember(const DelayQueueMember&) = delete;
DelayQueueMember& operator=(const DelayQueueMember&) = delete;

};

#endif // TIA_DELAY_QUEUE_MEMBER

0 comments on commit 94cd456

Please sign in to comment.