in atari_py/ale_interface/src/emucore/TIA.cxx [1022:1150]
void TIA::computePlayerPositionResetWhenTable()
{
uInt32 mode, oldx, newx;
// Loop through all player modes, all old player positions, and all new
// player positions and determine where the new position is located:
// 1 means the new position is within the display of an old copy of the
// player, -1 means the new position is within the delay portion of an
// old copy of the player, and 0 means it's neither of these two
for(mode = 0; mode < 8; ++mode)
{
for(oldx = 0; oldx < 160; ++oldx)
{
// Set everything to 0 for non-delay/non-display section
for(newx = 0; newx < 160; ++newx)
{
ourPlayerPositionResetWhenTable[mode][oldx][newx] = 0;
}
// Now, we'll set the entries for non-delay/non-display section
for(newx = 0; newx < 160 + 72 + 5; ++newx)
{
if(mode == 0x00)
{
if((newx >= oldx) && (newx < (oldx + 4)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = -1;
if((newx >= oldx + 4) && (newx < (oldx + 4 + 8)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = 1;
}
else if(mode == 0x01)
{
if((newx >= oldx) && (newx < (oldx + 4)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = -1;
else if((newx >= (oldx + 16)) && (newx < (oldx + 16 + 4)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = -1;
if((newx >= oldx + 4) && (newx < (oldx + 4 + 8)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = 1;
else if((newx >= oldx + 16 + 4) && (newx < (oldx + 16 + 4 + 8)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = 1;
}
else if(mode == 0x02)
{
if((newx >= oldx) && (newx < (oldx + 4)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = -1;
else if((newx >= (oldx + 32)) && (newx < (oldx + 32 + 4)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = -1;
if((newx >= oldx + 4) && (newx < (oldx + 4 + 8)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = 1;
else if((newx >= oldx + 32 + 4) && (newx < (oldx + 32 + 4 + 8)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = 1;
}
else if(mode == 0x03)
{
if((newx >= oldx) && (newx < (oldx + 4)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = -1;
else if((newx >= (oldx + 16)) && (newx < (oldx + 16 + 4)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = -1;
else if((newx >= (oldx + 32)) && (newx < (oldx + 32 + 4)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = -1;
if((newx >= oldx + 4) && (newx < (oldx + 4 + 8)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = 1;
else if((newx >= oldx + 16 + 4) && (newx < (oldx + 16 + 4 + 8)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = 1;
else if((newx >= oldx + 32 + 4) && (newx < (oldx + 32 + 4 + 8)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = 1;
}
else if(mode == 0x04)
{
if((newx >= oldx) && (newx < (oldx + 4)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = -1;
else if((newx >= (oldx + 64)) && (newx < (oldx + 64 + 4)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = -1;
if((newx >= oldx + 4) && (newx < (oldx + 4 + 8)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = 1;
else if((newx >= oldx + 64 + 4) && (newx < (oldx + 64 + 4 + 8)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = 1;
}
else if(mode == 0x05)
{
if((newx >= oldx) && (newx < (oldx + 4)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = -1;
if((newx >= oldx + 4) && (newx < (oldx + 4 + 16)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = 1;
}
else if(mode == 0x06)
{
if((newx >= oldx) && (newx < (oldx + 4)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = -1;
else if((newx >= (oldx + 32)) && (newx < (oldx + 32 + 4)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = -1;
else if((newx >= (oldx + 64)) && (newx < (oldx + 64 + 4)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = -1;
if((newx >= oldx + 4) && (newx < (oldx + 4 + 8)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = 1;
else if((newx >= oldx + 32 + 4) && (newx < (oldx + 32 + 4 + 8)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = 1;
else if((newx >= oldx + 64 + 4) && (newx < (oldx + 64 + 4 + 8)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = 1;
}
else if(mode == 0x07)
{
if((newx >= oldx) && (newx < (oldx + 4)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = -1;
if((newx >= oldx + 4) && (newx < (oldx + 4 + 32)))
ourPlayerPositionResetWhenTable[mode][oldx][newx % 160] = 1;
}
}
// Let's do a sanity check on our table entries
uInt32 s1 = 0, s2 = 0;
for(newx = 0; newx < 160; ++newx)
{
if(ourPlayerPositionResetWhenTable[mode][oldx][newx] == -1)
++s1;
if(ourPlayerPositionResetWhenTable[mode][oldx][newx] == 1)
++s2;
}
assert((s1 % 4 == 0) && (s2 % 8 == 0));
}
}
}