Some cleanups for moviecart code.

- Compiles in Linux now, and without any warnings or errors
 - Converted some code to use that already in Stella
 - Formatting cleanups to match Stella style
This commit is contained in:
Stephen Anthony 2021-04-21 22:13:38 -02:30
parent 8873ffd0b7
commit 9f12d5c16c
6 changed files with 1036 additions and 1163 deletions

View File

@ -456,7 +456,7 @@ bool CartDetector::isProbablyCDF(const ByteBuffer& image, size_t size)
// 0x10adab1e (LOADABLE) if needed for future improvement
uInt8 cdf[] = { 'C', 'D', 'F' };
uInt8 cdfjplus[] = { 'P', 'L', 'U', 'S', 'C', 'D', 'F', 'J' };
return (searchForBytes(image, size, cdf, 3, 3) ||
return (searchForBytes(image, size, cdf, 3, 3) ||
searchForBytes(image, size, cdfjplus, 8, 1));
}
@ -704,11 +704,11 @@ bool CartDetector::isProbablyMVC(const ByteBuffer& image, size_t size)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
size_t CartDetector::isProbablyMVC(std::istream &in, size_t maxSize)
{
const size_t frameSize = 2 * MVC_FIELD_PAD_SIZE;
const size_t frameSize = 2 * CartridgeMVC::MVC_FIELD_PAD_SIZE;
bool found = false;
// Returns size of field if stream is probably an MVC movie cartridge
if (maxSize >= frameSize)
{
auto pos = in.tellg();

2101
src/emucore/CartMVC.cxx Executable file → Normal file

File diff suppressed because it is too large Load Diff

71
src/emucore/CartMVC.hxx Executable file → Normal file
View File

@ -33,26 +33,26 @@ class MovieCart;
@author Rob Bairos
*/
#define MVC_FIELD_SIZE 2560 // round field to nearest 512 byte boundary
#define MVC_FIELD_PAD_SIZE 4096 // round to nearest 4K
class CartridgeMVC : public Cartridge
{
public:
static constexpr uInt32
MVC_FIELD_SIZE = 2560, // round field to nearest 512 byte boundary
MVC_FIELD_PAD_SIZE = 4096; // round to nearest 4K
public:
/**
Create a new cartridge using the specified image
@param image Pointer to the ROM image
@param path Path to the ROM image file
@param size The size of the ROM image (<= 2048 bytes)
@param md5 The md5sum of the ROM image
@param settings A reference to the various settings (read-only)
@param bsSize The size specified by the bankswitching scheme
*/
CartridgeMVC(const string& path, size_t size, const string& md5,
const Settings& settings, size_t bsSize = 2_KB);
~CartridgeMVC() override = default;
const Settings& settings, size_t bsSize = 1_KB);
~CartridgeMVC() override;
/**
Reset device to its power-on state
@ -73,7 +73,7 @@ class CartridgeMVC : public Cartridge
@param size Set to the size of the internal ROM image data
@return A reference to the internal ROM image data
*/
virtual const ByteBuffer& getImage(size_t& size) const;
const ByteBuffer& getImage(size_t& size) const override;
/**
Patch the cartridge ROM.
@ -82,7 +82,7 @@ class CartridgeMVC : public Cartridge
@param value The value to place into the address
@return Success or failure of the patch operation
*/
virtual bool patch(uInt16 address, uInt8 value);
bool patch(uInt16 address, uInt8 value) override;
/**
Get the byte at the specified address.
@ -113,10 +113,7 @@ class CartridgeMVC : public Cartridge
@param out The Serializer object to use
@return False on any errors, else true
*/
bool save(Serializer& out) const override
{
return false;
}
bool save(Serializer& out) const override { return false; }
/**
Load the current state of this cart from the given Serializer.
@ -124,49 +121,17 @@ class CartridgeMVC : public Cartridge
@param in The Serializer object to use
@return False on any errors, else true
*/
bool load(Serializer& in) override
{
return false;
}
/**
Install pages for the specified bank in the system.
@param bank The bank that should be installed in the system
@param segment The segment the bank should be using
@return true, if bank has changed
*/
bool bank(uInt16 bank, uInt16 segment = 0) override
{
return false;
}
/**
Get the current bank.
@param address The address to use when querying the bank
*/
uInt16 getBank(uInt16 address = 0) const override
{
return 0;
}
/**
Query the number of banks supported by the cartridge.
*/
uInt16 romBankCount() const override
{
return 1;
}
bool load(Serializer& in) override { return false; }
private:
// Currently not used:
// Currently not used:
// Pointer to a dynamically allocated ROM image of the cartridge
ByteBuffer myImage{nullptr};
size_t mySize{0};
unique_ptr<MovieCart> myMovie;
string myPath;
private:
// Following constructors and assignment operators not supported
CartridgeMVC() = delete;
@ -174,12 +139,6 @@ class CartridgeMVC : public Cartridge
CartridgeMVC(CartridgeMVC&&) = delete;
CartridgeMVC& operator=(const CartridgeMVC&) = delete;
CartridgeMVC& operator=(CartridgeMVC&&) = delete;
private:
unique_ptr<MovieCart> myMovie;
string myPath;
};
#endif

View File

@ -77,6 +77,14 @@ Serializer::Serializer()
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Serializer::setPosition(size_t pos)
{
myStream->clear();
myStream->seekg(pos);
myStream->seekp(pos);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void Serializer::rewind()
{

View File

@ -59,6 +59,11 @@ class Serializer
*/
explicit operator bool() const { return myStream != nullptr; }
/**
Sets the read/write location to the given offset in the stream.
*/
void setPosition(size_t pos);
/**
Resets the read/write location to the beginning of the stream.
*/
@ -220,13 +225,6 @@ class Serializer
unique_ptr<iostream> myStream;
static constexpr uInt8 TruePattern = 0xfe, FalsePattern = 0x01;
private:
// Following constructors and assignment operators not supported
Serializer(const Serializer&) = delete;
Serializer(Serializer&&) = delete;
Serializer& operator=(const Serializer&) = delete;
Serializer& operator=(Serializer&&) = delete;
};
#endif

View File

@ -47,6 +47,7 @@ MODULE_OBJS := \
src/emucore/CartFC.o \
src/emucore/CartFE.o \
src/emucore/CartMDM.o \
src/emucore/CartMVC.o \
src/emucore/CartSB.o \
src/emucore/CartTVBoy.o \
src/emucore/CartUA.o \