2009-04-05 20:18:41 +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
|
|
|
|
//
|
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
|
2009-04-05 20:18:41 +00:00
|
|
|
//
|
2010-01-10 03:23:32 +00:00
|
|
|
// See the file "License.txt" for information on usage and redistribution of
|
2009-04-05 20:18:41 +00:00
|
|
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include "System.hxx"
|
|
|
|
#include "CartEFSC.hxx"
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2019-09-16 23:59:08 +00:00
|
|
|
CartridgeEFSC::CartridgeEFSC(const ByteBuffer& image, size_t size,
|
2018-12-18 13:54:40 +00:00
|
|
|
const string& md5, const Settings& settings)
|
2019-12-29 22:06:56 +00:00
|
|
|
: Cartridge(settings, md5)
|
2009-04-05 20:18:41 +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());
|
2009-04-05 20:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
void CartridgeEFSC::reset()
|
|
|
|
{
|
2019-09-16 22:16:15 +00:00
|
|
|
initializeRAM(myRAM.data(), myRAM.size());
|
2018-09-14 23:27:36 +00:00
|
|
|
initializeStartBank(15);
|
2009-04-05 20:18:41 +00:00
|
|
|
|
2010-03-05 22:02:12 +00:00
|
|
|
// Upon reset we switch to the startup bank
|
2018-09-14 23:27:36 +00:00
|
|
|
bank(startBank());
|
2009-04-05 20:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
void CartridgeEFSC::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
|
|
|
|
2009-04-05 20:18:41 +00:00
|
|
|
// Set the page accessing method for the RAM writing pages
|
2018-12-17 23:45:11 +00:00
|
|
|
// Map access to this class, since we need to inspect all accesses to
|
|
|
|
// check if RWP happens
|
2019-03-09 19:32:43 +00:00
|
|
|
access.type = System::PageAccessType::WRITE;
|
2017-09-16 01:58:20 +00:00
|
|
|
for(uInt16 addr = 0x1000; addr < 0x1080; addr += System::PAGE_SIZE)
|
2009-04-05 20:18:41 +00:00
|
|
|
{
|
2020-03-30 07:22:45 +00:00
|
|
|
access.romAccessBase = &myRomAccessBase[addr & 0x007F];
|
2020-04-02 08:38:15 +00:00
|
|
|
access.romPeekCounter = &myRomAccessCounter[addr & 0x007F];
|
2020-04-02 10:03:35 +00:00
|
|
|
access.romPokeCounter = &myRomAccessCounter[(addr & 0x007F) + myAccessSize];
|
2017-09-16 01:58:20 +00:00
|
|
|
mySystem->setPageAccess(addr, access);
|
2009-04-05 20:18:41 +00:00
|
|
|
}
|
2015-12-04 19:08:14 +00:00
|
|
|
|
2009-04-05 20:18:41 +00:00
|
|
|
// Set the page accessing method for the RAM reading pages
|
2019-03-09 19:32:43 +00:00
|
|
|
access.type = System::PageAccessType::READ;
|
2017-09-16 01:58:20 +00:00
|
|
|
for(uInt16 addr = 0x1080; addr < 0x1100; addr += System::PAGE_SIZE)
|
2009-04-05 20:18:41 +00:00
|
|
|
{
|
2017-09-16 01:58:20 +00:00
|
|
|
access.directPeekBase = &myRAM[addr & 0x007F];
|
2020-03-30 07:22:45 +00:00
|
|
|
access.romAccessBase = &myRomAccessBase[0x80 + (addr & 0x007F)];
|
2020-04-02 08:38:15 +00:00
|
|
|
access.romPeekCounter = &myRomAccessCounter[0x80 + (addr & 0x007F)];
|
2020-04-02 10:03:35 +00:00
|
|
|
access.romPokeCounter = &myRomAccessCounter[0x80 + (addr & 0x007F) + myAccessSize];
|
2017-09-16 01:58:20 +00:00
|
|
|
mySystem->setPageAccess(addr, access);
|
2009-04-05 20:18:41 +00:00
|
|
|
}
|
|
|
|
|
2010-03-05 22:02:12 +00:00
|
|
|
// Install pages for the startup bank
|
2018-09-14 23:27:36 +00:00
|
|
|
bank(startBank());
|
2009-04-05 20:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
uInt8 CartridgeEFSC::peek(uInt16 address)
|
|
|
|
{
|
OK, this is the first pass at a huge reorganization of the debugger
classes. First off, the distella code has been integrated into a
DiStella class. This code isn't yet tied to the debugger, but it does
at least compile and generate valid output.
The RamDebug class has been replaced by a CartDebug class, which
takes responsibility for the previous RamDebug stuff as well as
things related to Cart address space (read from write ports,
disassembly, etc).
Fixed E7 bankswitching when reading from the write port in the upper
256byte area.
Fixed 'read from write port functionality' in general for all carts
that supported it previously. Basically, if _rwport is enabled, the
address is checked to be an actual read (vs. one that's part of a
normal write cycle), *and* it's actually an illegal access (each
cart/bankswitch type now provides a hint to indicate this condition).
Still TODO is clean up the rework, properly integrate DiStella, and
fix labels and defines (which seem to be completely broken).
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1922 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2010-01-17 16:48:45 +00:00
|
|
|
uInt16 peekAddress = address;
|
2009-05-01 11:25:07 +00:00
|
|
|
address &= 0x0FFF;
|
2009-04-05 20:18:41 +00:00
|
|
|
|
|
|
|
// Switch banks if necessary
|
|
|
|
if((address >= 0x0FE0) && (address <= 0x0FEF))
|
|
|
|
bank(address - 0x0FE0);
|
|
|
|
|
2018-12-08 01:15:28 +00:00
|
|
|
if(address < 0x0080) // Write port is at 0xF000 - 0xF07F (128 bytes)
|
2018-12-17 23:45:11 +00:00
|
|
|
return peekRAM(myRAM[address], peekAddress);
|
2009-05-25 17:51:52 +00:00
|
|
|
else
|
2017-08-31 15:31:45 +00:00
|
|
|
return myImage[myBankOffset + address];
|
2009-04-05 20:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2018-12-17 23:45:11 +00:00
|
|
|
bool CartridgeEFSC::poke(uInt16 address, uInt8 value)
|
2009-04-05 20:18:41 +00:00
|
|
|
{
|
2018-12-18 00:11:39 +00:00
|
|
|
uInt16 pokeAddress = address;
|
2009-05-01 11:25:07 +00:00
|
|
|
address &= 0x0FFF;
|
2009-04-05 20:18:41 +00:00
|
|
|
|
|
|
|
// Switch banks if necessary
|
|
|
|
if((address >= 0x0FE0) && (address <= 0x0FEF))
|
2018-12-17 23:45:11 +00:00
|
|
|
{
|
2009-04-05 20:18:41 +00:00
|
|
|
bank(address - 0x0FE0);
|
2018-12-17 23:45:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-04-05 20:18:41 +00:00
|
|
|
|
2019-09-15 09:36:46 +00:00
|
|
|
if (!(address & 0x080))
|
2019-09-12 09:08:26 +00:00
|
|
|
{
|
|
|
|
pokeRAM(myRAM[address & 0x007F], pokeAddress, value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-15 15:04:25 +00:00
|
|
|
// Writing to the read port should be ignored, but trigger a break if option enabled
|
2019-09-12 09:08:26 +00:00
|
|
|
uInt8 dummy;
|
|
|
|
|
|
|
|
pokeRAM(dummy, pokeAddress, value);
|
2019-09-15 15:04:25 +00:00
|
|
|
myRamWriteAccess = pokeAddress;
|
2019-09-12 09:08:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-04-05 20:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2010-08-16 16:41:24 +00:00
|
|
|
bool CartridgeEFSC::bank(uInt16 bank)
|
2009-04-05 20:18:41 +00:00
|
|
|
{
|
2010-08-16 16:41:24 +00:00
|
|
|
if(bankLocked()) return false;
|
2009-04-05 20:18:41 +00:00
|
|
|
|
|
|
|
// Remember what bank we're in
|
2017-08-31 15:31:45 +00:00
|
|
|
myBankOffset = bank << 12;
|
2009-04-05 20:18:41 +00:00
|
|
|
|
2019-03-09 19:32:43 +00:00
|
|
|
System::PageAccess access(this, System::PageAccessType::READ);
|
2009-04-05 20:18:41 +00:00
|
|
|
|
The emulation core now tracks access to DATA areas (currently, any address
used as a peek operand). Still TODO is deal with poke areas, which would
be relevant in carts with extended RAM.
The interaction between the internal tracking and Distella is now much
tighter, in that knowledge gained by Distella is used in the core code,
and vice versa. This allows the best of both worlds, where the internal
tracking finds stuff at runtime (that couldn't be found in a static
analysis), and Distella tracks potential paths (that haven't occurred at
runtime yet).
Added 'type' debugger prompt command, which basically queries an address
for its disassembly type (CODE/GFX/DATA, etc).
Added debugger commands to query the last address used in an operation
for various registers, but they're only stubs at the moment.
Updated the bankswitch schemes to deal with accesses in and around the
hotspot areas. Previously, peek accesses in these areas weren't being
recorded as DATA areas.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2145 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2010-10-10 20:24:22 +00:00
|
|
|
// Set the page accessing methods for the hot spots
|
2017-09-16 01:58:20 +00:00
|
|
|
for(uInt16 addr = (0x1FE0 & ~System::PAGE_MASK); addr < 0x2000;
|
|
|
|
addr += System::PAGE_SIZE)
|
The emulation core now tracks access to DATA areas (currently, any address
used as a peek operand). Still TODO is deal with poke areas, which would
be relevant in carts with extended RAM.
The interaction between the internal tracking and Distella is now much
tighter, in that knowledge gained by Distella is used in the core code,
and vice versa. This allows the best of both worlds, where the internal
tracking finds stuff at runtime (that couldn't be found in a static
analysis), and Distella tracks potential paths (that haven't occurred at
runtime yet).
Added 'type' debugger prompt command, which basically queries an address
for its disassembly type (CODE/GFX/DATA, etc).
Added debugger commands to query the last address used in an operation
for various registers, but they're only stubs at the moment.
Updated the bankswitch schemes to deal with accesses in and around the
hotspot areas. Previously, peek accesses in these areas weren't being
recorded as DATA areas.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2145 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2010-10-10 20:24:22 +00:00
|
|
|
{
|
2020-03-30 07:22:45 +00:00
|
|
|
access.romAccessBase = &myRomAccessBase[myBankOffset + (addr & 0x0FFF)];
|
2020-04-02 08:38:15 +00:00
|
|
|
access.romPeekCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF)];
|
2020-04-02 10:03:35 +00:00
|
|
|
access.romPokeCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF) + myAccessSize];
|
2017-09-16 01:58:20 +00:00
|
|
|
mySystem->setPageAccess(addr, access);
|
The emulation core now tracks access to DATA areas (currently, any address
used as a peek operand). Still TODO is deal with poke areas, which would
be relevant in carts with extended RAM.
The interaction between the internal tracking and Distella is now much
tighter, in that knowledge gained by Distella is used in the core code,
and vice versa. This allows the best of both worlds, where the internal
tracking finds stuff at runtime (that couldn't be found in a static
analysis), and Distella tracks potential paths (that haven't occurred at
runtime yet).
Added 'type' debugger prompt command, which basically queries an address
for its disassembly type (CODE/GFX/DATA, etc).
Added debugger commands to query the last address used in an operation
for various registers, but they're only stubs at the moment.
Updated the bankswitch schemes to deal with accesses in and around the
hotspot areas. Previously, peek accesses in these areas weren't being
recorded as DATA areas.
git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2145 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
2010-10-10 20:24:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Setup the page access methods for the current bank
|
2019-12-25 01:41:36 +00:00
|
|
|
for(uInt16 addr = 0x1100; addr < static_cast<uInt16>(0x1FE0U & ~System::PAGE_MASK);
|
2017-09-16 01:58:20 +00:00
|
|
|
addr += System::PAGE_SIZE)
|
2009-04-05 20:18:41 +00:00
|
|
|
{
|
2017-09-16 01:58:20 +00:00
|
|
|
access.directPeekBase = &myImage[myBankOffset + (addr & 0x0FFF)];
|
2020-03-30 07:22:45 +00:00
|
|
|
access.romAccessBase = &myRomAccessBase[myBankOffset + (addr & 0x0FFF)];
|
2020-04-02 08:38:15 +00:00
|
|
|
access.romPeekCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF)];
|
2020-04-02 10:03:35 +00:00
|
|
|
access.romPokeCounter = &myRomAccessCounter[myBankOffset + (addr & 0x0FFF) + myAccessSize];
|
2017-09-16 01:58:20 +00:00
|
|
|
mySystem->setPageAccess(addr, access);
|
2009-04-05 20:18:41 +00:00
|
|
|
}
|
2010-08-16 16:41:24 +00:00
|
|
|
return myBankChanged = true;
|
2009-04-05 20:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2019-09-16 22:16:15 +00:00
|
|
|
uInt16 CartridgeEFSC::getBank(uInt16) const
|
2009-04-05 20:18:41 +00:00
|
|
|
{
|
2017-08-31 15:31:45 +00:00
|
|
|
return myBankOffset >> 12;
|
2009-04-05 20:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2010-04-02 22:09:31 +00:00
|
|
|
uInt16 CartridgeEFSC::bankCount() const
|
2009-04-05 20:18:41 +00:00
|
|
|
{
|
|
|
|
return 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool CartridgeEFSC::patch(uInt16 address, uInt8 value)
|
|
|
|
{
|
2010-03-28 16:01:31 +00:00
|
|
|
address &= 0x0FFF;
|
|
|
|
|
2010-03-30 20:36:13 +00:00
|
|
|
if(address < 0x0100)
|
2010-03-28 16:01:31 +00:00
|
|
|
{
|
|
|
|
// Normally, a write to the read port won't do anything
|
|
|
|
// However, the patch command is special in that ignores such
|
|
|
|
// cart restrictions
|
2010-03-30 20:36:13 +00:00
|
|
|
myRAM[address & 0x007F] = value;
|
2010-03-28 16:01:31 +00:00
|
|
|
}
|
|
|
|
else
|
2017-08-31 15:31:45 +00:00
|
|
|
myImage[myBankOffset + address] = value;
|
2010-03-28 16:01:31 +00:00
|
|
|
|
2010-03-06 18:56:36 +00:00
|
|
|
return myBankChanged = true;
|
2016-01-23 18:16:09 +00:00
|
|
|
}
|
2009-04-05 20:18:41 +00:00
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2019-09-16 23:59:08 +00:00
|
|
|
const uInt8* CartridgeEFSC::getImage(size_t& size) const
|
2009-04-05 20:18:41 +00:00
|
|
|
{
|
2019-09-16 22:16:15 +00:00
|
|
|
size = myImage.size();
|
|
|
|
return myImage.data();
|
2009-04-05 20:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool CartridgeEFSC::save(Serializer& out) const
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2017-08-31 15:31:45 +00:00
|
|
|
out.putShort(myBankOffset);
|
2019-09-16 22:16:15 +00:00
|
|
|
out.putByteArray(myRAM.data(), myRAM.size());
|
2009-04-05 20:18:41 +00:00
|
|
|
}
|
2012-05-25 12:41:19 +00:00
|
|
|
catch(...)
|
2009-04-05 20:18:41 +00:00
|
|
|
{
|
2012-05-25 12:41:19 +00:00
|
|
|
cerr << "ERROR: CartridgeEFSC::save" << endl;
|
2009-04-05 20:18:41 +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 CartridgeEFSC::load(Serializer& in)
|
2009-04-05 20:18:41 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2017-08-31 15:31:45 +00:00
|
|
|
myBankOffset = in.getShort();
|
2019-09-16 22:16:15 +00:00
|
|
|
in.getByteArray(myRAM.data(), myRAM.size());
|
2009-04-05 20:18:41 +00:00
|
|
|
}
|
2012-05-25 12:41:19 +00:00
|
|
|
catch(...)
|
2009-04-05 20:18:41 +00:00
|
|
|
{
|
2012-05-25 12:41:19 +00:00
|
|
|
cerr << "ERROR: CartridgeEFSC::load" << endl;
|
2009-04-05 20:18:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remember what bank we were in
|
2017-08-31 15:31:45 +00:00
|
|
|
bank(myBankOffset >> 12);
|
2009-04-05 20:18:41 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|