2001-12-27 19:54:36 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
2016-12-30 00:00:30 +00:00
|
|
|
// SSSS tt lll lll
|
|
|
|
// SS SS tt ll ll
|
|
|
|
// SS tttttt eeee ll ll aaaa
|
2001-12-27 19:54:36 +00:00
|
|
|
// 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
|
|
|
|
//
|
2019-12-31 17:18:56 +00:00
|
|
|
// Copyright (c) 1995-2020 by Bradford W. Mott, Stephen Anthony
|
2010-04-10 21:37:23 +00:00
|
|
|
// and the Stella Team
|
2001-12-27 19:54:36 +00:00
|
|
|
//
|
2010-01-10 03:23:32 +00:00
|
|
|
// See the file "License.txt" for information on usage and redistribution of
|
2001-12-27 19:54:36 +00:00
|
|
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include "System.hxx"
|
2007-01-14 16:17:57 +00:00
|
|
|
#include "CartE0.hxx"
|
2001-12-27 19:54:36 +00:00
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2019-09-16 23:59:08 +00:00
|
|
|
CartridgeE0::CartridgeE0(const ByteBuffer& image, size_t size,
|
2018-12-18 13:54:40 +00:00
|
|
|
const string& md5, const Settings& settings)
|
|
|
|
: Cartridge(settings, md5)
|
2001-12-27 19:54:36 +00:00
|
|
|
{
|
|
|
|
// Copy the ROM image into my buffer
|
2019-09-16 23:59:08 +00:00
|
|
|
std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin());
|
2020-04-01 09:06:03 +00:00
|
|
|
createRomAccessArrays(myImage.size());
|
2001-12-27 19:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
void CartridgeE0::reset()
|
|
|
|
{
|
|
|
|
// Setup segments to some default slices
|
2017-12-01 09:08:10 +00:00
|
|
|
if(randomStartBank())
|
|
|
|
{
|
2020-04-03 15:08:42 +00:00
|
|
|
bank(mySystem->randGenerator().next() % 8, 0);
|
|
|
|
bank(mySystem->randGenerator().next() % 8, 1);
|
|
|
|
bank(mySystem->randGenerator().next() % 8, 2);
|
2017-12-01 09:08:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-03 15:08:42 +00:00
|
|
|
bank(4, 0);
|
|
|
|
bank(5, 1);
|
|
|
|
bank(6, 2);
|
2017-12-01 09:08:10 +00:00
|
|
|
}
|
2020-04-03 15:08:42 +00:00
|
|
|
myCurrentBank[3] = bankCount() - 1; // fixed
|
2010-03-28 03:13:10 +00:00
|
|
|
|
|
|
|
myBankChanged = true;
|
2001-12-27 19:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
void CartridgeE0::install(System& system)
|
|
|
|
{
|
|
|
|
mySystem = &system;
|
|
|
|
|
2019-03-09 19:32:43 +00:00
|
|
|
System::PageAccess access(this, System::PageAccessType::READ);
|
2010-04-12 19:56:14 +00:00
|
|
|
|
|
|
|
// Set the page acessing methods for the first part of the last segment
|
2019-12-25 01:41:36 +00:00
|
|
|
for(uInt16 addr = 0x1C00; addr < static_cast<uInt16>(0x1FE0U & ~System::PAGE_MASK);
|
2017-09-16 01:58:20 +00:00
|
|
|
addr += System::PAGE_SIZE)
|
2001-12-27 19:54:36 +00:00
|
|
|
{
|
2019-09-17 07:38:47 +00:00
|
|
|
access.directPeekBase = &myImage[0x1C00 + (addr & 0x03FF)];
|
2020-03-30 07:22:45 +00:00
|
|
|
access.romAccessBase = &myRomAccessBase[0x1C00 + (addr & 0x03FF)];
|
2020-04-02 08:38:15 +00:00
|
|
|
access.romPeekCounter = &myRomAccessCounter[0x1C00 + (addr & 0x03FF)];
|
2020-04-02 10:03:35 +00:00
|
|
|
access.romPokeCounter = &myRomAccessCounter[0x1C00 + (addr & 0x03FF) + myAccessSize];
|
2017-09-16 01:58:20 +00:00
|
|
|
mySystem->setPageAccess(addr, access);
|
2001-12-27 19:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the page accessing methods for the hot spots in the last segment
|
2017-10-11 14:53:54 +00:00
|
|
|
access.directPeekBase = nullptr;
|
2020-04-03 15:08:42 +00:00
|
|
|
access.romAccessBase = &myRomAccessBase[0x1FC0];
|
2020-04-02 08:38:15 +00:00
|
|
|
access.romPeekCounter = &myRomAccessCounter[0x1FC0];
|
2020-04-02 10:03:35 +00:00
|
|
|
access.romPokeCounter = &myRomAccessCounter[0x1FC0 + myAccessSize];
|
2019-03-09 19:32:43 +00:00
|
|
|
access.type = System::PageAccessType::READ;
|
2017-09-16 01:58:20 +00:00
|
|
|
for(uInt16 addr = (0x1FE0 & ~System::PAGE_MASK); addr < 0x2000;
|
|
|
|
addr += System::PAGE_SIZE)
|
|
|
|
mySystem->setPageAccess(addr, access);
|
2001-12-27 19:54:36 +00:00
|
|
|
}
|
|
|
|
|
2019-09-07 12:29:33 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2019-09-16 22:16:15 +00:00
|
|
|
uInt16 CartridgeE0::getBank(uInt16 address) const
|
2019-09-07 12:29:33 +00:00
|
|
|
{
|
2020-04-03 15:08:42 +00:00
|
|
|
return myCurrentBank[(address & 0xFFF) >> 10]; // 1K slices
|
2019-09-07 12:29:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
uInt16 CartridgeE0::bankCount() const
|
|
|
|
{
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
|
2001-12-27 19:54:36 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
uInt8 CartridgeE0::peek(uInt16 address)
|
|
|
|
{
|
2009-05-01 11:25:07 +00:00
|
|
|
address &= 0x0FFF;
|
2001-12-27 19:54:36 +00:00
|
|
|
|
2008-03-28 23:29:14 +00:00
|
|
|
// Switch banks if necessary
|
|
|
|
if((address >= 0x0FE0) && (address <= 0x0FE7))
|
|
|
|
{
|
2020-04-03 15:08:42 +00:00
|
|
|
bank(address & 0x0007, 0);
|
2008-03-28 23:29:14 +00:00
|
|
|
}
|
|
|
|
else if((address >= 0x0FE8) && (address <= 0x0FEF))
|
|
|
|
{
|
2020-04-03 15:08:42 +00:00
|
|
|
bank(address & 0x0007, 1);
|
2008-03-28 23:29:14 +00:00
|
|
|
}
|
|
|
|
else if((address >= 0x0FF0) && (address <= 0x0FF7))
|
|
|
|
{
|
2020-04-03 15:08:42 +00:00
|
|
|
bank(address & 0x0007, 2);
|
2001-12-27 19:54:36 +00:00
|
|
|
}
|
|
|
|
|
2020-04-03 15:08:42 +00:00
|
|
|
return myImage[(myCurrentBank[address >> 10] << 10) + (address & 0x03FF)];
|
2001-12-27 19:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2010-03-28 03:13:10 +00:00
|
|
|
bool CartridgeE0::poke(uInt16 address, uInt8)
|
2001-12-27 19:54:36 +00:00
|
|
|
{
|
2009-05-01 11:25:07 +00:00
|
|
|
address &= 0x0FFF;
|
2001-12-27 19:54:36 +00:00
|
|
|
|
2008-03-28 23:29:14 +00:00
|
|
|
// Switch banks if necessary
|
|
|
|
if((address >= 0x0FE0) && (address <= 0x0FE7))
|
|
|
|
{
|
2020-04-03 15:08:42 +00:00
|
|
|
bank(address & 0x0007, 0);
|
2008-03-28 23:29:14 +00:00
|
|
|
}
|
|
|
|
else if((address >= 0x0FE8) && (address <= 0x0FEF))
|
|
|
|
{
|
2020-04-03 15:08:42 +00:00
|
|
|
bank(address & 0x0007, 1);
|
2008-03-28 23:29:14 +00:00
|
|
|
}
|
|
|
|
else if((address >= 0x0FF0) && (address <= 0x0FF7))
|
|
|
|
{
|
2020-04-03 15:08:42 +00:00
|
|
|
bank(address & 0x0007, 2);
|
2001-12-27 19:54:36 +00:00
|
|
|
}
|
2010-03-28 03:13:10 +00:00
|
|
|
return false;
|
2001-12-27 19:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2020-04-03 15:08:42 +00:00
|
|
|
void CartridgeE0::bank(uInt16 bank, uInt16 slice)
|
2016-01-23 18:16:09 +00:00
|
|
|
{
|
2010-03-06 18:56:36 +00:00
|
|
|
if(bankLocked()) return;
|
2008-03-28 23:29:14 +00:00
|
|
|
|
2001-12-27 19:54:36 +00:00
|
|
|
// Remember the new slice
|
2020-04-03 15:08:42 +00:00
|
|
|
myCurrentBank[slice] = bank;
|
|
|
|
uInt16 sliceOffset = slice * (1 << 10);
|
|
|
|
uInt16 bankOffset = bank << 10;
|
2001-12-27 19:54:36 +00:00
|
|
|
|
|
|
|
// Setup the page access methods for the current bank
|
2019-03-09 19:32:43 +00:00
|
|
|
System::PageAccess access(this, System::PageAccessType::READ);
|
2001-12-27 19:54:36 +00:00
|
|
|
|
2020-04-03 15:08:42 +00:00
|
|
|
for(uInt16 addr = 0x1000 + sliceOffset; addr < 0x1000 + sliceOffset + 0x400; addr += System::PAGE_SIZE)
|
2001-12-27 19:54:36 +00:00
|
|
|
{
|
2020-04-03 15:08:42 +00:00
|
|
|
access.directPeekBase = &myImage[bankOffset + (addr & 0x03FF)];
|
|
|
|
access.romAccessBase = &myRomAccessBase[bankOffset + (addr & 0x03FF)];
|
|
|
|
access.romPeekCounter = &myRomAccessCounter[bankOffset + (addr & 0x03FF)];
|
|
|
|
access.romPokeCounter = &myRomAccessCounter[bankOffset + (addr & 0x03FF) + myAccessSize];
|
2017-09-16 01:58:20 +00:00
|
|
|
mySystem->setPageAccess(addr, access);
|
2001-12-27 19:54:36 +00:00
|
|
|
}
|
2010-03-28 03:13:10 +00:00
|
|
|
myBankChanged = true;
|
2001-12-27 19:54:36 +00:00
|
|
|
}
|
|
|
|
|
2002-05-13 19:17:32 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
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 CartridgeE0::patch(uInt16 address, uInt8 value)
|
|
|
|
{
|
2009-05-25 17:51:52 +00:00
|
|
|
address &= 0x0FFF;
|
2020-04-03 15:08:42 +00:00
|
|
|
myImage[(myCurrentBank[address >> 10] << 10) + (address & 0x03FF)] = value;
|
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
|
|
|
return true;
|
2016-01-23 18:16:09 +00:00
|
|
|
}
|
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
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2019-09-16 23:59:08 +00:00
|
|
|
const uInt8* CartridgeE0::getImage(size_t& size) const
|
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
|
|
|
{
|
2019-09-16 22:16:15 +00:00
|
|
|
size = myImage.size();
|
|
|
|
return myImage.data();
|
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 CartridgeE0::save(Serializer& out) const
|
2002-05-13 19:17:32 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2020-04-03 15:08:42 +00:00
|
|
|
out.putShortArray(myCurrentBank.data(), myCurrentBank.size());
|
2002-05-13 19:17:32 +00:00
|
|
|
}
|
2012-05-25 12:41:19 +00:00
|
|
|
catch(...)
|
2002-05-13 19:17:32 +00:00
|
|
|
{
|
2012-05-25 12:41:19 +00:00
|
|
|
cerr << "ERROR: CartridgeE0::save" << endl;
|
2002-05-13 19:17:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
OK, this looks like a huge update, but it's only because of some Serializer
class reworking. Serializer class now handles read/write of state from
files as well as in-memory streams. As a result, Deserializer class has
been removed.
Added state rewinding to the debugger. For now, this is limited to 100
levels of undo, with a new state generated each time a step/trace/frame/
scanline advance is performed. The undo level is 'rolling', in that it
remembers the last 100 levels (so you lose the oldest states when you
start adding more than 100). For now, this is tied to the 'Alt-r' key
in the debugger. Still TODO is add a button for it, and clean up some
TIA output issues when rewinding.
Added support for 6K version of Supercharger ROMs (this fixes issues
with the 6K version of Cubis).
Cleaned up the Serializable infrastructure, making sure that all
classes that need to implement it actually do so now.
Fixed issue with editable widgets in the UI, where pressing Enter
on the keypad wasn't actually being registered.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1849 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2009-08-05 16:05:34 +00:00
|
|
|
bool CartridgeE0::load(Serializer& in)
|
2002-05-13 19:17:32 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2020-04-03 15:08:42 +00:00
|
|
|
in.getShortArray(myCurrentBank.data(), myCurrentBank.size());
|
2002-05-13 19:17:32 +00:00
|
|
|
}
|
2012-05-25 12:41:19 +00:00
|
|
|
catch(...)
|
2002-05-13 19:17:32 +00:00
|
|
|
{
|
2012-05-25 12:41:19 +00:00
|
|
|
cerr << "ERROR: CartridgeE0::load" << endl;
|
2002-05-13 19:17:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|