in atari_py/ale_interface/src/emucore/CartDPC.cxx [150:201]
inline void CartridgeDPC::updateMusicModeDataFetchers()
{
// Calculate the number of cycles since the last update
Int32 cycles = mySystem->cycles() - mySystemCycles;
mySystemCycles = mySystem->cycles();
// Calculate the number of DPC OSC clocks since the last update
double clocks = ((15750.0 * cycles) / 1193191.66666667) + myFractionalClocks;
Int32 wholeClocks = (Int32)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)
{
// Update only if the data fetcher is in music mode
if(myMusicMode[x - 5])
{
Int32 top = myTops[x] + 1;
Int32 newLow = (Int32)(myCounters[x] & 0x00ff);
if(myTops[x] != 0)
{
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;
}
}
}