From 55e3874097465147f0f9eea3f4eedf64851f4dbb Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Tue, 1 Aug 2023 17:44:44 -0230 Subject: [PATCH] Some cleanup of CartAR class, in preparation for moving some code from System class. --- src/emucore/CartAR.cxx | 45 ++++++++-------------------------------- src/emucore/CartAR.hxx | 47 ++++++++++++++++++++++++++++++++---------- src/emucore/M6502.cxx | 7 ++++--- 3 files changed, 49 insertions(+), 50 deletions(-) diff --git a/src/emucore/CartAR.cxx b/src/emucore/CartAR.cxx index f8950723f..9199a8bed 100644 --- a/src/emucore/CartAR.cxx +++ b/src/emucore/CartAR.cxx @@ -15,11 +15,20 @@ // this file, and for a DISCLAIMER OF ALL WARRANTIES. //============================================================================ +#include + #include "M6502.hxx" #include "System.hxx" #include "Settings.hxx" #include "CartAR.hxx" +namespace { + // Compute the sum of the array of bytes + uInt8 checksum(const uInt8* s, uInt16 length) { + return static_cast(std::accumulate(s, s + length, 0)); + } +} // namespace + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - CartridgeAR::CartridgeAR(const ByteBuffer& image, size_t size, string_view md5, const Settings& settings) @@ -509,39 +518,3 @@ std::array CartridgeAR::ourDummyROMCode = { 0xa9, 0x9a, 0xa2, 0xff, 0xa0, 0x00, 0x9a, 0x4c, 0xfa, 0x00, 0xcd, 0xf8, 0xff, 0x4c }; - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -const std::array CartridgeAR::ourDefaultHeader = { - 0xac, 0xfa, 0x0f, 0x18, 0x62, 0x00, 0x24, 0x02, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x04, 0x08, 0x0c, 0x10, 0x14, 0x18, 0x1c, - 0x01, 0x05, 0x09, 0x0d, 0x11, 0x15, 0x19, 0x1d, - 0x02, 0x06, 0x0a, 0x0e, 0x12, 0x16, 0x1a, 0x1e, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 -}; diff --git a/src/emucore/CartAR.hxx b/src/emucore/CartAR.hxx index 79b17af78..f4a2efb26 100644 --- a/src/emucore/CartAR.hxx +++ b/src/emucore/CartAR.hxx @@ -173,7 +173,7 @@ class CartridgeAR : public Cartridge @param address The address to query */ - Device::AccessFlags getAccessFlags(uInt16 address) const override; + Device::AccessFlags getAccessFlags(uInt16 address) const override; /** Change the given address to use the given access flags. @@ -186,15 +186,6 @@ class CartridgeAR : public Cartridge // Handle a change to the bank configuration bool bankConfiguration(uInt8 configuration); - // Compute the sum of the array of bytes - static uInt8 checksum(const uInt8* s, uInt16 length) { - uInt8 sum = 0; - for(uInt32 i = 0; i < length; ++i) - sum += s[i]; - - return sum; - } - // Load the specified load into SC RAM void loadIntoRAM(uInt8 load); @@ -239,11 +230,45 @@ class CartridgeAR : public Cartridge uInt16 myCurrentBank{0}; // Fake SC-BIOS code to simulate the Supercharger load bars + // This is not marked 'constexpr', since it's patched at runtime static std::array ourDummyROMCode; // Default 256-byte header to use if one isn't included in the ROM // This data comes from z26 - static const std::array ourDefaultHeader; + static constexpr std::array ourDefaultHeader = { + 0xac, 0xfa, 0x0f, 0x18, 0x62, 0x00, 0x24, 0x02, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x04, 0x08, 0x0c, 0x10, 0x14, 0x18, 0x1c, + 0x01, 0x05, 0x09, 0x0d, 0x11, 0x15, 0x19, 0x1d, + 0x02, 0x06, 0x0a, 0x0e, 0x12, 0x16, 0x1a, 0x1e, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 + }; private: // Following constructors and assignment operators not supported diff --git a/src/emucore/M6502.cxx b/src/emucore/M6502.cxx index ddc4be7f1..ace6b3f9a 100644 --- a/src/emucore/M6502.cxx +++ b/src/emucore/M6502.cxx @@ -83,7 +83,8 @@ void M6502::reset() // Load PC from the reset vector PC = static_cast(mySystem->peek(0xfffc)) | (static_cast(mySystem->peek(0xfffd)) << 8); - myLastAddress = myLastPeekAddress = myLastPokeAddress = myLastPeekBaseAddress = myLastPokeBaseAddress; + myLastAddress = myLastPeekAddress = myLastPokeAddress = + myLastPeekBaseAddress = myLastPokeBaseAddress = 0; myLastSrcAddressS = myLastSrcAddressA = myLastSrcAddressX = myLastSrcAddressY = -1; myDataAddressForPoke = 0; @@ -489,7 +490,7 @@ bool M6502::save(Serializer& out) const // Indicates the number of distinct memory accesses out.putInt(myNumberOfDistinctAccesses); - // Indicates the last address(es) which was accessed + // Indicates the last addresses which were accessed out.putShort(myLastAddress); out.putShort(myLastPeekAddress); out.putShort(myLastPokeAddress); @@ -536,7 +537,7 @@ bool M6502::load(Serializer& in) // Indicates the number of distinct memory accesses myNumberOfDistinctAccesses = in.getInt(); - // Indicates the last address(es) which was accessed + // Indicates the last addresses which were accessed myLastAddress = in.getShort(); myLastPeekAddress = in.getShort(); myLastPokeAddress = in.getShort();