From 2e440f7e26ecfa101faf3d269c2f4a5c1ee7eb54 Mon Sep 17 00:00:00 2001 From: urchlay Date: Fri, 8 Jul 2005 12:14:18 +0000 Subject: [PATCH] Cart3E save state now saves RAM as it should. Cart3E::patch() now can patch RAM (before, it would have segfaulted if you'd tried) Cart3E constructor now initializes RAM to random junk instead of leaving it uninitialized (which still means full of junk...) git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@621 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/emucore/Cart3E.cxx | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/stella/src/emucore/Cart3E.cxx b/stella/src/emucore/Cart3E.cxx index 20ca254ba..ca2185bf2 100644 --- a/stella/src/emucore/Cart3E.cxx +++ b/stella/src/emucore/Cart3E.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Cart3E.cxx,v 1.1 2005-07-08 04:00:09 urchlay Exp $ +// $Id: Cart3E.cxx,v 1.2 2005-07-08 12:14:18 urchlay Exp $ //============================================================================ #include @@ -35,6 +35,13 @@ Cartridge3E::Cartridge3E(const uInt8* image, uInt32 size) { myImage[addr] = image[addr]; } + + // Initialize RAM with random values + Random random; + for(uInt32 i = 0; i < 32768; ++i) + { + myRAM[i] = random.next(); + } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -123,6 +130,9 @@ void Cartridge3E::poke(uInt16 address, uInt8 value) { bank(value + 256); } + + // TODO: Ask Kroko whether addresses 0-0x3d do anything (on 3F, they + // cause a bankswitch) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -131,7 +141,10 @@ bool Cartridge3E::patch(uInt16 address, uInt8 value) address = address & 0x0FFF; if(address < 0x0800) { - myImage[(address & 0x07FF) + myCurrentBank * 2048] = value; + if(myCurrentBank < 256) + myImage[(address & 0x07FF) + myCurrentBank * 2048] = value; + else + myRam[(address & 0x03FF) + (myCurrentBank - 256) * 1024] = value; } else { @@ -224,6 +237,11 @@ bool Cartridge3E::save(Serializer& out) { out.putString(cart); out.putLong(myCurrentBank); + + // Output RAM + out.putLong(32768); + for(uInt32 addr = 0; addr < 32768; ++addr) + out.putLong(myRAM[addr]); } catch(char *msg) { @@ -250,6 +268,11 @@ bool Cartridge3E::load(Deserializer& in) return false; myCurrentBank = (uInt16) in.getLong(); + + // Input RAM + uInt32 limit = (uInt32) in.getLong(); + for(uInt32 addr = 0; addr < limit; ++addr) + myRAM[addr] = (uInt8) in.getLong(); } catch(char *msg) {