Fix potential crash in ARM code in DPC+ scheme.

This commit is contained in:
Stephen Anthony 2017-04-27 20:24:19 -02:30
parent 8c756001f8
commit ba2bed21b5
2 changed files with 11 additions and 19 deletions

View File

@ -35,15 +35,16 @@ CartridgeDPCPlus::CartridgeDPCPlus(const uInt8* image, uInt32 size,
myARMCycles(0), myARMCycles(0),
myCurrentBank(0) myCurrentBank(0)
{ {
// Store image, making sure it's at least 29KB // Image is always 32K, but in the case of ROM > 29K, the image is
uInt32 minsize = 4096 * 6 + 4096 + 1024 + 255; // copied to the end of the buffer
mySize = std::max(minsize, size); mySize = std::min(size, 32768u);
myImage = make_ptr<uInt8[]>(mySize); if(mySize < 32768u)
memcpy(myImage.get(), image, size); memset(myImage, 0, 32768);
memcpy(myImage + (32768u - mySize), image, size);
createCodeAccessBase(4096 * 6); createCodeAccessBase(4096 * 6);
// Pointer to the program ROM (24K @ 0 byte offset) // Pointer to the program ROM (24K @ 3072 byte offset; ignore first 3K)
myProgramImage = myImage.get(); myProgramImage = myImage + 0xC00;
// Pointer to the display RAM // Pointer to the display RAM
myDisplayImage = myDPCRAM + 0xC00; myDisplayImage = myDPCRAM + 0xC00;
@ -51,15 +52,10 @@ CartridgeDPCPlus::CartridgeDPCPlus(const uInt8* image, uInt32 size,
// Pointer to the Frequency RAM // Pointer to the Frequency RAM
myFrequencyImage = myDisplayImage + 0x1000; myFrequencyImage = myDisplayImage + 0x1000;
// If the image is larger than 29K, we assume any excess at the
// beginning is ARM code, and skip over it
if(size > 29 * 1024)
myProgramImage += (size - 29 * 1024);
#ifdef THUMB_SUPPORT #ifdef THUMB_SUPPORT
// Create Thumbulator ARM emulator // Create Thumbulator ARM emulator
myThumbEmulator = make_ptr<Thumbulator> myThumbEmulator = make_ptr<Thumbulator>
(reinterpret_cast<uInt16*>(myProgramImage-0xC00), (reinterpret_cast<uInt16*>(myImage),
reinterpret_cast<uInt16*>(myDPCRAM), reinterpret_cast<uInt16*>(myDPCRAM),
settings.getBool("thumb.trapfatal"), settings.getBool("thumb.trapfatal"),
Thumbulator::ConfigureFor::DPCplus, Thumbulator::ConfigureFor::DPCplus,
@ -166,15 +162,11 @@ inline void CartridgeDPCPlus::updateMusicModeDataFetchers()
myFractionalClocks = clocks - double(wholeClocks); myFractionalClocks = clocks - double(wholeClocks);
if(wholeClocks <= 0) if(wholeClocks <= 0)
{
return; return;
}
// Let's update counters and flags of the music mode data fetchers // Let's update counters and flags of the music mode data fetchers
for(int x = 0; x <= 2; ++x) for(int x = 0; x <= 2; ++x)
{
myMusicCounters[x] += myMusicFrequencies[x] * wholeClocks; myMusicCounters[x] += myMusicFrequencies[x] * wholeClocks;
}
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -648,7 +640,7 @@ bool CartridgeDPCPlus::patch(uInt16 address, uInt8 value)
const uInt8* CartridgeDPCPlus::getImage(int& size) const const uInt8* CartridgeDPCPlus::getImage(int& size) const
{ {
size = mySize; size = mySize;
return myImage.get(); return myImage + (32768u - mySize);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -201,7 +201,7 @@ class CartridgeDPCPlus : public Cartridge
private: private:
// The ROM image and size // The ROM image and size
BytePtr myImage; uInt8 myImage[32768];
uInt32 mySize; uInt32 mySize;
// Pointer to the 24K program ROM image of the cartridge // Pointer to the 24K program ROM image of the cartridge