//============================================================================ // // 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-2009 by Bradford W. Mott and the Stella team // // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // // $Id$ //============================================================================ #include #include #include "System.hxx" #include "CartF8.hxx" // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CartridgeF8::CartridgeF8(const uInt8* image, bool startlow) { // Copy the ROM image into my buffer memcpy(myImage, image, 8192); // Normally bank 1 is the reset bank, unless we're dealing with ROMs // that have been incorrectly created with banks in the opposite order myResetBank = startlow ? 0 : 1; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CartridgeF8::~CartridgeF8() { } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeF8::reset() { // Upon reset we switch to the reset bank bank(myResetBank); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeF8::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); // Set the page accessing methods for the hot spots System::PageAccess access; for(uInt32 i = (0x1FF8 & ~mask); i < 0x2000; i += (1 << shift)) { access.directPeekBase = 0; access.directPokeBase = 0; access.device = this; mySystem->setPageAccess(i >> shift, access); } // Install pages for bank 1 bank(1); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt8 CartridgeF8::peek(uInt16 address) { address &= 0x0FFF; // Switch banks if necessary switch(address) { case 0x0FF8: // Set the current bank to the lower 4k bank bank(0); break; case 0x0FF9: // Set the current bank to the upper 4k bank bank(1); break; default: break; } return myImage[myCurrentBank * 4096 + address]; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeF8::poke(uInt16 address, uInt8) { address &= 0x0FFF; // Switch banks if necessary switch(address) { case 0x0FF8: // Set the current bank to the lower 4k bank bank(0); break; case 0x0FF9: // Set the current bank to the upper 4k bank bank(1); break; default: break; } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeF8::bank(uInt16 bank) { if(myBankLocked) return; // 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 < (0x1FF8U & ~mask); address += (1 << shift)) { access.directPeekBase = &myImage[offset + (address & 0x0FFF)]; mySystem->setPageAccess(address >> shift, access); } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int CartridgeF8::bank() { return myCurrentBank; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - int CartridgeF8::bankCount() { return 2; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeF8::patch(uInt16 address, uInt8 value) { address &= 0xfff; myImage[myCurrentBank * 4096 + address] = value; bank(myCurrentBank); return true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - uInt8* CartridgeF8::getImage(int& size) { size = 8192; return &myImage[0]; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeF8::save(Serializer& out) const { string cart = name(); try { out.putString(cart); out.putInt(myCurrentBank); } catch(const char* msg) { cerr << msg << endl; return false; } catch(...) { cerr << "Unknown error in save state for " << cart << endl; return false; } return true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeF8::load(Deserializer& in) { string cart = name(); try { if(in.getString() != cart) return false; myCurrentBank = (uInt16) in.getInt(); } catch(const 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; }