Refactor Cart::getImage, always return a ByteBuffer.

Most classes did this already, but some didn't.  So we standardize on this, and eliminate raw pointers.
This commit is contained in:
Stephen Anthony 2020-07-02 17:28:48 -02:30
parent 2245d87875
commit 29cbdb09cf
31 changed files with 139 additions and 126 deletions

View File

@ -35,7 +35,7 @@ string Cartridge3EPlusWidget::description()
{ {
ostringstream info; ostringstream info;
size_t size; size_t size;
const uInt8* image = myCart.getImage(size); const ByteBuffer& image = myCart.getImage(size);
uInt16 numRomBanks = myCart.romBankCount(); uInt16 numRomBanks = myCart.romBankCount();
uInt16 numRamBanks = myCart.ramBankCount(); uInt16 numRamBanks = myCart.ramBankCount();
@ -60,7 +60,7 @@ string Cartridge3EPlusWidget::description()
void Cartridge3EPlusWidget::bankSelect(int& ypos) void Cartridge3EPlusWidget::bankSelect(int& ypos)
{ {
size_t size; size_t size;
const uInt8* image = myCart.getImage(size); const ByteBuffer& image = myCart.getImage(size);
const int VGAP = myFontHeight / 4; const int VGAP = myFontHeight / 4;
VariantList banktype; VariantList banktype;

View File

@ -33,7 +33,7 @@ string Cartridge3EWidget::description()
{ {
ostringstream info; ostringstream info;
size_t size; size_t size;
const uInt8* image = myCart.getImage(size); const ByteBuffer& image = myCart.getImage(size);
uInt16 numRomBanks = myCart.romBankCount(); uInt16 numRomBanks = myCart.romBankCount();
uInt16 numRamBanks = myCart.ramBankCount(); uInt16 numRamBanks = myCart.ramBankCount();

View File

@ -33,7 +33,7 @@ string Cartridge3FWidget::description()
{ {
ostringstream info; ostringstream info;
size_t size; size_t size;
const uInt8* image = myCart.getImage(size); const ByteBuffer& image = myCart.getImage(size);
info << "Tigervision 3F cartridge, 2 - 256 2K banks\n" info << "Tigervision 3F cartridge, 2 - 256 2K banks\n"
<< "First 2K bank selected by writing to " << hotspotStr() << "\n" << "First 2K bank selected by writing to " << hotspotStr() << "\n"

View File

@ -94,7 +94,7 @@ string CartridgeEnhancedWidget::romDescription()
{ {
ostringstream info; ostringstream info;
size_t size; size_t size;
const uInt8* image = myCart.getImage(size); const ByteBuffer& image = myCart.getImage(size);
if(myCart.romBankCount() > 1) if(myCart.romBankCount() > 1)
{ {

View File

@ -56,14 +56,14 @@ bool Cartridge::saveROM(ofstream& out) const
{ {
size_t size = 0; size_t size = 0;
const uInt8* image = getImage(size); const ByteBuffer& image = getImage(size);
if(image == nullptr || size == 0) if(size == 0)
{ {
cerr << "save not supported" << endl; cerr << "save not supported" << endl;
return false; return false;
} }
out.write(reinterpret_cast<const char*>(image), size); out.write(reinterpret_cast<const char*>(image.get()), size);
return true; return true;
} }

View File

@ -229,9 +229,9 @@ class Cartridge : public Device
Access the internal ROM image for this cartridge. Access the internal ROM image for this cartridge.
@param size Set to the size of the internal ROM image data @param size Set to the size of the internal ROM image data
@return A pointer to the internal ROM image data @return A reference to the internal ROM image data
*/ */
virtual const uInt8* getImage(size_t& size) const = 0; virtual const ByteBuffer& getImage(size_t& size) const = 0;
/** /**
Get a descriptor for the cart name. Get a descriptor for the cart name.

View File

@ -24,6 +24,7 @@
Cartridge4A50::Cartridge4A50(const ByteBuffer& image, size_t size, Cartridge4A50::Cartridge4A50(const ByteBuffer& image, size_t size,
const string& md5, const Settings& settings) const string& md5, const Settings& settings)
: Cartridge(settings, md5), : Cartridge(settings, md5),
myImage(make_unique<uInt8[]>(128_KB)),
mySize(size) mySize(size)
{ {
// Copy the ROM image into my buffer // Copy the ROM image into my buffer
@ -32,7 +33,7 @@ Cartridge4A50::Cartridge4A50(const ByteBuffer& image, size_t size,
else if(size < 128_KB) size = 64_KB; else if(size < 128_KB) size = 64_KB;
else size = 128_KB; else size = 128_KB;
for(uInt32 slice = 0; slice < 128_KB / size; ++slice) for(uInt32 slice = 0; slice < 128_KB / size; ++slice)
std::copy_n(image.get(), size, myImage.begin() + (slice*size)); std::copy_n(image.get(), size, myImage.get() + (slice*size));
// We use System::PageAccess.romAccessBase, but don't allow its use // We use System::PageAccess.romAccessBase, but don't allow its use
// through a pointer, since the address space of 4A50 carts can change // through a pointer, since the address space of 4A50 carts can change
@ -41,7 +42,7 @@ Cartridge4A50::Cartridge4A50(const ByteBuffer& image, size_t size,
// //
// Instead, access will be through the getAccessFlags and setAccessFlags // Instead, access will be through the getAccessFlags and setAccessFlags
// methods below // methods below
createRomAccessArrays(myImage.size() + myRAM.size()); createRomAccessArrays(128_KB + myRAM.size());
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -350,10 +351,10 @@ bool Cartridge4A50::patch(uInt16 address, uInt8 value)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const uInt8* Cartridge4A50::getImage(size_t& size) const const ByteBuffer& Cartridge4A50::getImage(size_t& size) const
{ {
size = mySize; size = mySize;
return myImage.data(); return myImage;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -96,9 +96,9 @@ class Cartridge4A50 : public Cartridge
Access the internal ROM image for this cartridge. Access the internal ROM image for this cartridge.
@param size Set to the size of the internal ROM image data @param size Set to the size of the internal ROM image data
@return A pointer to the internal ROM image data @return A reference to the internal ROM image data
*/ */
const uInt8* getImage(size_t& size) const override; const ByteBuffer& getImage(size_t& size) const override;
/** /**
Save the current state of this cart to the given Serializer. Save the current state of this cart to the given Serializer.
@ -220,7 +220,7 @@ class Cartridge4A50 : public Cartridge
private: private:
// The 128K ROM image of the cartridge // The 128K ROM image of the cartridge
std::array<uInt8, 128_KB> myImage; ByteBuffer myImage;
// The 32K of RAM on the cartridge // The 32K of RAM on the cartridge
std::array<uInt8, 32_KB> myRAM; std::array<uInt8, 32_KB> myRAM;

View File

@ -420,10 +420,10 @@ bool CartridgeAR::patch(uInt16 address, uInt8 value)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const uInt8* CartridgeAR::getImage(size_t& size) const const ByteBuffer& CartridgeAR::getImage(size_t& size) const
{ {
size = mySize; size = mySize;
return myLoadImages.get(); return myLoadImages;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -105,9 +105,9 @@ class CartridgeAR : public Cartridge
Access the internal ROM image for this cartridge. Access the internal ROM image for this cartridge.
@param size Set to the size of the internal ROM image data @param size Set to the size of the internal ROM image data
@return A pointer to the internal ROM image data @return A reference to the internal ROM image data
*/ */
const uInt8* getImage(size_t& size) const override; const ByteBuffer& getImage(size_t& size) const override;
/** /**
Save the current state of this cart to the given Serializer. Save the current state of this cart to the given Serializer.

View File

@ -43,17 +43,18 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CartridgeBUS::CartridgeBUS(const ByteBuffer& image, size_t size, CartridgeBUS::CartridgeBUS(const ByteBuffer& image, size_t size,
const string& md5, const Settings& settings) const string& md5, const Settings& settings)
: Cartridge(settings, md5) : Cartridge(settings, md5),
myImage(make_unique<uInt8[]>(32_KB))
{ {
// Copy the ROM image into my buffer // Copy the ROM image into my buffer
std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); std::copy_n(image.get(), std::min(32_KB, size), myImage.get());
// Even though the ROM is 32K, only 28K is accessible to the 6507 // Even though the ROM is 32K, only 28K is accessible to the 6507
createRomAccessArrays(28_KB); createRomAccessArrays(28_KB);
// Pointer to the program ROM (28K @ 0 byte offset) // Pointer to the program ROM (28K @ 0 byte offset)
// which starts after the 2K BUS Driver and 2K C Code // which starts after the 2K BUS Driver and 2K C Code
myProgramImage = myImage.data() + 4_KB; myProgramImage = myImage.get() + 4_KB;
// Pointer to BUS driver in RAM // Pointer to BUS driver in RAM
myDriverImage = myRAM.data(); myDriverImage = myRAM.data();
@ -64,9 +65,9 @@ CartridgeBUS::CartridgeBUS(const ByteBuffer& image, size_t size,
// Create Thumbulator ARM emulator // Create Thumbulator ARM emulator
bool devSettings = settings.getBool("dev.settings"); bool devSettings = settings.getBool("dev.settings");
myThumbEmulator = make_unique<Thumbulator>( myThumbEmulator = make_unique<Thumbulator>(
reinterpret_cast<uInt16*>(myImage.data()), reinterpret_cast<uInt16*>(myImage.get()),
reinterpret_cast<uInt16*>(myRAM.data()), reinterpret_cast<uInt16*>(myRAM.data()),
static_cast<uInt32>(myImage.size()), static_cast<uInt32>(32_KB),
devSettings ? settings.getBool("dev.thumb.trapfatal") : false, Thumbulator::ConfigureFor::BUS, this devSettings ? settings.getBool("dev.thumb.trapfatal") : false, Thumbulator::ConfigureFor::BUS, this
); );
@ -95,7 +96,7 @@ void CartridgeBUS::reset()
void CartridgeBUS::setInitialState() void CartridgeBUS::setInitialState()
{ {
// Copy initial BUS driver to Harmony RAM // Copy initial BUS driver to Harmony RAM
std::copy_n(myImage.begin(), 2_KB, myDriverImage); std::copy_n(myImage.get(), 2_KB, myDriverImage);
myMusicWaveformSize.fill(27); myMusicWaveformSize.fill(27);
@ -478,10 +479,10 @@ bool CartridgeBUS::patch(uInt16 address, uInt8 value)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const uInt8* CartridgeBUS::getImage(size_t& size) const const ByteBuffer& CartridgeBUS::getImage(size_t& size) const
{ {
size = myImage.size(); size = 32_KB;
return myImage.data(); return myImage;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -116,9 +116,9 @@ class CartridgeBUS : public Cartridge
Access the internal ROM image for this cartridge. Access the internal ROM image for this cartridge.
@param size Set to the size of the internal ROM image data @param size Set to the size of the internal ROM image data
@return A pointer to the internal ROM image data @return A reference to the internal ROM image data
*/ */
const uInt8* getImage(size_t& size) const override; const ByteBuffer& getImage(size_t& size) const override;
/** /**
Save the current state of this cart to the given Serializer. Save the current state of this cart to the given Serializer.
@ -214,7 +214,7 @@ class CartridgeBUS : public Cartridge
private: private:
// The 32K ROM image of the cartridge // The 32K ROM image of the cartridge
std::array<uInt8, 32_KB> myImage; ByteBuffer myImage;
// Pointer to the 28K program ROM image of the cartridge // Pointer to the 28K program ROM image of the cartridge
uInt8* myProgramImage{nullptr}; uInt8* myProgramImage{nullptr};

View File

@ -59,17 +59,19 @@ namespace {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CartridgeCDF::CartridgeCDF(const ByteBuffer& image, size_t size, CartridgeCDF::CartridgeCDF(const ByteBuffer& image, size_t size,
const string& md5, const Settings& settings) const string& md5, const Settings& settings)
: Cartridge(settings, md5) : Cartridge(settings, md5),
myImage(make_unique<uInt8[]>(32_KB))
{ {
// Copy the ROM image into my buffer // Copy the ROM image into my buffer
std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); std::fill_n(myImage.get(), 32_KB, 0);
std::copy_n(image.get(), std::min(32_KB, size), myImage.get());
// even though the ROM is 32K, only 28K is accessible to the 6507 // even though the ROM is 32K, only 28K is accessible to the 6507
createRomAccessArrays(28_KB); createRomAccessArrays(28_KB);
// Pointer to the program ROM (28K @ 0 byte offset) // Pointer to the program ROM (28K @ 0 byte offset)
// which starts after the 2K CDF Driver and 2K C Code // which starts after the 2K CDF Driver and 2K C Code
myProgramImage = myImage.data() + 4_KB; myProgramImage = myImage.get() + 4_KB;
// Pointer to CDF driver in RAM // Pointer to CDF driver in RAM
myDriverImage = myRAM.data(); myDriverImage = myRAM.data();
@ -82,9 +84,9 @@ CartridgeCDF::CartridgeCDF(const ByteBuffer& image, size_t size,
// Create Thumbulator ARM emulator // Create Thumbulator ARM emulator
bool devSettings = settings.getBool("dev.settings"); bool devSettings = settings.getBool("dev.settings");
myThumbEmulator = make_unique<Thumbulator>( myThumbEmulator = make_unique<Thumbulator>(
reinterpret_cast<uInt16*>(myImage.data()), reinterpret_cast<uInt16*>(myImage.get()),
reinterpret_cast<uInt16*>(myRAM.data()), reinterpret_cast<uInt16*>(myRAM.data()),
static_cast<uInt32>(myImage.size()), static_cast<uInt32>(32_KB),
devSettings ? settings.getBool("dev.thumb.trapfatal") : false, thumulatorConfiguration(myCDFSubtype), this); devSettings ? settings.getBool("dev.thumb.trapfatal") : false, thumulatorConfiguration(myCDFSubtype), this);
setInitialState(); setInitialState();
@ -111,7 +113,7 @@ void CartridgeCDF::reset()
void CartridgeCDF::setInitialState() void CartridgeCDF::setInitialState()
{ {
// Copy initial CDF driver to Harmony RAM // Copy initial CDF driver to Harmony RAM
std::copy_n(myImage.begin(), 2_KB, myDriverImage); std::copy_n(myImage.get(), 2_KB, myDriverImage);
myMusicWaveformSize.fill(27); myMusicWaveformSize.fill(27);
@ -451,10 +453,10 @@ bool CartridgeCDF::patch(uInt16 address, uInt8 value)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const uInt8* CartridgeCDF::getImage(size_t& size) const const ByteBuffer& CartridgeCDF::getImage(size_t& size) const
{ {
size = myImage.size(); size = 32_KB;
return myImage.data(); return myImage;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -122,9 +122,9 @@ class CartridgeCDF : public Cartridge
Access the internal ROM image for this cartridge. Access the internal ROM image for this cartridge.
@param size Set to the size of the internal ROM image data @param size Set to the size of the internal ROM image data
@return A pointer to the internal ROM image data @return A reference to the internal ROM image data
*/ */
const uInt8* getImage(size_t& size) const override; const ByteBuffer& getImage(size_t& size) const override;
/** /**
Save the current state of this cart to the given Serializer. Save the current state of this cart to the given Serializer.
@ -214,7 +214,7 @@ class CartridgeCDF : public Cartridge
private: private:
// The 32K ROM image of the cartridge // The 32K ROM image of the cartridge
std::array<uInt8, 32_KB> myImage; ByteBuffer myImage;
// Pointer to the 28K program ROM image of the cartridge // Pointer to the 28K program ROM image of the cartridge
uInt8* myProgramImage{nullptr}; uInt8* myProgramImage{nullptr};

View File

@ -23,11 +23,12 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CartridgeCM::CartridgeCM(const ByteBuffer& image, size_t size, CartridgeCM::CartridgeCM(const ByteBuffer& image, size_t size,
const string& md5, const Settings& settings) const string& md5, const Settings& settings)
: Cartridge(settings, md5) : Cartridge(settings, md5),
myImage(make_unique<uInt8[]>(16_KB))
{ {
// Copy the ROM image into my buffer // Copy the ROM image into my buffer
std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); std::copy_n(image.get(), std::min(16_KB, size), myImage.get());
createRomAccessArrays(myImage.size()); createRomAccessArrays(16_KB);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -184,10 +185,10 @@ bool CartridgeCM::patch(uInt16 address, uInt8 value)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const uInt8* CartridgeCM::getImage(size_t& size) const const ByteBuffer& CartridgeCM::getImage(size_t& size) const
{ {
size = myImage.size(); size = 16_KB;
return myImage.data(); return myImage;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -173,9 +173,9 @@ class CartridgeCM : public Cartridge
Access the internal ROM image for this cartridge. Access the internal ROM image for this cartridge.
@param size Set to the size of the internal ROM image data @param size Set to the size of the internal ROM image data
@return A pointer to the internal ROM image data @return A reference to the internal ROM image data
*/ */
const uInt8* getImage(size_t& size) const override; const ByteBuffer& getImage(size_t& size) const override;
/** /**
Save the current state of this cart to the given Serializer. Save the current state of this cart to the given Serializer.
@ -246,7 +246,7 @@ class CartridgeCM : public Cartridge
shared_ptr<CompuMate> myCompuMate; shared_ptr<CompuMate> myCompuMate;
// The 16K ROM image of the cartridge // The 16K ROM image of the cartridge
std::array<uInt8, 16_KB> myImage; ByteBuffer myImage;
// The 2K of RAM // The 2K of RAM
std::array<uInt8, 2_KB> myRAM; std::array<uInt8, 2_KB> myRAM;

View File

@ -24,18 +24,19 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CartridgeCTY::CartridgeCTY(const ByteBuffer& image, size_t size, CartridgeCTY::CartridgeCTY(const ByteBuffer& image, size_t size,
const string& md5, const Settings& settings) const string& md5, const Settings& settings)
: Cartridge(settings, md5) : Cartridge(settings, md5),
myImage(make_unique<uInt8[]>(32_KB))
{ {
// Copy the ROM image into my buffer // Copy the ROM image into my buffer
std::copy_n(image.get(), std::min(myImage.size(), size), myImage.begin()); std::copy_n(image.get(), std::min(32_KB, size), myImage.get());
createRomAccessArrays(myImage.size()); createRomAccessArrays(32_KB);
// Default to no tune data in case user is utilizing an old ROM // Default to no tune data in case user is utilizing an old ROM
myTuneData.fill(0); myTuneData.fill(0);
// Extract tune data if it exists // Extract tune data if it exists
if(size > myImage.size()) if(size > 32_KB)
std::copy_n(image.get() + myImage.size(), size - myImage.size(), myTuneData.begin()); std::copy_n(image.get() + 32_KB, size - 32_KB, myTuneData.begin());
// Point to the first tune // Point to the first tune
myFrequencyImage = myTuneData.data(); myFrequencyImage = myTuneData.data();
@ -279,10 +280,10 @@ bool CartridgeCTY::patch(uInt16 address, uInt8 value)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const uInt8* CartridgeCTY::getImage(size_t& size) const const ByteBuffer& CartridgeCTY::getImage(size_t& size) const
{ {
size = myImage.size(); size = 32_KB;
return myImage.data(); return myImage;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -171,9 +171,9 @@ class CartridgeCTY : public Cartridge
Access the internal ROM image for this cartridge. Access the internal ROM image for this cartridge.
@param size Set to the size of the internal ROM image data @param size Set to the size of the internal ROM image data
@return A pointer to the internal ROM image data @return A reference to the internal ROM image data
*/ */
const uInt8* getImage(size_t& size) const override; const ByteBuffer& getImage(size_t& size) const override;
/** /**
Save the current state of this cart to the given Serializer. Save the current state of this cart to the given Serializer.
@ -263,7 +263,7 @@ class CartridgeCTY : public Cartridge
private: private:
// The 32K ROM image of the cartridge // The 32K ROM image of the cartridge
std::array<uInt8, 32_KB> myImage; ByteBuffer myImage;
// The 28K ROM image of the music // The 28K ROM image of the music
std::array<uInt8, 28_KB> myTuneData; std::array<uInt8, 28_KB> myTuneData;

View File

@ -29,17 +29,18 @@
CartridgeDPCPlus::CartridgeDPCPlus(const ByteBuffer& image, size_t size, CartridgeDPCPlus::CartridgeDPCPlus(const ByteBuffer& image, size_t size,
const string& md5, const Settings& settings) const string& md5, const Settings& settings)
: Cartridge(settings, md5), : Cartridge(settings, md5),
mySize(std::min(size, myImage.size())) myImage(make_unique<uInt8[]>(32_KB)),
mySize(std::min(size, 32_KB))
{ {
// Image is always 32K, but in the case of ROM > 29K, the image is // Image is always 32K, but in the case of ROM < 32K, the image is
// copied to the end of the buffer // copied to the end of the buffer
if(mySize < myImage.size()) if(mySize < 32_KB)
myImage.fill(0); std::fill_n(myImage.get(), mySize, 0);
std::copy_n(image.get(), size, myImage.begin() + (myImage.size() - mySize)); std::copy_n(image.get(), size, myImage.get() + (32_KB - mySize));
createRomAccessArrays(24_KB); createRomAccessArrays(24_KB);
// Pointer to the program ROM (24K @ 3K offset; ignore first 3K) // Pointer to the program ROM (24K @ 3K offset; ignore first 3K)
myProgramImage = myImage.data() + 3_KB; myProgramImage = myImage.get() + 3_KB;
// Pointer to the display RAM // Pointer to the display RAM
myDisplayImage = myDPCRAM.data() + 3_KB; myDisplayImage = myDPCRAM.data() + 3_KB;
@ -50,9 +51,9 @@ CartridgeDPCPlus::CartridgeDPCPlus(const ByteBuffer& image, size_t size,
// Create Thumbulator ARM emulator // Create Thumbulator ARM emulator
bool devSettings = settings.getBool("dev.settings"); bool devSettings = settings.getBool("dev.settings");
myThumbEmulator = make_unique<Thumbulator> myThumbEmulator = make_unique<Thumbulator>
(reinterpret_cast<uInt16*>(myImage.data()), (reinterpret_cast<uInt16*>(myImage.get()),
reinterpret_cast<uInt16*>(myDPCRAM.data()), reinterpret_cast<uInt16*>(myDPCRAM.data()),
static_cast<uInt32>(myImage.size()), static_cast<uInt32>(32_KB),
devSettings ? settings.getBool("dev.thumb.trapfatal") : false, devSettings ? settings.getBool("dev.thumb.trapfatal") : false,
Thumbulator::ConfigureFor::DPCplus, Thumbulator::ConfigureFor::DPCplus,
this); this);
@ -640,10 +641,10 @@ bool CartridgeDPCPlus::patch(uInt16 address, uInt8 value)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const uInt8* CartridgeDPCPlus::getImage(size_t& size) const const ByteBuffer& CartridgeDPCPlus::getImage(size_t& size) const
{ {
size = mySize; size = mySize;
return myImage.data() + (myImage.size() - mySize); return myImage;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -118,9 +118,9 @@ class CartridgeDPCPlus : public Cartridge
Access the internal ROM image for this cartridge. Access the internal ROM image for this cartridge.
@param size Set to the size of the internal ROM image data @param size Set to the size of the internal ROM image data
@return A pointer to the internal ROM image data @return A reference to the internal ROM image data
*/ */
const uInt8* getImage(size_t& size) const override; const ByteBuffer& getImage(size_t& size) const override;
/** /**
Save the current state of this cart to the given Serializer. Save the current state of this cart to the given Serializer.
@ -203,7 +203,7 @@ class CartridgeDPCPlus : public Cartridge
private: private:
// The ROM image and size // The ROM image and size
std::array<uInt8, 32_KB> myImage; ByteBuffer myImage;
size_t mySize{0}; size_t mySize{0};
// Pointer to the 24K program ROM image of the cartridge // Pointer to the 24K program ROM image of the cartridge

View File

@ -364,10 +364,10 @@ bool CartridgeEnhanced::patch(uInt16 address, uInt8 value)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const uInt8* CartridgeEnhanced::getImage(size_t& size) const const ByteBuffer& CartridgeEnhanced::getImage(size_t& size) const
{ {
size = mySize; size = mySize;
return myImage.get(); return myImage;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -120,9 +120,9 @@ class CartridgeEnhanced : public Cartridge
Access the internal ROM image for this cartridge. Access the internal ROM image for this cartridge.
@param size Set to the size of the internal ROM image data @param size Set to the size of the internal ROM image data
@return A pointer to the internal ROM image data @return A reference to the internal ROM image data
*/ */
const uInt8* getImage(size_t& size) const override; const ByteBuffer& getImage(size_t& size) const override;
/** /**
Save the current state of this cart to the given Serializer. Save the current state of this cart to the given Serializer.

View File

@ -37,4 +37,3 @@ bool CartridgeF6::checkSwitchBank(uInt16 address, uInt8)
} }
return false; return false;
} }

View File

@ -263,10 +263,10 @@ bool CartridgeMNetwork::patch(uInt16 address, uInt8 value)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const uInt8* CartridgeMNetwork::getImage(size_t& size) const const ByteBuffer& CartridgeMNetwork::getImage(size_t& size) const
{ {
size = romBankCount() * BANK_SIZE; size = romBankCount() * BANK_SIZE;
return myImage.get(); return myImage;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -126,9 +126,9 @@ class CartridgeMNetwork : public Cartridge
Access the internal ROM image for this cartridge. Access the internal ROM image for this cartridge.
@param size Set to the size of the internal ROM image data @param size Set to the size of the internal ROM image data
@return A pointer to the internal ROM image data @return A reference to the internal ROM image data
*/ */
const uInt8* getImage(size_t& size) const override; const ByteBuffer& getImage(size_t& size) const override;
/** /**
Save the current state of this cart to the given Serializer. Save the current state of this cart to the given Serializer.

View File

@ -726,7 +726,7 @@ void Console::setControllers(const string& romMd5)
Controller::Type leftType = Controller::getType(myProperties.get(PropType::Controller_Left)); Controller::Type leftType = Controller::getType(myProperties.get(PropType::Controller_Left));
Controller::Type rightType = Controller::getType(myProperties.get(PropType::Controller_Right)); Controller::Type rightType = Controller::getType(myProperties.get(PropType::Controller_Right));
size_t size = 0; size_t size = 0;
const uInt8* image = myCart->getImage(size); const ByteBuffer& image = myCart->getImage(size);
const bool swappedPorts = myProperties.get(PropType::Console_SwapPorts) == "YES"; const bool swappedPorts = myProperties.get(PropType::Console_SwapPorts) == "YES";
// Try to detect controllers // Try to detect controllers

View File

@ -22,8 +22,10 @@
#include "ControllerDetector.hxx" #include "ControllerDetector.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Controller::Type ControllerDetector::detectType(const uInt8* image, size_t size, Controller::Type ControllerDetector::detectType(
const Controller::Type type, const Controller::Jack port, const Settings& settings) const ByteBuffer& image, size_t size,
const Controller::Type type, const Controller::Jack port,
const Settings& settings)
{ {
if(type == Controller::Type::Unknown || settings.getBool("rominfo")) if(type == Controller::Type::Unknown || settings.getBool("rominfo"))
{ {
@ -43,7 +45,7 @@ Controller::Type ControllerDetector::detectType(const uInt8* image, size_t size,
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string ControllerDetector::detectName(const uInt8* image, size_t size, string ControllerDetector::detectName(const ByteBuffer& image, size_t size,
const Controller::Type controller, const Controller::Jack port, const Controller::Type controller, const Controller::Jack port,
const Settings& settings) const Settings& settings)
{ {
@ -51,7 +53,8 @@ string ControllerDetector::detectName(const uInt8* image, size_t size,
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Controller::Type ControllerDetector::autodetectPort(const uInt8* image, size_t size, Controller::Type ControllerDetector::autodetectPort(
const ByteBuffer& image, size_t size,
Controller::Jack port, const Settings& settings) Controller::Jack port, const Settings& settings)
{ {
// default type joystick // default type joystick
@ -88,7 +91,7 @@ Controller::Type ControllerDetector::autodetectPort(const uInt8* image, size_t s
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool ControllerDetector::searchForBytes(const uInt8* image, size_t imagesize, bool ControllerDetector::searchForBytes(const ByteBuffer& image, size_t imagesize,
const uInt8* signature, uInt32 sigsize) const uInt8* signature, uInt32 sigsize)
{ {
if (imagesize >= sigsize) if (imagesize >= sigsize)
@ -112,7 +115,7 @@ bool ControllerDetector::searchForBytes(const uInt8* image, size_t imagesize,
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool ControllerDetector::usesJoystickButton(const uInt8* image, size_t size, bool ControllerDetector::usesJoystickButton(const ByteBuffer& image, size_t size,
Controller::Jack port) Controller::Jack port)
{ {
if(port == Controller::Jack::Left) if(port == Controller::Jack::Left)
@ -242,7 +245,7 @@ bool ControllerDetector::usesJoystickButton(const uInt8* image, size_t size,
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool ControllerDetector::usesKeyboard(const uInt8* image, size_t size, bool ControllerDetector::usesKeyboard(const ByteBuffer& image, size_t size,
Controller::Jack port) Controller::Jack port)
{ {
if(port == Controller::Jack::Left) if(port == Controller::Jack::Left)
@ -383,7 +386,7 @@ bool ControllerDetector::usesKeyboard(const uInt8* image, size_t size,
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool ControllerDetector::usesGenesisButton(const uInt8* image, size_t size, bool ControllerDetector::usesGenesisButton(const ByteBuffer& image, size_t size,
Controller::Jack port) Controller::Jack port)
{ {
if(port == Controller::Jack::Left) if(port == Controller::Jack::Left)
@ -440,7 +443,7 @@ bool ControllerDetector::usesGenesisButton(const uInt8* image, size_t size,
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool ControllerDetector::usesPaddle(const uInt8* image, size_t size, bool ControllerDetector::usesPaddle(const ByteBuffer& image, size_t size,
Controller::Jack port, const Settings& settings) Controller::Jack port, const Settings& settings)
{ {
if(port == Controller::Jack::Left) if(port == Controller::Jack::Left)
@ -549,7 +552,7 @@ bool ControllerDetector::usesPaddle(const uInt8* image, size_t size,
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool ControllerDetector::isProbablyTrakBall(const uInt8* image, size_t size) bool ControllerDetector::isProbablyTrakBall(const ByteBuffer& image, size_t size)
{ {
// check for TrakBall tables // check for TrakBall tables
const int NUM_SIGS = 3; const int NUM_SIGS = 3;
@ -568,7 +571,7 @@ bool ControllerDetector::isProbablyTrakBall(const uInt8* image, size_t size)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool ControllerDetector::isProbablyAtariMouse(const uInt8* image, size_t size) bool ControllerDetector::isProbablyAtariMouse(const ByteBuffer& image, size_t size)
{ {
// check for Atari Mouse tables // check for Atari Mouse tables
const int NUM_SIGS = 3; const int NUM_SIGS = 3;
@ -587,7 +590,7 @@ bool ControllerDetector::isProbablyAtariMouse(const uInt8* image, size_t size)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool ControllerDetector::isProbablyAmigaMouse(const uInt8* image, size_t size) bool ControllerDetector::isProbablyAmigaMouse(const ByteBuffer& image, size_t size)
{ {
// check for Amiga Mouse tables // check for Amiga Mouse tables
const int NUM_SIGS = 4; const int NUM_SIGS = 4;
@ -607,7 +610,7 @@ bool ControllerDetector::isProbablyAmigaMouse(const uInt8* image, size_t size)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool ControllerDetector::isProbablySaveKey(const uInt8* image, size_t size, bool ControllerDetector::isProbablySaveKey(const ByteBuffer& image, size_t size,
Controller::Jack port) Controller::Jack port)
{ {
// check for known SaveKey code, only supports right port // check for known SaveKey code, only supports right port
@ -652,7 +655,7 @@ bool ControllerDetector::isProbablySaveKey(const uInt8* image, size_t size,
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool ControllerDetector::isProbablyLightGun(const uInt8* image, size_t size, bool ControllerDetector::isProbablyLightGun(const ByteBuffer& image, size_t size,
Controller::Jack port) Controller::Jack port)
{ {
if (port == Controller::Jack::Left) if (port == Controller::Jack::Left)

View File

@ -34,14 +34,14 @@ class ControllerDetector
/** /**
Detects the controller type at the given port if no controller is provided. Detects the controller type at the given port if no controller is provided.
@param image A pointer to the ROM image @param image A reference to the ROM image
@param size The size of the ROM image @param size The size of the ROM image
@param controller The provided controller type of the ROM image @param controller The provided controller type of the ROM image
@param port The port to be checked @param port The port to be checked
@param settings A reference to the various settings (read-only) @param settings A reference to the various settings (read-only)
@return The detected controller type @return The detected controller type
*/ */
static Controller::Type detectType(const uInt8* image, size_t size, static Controller::Type detectType(const ByteBuffer& image, size_t size,
const Controller::Type controller, const Controller::Jack port, const Controller::Type controller, const Controller::Jack port,
const Settings& settings); const Settings& settings);
@ -49,7 +49,7 @@ class ControllerDetector
Detects the controller type at the given port if no controller is provided Detects the controller type at the given port if no controller is provided
and returns its name. and returns its name.
@param image A pointer to the ROM image @param image A reference to the ROM image
@param size The size of the ROM image @param size The size of the ROM image
@param type The provided controller type of the ROM image @param type The provided controller type of the ROM image
@param port The port to be checked @param port The port to be checked
@ -57,7 +57,7 @@ class ControllerDetector
@return The (detected) controller name @return The (detected) controller name
*/ */
static string detectName(const uInt8* image, size_t size, static string detectName(const ByteBuffer& image, size_t size,
const Controller::Type type, const Controller::Jack port, const Controller::Type type, const Controller::Jack port,
const Settings& settings); const Settings& settings);
@ -65,14 +65,14 @@ class ControllerDetector
/** /**
Detects the controller type at the given port. Detects the controller type at the given port.
@param image A pointer to the ROM image @param image A reference to the ROM image
@param size The size of the ROM image @param size The size of the ROM image
@param port The port to be checked @param port The port to be checked
@param settings A reference to the various settings (read-only) @param settings A reference to the various settings (read-only)
@return The detected controller type @return The detected controller type
*/ */
static Controller::Type autodetectPort(const uInt8* image, size_t size, static Controller::Type autodetectPort(const ByteBuffer& image, size_t size,
Controller::Jack port, const Settings& settings); Controller::Jack port, const Settings& settings);
/** /**
@ -85,36 +85,41 @@ class ControllerDetector
@return True if the signature was found, else false @return True if the signature was found, else false
*/ */
static bool searchForBytes(const uInt8* image, size_t imagesize, static bool searchForBytes(const ByteBuffer& image, size_t imagesize,
const uInt8* signature, uInt32 sigsize); const uInt8* signature, uInt32 sigsize);
// Returns true if the port's joystick button access code is found. // Returns true if the port's joystick button access code is found.
static bool usesJoystickButton(const uInt8* image, size_t size, Controller::Jack port); static bool usesJoystickButton(const ByteBuffer& image, size_t size,
Controller::Jack port);
// Returns true if the port's keyboard access code is found. // Returns true if the port's keyboard access code is found.
static bool usesKeyboard(const uInt8* image, size_t size, Controller::Jack port); static bool usesKeyboard(const ByteBuffer& image, size_t size,
Controller::Jack port);
// Returns true if the port's 2nd Genesis button access code is found. // Returns true if the port's 2nd Genesis button access code is found.
static bool usesGenesisButton(const uInt8* image, size_t size, Controller::Jack port); static bool usesGenesisButton(const ByteBuffer& image, size_t size,
Controller::Jack port);
// Returns true if the port's paddle button access code is found. // Returns true if the port's paddle button access code is found.
static bool usesPaddle(const uInt8* image, size_t size, Controller::Jack port, static bool usesPaddle(const ByteBuffer& image, size_t size,
const Settings& settings); Controller::Jack port, const Settings& settings);
// Returns true if a Trak-Ball table is found. // Returns true if a Trak-Ball table is found.
static bool isProbablyTrakBall(const uInt8* image, size_t size); static bool isProbablyTrakBall(const ByteBuffer& image, size_t size);
// Returns true if an Atari Mouse table is found. // Returns true if an Atari Mouse table is found.
static bool isProbablyAtariMouse(const uInt8* image, size_t size); static bool isProbablyAtariMouse(const ByteBuffer& image, size_t size);
// Returns true if an Amiga Mouse table is found. // Returns true if an Amiga Mouse table is found.
static bool isProbablyAmigaMouse(const uInt8* image, size_t size); static bool isProbablyAmigaMouse(const ByteBuffer& image, size_t size);
// Returns true if a SaveKey code pattern is found. // Returns true if a SaveKey code pattern is found.
static bool isProbablySaveKey(const uInt8* image, size_t size, Controller::Jack port); static bool isProbablySaveKey(const ByteBuffer& image, size_t size,
Controller::Jack port);
// Returns true if a Lightgun code pattern is found // Returns true if a Lightgun code pattern is found
static bool isProbablyLightGun(const uInt8* image, size_t size, Controller::Jack port); static bool isProbablyLightGun(const ByteBuffer& image, size_t size,
Controller::Jack port);
private: private:
@ -127,4 +132,3 @@ class ControllerDetector
}; };
#endif #endif

View File

@ -707,7 +707,7 @@ void GameInfoDialog::updateControllerStates()
label = (!swapPorts ? instance().console().leftController().name() label = (!swapPorts ? instance().console().leftController().name()
: instance().console().rightController().name()) + " detected"; : instance().console().rightController().name()) + " detected";
else if(autoDetect) else if(autoDetect)
label = ControllerDetector::detectName(image.get(), size, type, label = ControllerDetector::detectName(image, size, type,
!swapPorts ? Controller::Jack::Left : Controller::Jack::Right, !swapPorts ? Controller::Jack::Left : Controller::Jack::Right,
instance().settings()) + " detected"; instance().settings()) + " detected";
} }
@ -722,7 +722,7 @@ void GameInfoDialog::updateControllerStates()
label = (!swapPorts ? instance().console().rightController().name() label = (!swapPorts ? instance().console().rightController().name()
: instance().console().leftController().name()) + " detected"; : instance().console().leftController().name()) + " detected";
else if(autoDetect) else if(autoDetect)
label = ControllerDetector::detectName(image.get(), size, type, label = ControllerDetector::detectName(image, size, type,
!swapPorts ? Controller::Jack::Right : Controller::Jack::Left, !swapPorts ? Controller::Jack::Right : Controller::Jack::Left,
instance().settings()) + " detected"; instance().settings()) + " detected";
} }

View File

@ -152,10 +152,10 @@ void RomInfoWidget::parseProperties(const FilesystemNode& node)
(image = instance().openROM(node, md5, size)) != nullptr) (image = instance().openROM(node, md5, size)) != nullptr)
{ {
Logger::debug(myProperties.get(PropType::Cart_Name) + ":"); Logger::debug(myProperties.get(PropType::Cart_Name) + ":");
left = ControllerDetector::detectName(image.get(), size, leftType, left = ControllerDetector::detectName(image, size, leftType,
!swappedPorts ? Controller::Jack::Left : Controller::Jack::Right, !swappedPorts ? Controller::Jack::Left : Controller::Jack::Right,
instance().settings()); instance().settings());
right = ControllerDetector::detectName(image.get(), size, rightType, right = ControllerDetector::detectName(image, size, rightType,
!swappedPorts ? Controller::Jack::Right : Controller::Jack::Left, !swappedPorts ? Controller::Jack::Right : Controller::Jack::Left,
instance().settings()); instance().settings());
if (bsDetected == "AUTO") if (bsDetected == "AUTO")

View File

@ -540,7 +540,7 @@ void StellaSettingsDialog::updateControllerStates()
if(instance().hasConsole()) if(instance().hasConsole())
label = (instance().console().leftController().name()) + " detected"; label = (instance().console().leftController().name()) + " detected";
else if(autoDetect) else if(autoDetect)
label = ControllerDetector::detectName(image.get(), size, type, label = ControllerDetector::detectName(image, size, type,
Controller::Jack::Left, Controller::Jack::Left,
instance().settings()) + " detected"; instance().settings()) + " detected";
} }
@ -554,7 +554,7 @@ void StellaSettingsDialog::updateControllerStates()
if(instance().hasConsole()) if(instance().hasConsole())
label = (instance().console().rightController().name()) + " detected"; label = (instance().console().rightController().name()) + " detected";
else if(autoDetect) else if(autoDetect)
label = ControllerDetector::detectName(image.get(), size, type, label = ControllerDetector::detectName(image, size, type,
Controller::Jack::Right, Controller::Jack::Right,
instance().settings()) + " detected"; instance().settings()) + " detected";
} }