2014-01-17 15:39:11 +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
|
2014-01-17 15:39:11 +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
|
2014-01-17 15:39:11 +00:00
|
|
|
// and the Stella Team
|
|
|
|
//
|
|
|
|
// See the file "License.txt" for information on usage and redistribution of
|
|
|
|
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include "System.hxx"
|
|
|
|
#include "Cart4KSC.hxx"
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2019-09-16 23:59:08 +00:00
|
|
|
Cartridge4KSC::Cartridge4KSC(const ByteBuffer& image, size_t size,
|
2018-12-18 13:54:40 +00:00
|
|
|
const string& md5, const Settings& settings)
|
|
|
|
: Cartridge(settings, md5)
|
2014-01-17 15:39:11 +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());
|
2014-01-17 15:39:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
void Cartridge4KSC::reset()
|
|
|
|
{
|
2019-09-16 22:16:15 +00:00
|
|
|
initializeRAM(myRAM.data(), myRAM.size());
|
2016-08-24 23:57:07 +00:00
|
|
|
|
2014-01-17 15:39:11 +00:00
|
|
|
myBankChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
void Cartridge4KSC::install(System& system)
|
|
|
|
{
|
|
|
|
mySystem = &system;
|
|
|
|
|
2019-03-09 19:32:43 +00:00
|
|
|
System::PageAccess access(this, System::PageAccessType::READ);
|
2014-01-17 15:39:11 +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)
|
2014-01-17 15:39:11 +00:00
|
|
|
{
|
2020-03-30 07:22:45 +00:00
|
|
|
access.romAccessBase = &myRomAccessBase[addr & 0x007F];
|
2017-09-16 01:58:20 +00:00
|
|
|
mySystem->setPageAccess(addr, access);
|
2014-01-17 15:39:11 +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)
|
2014-01-17 15:39:11 +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)];
|
2017-09-16 01:58:20 +00:00
|
|
|
mySystem->setPageAccess(addr, access);
|
2014-01-17 15:39:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Map ROM image into the system
|
2017-09-16 01:58:20 +00:00
|
|
|
for(uInt16 addr = 0x1100; addr < 0x2000; addr += System::PAGE_SIZE)
|
2014-01-17 15:39:11 +00:00
|
|
|
{
|
2017-09-16 01:58:20 +00:00
|
|
|
access.directPeekBase = &myImage[addr & 0x0FFF];
|
2020-03-30 07:22:45 +00:00
|
|
|
access.romAccessBase = &myRomAccessBase[addr & 0x0FFF];
|
2017-09-16 01:58:20 +00:00
|
|
|
mySystem->setPageAccess(addr, access);
|
2014-01-17 15:39:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
uInt8 Cartridge4KSC::peek(uInt16 address)
|
|
|
|
{
|
2017-08-30 22:15:57 +00:00
|
|
|
// The only way we can get to this method is if we attempt to read from
|
2018-12-08 01:15:28 +00:00
|
|
|
// the write port (0xF000 - 0xF07F, 128 bytes), in which case an
|
2018-12-17 23:45:11 +00:00
|
|
|
// unwanted write is potentially triggered
|
|
|
|
return peekRAM(myRAM[address & 0x007F], address);
|
|
|
|
}
|
2014-01-17 15:39:11 +00:00
|
|
|
|
2018-12-17 23:45:11 +00:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool Cartridge4KSC::poke(uInt16 address, uInt8 value)
|
|
|
|
{
|
2019-09-15 09:36:46 +00:00
|
|
|
if (!(address & 0x080))
|
2019-09-12 09:08:26 +00:00
|
|
|
{
|
|
|
|
pokeRAM(myRAM[address & 0x007F], address, 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, address, value);
|
2019-09-15 15:04:25 +00:00
|
|
|
myRamWriteAccess = address;
|
2019-09-12 09:08:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
2014-01-17 15:39:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool Cartridge4KSC::patch(uInt16 address, uInt8 value)
|
|
|
|
{
|
|
|
|
address &= 0x0FFF;
|
|
|
|
|
|
|
|
if(address < 0x0100)
|
|
|
|
{
|
|
|
|
// Normally, a write to the read port won't do anything
|
|
|
|
// However, the patch command is special in that ignores such
|
|
|
|
// cart restrictions
|
|
|
|
myRAM[address & 0x007F] = value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
myImage[address & 0xFFF] = value;
|
|
|
|
|
|
|
|
return myBankChanged = true;
|
2016-01-23 18:16:09 +00:00
|
|
|
}
|
2014-01-17 15:39:11 +00:00
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2019-09-16 23:59:08 +00:00
|
|
|
const uInt8* Cartridge4KSC::getImage(size_t& size) const
|
2014-01-17 15:39:11 +00:00
|
|
|
{
|
2019-09-16 22:16:15 +00:00
|
|
|
size = myImage.size();
|
|
|
|
return myImage.data();
|
2014-01-17 15:39:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool Cartridge4KSC::save(Serializer& out) const
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2019-09-16 22:16:15 +00:00
|
|
|
out.putByteArray(myRAM.data(), myRAM.size());
|
2014-01-17 15:39:11 +00:00
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
cerr << "ERROR: Cartridge4KSC::save" << endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
bool Cartridge4KSC::load(Serializer& in)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2019-09-16 22:16:15 +00:00
|
|
|
in.getByteArray(myRAM.data(), myRAM.size());
|
2014-01-17 15:39:11 +00:00
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
cerr << "ERROR: Cartridge4KSC::load" << endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|