diff --git a/stella/src/emucore/Cart.cxx b/stella/src/emucore/Cart.cxx index 075765da1..7d7b4c44f 100644 --- a/stella/src/emucore/Cart.cxx +++ b/stella/src/emucore/Cart.cxx @@ -8,12 +8,12 @@ // SS SS tt ee ll ll aa aa // SSSS ttt eeeee llll llll aaaaa // -// Copyright (c) 1995-2003 by Bradford W. Mott +// Copyright (c) 1995-2004 by Bradford W. Mott // // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: Cart.cxx,v 1.6 2003-02-17 04:59:54 bwmott Exp $ +// $Id: Cart.cxx,v 1.7 2004-06-25 03:44:12 bwmott Exp $ //============================================================================ #include @@ -37,6 +37,7 @@ #include "CartMC.hxx" #include "CartMB.hxx" #include "CartCV.hxx" +#include "CartUA.hxx" #include "MD5.hxx" #include "Props.hxx" @@ -92,6 +93,8 @@ Cartridge* Cartridge::create(const uInt8* image, uInt32 size, cartridge = new CartridgeMB(image); else if(type == "CV") cartridge = new CartridgeCV(image, size); + else if(type == "UA") + cartridge = new CartridgeUA(image); else { // TODO: At some point this should be handled in a better way... @@ -142,6 +145,8 @@ string Cartridge::autodetectType(const uInt8* image, uInt32 size) {"ac7c2260378975614192ca2bc3d20e0b", "FE"}, // Decathlon {"4f618c2429138e0280969193ed6c107e", "FE"}, // Robot Tank {"6d842c96d5a01967be9680080dd5be54", "DPC"}, // Pitfall II + {"d3bb42228a6cd452c111c1932503cc03", "UA"}, // Funky Fish + {"8bbfd951c89cc09c148bfabdefa08bec", "UA"}, // Pleiades {(char*)0, (char*)0} }; diff --git a/stella/src/emucore/CartUA.cxx b/stella/src/emucore/CartUA.cxx new file mode 100644 index 000000000..d554817c3 --- /dev/null +++ b/stella/src/emucore/CartUA.cxx @@ -0,0 +1,215 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2004 by Bradford W. Mott +// +// See the file "license" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +// +// $Id: CartUA.cxx,v 1.1 2004-06-25 03:44:12 bwmott Exp $ +//============================================================================ + +#include +#include +#include "CartUA.hxx" +#include "System.hxx" +#include "Serializer.hxx" +#include "Deserializer.hxx" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +CartridgeUA::CartridgeUA(const uInt8* image) +{ + // Copy the ROM image into my buffer + for(uInt32 addr = 0; addr < 8192; ++addr) + { + myImage[addr] = image[addr]; + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +CartridgeUA::~CartridgeUA() +{ +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +const char* CartridgeUA::name() const +{ + return "CartridgeUA"; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void CartridgeUA::reset() +{ + // Upon reset we switch to bank 0 + bank(0); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void CartridgeUA::install(System& system) +{ + mySystem = &system; + uInt16 shift = mySystem->pageShift(); + uInt16 mask = mySystem->pageMask(); + + // Make sure the system we're being installed in has a page size that'll work + assert((0x1000 & mask) == 0); + + // Get the page accessing methods for the hot spots since they overlap + // areas within the TIA we'll need to forward requests to the TIA + myHotSpotPageAccess = mySystem->getPageAccess(0x0220 >> shift); + + // Set the page accessing methods for the hot spots + System::PageAccess access; + access.directPeekBase = 0; + access.directPokeBase = 0; + access.device = this; + mySystem->setPageAccess(0x0220 >> shift, access); + mySystem->setPageAccess(0x0240 >> shift, access); + + // Install pages for bank 0 + bank(0); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +uInt8 CartridgeUA::peek(uInt16 address) +{ + address = address & 0x1FFF; + + // Switch banks if necessary + switch(address) + { + case 0x0220: + // Set the current bank to the lower 4k bank + bank(0); + break; + + case 0x0240: + // Set the current bank to the upper 4k bank + bank(1); + break; + + default: + break; + } + + if(!(address & 0x1000)) + { + return myHotSpotPageAccess.device->peek(address); + } + else + { + return 0; + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void CartridgeUA::poke(uInt16 address, uInt8 value) +{ + address = address & 0x1FFF; + + // Switch banks if necessary + switch(address) + { + case 0x0220: + // Set the current bank to the lower 4k bank + bank(0); + break; + + case 0x0240: + // Set the current bank to the upper 4k bank + bank(1); + break; + + default: + break; + } + + if(!(address & 0x1000)) + { + myHotSpotPageAccess.device->poke(address, value); + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void CartridgeUA::bank(uInt16 bank) +{ + // Remember what bank we're in + myCurrentBank = bank; + uInt16 offset = myCurrentBank * 4096; + uInt16 shift = mySystem->pageShift(); + uInt16 mask = mySystem->pageMask(); + + // Setup the page access methods for the current bank + System::PageAccess access; + access.device = this; + access.directPokeBase = 0; + + // Map ROM image into the system + for(uInt32 address = 0x1000; address < 0x2000; address += (1 << shift)) + { + access.directPeekBase = &myImage[offset + (address & 0x0FFF)]; + mySystem->setPageAccess(address >> shift, access); + } +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool CartridgeUA::save(Serializer& out) +{ + string cart = name(); + + try + { + out.putString(cart); + + out.putLong(myCurrentBank); + } + catch(char *msg) + { + cerr << msg << endl; + return false; + } + catch(...) + { + cerr << "Unknown error in save state for " << cart << endl; + return false; + } + + return true; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool CartridgeUA::load(Deserializer& in) +{ + string cart = name(); + + try + { + if(in.getString() != cart) + return false; + + myCurrentBank = (uInt16)in.getLong(); + } + catch(char *msg) + { + cerr << msg << endl; + return false; + } + catch(...) + { + cerr << "Unknown error in load state for " << cart << endl; + return false; + } + + // Remember what bank we were in + bank(myCurrentBank); + + return true; +} + diff --git a/stella/src/emucore/CartUA.hxx b/stella/src/emucore/CartUA.hxx new file mode 100644 index 000000000..a7372d502 --- /dev/null +++ b/stella/src/emucore/CartUA.hxx @@ -0,0 +1,124 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2004 by Bradford W. Mott +// +// See the file "license" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +// +// $Id: CartUA.hxx,v 1.1 2004-06-25 03:44:12 bwmott Exp $ +//============================================================================ + +#ifndef CARTRIDGEUA_HXX +#define CARTRIDGEUA_HXX + +class CartridgeUA; +class Serializer; +class Deserializer; + +#include "bspf.hxx" +#include "Cart.hxx" +#include "System.hxx" + +/** + Cartridge class used for UA Limited's 8K bankswitched games. There + are two 4K banks. + + @author Bradford W. Mott + @version $Id: CartUA.hxx,v 1.1 2004-06-25 03:44:12 bwmott Exp $ +*/ +class CartridgeUA : public Cartridge +{ + public: + /** + Create a new cartridge using the specified image + + @param image Pointer to the ROM image + */ + CartridgeUA(const uInt8* image); + + /** + Destructor + */ + virtual ~CartridgeUA(); + + public: + /** + Get a null terminated string which is the device's name (i.e. "M6532") + + @return The name of the device + */ + virtual const char* name() const; + + /** + Reset device to its power-on state + */ + virtual void reset(); + + /** + Install cartridge in the specified system. Invoked by the system + when the cartridge is attached to it. + + @param system The system the device should install itself in + */ + virtual void install(System& system); + + /** + Saves the current state of this device to the given Serializer. + + @param out The serializer device to save to. + @return The result of the save. True on success, false on failure. + */ + virtual bool save(Serializer& out); + + /** + Loads the current state of this device from the given Deserializer. + + @param in The deserializer device to load from. + @return The result of the load. True on success, false on failure. + */ + virtual bool load(Deserializer& in); + + public: + /** + Get the byte at the specified address. + + @return The byte at the specified address + */ + virtual uInt8 peek(uInt16 address); + + /** + Change the byte at the specified address to the given value + + @param address The address where the value should be stored + @param value The value to be stored at the address + */ + virtual void poke(uInt16 address, uInt8 value); + + private: + /** + Install pages for the specified bank in the system + + @param bank The bank that should be installed in the system + */ + void bank(uInt16 bank); + + private: + // Indicates which bank is currently active + uInt16 myCurrentBank; + + // The 8K ROM image of the cartridge + uInt8 myImage[8192]; + + // Previous Device's page access + System::PageAccess myHotSpotPageAccess; +}; +#endif +