2001-12-27 19:54:36 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
2009-01-01 18:13:40 +00:00
|
|
|
// Copyright (c) 1995-2009 by Bradford W. Mott and the Stella team
|
2001-12-27 19:54:36 +00:00
|
|
|
//
|
|
|
|
// See the file "license" for information on usage and redistribution of
|
|
|
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
|
|
//
|
2009-05-13 13:55:40 +00:00
|
|
|
// $Id$
|
2001-12-27 19:54:36 +00:00
|
|
|
//============================================================================
|
|
|
|
|
2007-01-14 16:17:57 +00:00
|
|
|
#include <cassert>
|
2008-08-25 23:22:22 +00:00
|
|
|
#include <cstring>
|
2007-01-14 16:17:57 +00:00
|
|
|
|
2001-12-27 19:54:36 +00:00
|
|
|
#include "Random.hxx"
|
|
|
|
#include "System.hxx"
|
2007-01-14 16:17:57 +00:00
|
|
|
#include "CartE7.hxx"
|
2001-12-27 19:54:36 +00:00
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
CartridgeE7::CartridgeE7(const uInt8* image)
|
|
|
|
{
|
|
|
|
// Copy the ROM image into my buffer
|
2008-08-01 12:16:00 +00:00
|
|
|
memcpy(myImage, image, 16384);
|
2001-12-27 19:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
CartridgeE7::~CartridgeE7()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
void CartridgeE7::reset()
|
|
|
|
{
|
2008-08-01 12:16:00 +00:00
|
|
|
// Initialize RAM with random values
|
|
|
|
class Random random;
|
|
|
|
for(uInt32 i = 0; i < 2048; ++i)
|
|
|
|
myRAM[i] = random.next();
|
|
|
|
|
2001-12-27 19:54:36 +00:00
|
|
|
// Install some default banks for the RAM and first segment
|
|
|
|
bankRAM(0);
|
|
|
|
bank(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
void CartridgeE7::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(((0x1400 & mask) == 0) && ((0x1800 & mask) == 0) &&
|
|
|
|
((0x1900 & mask) == 0) && ((0x1A00 & mask) == 0));
|
|
|
|
|
|
|
|
// Set the page accessing methods for the hot spots
|
|
|
|
System::PageAccess access;
|
|
|
|
for(uInt32 i = (0x1FE0 & ~mask); i < 0x2000; i += (1 << shift))
|
|
|
|
{
|
|
|
|
access.directPeekBase = 0;
|
|
|
|
access.directPokeBase = 0;
|
|
|
|
access.device = this;
|
|
|
|
mySystem->setPageAccess(i >> shift, access);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup the second segment to always point to the last ROM slice
|
|
|
|
for(uInt32 j = 0x1A00; j < (0x1FE0U & ~mask); j += (1 << shift))
|
|
|
|
{
|
|
|
|
access.device = this;
|
|
|
|
access.directPeekBase = &myImage[7 * 2048 + (j & 0x07FF)];
|
|
|
|
access.directPokeBase = 0;
|
|
|
|
mySystem->setPageAccess(j >> shift, access);
|
|
|
|
}
|
|
|
|
myCurrentSlice[1] = 7;
|
|
|
|
|
|
|
|
// Install some default banks for the RAM and first segment
|
|
|
|
bankRAM(0);
|
|
|
|
bank(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
uInt8 CartridgeE7::peek(uInt16 address)
|
|
|
|
{
|
2009-05-01 11:25:07 +00:00
|
|
|
address &= 0x0FFF;
|
2001-12-27 19:54:36 +00:00
|
|
|
|
|
|
|
// Switch banks if necessary
|
|
|
|
if((address >= 0x0FE0) && (address <= 0x0FE7))
|
|
|
|
{
|
|
|
|
bank(address & 0x0007);
|
|
|
|
}
|
|
|
|
else if((address >= 0x0FE8) && (address <= 0x0FEB))
|
|
|
|
{
|
|
|
|
bankRAM(address & 0x0003);
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: The following does not handle reading from RAM, however,
|
|
|
|
// this function should never be called for RAM because of the
|
|
|
|
// way page accessing has been setup
|
|
|
|
return myImage[(myCurrentSlice[address >> 11] << 11) + (address & 0x07FF)];
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
void CartridgeE7::poke(uInt16 address, uInt8)
|
|
|
|
{
|
2009-05-01 11:25:07 +00:00
|
|
|
address &= 0x0FFF;
|
2001-12-27 19:54:36 +00:00
|
|
|
|
|
|
|
// Switch banks if necessary
|
|
|
|
if((address >= 0x0FE0) && (address <= 0x0FE7))
|
|
|
|
{
|
|
|
|
bank(address & 0x0007);
|
|
|
|
}
|
|
|
|
else if((address >= 0x0FE8) && (address <= 0x0FEB))
|
|
|
|
{
|
|
|
|
bankRAM(address & 0x0003);
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: This does not handle writing to RAM, however, this
|
|
|
|
// function should never be called for RAM because of the
|
|
|
|
// way page accessing has been setup
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
void CartridgeE7::bankRAM(uInt16 bank)
|
|
|
|
{
|
|
|
|
// Remember what bank we're in
|
|
|
|
myCurrentRAM = bank;
|
|
|
|
uInt16 offset = bank << 8;
|
|
|
|
uInt16 shift = mySystem->pageShift();
|
|
|
|
|
|
|
|
// Setup the page access methods for the current bank
|
|
|
|
System::PageAccess access;
|
|
|
|
access.device = this;
|
|
|
|
|
|
|
|
// Set the page accessing method for the 256 bytes of RAM writing pages
|
|
|
|
access.directPeekBase = 0;
|
|
|
|
access.directPokeBase = 0;
|
|
|
|
for(uInt32 j = 0x1800; j < 0x1900; j += (1 << shift))
|
|
|
|
{
|
|
|
|
access.directPokeBase = &myRAM[1024 + offset + (j & 0x00FF)];
|
|
|
|
mySystem->setPageAccess(j >> shift, access);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the page accessing method for the 256 bytes of RAM reading pages
|
|
|
|
access.directPeekBase = 0;
|
|
|
|
access.directPokeBase = 0;
|
|
|
|
for(uInt32 k = 0x1900; k < 0x1A00; k += (1 << shift))
|
|
|
|
{
|
|
|
|
access.directPeekBase = &myRAM[1024 + offset + (k & 0x00FF)];
|
|
|
|
mySystem->setPageAccess(k >> shift, access);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-30 16:58:22 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2007-01-14 16:17:57 +00:00
|
|
|
void CartridgeE7::bank(uInt16 slice)
|
|
|
|
{
|
2008-03-28 23:29:14 +00:00
|
|
|
if(myBankLocked) return;
|
2007-01-14 16:17:57 +00:00
|
|
|
|
|
|
|
// Remember what bank we're in
|
|
|
|
myCurrentSlice[0] = slice;
|
|
|
|
uInt16 offset = slice << 11;
|
|
|
|
uInt16 shift = mySystem->pageShift();
|
|
|
|
|
|
|
|
// Setup the page access methods for the current bank
|
|
|
|
if(slice != 7)
|
|
|
|
{
|
|
|
|
System::PageAccess access;
|
|
|
|
access.device = this;
|
|
|
|
access.directPokeBase = 0;
|
|
|
|
|
|
|
|
// Map ROM image into first segment
|
|
|
|
for(uInt32 address = 0x1000; address < 0x1800; address += (1 << shift))
|
|
|
|
{
|
|
|
|
access.directPeekBase = &myImage[offset + (address & 0x07FF)];
|
|
|
|
mySystem->setPageAccess(address >> shift, access);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
System::PageAccess access;
|
|
|
|
access.device = this;
|
|
|
|
|
|
|
|
// Set the page accessing method for the 1K slice of RAM writing pages
|
|
|
|
access.directPeekBase = 0;
|
|
|
|
access.directPokeBase = 0;
|
|
|
|
for(uInt32 j = 0x1000; j < 0x1400; j += (1 << shift))
|
|
|
|
{
|
|
|
|
access.directPokeBase = &myRAM[j & 0x03FF];
|
|
|
|
mySystem->setPageAccess(j >> shift, access);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the page accessing method for the 1K slice of RAM reading pages
|
|
|
|
access.directPeekBase = 0;
|
|
|
|
access.directPokeBase = 0;
|
|
|
|
for(uInt32 k = 0x1400; k < 0x1800; k += (1 << shift))
|
|
|
|
{
|
|
|
|
access.directPeekBase = &myRAM[k & 0x03FF];
|
|
|
|
mySystem->setPageAccess(k >> shift, access);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
int CartridgeE7::bank()
|
|
|
|
{
|
|
|
|
return myCurrentSlice[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
int CartridgeE7::bankCount()
|
|
|
|
{
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool CartridgeE7::patch(uInt16 address, uInt8 value)
|
|
|
|
{
|
|
|
|
address = address & 0x0FFF;
|
|
|
|
myImage[(myCurrentSlice[address >> 11] << 11) + (address & 0x07FF)] = value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
uInt8* CartridgeE7::getImage(int& size)
|
|
|
|
{
|
2005-07-30 16:58:22 +00:00
|
|
|
size = 16384;
|
|
|
|
return &myImage[0];
|
|
|
|
}
|
OK, another huge commit. I need to commit this now, because things are
starting to go out of sync on my development machines. OK, where to
begin ...
Changed state file format, so older state files will no longer work. The
changes aren't finalized yet, so expect more breakage.
Added getByte() and putByte() methods to serialized data, resulting in
smaller state files (previously, 1-byte values were stored as 4-byte ints).
Totally reworked controller handling code. Controller state is now
explicitly set with an ::update() method, making it easier to serialize.
Some work is still required on the serialization stuff for more advanced
controllers.
Added a 'Serializable' interface to all carts, device, controllers, etc
that can be (de)serialized. This fixes a long-standing design issue
which I personally caused many years ago.
Console switches state (SWCHB register) is now saved to state files.
Added beginnings of movie support. Basically, this saves an initial
state file, and thereafter continuously saves controller and console
switches state. Support is still somewhat rough and there's no UI for
it, but it does successfully save and later load/play state movies.
Removed specific events for driving controllers, and have them use
joystick events instead. This has the nice side effect that
joystick direction remapping 'just works' for driving controllers too.
Fixed issues with paddle emulation seen in 'Night Driver' ROM. Related
to this, removed a hack wrt paddles when grabmouse is enabled. There's
still some work to do when using the mouse to emulate paddles, but the
Stelladaptor and real paddles work fine.
Added beginnings of TrackBall CX-22 controller emulation. It doesn't
actually do anything yet, but the class is there :)
Probably some other stuff that I'm forgetting ...
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1385 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2007-10-03 21:41:19 +00:00
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool CartridgeE7::save(Serializer& out) const
|
|
|
|
{
|
|
|
|
string cart = name();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
uInt32 i;
|
|
|
|
|
|
|
|
out.putString(cart);
|
|
|
|
|
|
|
|
out.putInt(2);
|
|
|
|
for(i = 0; i < 2; ++i)
|
|
|
|
out.putInt(myCurrentSlice[i]);
|
|
|
|
|
|
|
|
out.putInt(myCurrentRAM);
|
|
|
|
|
|
|
|
// The 2048 bytes of RAM
|
|
|
|
out.putInt(2048);
|
|
|
|
for(i = 0; i < 2048; ++i)
|
|
|
|
out.putByte((char)myRAM[i]);
|
|
|
|
}
|
|
|
|
catch(const char* msg)
|
|
|
|
{
|
|
|
|
cerr << msg << endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
cerr << "Unknown error in save state for " << cart << endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool CartridgeE7::load(Deserializer& in)
|
|
|
|
{
|
|
|
|
string cart = name();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if(in.getString() != cart)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
uInt32 i, limit;
|
|
|
|
|
|
|
|
limit = (uInt32) in.getInt();
|
|
|
|
for(i = 0; i < limit; ++i)
|
|
|
|
myCurrentSlice[i] = (uInt16) in.getInt();
|
|
|
|
|
|
|
|
myCurrentRAM = (uInt16) in.getInt();
|
|
|
|
|
|
|
|
// The 2048 bytes of RAM
|
|
|
|
limit = (uInt32) in.getInt();
|
|
|
|
for(i = 0; i < limit; ++i)
|
|
|
|
myRAM[i] = (uInt8) in.getByte();
|
|
|
|
}
|
|
|
|
catch(const char* msg)
|
|
|
|
{
|
|
|
|
cerr << msg << endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
cerr << "Unknown error in load state for " << cart << endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up the previously used banks for the RAM and segment
|
|
|
|
bankRAM(myCurrentRAM);
|
|
|
|
bank(myCurrentSlice[0]);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|