Some fixes to the Serializer/Deserializer classes wrt portability.

After this, hopefully state (and eventstream) files will be portable
between different platforms, even those differing in endian-ness and
bit length.  Ints are now stored and retrieved in little endian format
and are 4 bytes long.  So state files should still work on 32-bit x86 Linux,
but old state files will no longer be valid for 64-bit or non-x86 systems.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@911 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2005-12-17 01:23:07 +00:00
parent e6aa6391eb
commit 3d760c8238
28 changed files with 335 additions and 348 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: SoundNull.cxx,v 1.3 2005-06-16 00:55:56 stephena Exp $ // $Id: SoundNull.cxx,v 1.4 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include "Serializer.hxx" #include "Serializer.hxx"
@ -47,15 +47,15 @@ bool SoundNull::load(Deserializer& in)
return false; return false;
uInt8 reg; uInt8 reg;
reg = (uInt8) in.getLong(); reg = (uInt8) in.getInt();
reg = (uInt8) in.getLong(); reg = (uInt8) in.getInt();
reg = (uInt8) in.getLong(); reg = (uInt8) in.getInt();
reg = (uInt8) in.getLong(); reg = (uInt8) in.getInt();
reg = (uInt8) in.getLong(); reg = (uInt8) in.getInt();
reg = (uInt8) in.getLong(); reg = (uInt8) in.getInt();
// myLastRegisterSetCycle // myLastRegisterSetCycle
in.getLong(); in.getInt();
return true; return true;
} }
@ -66,15 +66,15 @@ bool SoundNull::save(Serializer& out)
out.putString("TIASound"); out.putString("TIASound");
uInt8 reg = 0; uInt8 reg = 0;
out.putLong(reg); out.putInt(reg);
out.putLong(reg); out.putInt(reg);
out.putLong(reg); out.putInt(reg);
out.putLong(reg); out.putInt(reg);
out.putLong(reg); out.putInt(reg);
out.putLong(reg); out.putInt(reg);
// myLastRegisterSetCycle // myLastRegisterSetCycle
out.putLong(0); out.putInt(0);
return true; return true;
} }

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: SoundSDL.cxx,v 1.26 2005-09-30 00:40:33 stephena Exp $ // $Id: SoundSDL.cxx,v 1.27 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#ifdef SOUND_SUPPORT #ifdef SOUND_SUPPORT
@ -412,14 +412,14 @@ bool SoundSDL::load(Deserializer& in)
return false; return false;
uInt8 reg1 = 0, reg2 = 0, reg3 = 0, reg4 = 0, reg5 = 0, reg6 = 0; uInt8 reg1 = 0, reg2 = 0, reg3 = 0, reg4 = 0, reg5 = 0, reg6 = 0;
reg1 = (uInt8) in.getLong(); reg1 = (uInt8) in.getInt();
reg2 = (uInt8) in.getLong(); reg2 = (uInt8) in.getInt();
reg3 = (uInt8) in.getLong(); reg3 = (uInt8) in.getInt();
reg4 = (uInt8) in.getLong(); reg4 = (uInt8) in.getInt();
reg5 = (uInt8) in.getLong(); reg5 = (uInt8) in.getInt();
reg6 = (uInt8) in.getLong(); reg6 = (uInt8) in.getInt();
myLastRegisterSetCycle = (Int32) in.getLong(); myLastRegisterSetCycle = (Int32) in.getInt();
// Only update the TIA sound registers if sound is enabled // Only update the TIA sound registers if sound is enabled
// Make sure to empty the queue of previous sound fragments // Make sure to empty the queue of previous sound fragments
@ -472,14 +472,14 @@ bool SoundSDL::save(Serializer& out)
reg6 = myTIASound.get(0x1a); reg6 = myTIASound.get(0x1a);
} }
out.putLong(reg1); out.putInt(reg1);
out.putLong(reg2); out.putInt(reg2);
out.putLong(reg3); out.putInt(reg3);
out.putLong(reg4); out.putInt(reg4);
out.putLong(reg5); out.putInt(reg5);
out.putLong(reg6); out.putInt(reg6);
out.putLong(myLastRegisterSetCycle); out.putInt(myLastRegisterSetCycle);
} }
catch(char *msg) catch(char *msg)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Cart3E.cxx,v 1.8 2005-10-12 03:32:28 urchlay Exp $ // $Id: Cart3E.cxx,v 1.9 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -245,12 +245,12 @@ bool Cartridge3E::save(Serializer& out)
try try
{ {
out.putString(cart); out.putString(cart);
out.putLong(myCurrentBank); out.putInt(myCurrentBank);
// Output RAM // Output RAM
out.putLong(32768); out.putInt(32768);
for(uInt32 addr = 0; addr < 32768; ++addr) for(uInt32 addr = 0; addr < 32768; ++addr)
out.putLong(myRam[addr]); out.putInt(myRam[addr]);
} }
catch(char *msg) catch(char *msg)
{ {
@ -276,12 +276,12 @@ bool Cartridge3E::load(Deserializer& in)
if(in.getString() != cart) if(in.getString() != cart)
return false; return false;
myCurrentBank = (uInt16) in.getLong(); myCurrentBank = (uInt16) in.getInt();
// Input RAM // Input RAM
uInt32 limit = (uInt32) in.getLong(); uInt32 limit = (uInt32) in.getInt();
for(uInt32 addr = 0; addr < limit; ++addr) for(uInt32 addr = 0; addr < limit; ++addr)
myRam[addr] = (uInt8) in.getLong(); myRam[addr] = (uInt8) in.getInt();
} }
catch(char *msg) catch(char *msg)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Cart3F.cxx,v 1.11 2005-10-12 03:32:28 urchlay Exp $ // $Id: Cart3F.cxx,v 1.12 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -189,7 +189,7 @@ bool Cartridge3F::save(Serializer& out)
try try
{ {
out.putString(cart); out.putString(cart);
out.putLong(myCurrentBank); out.putInt(myCurrentBank);
} }
catch(char *msg) catch(char *msg)
{ {
@ -215,7 +215,7 @@ bool Cartridge3F::load(Deserializer& in)
if(in.getString() != cart) if(in.getString() != cart)
return false; return false;
myCurrentBank = (uInt16) in.getLong(); myCurrentBank = (uInt16) in.getInt();
} }
catch(char *msg) catch(char *msg)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: CartAR.cxx,v 1.12 2005-10-12 03:32:28 urchlay Exp $ // $Id: CartAR.cxx,v 1.13 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -460,28 +460,28 @@ bool CartridgeAR::save(Serializer& out)
out.putString(cart); out.putString(cart);
// Indicates the offest within the image for the corresponding bank // Indicates the offest within the image for the corresponding bank
out.putLong(2); out.putInt(2);
for(i = 0; i < 2; ++i) for(i = 0; i < 2; ++i)
out.putLong(myImageOffset[i]); out.putInt(myImageOffset[i]);
// The 6K of RAM and 2K of ROM contained in the Supercharger // The 6K of RAM and 2K of ROM contained in the Supercharger
out.putLong(8192); out.putInt(8192);
for(i = 0; i < 8192; ++i) for(i = 0; i < 8192; ++i)
out.putLong(myImage[i]); out.putInt(myImage[i]);
// The 256 byte header for the current 8448 byte load // The 256 byte header for the current 8448 byte load
out.putLong(256); out.putInt(256);
for(i = 0; i < 256; ++i) for(i = 0; i < 256; ++i)
out.putLong(myHeader[i]); out.putInt(myHeader[i]);
// All of the 8448 byte loads associated with the game // All of the 8448 byte loads associated with the game
// Note that the size of this array is myNumberOfLoadImages * 8448 // Note that the size of this array is myNumberOfLoadImages * 8448
out.putLong(myNumberOfLoadImages * 8448); out.putInt(myNumberOfLoadImages * 8448);
for(i = 0; i < (uInt32) myNumberOfLoadImages * 8448; ++i) for(i = 0; i < (uInt32) myNumberOfLoadImages * 8448; ++i)
out.putLong(myLoadImages[i]); out.putInt(myLoadImages[i]);
// Indicates how many 8448 loads there are // Indicates how many 8448 loads there are
out.putLong(myNumberOfLoadImages); out.putInt(myNumberOfLoadImages);
// Indicates if the RAM is write enabled // Indicates if the RAM is write enabled
out.putBool(myWriteEnabled); out.putBool(myWriteEnabled);
@ -490,13 +490,13 @@ bool CartridgeAR::save(Serializer& out)
out.putBool(myPower); out.putBool(myPower);
// Indicates when the power was last turned on // Indicates when the power was last turned on
out.putLong(myPowerRomCycle); out.putInt(myPowerRomCycle);
// Data hold register used for writing // Data hold register used for writing
out.putLong(myDataHoldRegister); out.putInt(myDataHoldRegister);
// Indicates number of distinct accesses when data hold register was set // Indicates number of distinct accesses when data hold register was set
out.putLong(myNumberOfDistinctAccesses); out.putInt(myNumberOfDistinctAccesses);
// Indicates if a write is pending or not // Indicates if a write is pending or not
out.putBool(myWritePending); out.putBool(myWritePending);
@ -528,28 +528,28 @@ bool CartridgeAR::load(Deserializer& in)
uInt32 i, limit; uInt32 i, limit;
// Indicates the offest within the image for the corresponding bank // Indicates the offest within the image for the corresponding bank
limit = (uInt32) in.getLong(); limit = (uInt32) in.getInt();
for(i = 0; i < limit; ++i) for(i = 0; i < limit; ++i)
myImageOffset[i] = (uInt32) in.getLong(); myImageOffset[i] = (uInt32) in.getInt();
// The 6K of RAM and 2K of ROM contained in the Supercharger // The 6K of RAM and 2K of ROM contained in the Supercharger
limit = (uInt32) in.getLong(); limit = (uInt32) in.getInt();
for(i = 0; i < limit; ++i) for(i = 0; i < limit; ++i)
myImage[i] = (uInt8) in.getLong(); myImage[i] = (uInt8) in.getInt();
// The 256 byte header for the current 8448 byte load // The 256 byte header for the current 8448 byte load
limit = (uInt32) in.getLong(); limit = (uInt32) in.getInt();
for(i = 0; i < limit; ++i) for(i = 0; i < limit; ++i)
myHeader[i] = (uInt8) in.getLong(); myHeader[i] = (uInt8) in.getInt();
// All of the 8448 byte loads associated with the game // All of the 8448 byte loads associated with the game
// Note that the size of this array is myNumberOfLoadImages * 8448 // Note that the size of this array is myNumberOfLoadImages * 8448
limit = (uInt32) in.getLong(); limit = (uInt32) in.getInt();
for(i = 0; i < limit; ++i) for(i = 0; i < limit; ++i)
myLoadImages[i] = (uInt8) in.getLong(); myLoadImages[i] = (uInt8) in.getInt();
// Indicates how many 8448 loads there are // Indicates how many 8448 loads there are
myNumberOfLoadImages = (uInt8) in.getLong(); myNumberOfLoadImages = (uInt8) in.getInt();
// Indicates if the RAM is write enabled // Indicates if the RAM is write enabled
myWriteEnabled = in.getBool(); myWriteEnabled = in.getBool();
@ -558,13 +558,13 @@ bool CartridgeAR::load(Deserializer& in)
myPower = in.getBool(); myPower = in.getBool();
// Indicates when the power was last turned on // Indicates when the power was last turned on
myPowerRomCycle = (Int32) in.getLong(); myPowerRomCycle = (Int32) in.getInt();
// Data hold register used for writing // Data hold register used for writing
myDataHoldRegister = (uInt8) in.getLong(); myDataHoldRegister = (uInt8) in.getInt();
// Indicates number of distinct accesses when data hold register was set // Indicates number of distinct accesses when data hold register was set
myNumberOfDistinctAccesses = (uInt32) in.getLong(); myNumberOfDistinctAccesses = (uInt32) in.getInt();
// Indicates if a write is pending or not // Indicates if a write is pending or not
myWritePending = in.getBool(); myWritePending = in.getBool();

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: CartCV.cxx,v 1.9 2005-10-09 17:31:47 stephena Exp $ // $Id: CartCV.cxx,v 1.10 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -148,9 +148,9 @@ bool CartridgeCV::save(Serializer& out)
out.putString(cart); out.putString(cart);
// Output RAM // Output RAM
out.putLong(1024); out.putInt(1024);
for(uInt32 addr = 0; addr < 1024; ++addr) for(uInt32 addr = 0; addr < 1024; ++addr)
out.putLong(myRAM[addr]); out.putInt(myRAM[addr]);
} }
catch(char *msg) catch(char *msg)
{ {
@ -177,9 +177,9 @@ bool CartridgeCV::load(Deserializer& in)
return false; return false;
// Input RAM // Input RAM
uInt32 limit = (uInt32) in.getLong(); uInt32 limit = (uInt32) in.getInt();
for(uInt32 addr = 0; addr < limit; ++addr) for(uInt32 addr = 0; addr < limit; ++addr)
myRAM[addr] = (uInt8) in.getLong(); myRAM[addr] = (uInt8) in.getInt();
} }
catch(char *msg) catch(char *msg)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: CartDPC.cxx,v 1.14 2005-10-12 03:32:28 urchlay Exp $ // $Id: CartDPC.cxx,v 1.15 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -483,38 +483,38 @@ bool CartridgeDPC::save(Serializer& out)
out.putString(cart); out.putString(cart);
// Indicates which bank is currently active // Indicates which bank is currently active
out.putLong(myCurrentBank); out.putInt(myCurrentBank);
// The top registers for the data fetchers // The top registers for the data fetchers
out.putLong(8); out.putInt(8);
for(i = 0; i < 8; ++i) for(i = 0; i < 8; ++i)
out.putLong(myTops[i]); out.putInt(myTops[i]);
// The bottom registers for the data fetchers // The bottom registers for the data fetchers
out.putLong(8); out.putInt(8);
for(i = 0; i < 8; ++i) for(i = 0; i < 8; ++i)
out.putLong(myBottoms[i]); out.putInt(myBottoms[i]);
// The counter registers for the data fetchers // The counter registers for the data fetchers
out.putLong(8); out.putInt(8);
for(i = 0; i < 8; ++i) for(i = 0; i < 8; ++i)
out.putLong(myCounters[i]); out.putInt(myCounters[i]);
// The flag registers for the data fetchers // The flag registers for the data fetchers
out.putLong(8); out.putInt(8);
for(i = 0; i < 8; ++i) for(i = 0; i < 8; ++i)
out.putLong(myFlags[i]); out.putInt(myFlags[i]);
// The music mode flags for the data fetchers // The music mode flags for the data fetchers
out.putLong(3); out.putInt(3);
for(i = 0; i < 3; ++i) for(i = 0; i < 3; ++i)
out.putBool(myMusicMode[i]); out.putBool(myMusicMode[i]);
// The random number generator register // The random number generator register
out.putLong(myRandomNumber); out.putInt(myRandomNumber);
out.putLong(mySystemCycles); out.putInt(mySystemCycles);
out.putLong((uInt32)(myFractionalClocks * 100000000.0)); out.putInt((uInt32)(myFractionalClocks * 100000000.0));
} }
catch(char *msg) catch(char *msg)
{ {
@ -543,39 +543,39 @@ bool CartridgeDPC::load(Deserializer& in)
uInt32 i, limit; uInt32 i, limit;
// Indicates which bank is currently active // Indicates which bank is currently active
myCurrentBank = (uInt16) in.getLong(); myCurrentBank = (uInt16) in.getInt();
// The top registers for the data fetchers // The top registers for the data fetchers
limit = (uInt32) in.getLong(); limit = (uInt32) in.getInt();
for(i = 0; i < limit; ++i) for(i = 0; i < limit; ++i)
myTops[i] = (uInt8) in.getLong(); myTops[i] = (uInt8) in.getInt();
// The bottom registers for the data fetchers // The bottom registers for the data fetchers
limit = (uInt32) in.getLong(); limit = (uInt32) in.getInt();
for(i = 0; i < limit; ++i) for(i = 0; i < limit; ++i)
myBottoms[i] = (uInt8) in.getLong(); myBottoms[i] = (uInt8) in.getInt();
// The counter registers for the data fetchers // The counter registers for the data fetchers
limit = (uInt32) in.getLong(); limit = (uInt32) in.getInt();
for(i = 0; i < limit; ++i) for(i = 0; i < limit; ++i)
myCounters[i] = (uInt16) in.getLong(); myCounters[i] = (uInt16) in.getInt();
// The flag registers for the data fetchers // The flag registers for the data fetchers
limit = (uInt32) in.getLong(); limit = (uInt32) in.getInt();
for(i = 0; i < limit; ++i) for(i = 0; i < limit; ++i)
myFlags[i] = (uInt8) in.getLong(); myFlags[i] = (uInt8) in.getInt();
// The music mode flags for the data fetchers // The music mode flags for the data fetchers
limit = (uInt32) in.getLong(); limit = (uInt32) in.getInt();
for(i = 0; i < limit; ++i) for(i = 0; i < limit; ++i)
myMusicMode[i] = in.getBool(); myMusicMode[i] = in.getBool();
// The random number generator register // The random number generator register
myRandomNumber = (uInt8) in.getLong(); myRandomNumber = (uInt8) in.getInt();
// Get system cycles and fractional clocks // Get system cycles and fractional clocks
mySystemCycles = in.getLong(); mySystemCycles = in.getInt();
myFractionalClocks = (double)in.getLong() / 100000000.0; myFractionalClocks = (double)in.getInt() / 100000000.0;
} }
catch(char *msg) catch(char *msg)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: CartE0.cxx,v 1.9 2005-10-12 03:32:28 urchlay Exp $ // $Id: CartE0.cxx,v 1.10 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -213,9 +213,9 @@ bool CartridgeE0::save(Serializer& out)
{ {
out.putString(cart); out.putString(cart);
out.putLong(4); out.putInt(4);
for(uInt32 i = 0; i < 4; ++i) for(uInt32 i = 0; i < 4; ++i)
out.putLong(myCurrentSlice[i]); out.putInt(myCurrentSlice[i]);
} }
catch(char *msg) catch(char *msg)
{ {
@ -241,9 +241,9 @@ bool CartridgeE0::load(Deserializer& in)
if(in.getString() != cart) if(in.getString() != cart)
return false; return false;
uInt32 limit = (uInt32) in.getLong(); uInt32 limit = (uInt32) in.getInt();
for(uInt32 i = 0; i < limit; ++i) for(uInt32 i = 0; i < limit; ++i)
myCurrentSlice[i] = (uInt16) in.getLong(); myCurrentSlice[i] = (uInt16) in.getInt();
} }
catch(char *msg) catch(char *msg)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: CartE7.cxx,v 1.12 2005-10-12 03:32:28 urchlay Exp $ // $Id: CartE7.cxx,v 1.13 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -247,16 +247,16 @@ bool CartridgeE7::save(Serializer& out)
out.putString(cart); out.putString(cart);
out.putLong(2); out.putInt(2);
for(i = 0; i < 2; ++i) for(i = 0; i < 2; ++i)
out.putLong(myCurrentSlice[i]); out.putInt(myCurrentSlice[i]);
out.putLong(myCurrentRAM); out.putInt(myCurrentRAM);
// The 2048 bytes of RAM // The 2048 bytes of RAM
out.putLong(2048); out.putInt(2048);
for(i = 0; i < 2048; ++i) for(i = 0; i < 2048; ++i)
out.putLong(myRAM[i]); out.putInt(myRAM[i]);
} }
catch(char *msg) catch(char *msg)
{ {
@ -284,16 +284,16 @@ bool CartridgeE7::load(Deserializer& in)
uInt32 i, limit; uInt32 i, limit;
limit = (uInt32) in.getLong(); limit = (uInt32) in.getInt();
for(i = 0; i < limit; ++i) for(i = 0; i < limit; ++i)
myCurrentSlice[i] = (uInt16) in.getLong(); myCurrentSlice[i] = (uInt16) in.getInt();
myCurrentRAM = (uInt16) in.getLong(); myCurrentRAM = (uInt16) in.getInt();
// The 2048 bytes of RAM // The 2048 bytes of RAM
limit = (uInt32) in.getLong(); limit = (uInt32) in.getInt();
for(i = 0; i < limit; ++i) for(i = 0; i < limit; ++i)
myRAM[i] = (uInt8) in.getLong(); myRAM[i] = (uInt8) in.getInt();
} }
catch(char *msg) catch(char *msg)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: CartF4.cxx,v 1.6 2005-10-12 03:32:28 urchlay Exp $ // $Id: CartF4.cxx,v 1.7 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -153,7 +153,7 @@ bool CartridgeF4::save(Serializer& out)
try try
{ {
out.putString(cart); out.putString(cart);
out.putLong(myCurrentBank); out.putInt(myCurrentBank);
} }
catch(char* msg) catch(char* msg)
{ {
@ -181,7 +181,7 @@ bool CartridgeF4::load(Deserializer& in)
return false; return false;
} }
myCurrentBank = (uInt16)in.getLong(); myCurrentBank = (uInt16)in.getInt();
} }
catch(char* msg) catch(char* msg)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: CartF4SC.cxx,v 1.9 2005-10-12 03:32:28 urchlay Exp $ // $Id: CartF4SC.cxx,v 1.10 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -184,12 +184,12 @@ bool CartridgeF4SC::save(Serializer& out)
{ {
out.putString(cart); out.putString(cart);
out.putLong(myCurrentBank); out.putInt(myCurrentBank);
// The 128 bytes of RAM // The 128 bytes of RAM
out.putLong(128); out.putInt(128);
for(uInt32 i = 0; i < 128; ++i) for(uInt32 i = 0; i < 128; ++i)
out.putLong(myRAM[i]); out.putInt(myRAM[i]);
} }
catch(char *msg) catch(char *msg)
{ {
@ -215,11 +215,11 @@ bool CartridgeF4SC::load(Deserializer& in)
if(in.getString() != cart) if(in.getString() != cart)
return false; return false;
myCurrentBank = (uInt16) in.getLong(); myCurrentBank = (uInt16) in.getInt();
uInt32 limit = (uInt32) in.getLong(); uInt32 limit = (uInt32) in.getInt();
for(uInt32 i = 0; i < limit; ++i) for(uInt32 i = 0; i < limit; ++i)
myRAM[i] = (uInt8) in.getLong(); myRAM[i] = (uInt8) in.getInt();
} }
catch(char *msg) catch(char *msg)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: CartF6.cxx,v 1.9 2005-10-12 03:32:28 urchlay Exp $ // $Id: CartF6.cxx,v 1.10 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -195,7 +195,7 @@ bool CartridgeF6::save(Serializer& out)
{ {
out.putString(cart); out.putString(cart);
out.putLong(myCurrentBank); out.putInt(myCurrentBank);
} }
catch(char *msg) catch(char *msg)
{ {
@ -221,7 +221,7 @@ bool CartridgeF6::load(Deserializer& in)
if(in.getString() != cart) if(in.getString() != cart)
return false; return false;
myCurrentBank = (uInt16) in.getLong(); myCurrentBank = (uInt16) in.getInt();
} }
catch(char *msg) catch(char *msg)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: CartF6SC.cxx,v 1.9 2005-10-12 03:32:28 urchlay Exp $ // $Id: CartF6SC.cxx,v 1.10 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -228,12 +228,12 @@ bool CartridgeF6SC::save(Serializer& out)
{ {
out.putString(cart); out.putString(cart);
out.putLong(myCurrentBank); out.putInt(myCurrentBank);
// The 128 bytes of RAM // The 128 bytes of RAM
out.putLong(128); out.putInt(128);
for(uInt32 i = 0; i < 128; ++i) for(uInt32 i = 0; i < 128; ++i)
out.putLong(myRAM[i]); out.putInt(myRAM[i]);
} }
catch(char *msg) catch(char *msg)
@ -260,12 +260,12 @@ bool CartridgeF6SC::load(Deserializer& in)
if(in.getString() != cart) if(in.getString() != cart)
return false; return false;
myCurrentBank = (uInt16) in.getLong(); myCurrentBank = (uInt16) in.getInt();
// The 128 bytes of RAM // The 128 bytes of RAM
uInt32 limit = (uInt32) in.getLong(); uInt32 limit = (uInt32) in.getInt();
for(uInt32 i = 0; i < limit; ++i) for(uInt32 i = 0; i < limit; ++i)
myRAM[i] = (uInt8) in.getLong(); myRAM[i] = (uInt8) in.getInt();
} }
catch(char *msg) catch(char *msg)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: CartF8.cxx,v 1.10 2005-10-13 01:13:20 urchlay Exp $ // $Id: CartF8.cxx,v 1.11 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -176,7 +176,7 @@ bool CartridgeF8::save(Serializer& out)
{ {
out.putString(cart); out.putString(cart);
out.putLong(myCurrentBank); out.putInt(myCurrentBank);
} }
catch(char *msg) catch(char *msg)
{ {
@ -202,7 +202,7 @@ bool CartridgeF8::load(Deserializer& in)
if(in.getString() != cart) if(in.getString() != cart)
return false; return false;
myCurrentBank = (uInt16) in.getLong(); myCurrentBank = (uInt16) in.getInt();
} }
catch(char *msg) catch(char *msg)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: CartF8SC.cxx,v 1.8 2005-10-12 03:32:28 urchlay Exp $ // $Id: CartF8SC.cxx,v 1.9 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -210,12 +210,12 @@ bool CartridgeF8SC::save(Serializer& out)
{ {
out.putString(cart); out.putString(cart);
out.putLong(myCurrentBank); out.putInt(myCurrentBank);
// The 128 bytes of RAM // The 128 bytes of RAM
out.putLong(128); out.putInt(128);
for(uInt32 i = 0; i < 128; ++i) for(uInt32 i = 0; i < 128; ++i)
out.putLong(myRAM[i]); out.putInt(myRAM[i]);
} }
catch(char *msg) catch(char *msg)
{ {
@ -241,11 +241,11 @@ bool CartridgeF8SC::load(Deserializer& in)
if(in.getString() != cart) if(in.getString() != cart)
return false; return false;
myCurrentBank = (uInt16) in.getLong(); myCurrentBank = (uInt16) in.getInt();
uInt32 limit = (uInt32) in.getLong(); uInt32 limit = (uInt32) in.getInt();
for(uInt32 i = 0; i < limit; ++i) for(uInt32 i = 0; i < limit; ++i)
myRAM[i] = (uInt8) in.getLong(); myRAM[i] = (uInt8) in.getInt();
} }
catch(char *msg) catch(char *msg)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: CartFASC.cxx,v 1.8 2005-10-12 03:32:28 urchlay Exp $ // $Id: CartFASC.cxx,v 1.9 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -218,12 +218,12 @@ bool CartridgeFASC::save(Serializer& out)
{ {
out.putString(cart); out.putString(cart);
out.putLong(myCurrentBank); out.putInt(myCurrentBank);
// The 256 bytes of RAM // The 256 bytes of RAM
out.putLong(256); out.putInt(256);
for(uInt32 i = 0; i < 256; ++i) for(uInt32 i = 0; i < 256; ++i)
out.putLong(myRAM[i]); out.putInt(myRAM[i]);
} }
catch(char *msg) catch(char *msg)
{ {
@ -249,11 +249,11 @@ bool CartridgeFASC::load(Deserializer& in)
if(in.getString() != cart) if(in.getString() != cart)
return false; return false;
myCurrentBank = (uInt16) in.getLong(); myCurrentBank = (uInt16) in.getInt();
uInt32 limit = (uInt32) in.getLong(); uInt32 limit = (uInt32) in.getInt();
for(uInt32 i = 0; i < limit; ++i) for(uInt32 i = 0; i < limit; ++i)
myRAM[i] = (uInt8) in.getLong(); myRAM[i] = (uInt8) in.getInt();
} }
catch(char *msg) catch(char *msg)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: CartMB.cxx,v 1.7 2005-10-12 03:32:28 urchlay Exp $ // $Id: CartMB.cxx,v 1.8 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -156,7 +156,7 @@ bool CartridgeMB::save(Serializer& out)
{ {
out.putString(cart); out.putString(cart);
out.putLong(myCurrentBank); out.putInt(myCurrentBank);
} }
catch(char *msg) catch(char *msg)
{ {
@ -182,7 +182,7 @@ bool CartridgeMB::load(Deserializer& in)
if(in.getString() != cart) if(in.getString() != cart)
return false; return false;
myCurrentBank = (uInt16) in.getLong(); myCurrentBank = (uInt16) in.getInt();
} }
catch(char *msg) catch(char *msg)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: CartMC.cxx,v 1.8 2005-10-09 17:31:47 stephena Exp $ // $Id: CartMC.cxx,v 1.9 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -237,14 +237,14 @@ bool CartridgeMC::save(Serializer& out)
out.putString(cart); out.putString(cart);
// The currentBlock array // The currentBlock array
out.putLong(4); out.putInt(4);
for(i = 0; i < 4; ++i) for(i = 0; i < 4; ++i)
out.putLong(myCurrentBlock[i]); out.putInt(myCurrentBlock[i]);
// The 32K of RAM // The 32K of RAM
out.putLong(32 * 1024); out.putInt(32 * 1024);
for(i = 0; i < 32 * 1024; ++i) for(i = 0; i < 32 * 1024; ++i)
out.putLong(myRAM[i]); out.putInt(myRAM[i]);
} }
catch(char *msg) catch(char *msg)
{ {
@ -274,14 +274,14 @@ bool CartridgeMC::load(Deserializer& in)
return false; return false;
// The currentBlock array // The currentBlock array
limit = (uInt32) in.getLong(); limit = (uInt32) in.getInt();
for(i = 0; i < limit; ++i) for(i = 0; i < limit; ++i)
myCurrentBlock[i] = (uInt8) in.getLong(); myCurrentBlock[i] = (uInt8) in.getInt();
// The 32K of RAM // The 32K of RAM
limit = (uInt32) in.getLong(); limit = (uInt32) in.getInt();
for(i = 0; i < limit; ++i) for(i = 0; i < limit; ++i)
myRAM[i] = (uInt8) in.getLong(); myRAM[i] = (uInt8) in.getInt();
} }
catch(char *msg) catch(char *msg)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: CartUA.cxx,v 1.6 2005-10-12 03:32:28 urchlay Exp $ // $Id: CartUA.cxx,v 1.7 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <cassert> #include <cassert>
@ -189,7 +189,7 @@ bool CartridgeUA::save(Serializer& out)
{ {
out.putString(cart); out.putString(cart);
out.putLong(myCurrentBank); out.putInt(myCurrentBank);
} }
catch(char *msg) catch(char *msg)
{ {
@ -215,7 +215,7 @@ bool CartridgeUA::load(Deserializer& in)
if(in.getString() != cart) if(in.getString() != cart)
return false; return false;
myCurrentBank = (uInt16)in.getLong(); myCurrentBank = (uInt16)in.getInt();
} }
catch(char *msg) catch(char *msg)
{ {

View File

@ -13,22 +13,15 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Deserializer.cxx,v 1.6 2005-12-09 19:09:49 stephena Exp $ // $Id: Deserializer.cxx,v 1.7 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <iostream>
#include <fstream>
#include <string>
#include "Deserializer.hxx" #include "Deserializer.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Deserializer::Deserializer(void) Deserializer::Deserializer(void)
: myStream(0)
{ {
TruePattern = 0xfab1fab2;
FalsePattern = 0xbad1bad2;
myStream = (ifstream*) 0;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -66,23 +59,24 @@ bool Deserializer::isOpen(void)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
long Deserializer::getLong(void) int Deserializer::getInt(void)
{ {
if(myStream->eof()) if(myStream->eof())
throw "Deserializer: end of file"; throw "Deserializer: end of file";
long l; int val = 0;
myStream->read(reinterpret_cast<char *> (&l), sizeof (long)); unsigned char buf[4];
if(myStream->bad()) myStream->read((char*)buf, 4);
throw "Deserializer: file read failed"; for(int i = 0; i < 4; ++i)
val += (int)(buf[i]) << (i<<3);
return l; return val;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string Deserializer::getString(void) string Deserializer::getString(void)
{ {
long len = getLong(); int len = getInt();
string str; string str;
str.resize((string::size_type)len); str.resize((string::size_type)len);
myStream->read(&str[0], (streamsize)len); myStream->read(&str[0], (streamsize)len);
@ -98,13 +92,13 @@ bool Deserializer::getBool(void)
{ {
bool result = false; bool result = false;
long b = getLong(); int b = getInt();
if(myStream->bad()) if(myStream->bad())
throw "Deserializer: file read failed"; throw "Deserializer: file read failed";
if(b == TruePattern) if(b == (int)TruePattern)
result = true; result = true;
else if(b == FalsePattern) else if(b == (int)FalsePattern)
result = false; result = false;
else else
throw "Deserializer: data corruption"; throw "Deserializer: data corruption";

View File

@ -13,26 +13,25 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Deserializer.hxx,v 1.7 2005-12-09 19:09:49 stephena Exp $ // $Id: Deserializer.hxx,v 1.8 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#ifndef DESERIALIZER_HXX #ifndef DESERIALIZER_HXX
#define DESERIALIZER_HXX #define DESERIALIZER_HXX
#include "bspf.hxx"
#include <fstream> #include <fstream>
#include <string> #include "bspf.hxx"
/** /**
This class implements a Deserializer device, whereby data is This class implements a Deserializer device, whereby data is
deserialized from an input binary file in a system-independent deserialized from an input binary file in a system-independent
way. way.
All longs should be cast to their appropriate data type upon method All ints should be cast to their appropriate data type upon method
return. return.
@author Stephen Anthony @author Stephen Anthony
@version $Id: Deserializer.hxx,v 1.7 2005-12-09 19:09:49 stephena Exp $ @version $Id: Deserializer.hxx,v 1.8 2005-12-17 01:23:07 stephena Exp $
*/ */
class Deserializer class Deserializer
{ {
@ -71,11 +70,11 @@ class Deserializer
bool isOpen(void); bool isOpen(void);
/** /**
Reads a long value from the current input stream. Reads an int value from the current input stream.
@result The long value which has been read from the stream. @result The int value which has been read from the stream.
*/ */
long getLong(void); int getInt(void);
/** /**
Reads a string from the current input stream. Reads a string from the current input stream.
@ -95,11 +94,10 @@ class Deserializer
// The stream to get the deserialized data from. // The stream to get the deserialized data from.
ifstream* myStream; ifstream* myStream;
// A long pattern that represents a boolean value of true. enum {
long TruePattern; TruePattern = 0xfab1fab2,
FalsePattern = 0xbad1bad2
// A long pattern that represents a boolean value of false. };
long FalsePattern;
}; };
#endif #endif

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Event.cxx,v 1.5 2005-12-09 19:09:49 stephena Exp $ // $Id: Event.cxx,v 1.6 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include "Event.hxx" #include "Event.hxx"
@ -92,9 +92,9 @@ bool Event::save(Serializer& out)
{ {
int size = myEventHistory.size(); int size = myEventHistory.size();
out.putString("EventStream"); out.putString("EventStream");
out.putLong(size); out.putInt(size);
for(int i = 0; i < size; ++i) for(int i = 0; i < size; ++i)
out.putLong(myEventHistory[i]); out.putInt(myEventHistory[i]);
return true; return true;
} }

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: M6532.cxx,v 1.5 2005-10-09 17:31:47 stephena Exp $ // $Id: M6532.cxx,v 1.6 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -304,17 +304,17 @@ bool M6532::save(Serializer& out)
out.putString(device); out.putString(device);
// Output the RAM // Output the RAM
out.putLong(128); out.putInt(128);
for(uInt32 t = 0; t < 128; ++t) for(uInt32 t = 0; t < 128; ++t)
out.putLong(myRAM[t]); out.putInt(myRAM[t]);
out.putLong(myTimer); out.putInt(myTimer);
out.putLong(myIntervalShift); out.putInt(myIntervalShift);
out.putLong(myCyclesWhenTimerSet); out.putInt(myCyclesWhenTimerSet);
out.putLong(myCyclesWhenInterruptReset); out.putInt(myCyclesWhenInterruptReset);
out.putBool(myTimerReadAfterInterrupt); out.putBool(myTimerReadAfterInterrupt);
out.putLong(myDDRA); out.putInt(myDDRA);
out.putLong(myDDRB); out.putInt(myDDRB);
} }
catch(char *msg) catch(char *msg)
{ {
@ -341,18 +341,18 @@ bool M6532::load(Deserializer& in)
return false; return false;
// Input the RAM // Input the RAM
uInt32 limit = (uInt32) in.getLong(); uInt32 limit = (uInt32) in.getInt();
for(uInt32 t = 0; t < limit; ++t) for(uInt32 t = 0; t < limit; ++t)
myRAM[t] = (uInt8) in.getLong(); myRAM[t] = (uInt8) in.getInt();
myTimer = (uInt32) in.getLong(); myTimer = (uInt32) in.getInt();
myIntervalShift = (uInt32) in.getLong(); myIntervalShift = (uInt32) in.getInt();
myCyclesWhenTimerSet = (uInt32) in.getLong(); myCyclesWhenTimerSet = (uInt32) in.getInt();
myCyclesWhenInterruptReset = (uInt32) in.getLong(); myCyclesWhenInterruptReset = (uInt32) in.getInt();
myTimerReadAfterInterrupt = in.getBool(); myTimerReadAfterInterrupt = in.getBool();
myDDRA = (uInt8) in.getLong(); myDDRA = (uInt8) in.getInt();
myDDRB = (uInt8) in.getLong(); myDDRB = (uInt8) in.getInt();
} }
catch(char *msg) catch(char *msg)
{ {

View File

@ -13,22 +13,15 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Serializer.cxx,v 1.6 2005-12-09 19:09:49 stephena Exp $ // $Id: Serializer.cxx,v 1.7 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <iostream>
#include <fstream>
#include <string>
#include "Serializer.hxx" #include "Serializer.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Serializer::Serializer(void) Serializer::Serializer(void)
: myStream(0)
{ {
TruePattern = 0xfab1fab2;
FalsePattern = 0xbad1bad2;
myStream = (ofstream*) 0;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -66,9 +59,13 @@ bool Serializer::isOpen(void)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Serializer::putLong(long value) void Serializer::putInt(int value)
{ {
myStream->write(reinterpret_cast<char *> (&value), sizeof (long)); unsigned char buf[4];
for(int i = 0; i < 4; ++i)
buf[i] = (value >> (i<<3)) & 0xff;
myStream->write((char*)buf, 4);
if(myStream->bad()) if(myStream->bad())
throw "Serializer: file write failed"; throw "Serializer: file write failed";
} }
@ -77,8 +74,8 @@ void Serializer::putLong(long value)
void Serializer::putString(const string& str) void Serializer::putString(const string& str)
{ {
int len = str.length(); int len = str.length();
putLong(len); putInt(len);
myStream->write(str.data(), len); myStream->write(str.data(), (streamsize)len);
if(myStream->bad()) if(myStream->bad())
throw "Serializer: file write failed"; throw "Serializer: file write failed";
@ -87,8 +84,8 @@ void Serializer::putString(const string& str)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Serializer::putBool(bool b) void Serializer::putBool(bool b)
{ {
long l = b ? TruePattern: FalsePattern; int l = b ? TruePattern: FalsePattern;
putLong(l); putInt(l);
if(myStream->bad ()) if(myStream->bad ())
throw "Serializer: file write failed"; throw "Serializer: file write failed";

View File

@ -13,27 +13,26 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Serializer.hxx,v 1.8 2005-12-09 19:09:49 stephena Exp $ // $Id: Serializer.hxx,v 1.9 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#ifndef SERIALIZER_HXX #ifndef SERIALIZER_HXX
#define SERIALIZER_HXX #define SERIALIZER_HXX
#include "bspf.hxx"
#include <fstream> #include <fstream>
#include <string> #include "bspf.hxx"
/** /**
This class implements a Serializer device, whereby data is This class implements a Serializer device, whereby data is
serialized and sent to an output binary file in a system- serialized and sent to an output binary file in a system-
independent way. independent way.
All bytes and integers are written as long's. Strings are All bytes and integers are written as int's. Strings are
written as characters prepended by the length of the string. written as characters prepended by the length of the string.
Boolean values are written using a special pattern. Boolean values are written using a special pattern.
@author Stephen Anthony @author Stephen Anthony
@version $Id: Serializer.hxx,v 1.8 2005-12-09 19:09:49 stephena Exp $ @version $Id: Serializer.hxx,v 1.9 2005-12-17 01:23:07 stephena Exp $
*/ */
class Serializer class Serializer
{ {
@ -72,11 +71,11 @@ class Serializer
bool isOpen(void); bool isOpen(void);
/** /**
Writes a long value to the current output stream. Writes an int value to the current output stream.
@param value The long value to write to the output stream. @param value The int value to write to the output stream.
*/ */
void putLong(long value); void putInt(int value);
/** /**
Writes a string to the current output stream. Writes a string to the current output stream.
@ -96,11 +95,10 @@ class Serializer
// The stream to send the serialized data to. // The stream to send the serialized data to.
ofstream* myStream; ofstream* myStream;
// A long pattern that represents a boolean value of true. enum {
long TruePattern; TruePattern = 0xfab1fab2,
FalsePattern = 0xbad1bad2
// A long pattern that represents a boolean value of false. };
long FalsePattern;
}; };
#endif #endif

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: TIA.cxx,v 1.64 2005-10-11 19:38:10 stephena Exp $ // $Id: TIA.cxx,v 1.65 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <cassert> #include <cassert>
@ -310,59 +310,59 @@ bool TIA::save(Serializer& out)
{ {
out.putString(device); out.putString(device);
out.putLong(myClockWhenFrameStarted); out.putInt(myClockWhenFrameStarted);
out.putLong(myClockStartDisplay); out.putInt(myClockStartDisplay);
out.putLong(myClockStopDisplay); out.putInt(myClockStopDisplay);
out.putLong(myClockAtLastUpdate); out.putInt(myClockAtLastUpdate);
out.putLong(myClocksToEndOfScanLine); out.putInt(myClocksToEndOfScanLine);
out.putLong(myScanlineCountForLastFrame); out.putInt(myScanlineCountForLastFrame);
out.putLong(myCurrentScanline); out.putInt(myCurrentScanline);
out.putLong(myVSYNCFinishClock); out.putInt(myVSYNCFinishClock);
out.putLong(myEnabledObjects); out.putInt(myEnabledObjects);
out.putLong(myVSYNC); out.putInt(myVSYNC);
out.putLong(myVBLANK); out.putInt(myVBLANK);
out.putLong(myNUSIZ0); out.putInt(myNUSIZ0);
out.putLong(myNUSIZ1); out.putInt(myNUSIZ1);
out.putLong(myCOLUP0); out.putInt(myCOLUP0);
out.putLong(myCOLUP1); out.putInt(myCOLUP1);
out.putLong(myCOLUPF); out.putInt(myCOLUPF);
out.putLong(myCOLUBK); out.putInt(myCOLUBK);
out.putLong(myCTRLPF); out.putInt(myCTRLPF);
out.putLong(myPlayfieldPriorityAndScore); out.putInt(myPlayfieldPriorityAndScore);
out.putBool(myREFP0); out.putBool(myREFP0);
out.putBool(myREFP1); out.putBool(myREFP1);
out.putLong(myPF); out.putInt(myPF);
out.putLong(myGRP0); out.putInt(myGRP0);
out.putLong(myGRP1); out.putInt(myGRP1);
out.putLong(myDGRP0); out.putInt(myDGRP0);
out.putLong(myDGRP1); out.putInt(myDGRP1);
out.putBool(myENAM0); out.putBool(myENAM0);
out.putBool(myENAM1); out.putBool(myENAM1);
out.putBool(myENABL); out.putBool(myENABL);
out.putBool(myDENABL); out.putBool(myDENABL);
out.putLong(myHMP0); out.putInt(myHMP0);
out.putLong(myHMP1); out.putInt(myHMP1);
out.putLong(myHMM0); out.putInt(myHMM0);
out.putLong(myHMM1); out.putInt(myHMM1);
out.putLong(myHMBL); out.putInt(myHMBL);
out.putBool(myVDELP0); out.putBool(myVDELP0);
out.putBool(myVDELP1); out.putBool(myVDELP1);
out.putBool(myVDELBL); out.putBool(myVDELBL);
out.putBool(myRESMP0); out.putBool(myRESMP0);
out.putBool(myRESMP1); out.putBool(myRESMP1);
out.putLong(myCollision); out.putInt(myCollision);
out.putLong(myPOSP0); out.putInt(myPOSP0);
out.putLong(myPOSP1); out.putInt(myPOSP1);
out.putLong(myPOSM0); out.putInt(myPOSM0);
out.putLong(myPOSM1); out.putInt(myPOSM1);
out.putLong(myPOSBL); out.putInt(myPOSBL);
out.putLong(myCurrentGRP0); out.putInt(myCurrentGRP0);
out.putLong(myCurrentGRP1); out.putInt(myCurrentGRP1);
// pointers // pointers
// myCurrentBLMask = ourBallMaskTable[0][0]; // myCurrentBLMask = ourBallMaskTable[0][0];
@ -372,13 +372,13 @@ bool TIA::save(Serializer& out)
// myCurrentP1Mask = ourPlayerMaskTable[0][0][0]; // myCurrentP1Mask = ourPlayerMaskTable[0][0][0];
// myCurrentPFMask = ourPlayfieldTable[0]; // myCurrentPFMask = ourPlayfieldTable[0];
out.putLong(myLastHMOVEClock); out.putInt(myLastHMOVEClock);
out.putBool(myHMOVEBlankEnabled); out.putBool(myHMOVEBlankEnabled);
out.putBool(myM0CosmicArkMotionEnabled); out.putBool(myM0CosmicArkMotionEnabled);
out.putLong(myM0CosmicArkCounter); out.putInt(myM0CosmicArkCounter);
out.putBool(myDumpEnabled); out.putBool(myDumpEnabled);
out.putLong(myDumpDisabledCycle); out.putInt(myDumpDisabledCycle);
// Save the sound sample stuff ... // Save the sound sample stuff ...
mySound->save(out); mySound->save(out);
@ -407,59 +407,59 @@ bool TIA::load(Deserializer& in)
if(in.getString() != device) if(in.getString() != device)
return false; return false;
myClockWhenFrameStarted = (Int32) in.getLong(); myClockWhenFrameStarted = (Int32) in.getInt();
myClockStartDisplay = (Int32) in.getLong(); myClockStartDisplay = (Int32) in.getInt();
myClockStopDisplay = (Int32) in.getLong(); myClockStopDisplay = (Int32) in.getInt();
myClockAtLastUpdate = (Int32) in.getLong(); myClockAtLastUpdate = (Int32) in.getInt();
myClocksToEndOfScanLine = (Int32) in.getLong(); myClocksToEndOfScanLine = (Int32) in.getInt();
myScanlineCountForLastFrame = (Int32) in.getLong(); myScanlineCountForLastFrame = (Int32) in.getInt();
myCurrentScanline = (Int32) in.getLong(); myCurrentScanline = (Int32) in.getInt();
myVSYNCFinishClock = (Int32) in.getLong(); myVSYNCFinishClock = (Int32) in.getInt();
myEnabledObjects = (uInt8) in.getLong(); myEnabledObjects = (uInt8) in.getInt();
myVSYNC = (uInt8) in.getLong(); myVSYNC = (uInt8) in.getInt();
myVBLANK = (uInt8) in.getLong(); myVBLANK = (uInt8) in.getInt();
myNUSIZ0 = (uInt8) in.getLong(); myNUSIZ0 = (uInt8) in.getInt();
myNUSIZ1 = (uInt8) in.getLong(); myNUSIZ1 = (uInt8) in.getInt();
myCOLUP0 = (uInt32) in.getLong(); myCOLUP0 = (uInt32) in.getInt();
myCOLUP1 = (uInt32) in.getLong(); myCOLUP1 = (uInt32) in.getInt();
myCOLUPF = (uInt32) in.getLong(); myCOLUPF = (uInt32) in.getInt();
myCOLUBK = (uInt32) in.getLong(); myCOLUBK = (uInt32) in.getInt();
myCTRLPF = (uInt8) in.getLong(); myCTRLPF = (uInt8) in.getInt();
myPlayfieldPriorityAndScore = (uInt8) in.getLong(); myPlayfieldPriorityAndScore = (uInt8) in.getInt();
myREFP0 = in.getBool(); myREFP0 = in.getBool();
myREFP1 = in.getBool(); myREFP1 = in.getBool();
myPF = (uInt32) in.getLong(); myPF = (uInt32) in.getInt();
myGRP0 = (uInt8) in.getLong(); myGRP0 = (uInt8) in.getInt();
myGRP1 = (uInt8) in.getLong(); myGRP1 = (uInt8) in.getInt();
myDGRP0 = (uInt8) in.getLong(); myDGRP0 = (uInt8) in.getInt();
myDGRP1 = (uInt8) in.getLong(); myDGRP1 = (uInt8) in.getInt();
myENAM0 = in.getBool(); myENAM0 = in.getBool();
myENAM1 = in.getBool(); myENAM1 = in.getBool();
myENABL = in.getBool(); myENABL = in.getBool();
myDENABL = in.getBool(); myDENABL = in.getBool();
myHMP0 = (Int8) in.getLong(); myHMP0 = (Int8) in.getInt();
myHMP1 = (Int8) in.getLong(); myHMP1 = (Int8) in.getInt();
myHMM0 = (Int8) in.getLong(); myHMM0 = (Int8) in.getInt();
myHMM1 = (Int8) in.getLong(); myHMM1 = (Int8) in.getInt();
myHMBL = (Int8) in.getLong(); myHMBL = (Int8) in.getInt();
myVDELP0 = in.getBool(); myVDELP0 = in.getBool();
myVDELP1 = in.getBool(); myVDELP1 = in.getBool();
myVDELBL = in.getBool(); myVDELBL = in.getBool();
myRESMP0 = in.getBool(); myRESMP0 = in.getBool();
myRESMP1 = in.getBool(); myRESMP1 = in.getBool();
myCollision = (uInt16) in.getLong(); myCollision = (uInt16) in.getInt();
myPOSP0 = (Int16) in.getLong(); myPOSP0 = (Int16) in.getInt();
myPOSP1 = (Int16) in.getLong(); myPOSP1 = (Int16) in.getInt();
myPOSM0 = (Int16) in.getLong(); myPOSM0 = (Int16) in.getInt();
myPOSM1 = (Int16) in.getLong(); myPOSM1 = (Int16) in.getInt();
myPOSBL = (Int16) in.getLong(); myPOSBL = (Int16) in.getInt();
myCurrentGRP0 = (uInt8) in.getLong(); myCurrentGRP0 = (uInt8) in.getInt();
myCurrentGRP1 = (uInt8) in.getLong(); myCurrentGRP1 = (uInt8) in.getInt();
// pointers // pointers
// myCurrentBLMask = ourBallMaskTable[0][0]; // myCurrentBLMask = ourBallMaskTable[0][0];
@ -469,13 +469,13 @@ bool TIA::load(Deserializer& in)
// myCurrentP1Mask = ourPlayerMaskTable[0][0][0]; // myCurrentP1Mask = ourPlayerMaskTable[0][0][0];
// myCurrentPFMask = ourPlayfieldTable[0]; // myCurrentPFMask = ourPlayfieldTable[0];
myLastHMOVEClock = (Int32) in.getLong(); myLastHMOVEClock = (Int32) in.getInt();
myHMOVEBlankEnabled = in.getBool(); myHMOVEBlankEnabled = in.getBool();
myM0CosmicArkMotionEnabled = in.getBool(); myM0CosmicArkMotionEnabled = in.getBool();
myM0CosmicArkCounter = (uInt32) in.getLong(); myM0CosmicArkCounter = (uInt32) in.getInt();
myDumpEnabled = in.getBool(); myDumpEnabled = in.getBool();
myDumpDisabledCycle = (Int32) in.getLong(); myDumpDisabledCycle = (Int32) in.getInt();
// Load the sound sample stuff ... // Load the sound sample stuff ...
mySound->load(in); mySound->load(in);

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: M6502Hi.cxx,v 1.14 2005-10-11 19:38:10 stephena Exp $ // $Id: M6502Hi.cxx,v 1.15 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include "M6502Hi.hxx" #include "M6502Hi.hxx"
@ -236,12 +236,12 @@ bool M6502High::save(Serializer& out)
{ {
out.putString(CPU); out.putString(CPU);
out.putLong(A); // Accumulator out.putInt(A); // Accumulator
out.putLong(X); // X index register out.putInt(X); // X index register
out.putLong(Y); // Y index register out.putInt(Y); // Y index register
out.putLong(SP); // Stack Pointer out.putInt(SP); // Stack Pointer
out.putLong(IR); // Instruction register out.putInt(IR); // Instruction register
out.putLong(PC); // Program Counter out.putInt(PC); // Program Counter
out.putBool(N); // N flag for processor status register out.putBool(N); // N flag for processor status register
out.putBool(V); // V flag for processor status register out.putBool(V); // V flag for processor status register
@ -251,12 +251,12 @@ bool M6502High::save(Serializer& out)
out.putBool(notZ); // Z flag complement for processor status register out.putBool(notZ); // Z flag complement for processor status register
out.putBool(C); // C flag for processor status register out.putBool(C); // C flag for processor status register
out.putLong(myExecutionStatus); out.putInt(myExecutionStatus);
// Indicates the number of distinct memory accesses // Indicates the number of distinct memory accesses
out.putLong(myNumberOfDistinctAccesses); out.putInt(myNumberOfDistinctAccesses);
// Indicates the last address which was accessed // Indicates the last address which was accessed
out.putLong(myLastAddress); out.putInt(myLastAddress);
} }
catch(char *msg) catch(char *msg)
@ -283,12 +283,12 @@ bool M6502High::load(Deserializer& in)
if(in.getString() != CPU) if(in.getString() != CPU)
return false; return false;
A = (uInt8) in.getLong(); // Accumulator A = (uInt8) in.getInt(); // Accumulator
X = (uInt8) in.getLong(); // X index register X = (uInt8) in.getInt(); // X index register
Y = (uInt8) in.getLong(); // Y index register Y = (uInt8) in.getInt(); // Y index register
SP = (uInt8) in.getLong(); // Stack Pointer SP = (uInt8) in.getInt(); // Stack Pointer
IR = (uInt8) in.getLong(); // Instruction register IR = (uInt8) in.getInt(); // Instruction register
PC = (uInt16) in.getLong(); // Program Counter PC = (uInt16) in.getInt(); // Program Counter
N = in.getBool(); // N flag for processor status register N = in.getBool(); // N flag for processor status register
V = in.getBool(); // V flag for processor status register V = in.getBool(); // V flag for processor status register
@ -298,12 +298,12 @@ bool M6502High::load(Deserializer& in)
notZ = in.getBool(); // Z flag complement for processor status register notZ = in.getBool(); // Z flag complement for processor status register
C = in.getBool(); // C flag for processor status register C = in.getBool(); // C flag for processor status register
myExecutionStatus = (uInt8) in.getLong(); myExecutionStatus = (uInt8) in.getInt();
// Indicates the number of distinct memory accesses // Indicates the number of distinct memory accesses
myNumberOfDistinctAccesses = (uInt32) in.getLong(); myNumberOfDistinctAccesses = (uInt32) in.getInt();
// Indicates the last address which was accessed // Indicates the last address which was accessed
myLastAddress = (uInt16) in.getLong(); myLastAddress = (uInt16) in.getInt();
} }
catch(char *msg) catch(char *msg)
{ {

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: System.cxx,v 1.14 2005-12-09 19:09:49 stephena Exp $ // $Id: System.cxx,v 1.15 2005-12-17 01:23:07 stephena Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -128,7 +128,7 @@ bool System::save(Serializer& out)
try try
{ {
out.putString("System"); out.putString("System");
out.putLong(myCycles); out.putInt(myCycles);
} }
catch(char *msg) catch(char *msg)
{ {
@ -152,7 +152,7 @@ bool System::load(Deserializer& in)
if(in.getString() != "System") if(in.getString() != "System")
return false; return false;
myCycles = (uInt32) in.getLong(); myCycles = (uInt32) in.getInt();
} }
catch(char *msg) catch(char *msg)
{ {