in atari_py/ale_interface/src/emucore/CartDPC.cxx [204:324]
uInt8 CartridgeDPC::peek(uInt16 address)
{
address = address & 0x0FFF;
// Clock the random number generator. This should be done for every
// cartridge access, however, we're only doing it for the DPC and
// hot-spot accesses to save time.
clockRandomNumberGenerator();
if(address < 0x0040)
{
uInt8 result = 0;
// Get the index of the data fetcher that's being accessed
uInt32 index = address & 0x07;
uInt32 function = (address >> 3) & 0x07;
// Update flag register for selected data fetcher
if((myCounters[index] & 0x00ff) == myTops[index])
{
myFlags[index] = 0xff;
}
else if((myCounters[index] & 0x00ff) == myBottoms[index])
{
myFlags[index] = 0x00;
}
switch(function)
{
case 0x00:
{
// Is this a random number read
if(index < 4)
{
result = myRandomNumber;
}
// No, it's a music read
else
{
static const uInt8 musicAmplitudes[8] = {
0x00, 0x04, 0x05, 0x09, 0x06, 0x0a, 0x0b, 0x0f
};
// Update the music data fetchers (counter & flag)
updateMusicModeDataFetchers();
uInt8 i = 0;
if(myMusicMode[0] && myFlags[5])
{
i |= 0x01;
}
if(myMusicMode[1] && myFlags[6])
{
i |= 0x02;
}
if(myMusicMode[2] && myFlags[7])
{
i |= 0x04;
}
result = musicAmplitudes[i];
}
break;
}
// DFx display data read
case 0x01:
{
result = myDisplayImage[2047 - myCounters[index]];
break;
}
// DFx display data read AND'd w/flag
case 0x02:
{
result = myDisplayImage[2047 - myCounters[index]] & myFlags[index];
break;
}
// DFx flag
case 0x07:
{
result = myFlags[index];
break;
}
default:
{
result = 0;
}
}
// Clock the selected data fetcher's counter if needed
if((index < 5) || ((index >= 5) && (!myMusicMode[index - 5])))
{
myCounters[index] = (myCounters[index] - 1) & 0x07ff;
}
return result;
}
else
{
// Switch banks if necessary
switch(address)
{
case 0x0FF8:
// Set the current bank to the lower 4k bank
bank(0);
break;
case 0x0FF9:
// Set the current bank to the upper 4k bank
bank(1);
break;
default:
break;
}
return myProgramImage[myCurrentBank * 4096 + address];
}
}