From b40a614cee39b939a020d5a90d006028c72babd1 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Thu, 20 Dec 2018 18:37:27 -0330 Subject: [PATCH] Rework `Cartridge::initializeStartBank()` to require a specific starting bank. Randomization and reading from properties still work too. Fixes issues in several ROMs that essentially were getting bank randomization even though it was disabled. --- src/emucore/Cart.cxx | 8 +++----- src/emucore/Cart.hxx | 5 +++-- src/emucore/Cart0840.cxx | 3 +-- src/emucore/CartDPC.cxx | 4 +--- src/emucore/CartF0.cxx | 4 +--- src/emucore/CartF4.cxx | 4 +--- src/emucore/CartF4SC.cxx | 2 +- src/emucore/CartF6.cxx | 4 +--- src/emucore/CartF6SC.cxx | 2 +- src/emucore/CartF8SC.cxx | 2 +- src/emucore/CartFA2.cxx | 2 +- src/emucore/CartMNetwork.cxx | 3 +-- src/emucore/CartUA.cxx | 3 +-- src/emucore/CartX07.cxx | 3 +-- 14 files changed, 18 insertions(+), 31 deletions(-) diff --git a/src/emucore/Cart.cxx b/src/emucore/Cart.cxx index d0c047328..d0eb90d3b 100644 --- a/src/emucore/Cart.cxx +++ b/src/emucore/Cart.cxx @@ -139,18 +139,16 @@ void Cartridge::initializeRAM(uInt8* arr, uInt32 size, uInt8 val) const } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -uInt16 Cartridge::initializeStartBank(int defaultBank) +uInt16 Cartridge::initializeStartBank(uInt16 defaultBank) { int propsBank = myStartBankFromPropsFunc(); - bool userandom = randomStartBank() || (defaultBank < 0 && propsBank < 0); - - if(userandom) + if(randomStartBank()) return myStartBank = mySystem->randGenerator().next() % bankCount(); else if(propsBank >= 0) return myStartBank = BSPF::clamp(propsBank, 0, bankCount() - 1); else - return myStartBank = BSPF::clamp(defaultBank, 0, bankCount() - 1); + return myStartBank = BSPF::clamp(int(defaultBank), 0, bankCount() - 1); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Cart.hxx b/src/emucore/Cart.hxx index d8e890c00..8a3e2e3be 100644 --- a/src/emucore/Cart.hxx +++ b/src/emucore/Cart.hxx @@ -258,11 +258,12 @@ class Cartridge : public Device NOTE: If this method is used, it *must* be called from the cart reset() method, *not* from the c'tor. - @param defaultBank The actual bank to use during reset + @param defaultBank The default bank to use during reset, if + randomization or properties aren't being used @return The bank number that was determined */ - uInt16 initializeStartBank(int defaultBank = -1); + uInt16 initializeStartBank(uInt16 defaultBank); /** Checks if initial RAM randomization is enabled. diff --git a/src/emucore/Cart0840.cxx b/src/emucore/Cart0840.cxx index f8a362daf..b63b17c91 100644 --- a/src/emucore/Cart0840.cxx +++ b/src/emucore/Cart0840.cxx @@ -32,9 +32,8 @@ Cartridge0840::Cartridge0840(const BytePtr& image, uInt32 size, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Cartridge0840::reset() { - initializeStartBank(); - // Upon reset we switch to the startup bank + initializeStartBank(0); bank(startBank()); } diff --git a/src/emucore/CartDPC.cxx b/src/emucore/CartDPC.cxx index 51ea9c9c9..92d96340e 100644 --- a/src/emucore/CartDPC.cxx +++ b/src/emucore/CartDPC.cxx @@ -57,10 +57,8 @@ void CartridgeDPC::reset() myAudioCycles = 0; myFractionalClocks = 0.0; - // Use random startup bank - initializeStartBank(); - // Upon reset we switch to the startup bank + initializeStartBank(1); bank(startBank()); } diff --git a/src/emucore/CartF0.cxx b/src/emucore/CartF0.cxx index 698902cb1..7756c29dc 100644 --- a/src/emucore/CartF0.cxx +++ b/src/emucore/CartF0.cxx @@ -32,10 +32,8 @@ CartridgeF0::CartridgeF0(const BytePtr& image, uInt32 size, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeF0::reset() { - // Use random startup bank - initializeStartBank(); - // Upon reset we switch to the startup bank + initializeStartBank(15); bank(startBank()); } diff --git a/src/emucore/CartF4.cxx b/src/emucore/CartF4.cxx index 5f6626fbd..51e85b191 100644 --- a/src/emucore/CartF4.cxx +++ b/src/emucore/CartF4.cxx @@ -33,10 +33,8 @@ CartridgeF4::CartridgeF4(const BytePtr& image, uInt32 size, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeF4::reset() { - // Use random startup bank - initializeStartBank(); - // Upon reset we switch to the startup bank + initializeStartBank(0); bank(startBank()); } diff --git a/src/emucore/CartF4SC.cxx b/src/emucore/CartF4SC.cxx index fd0951d40..d29a8d5b6 100644 --- a/src/emucore/CartF4SC.cxx +++ b/src/emucore/CartF4SC.cxx @@ -33,7 +33,7 @@ CartridgeF4SC::CartridgeF4SC(const BytePtr& image, uInt32 size, void CartridgeF4SC::reset() { initializeRAM(myRAM, 128); - initializeStartBank(); + initializeStartBank(0); // Upon reset we switch to the startup bank bank(startBank()); diff --git a/src/emucore/CartF6.cxx b/src/emucore/CartF6.cxx index 77cb93c90..6f6054f63 100644 --- a/src/emucore/CartF6.cxx +++ b/src/emucore/CartF6.cxx @@ -32,10 +32,8 @@ CartridgeF6::CartridgeF6(const BytePtr& image, uInt32 size, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeF6::reset() { - // Use random startup bank - initializeStartBank(); - // Upon reset we switch to the startup bank + initializeStartBank(0); bank(startBank()); } diff --git a/src/emucore/CartF6SC.cxx b/src/emucore/CartF6SC.cxx index a0158cc19..9c673e223 100644 --- a/src/emucore/CartF6SC.cxx +++ b/src/emucore/CartF6SC.cxx @@ -33,7 +33,7 @@ CartridgeF6SC::CartridgeF6SC(const BytePtr& image, uInt32 size, void CartridgeF6SC::reset() { initializeRAM(myRAM, 128); - initializeStartBank(); + initializeStartBank(0); // Upon reset we switch to the startup bank bank(startBank()); diff --git a/src/emucore/CartF8SC.cxx b/src/emucore/CartF8SC.cxx index 827af0212..9bab7427c 100644 --- a/src/emucore/CartF8SC.cxx +++ b/src/emucore/CartF8SC.cxx @@ -33,7 +33,7 @@ CartridgeF8SC::CartridgeF8SC(const BytePtr& image, uInt32 size, void CartridgeF8SC::reset() { initializeRAM(myRAM, 128); - initializeStartBank(); + initializeStartBank(1); // Upon reset we switch to the startup bank bank(startBank()); diff --git a/src/emucore/CartFA2.cxx b/src/emucore/CartFA2.cxx index 882d77941..2275c1265 100644 --- a/src/emucore/CartFA2.cxx +++ b/src/emucore/CartFA2.cxx @@ -45,7 +45,7 @@ CartridgeFA2::CartridgeFA2(const BytePtr& image, uInt32 size, void CartridgeFA2::reset() { initializeRAM(myRAM, 256); - initializeStartBank(); + initializeStartBank(0); // Upon reset we switch to the startup bank bank(startBank()); diff --git a/src/emucore/CartMNetwork.cxx b/src/emucore/CartMNetwork.cxx index fb520427b..512db2a23 100644 --- a/src/emucore/CartMNetwork.cxx +++ b/src/emucore/CartMNetwork.cxx @@ -46,8 +46,7 @@ void CartridgeMNetwork::reset() { initializeRAM(myRAM, RAM_SIZE); - // Use random startup bank - initializeStartBank(); + initializeStartBank(0); uInt32 ramBank = randomStartBank() ? mySystem->randGenerator().next() % 4 : 0; diff --git a/src/emucore/CartUA.cxx b/src/emucore/CartUA.cxx index e0457c167..be03fa9de 100644 --- a/src/emucore/CartUA.cxx +++ b/src/emucore/CartUA.cxx @@ -32,9 +32,8 @@ CartridgeUA::CartridgeUA(const BytePtr& image, uInt32 size, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeUA::reset() { - initializeStartBank(); - // Upon reset we switch to the startup bank + initializeStartBank(0); bank(startBank()); } diff --git a/src/emucore/CartX07.cxx b/src/emucore/CartX07.cxx index 72e8be68e..dd550561c 100644 --- a/src/emucore/CartX07.cxx +++ b/src/emucore/CartX07.cxx @@ -34,9 +34,8 @@ CartridgeX07::CartridgeX07(const BytePtr& image, uInt32 size, // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void CartridgeX07::reset() { - initializeStartBank(); - // Upon reset we switch to the startup bank + initializeStartBank(0); bank(startBank()); }