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.
This commit is contained in:
Stephen Anthony 2018-12-20 18:37:27 -03:30
parent 497bfc92db
commit b40a614cee
14 changed files with 18 additions and 31 deletions

View File

@ -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);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -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.

View File

@ -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());
}

View File

@ -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());
}

View File

@ -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());
}

View File

@ -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());
}

View File

@ -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());

View File

@ -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());
}

View File

@ -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());

View File

@ -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());

View File

@ -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());

View File

@ -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;

View File

@ -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());
}

View File

@ -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());
}