Skip to content

Commit

Permalink
Some cleanup of CartAR class, in preparation for moving some code fro…
Browse files Browse the repository at this point in the history
…m System class.
  • Loading branch information
sa666666 committed Aug 1, 2023
1 parent 7222778 commit 55e3874
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 50 deletions.
45 changes: 9 additions & 36 deletions src/emucore/CartAR.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,20 @@
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================

#include <numeric>

#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<uInt8>(std::accumulate(s, s + length, 0));
}
} // namespace

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CartridgeAR::CartridgeAR(const ByteBuffer& image, size_t size,
string_view md5, const Settings& settings)
Expand Down Expand Up @@ -509,39 +518,3 @@ std::array<uInt8, 294> CartridgeAR::ourDummyROMCode = {
0xa9, 0x9a, 0xa2, 0xff, 0xa0, 0x00, 0x9a, 0x4c,
0xfa, 0x00, 0xcd, 0xf8, 0xff, 0x4c
};

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const std::array<uInt8, 256> 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
};
47 changes: 36 additions & 11 deletions src/emucore/CartAR.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);

Expand Down Expand Up @@ -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<uInt8, 294> ourDummyROMCode;

// Default 256-byte header to use if one isn't included in the ROM
// This data comes from z26
static const std::array<uInt8, 256> ourDefaultHeader;
static constexpr std::array<uInt8, 256> 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
Expand Down
7 changes: 4 additions & 3 deletions src/emucore/M6502.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ void M6502::reset()
// Load PC from the reset vector
PC = static_cast<uInt16>(mySystem->peek(0xfffc)) | (static_cast<uInt16>(mySystem->peek(0xfffd)) << 8);

myLastAddress = myLastPeekAddress = myLastPokeAddress = myLastPeekBaseAddress = myLastPokeBaseAddress;
myLastAddress = myLastPeekAddress = myLastPokeAddress =
myLastPeekBaseAddress = myLastPokeBaseAddress = 0;
myLastSrcAddressS = myLastSrcAddressA =
myLastSrcAddressX = myLastSrcAddressY = -1;
myDataAddressForPoke = 0;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 55e3874

Please sign in to comment.