CartCDF and friends refactoring (have similar functionality):

- rework music fetcher code; there can never be a negative cycle count
- use get/put double Serializer methods for doubles.
This commit is contained in:
Stephen Anthony 2017-09-08 18:36:06 -02:30
parent b6907d0d8a
commit c4d04ffe26
10 changed files with 68 additions and 95 deletions

View File

@ -43,7 +43,7 @@
CartridgeBUS::CartridgeBUS(const BytePtr& image, uInt32 size,
const Settings& settings)
: Cartridge(settings),
mySystemCycles(0),
myAudioCycles(0),
myARMCycles(0),
myFractionalClocks(0.0)
{
@ -77,8 +77,7 @@ void CartridgeBUS::reset()
initializeRAM(myBUSRAM+2048, 8192-2048);
// Update cycles to the current system cycles
mySystemCycles = mySystem->cycles();
myARMCycles = mySystem->cycles();
myAudioCycles = myARMCycles = 0;
myFractionalClocks = 0.0;
setInitialState();
@ -135,20 +134,18 @@ void CartridgeBUS::install(System& system)
inline void CartridgeBUS::updateMusicModeDataFetchers()
{
// Calculate the number of cycles since the last update
Int32 cycles = Int32(mySystem->cycles() - mySystemCycles);
mySystemCycles = mySystem->cycles();
uInt32 cycles = uInt32(mySystem->cycles() - myAudioCycles);
myAudioCycles = mySystem->cycles();
// Calculate the number of BUS OSC clocks since the last update
double clocks = ((20000.0 * cycles) / 1193191.66666667) + myFractionalClocks;
Int32 wholeClocks = Int32(clocks);
uInt32 wholeClocks = uInt32(clocks);
myFractionalClocks = clocks - double(wholeClocks);
if(wholeClocks <= 0)
return;
// Let's update counters and flags of the music mode data fetchers
for(int x = 0; x <= 2; ++x)
myMusicCounters[x] += myMusicFrequencies[x] * wholeClocks;
if(wholeClocks > 0)
for(int x = 0; x <= 2; ++x)
myMusicCounters[x] += myMusicFrequencies[x] * wholeClocks;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -562,8 +559,8 @@ bool CartridgeBUS::save(Serializer& out) const
out.putShort(myJMPoperandAddress);
// Save cycles and clocks
out.putLong(mySystemCycles);
out.putInt((uInt32)(myFractionalClocks * 100000000.0));
out.putLong(myAudioCycles);
out.putDouble(myFractionalClocks);
out.putLong(myARMCycles);
// Audio info
@ -606,8 +603,8 @@ bool CartridgeBUS::load(Serializer& in)
myJMPoperandAddress = in.getShort();
// Get system cycles and fractional clocks
mySystemCycles = in.getLong();
myFractionalClocks = (double)in.getInt() / 100000000.0;
myAudioCycles = in.getLong();
myFractionalClocks = in.getDouble();
myARMCycles = in.getLong();
// Audio info

View File

@ -244,8 +244,8 @@ class CartridgeBUS : public Cartridge
// *and* the next two bytes in ROM are 00 00
uInt16 myJMPoperandAddress;
// System cycle count when the last update to music data fetchers occurred
uInt64 mySystemCycles;
// System cycle count from when the last update to music data fetchers occurred
uInt64 myAudioCycles;
// ARM cycle count from when the last callFunction() occurred
uInt64 myARMCycles;

View File

@ -81,9 +81,7 @@ void CartridgeCDF::reset()
{
initializeRAM(myCDFRAM+2048, 8192-2048);
// Update cycles to the current system cycles
myAudioCycles = mySystem->cycles();
myARMCycles = mySystem->cycles();
myAudioCycles = myARMCycles = 0;
myFractionalClocks = 0.0;
setInitialState();
@ -137,20 +135,18 @@ void CartridgeCDF::install(System& system)
inline void CartridgeCDF::updateMusicModeDataFetchers()
{
// Calculate the number of cycles since the last update
Int32 cycles = Int32(mySystem->cycles() - myAudioCycles);
uInt32 cycles = uInt32(mySystem->cycles() - myAudioCycles);
myAudioCycles = mySystem->cycles();
// Calculate the number of CDF OSC clocks since the last update
double clocks = ((20000.0 * cycles) / 1193191.66666667) + myFractionalClocks;
Int32 wholeClocks = Int32(clocks);
uInt32 wholeClocks = uInt32(clocks);
myFractionalClocks = clocks - double(wholeClocks);
if(wholeClocks <= 0)
return;
// Let's update counters and flags of the music mode data fetchers
for(int x = 0; x <= 2; ++x)
myMusicCounters[x] += myMusicFrequencies[x] * wholeClocks;
if(wholeClocks > 0)
for(int x = 0; x <= 2; ++x)
myMusicCounters[x] += myMusicFrequencies[x] * wholeClocks;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -512,7 +508,7 @@ bool CartridgeCDF::save(Serializer& out) const
// Save cycles and clocks
out.putLong(myAudioCycles);
out.putInt((uInt32)(myFractionalClocks * 100000000.0));
out.putDouble(myFractionalClocks);
out.putLong(myARMCycles);
}
catch(...)
@ -555,7 +551,7 @@ bool CartridgeCDF::load(Serializer& in)
// Get cycles and clocks
myAudioCycles = in.getLong();
myFractionalClocks = (double)in.getInt() / 100000000.0;
myFractionalClocks = in.getDouble();
myARMCycles = in.getLong();
}
catch(...)

View File

@ -138,8 +138,6 @@ class CartridgeCDF : public Cartridge
*/
string name() const override { return "CartridgeCDF"; }
// uInt8 busOverdrive(uInt16 address) override;
/**
Used for Thumbulator to pass values back to the cartridge
*/

View File

@ -31,7 +31,7 @@ CartridgeCTY::CartridgeCTY(const BytePtr& image, uInt32 size,
myLDAimmediate(false),
myRandomNumber(0x2B435044),
myRamAccessTimeout(0),
mySystemCycles(0),
myAudioCycles(0),
myFractionalClocks(0.0),
myBankOffset(0)
{
@ -53,8 +53,7 @@ void CartridgeCTY::reset()
myRAM[0] = myRAM[1] = myRAM[2] = myRAM[3] = 0xFF;
// Update cycles to the current system cycles
mySystemCycles = mySystem->cycles();
myAudioCycles = 0;
myFractionalClocks = 0.0;
// Upon reset we switch to the startup bank
@ -289,8 +288,8 @@ bool CartridgeCTY::save(Serializer& out) const
out.putShort(myCounter);
out.putBool(myLDAimmediate);
out.putInt(myRandomNumber);
out.putLong(mySystemCycles);
out.putInt(uInt32(myFractionalClocks * 100000000.0));
out.putLong(myAudioCycles);
out.putDouble(myFractionalClocks);
}
catch(...)
@ -318,8 +317,8 @@ bool CartridgeCTY::load(Serializer& in)
myCounter = in.getShort();
myLDAimmediate = in.getBool();
myRandomNumber = in.getInt();
mySystemCycles = in.getLong();
myFractionalClocks = double(in.getInt()) / 100000000.0;
myAudioCycles = in.getLong();
myFractionalClocks = in.getDouble();
}
catch(...)
{
@ -506,18 +505,16 @@ void CartridgeCTY::wipeAllScores()
inline void CartridgeCTY::updateMusicModeDataFetchers()
{
// Calculate the number of cycles since the last update
Int32 cycles = Int32(mySystem->cycles() - mySystemCycles);
mySystemCycles = mySystem->cycles();
uInt32 cycles = uInt32(mySystem->cycles() - myAudioCycles);
myAudioCycles = mySystem->cycles();
// Calculate the number of DPC OSC clocks since the last update
// Calculate the number of CTY OSC clocks since the last update
double clocks = ((20000.0 * cycles) / 1193191.66666667) + myFractionalClocks;
Int32 wholeClocks = Int32(clocks);
uInt32 wholeClocks = uInt32(clocks);
myFractionalClocks = clocks - double(wholeClocks);
if(wholeClocks <= 0)
return;
// Let's update counters and flags of the music mode data fetchers
for(int x = 0; x <= 2; ++x)
; // myMusicCounters[x] += myMusicFrequencies[x] * wholeClocks;
if(wholeClocks > 0)
for(int x = 0; x <= 2; ++x)
; //myMusicCounters[x] += myMusicFrequencies[x] * wholeClocks;
}

View File

@ -292,8 +292,8 @@ class CartridgeCTY : public Cartridge
// of internal RAM to Harmony cart EEPROM
string myEEPROMFile;
// System cycle count when the last update to music data fetchers occurred
uInt64 mySystemCycles;
// System cycle count from when the last update to music data fetchers occurred
uInt64 myAudioCycles;
// Fractional DPC music OSC clocks unused during the last update
double myFractionalClocks;

View File

@ -23,7 +23,7 @@ CartridgeDPC::CartridgeDPC(const BytePtr& image, uInt32 size,
const Settings& settings)
: Cartridge(settings),
mySize(size),
mySystemCycles(0),
myAudioCycles(0),
myFractionalClocks(0.0),
myBankOffset(0)
{
@ -54,8 +54,7 @@ CartridgeDPC::CartridgeDPC(const BytePtr& image, uInt32 size,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartridgeDPC::reset()
{
// Update cycles to the current system cycles
mySystemCycles = mySystem->cycles();
myAudioCycles = 0;
myFractionalClocks = 0.0;
// Upon reset we switch to the startup bank
@ -98,18 +97,16 @@ inline void CartridgeDPC::clockRandomNumberGenerator()
inline void CartridgeDPC::updateMusicModeDataFetchers()
{
// Calculate the number of cycles since the last update
Int32 cycles = Int32(mySystem->cycles() - mySystemCycles);
mySystemCycles = mySystem->cycles();
uInt32 cycles = uInt32(mySystem->cycles() - myAudioCycles);
myAudioCycles = mySystem->cycles();
// Calculate the number of DPC OSC clocks since the last update
double clocks = ((20000.0 * cycles) / 1193191.66666667) + myFractionalClocks;
Int32 wholeClocks = Int32(clocks);
uInt32 wholeClocks = uInt32(clocks);
myFractionalClocks = clocks - double(wholeClocks);
if(wholeClocks <= 0)
{
return;
}
// Let's update counters and flags of the music mode data fetchers
for(int x = 5; x <= 7; ++x)
@ -124,24 +121,16 @@ inline void CartridgeDPC::updateMusicModeDataFetchers()
{
newLow -= (wholeClocks % top);
if(newLow < 0)
{
newLow += top;
}
}
else
{
newLow = 0;
}
// Update flag register for this data fetcher
if(newLow <= myBottoms[x])
{
myFlags[x] = 0x00;
}
else if(newLow <= myTops[x])
{
myFlags[x] = 0xff;
}
myCounters[x] = (myCounters[x] & 0x0700) | uInt16(newLow);
}
@ -474,8 +463,8 @@ bool CartridgeDPC::save(Serializer& out) const
// The random number generator register
out.putByte(myRandomNumber);
out.putLong(mySystemCycles);
out.putInt(uInt32(myFractionalClocks * 100000000.0));
out.putLong(myAudioCycles);
out.putDouble(myFractionalClocks);
}
catch(...)
{
@ -517,8 +506,8 @@ bool CartridgeDPC::load(Serializer& in)
myRandomNumber = in.getByte();
// Get system cycles and fractional clocks
mySystemCycles = in.getLong();
myFractionalClocks = double(in.getInt()) / 100000000.0;
myAudioCycles = in.getLong();
myFractionalClocks = in.getDouble();
}
catch(...)
{

View File

@ -195,8 +195,8 @@ class CartridgeDPC : public Cartridge
// The random number generator register
uInt8 myRandomNumber;
// System cycle count when the last update to music data fetchers occurred
uInt64 mySystemCycles;
// System cycle count from when the last update to music data fetchers occurred
uInt64 myAudioCycles;
// Fractional DPC music OSC clocks unused during the last update
double myFractionalClocks;

View File

@ -30,9 +30,9 @@ CartridgeDPCPlus::CartridgeDPCPlus(const BytePtr& image, uInt32 size,
myFastFetch(false),
myLDAimmediate(false),
myParameterPointer(0),
mySystemCycles(0),
myFractionalClocks(0.0),
myAudioCycles(0),
myARMCycles(0),
myFractionalClocks(0.0),
myBankOffset(0)
{
// Image is always 32K, but in the case of ROM > 29K, the image is
@ -70,9 +70,7 @@ CartridgeDPCPlus::CartridgeDPCPlus(const BytePtr& image, uInt32 size,
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartridgeDPCPlus::reset()
{
// Update cycles to the current system cycles
mySystemCycles = mySystem->cycles();
myARMCycles = mySystem->cycles();
myAudioCycles = myARMCycles = 0;
myFractionalClocks = 0.0;
setInitialState();
@ -145,20 +143,18 @@ inline void CartridgeDPCPlus::priorClockRandomNumberGenerator()
inline void CartridgeDPCPlus::updateMusicModeDataFetchers()
{
// Calculate the number of cycles since the last update
Int32 cycles = Int32(mySystem->cycles() - mySystemCycles);
mySystemCycles = mySystem->cycles();
uInt32 cycles = uInt32(mySystem->cycles() - myAudioCycles);
myAudioCycles = mySystem->cycles();
// Calculate the number of DPC OSC clocks since the last update
// Calculate the number of DPC+ OSC clocks since the last update
double clocks = ((20000.0 * cycles) / 1193191.66666667) + myFractionalClocks;
Int32 wholeClocks = Int32(clocks);
uInt32 wholeClocks = uInt32(clocks);
myFractionalClocks = clocks - double(wholeClocks);
if(wholeClocks <= 0)
return;
// Let's update counters and flags of the music mode data fetchers
for(int x = 0; x <= 2; ++x)
myMusicCounters[x] += myMusicFrequencies[x] * wholeClocks;
if(wholeClocks > 0)
for(int x = 0; x <= 2; ++x)
myMusicCounters[x] += myMusicFrequencies[x] * wholeClocks;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -682,8 +678,8 @@ bool CartridgeDPCPlus::save(Serializer& out) const
out.putInt(myRandomNumber);
// Get system cycles and fractional clocks
out.putLong(mySystemCycles);
out.putInt(uInt32(myFractionalClocks * 100000000.0));
out.putLong(myAudioCycles);
out.putDouble(myFractionalClocks);
// Clock info for Thumbulator
out.putLong(myARMCycles);
@ -745,9 +741,9 @@ bool CartridgeDPCPlus::load(Serializer& in)
// The random number generator register
myRandomNumber = in.getInt();
// Get system cycles and fractional clocks
mySystemCycles = in.getLong();
myFractionalClocks = double(in.getInt()) / 100000000.0;
// Get audio cycles and fractional clocks
myAudioCycles = in.getLong();
myFractionalClocks = in.getDouble();
// Clock info for Thumbulator
myARMCycles = in.getLong();

View File

@ -259,15 +259,15 @@ class CartridgeDPCPlus : public Cartridge
// The random number generator register
uInt32 myRandomNumber;
// System cycle count when the last update to music data fetchers occurred
uInt64 mySystemCycles;
// Fractional DPC music OSC clocks unused during the last update
double myFractionalClocks;
// System cycle count from when the last update to music data fetchers occurred
uInt64 myAudioCycles;
// System cycle count when the last Thumbulator::run() occurred
uInt64 myARMCycles;
// Fractional DPC music OSC clocks unused during the last update
double myFractionalClocks;
// Indicates the offset into the ROM image (aligns to current bank)
uInt16 myBankOffset;