I wanted to start making something simple that drew Sonic's collision mask on top of his sprite, so I got the camera coordinates and Sonic's coordinates, subtracted the former from the latter, and drew a box at the resulting position. No matter what I did, though, the box would always flicker and jump around randomly.
It turned out this was because memory.readword() and its ilk were giving me incorrect values, and I have made a test script to demonstrate (meant for Sonic 2).
timer = 0;
timerp = 0;
diff = false;
count = 0;
gens.registerafter( function()
timerp = timer;
timer = memory.readword(0xfffe04);
if (timer == timerp) then diff = true;
else diff = false;
end
end)
gui.register( function ()
message = string.format("Timer: $%X, %d", timer, count)
gui.text(10, 50, message, "#FFFF00FF", "black")
if (diff) then gui.drawbox(0, 0, 320, 224, "black", "black");
count = count + 1;
end
end)
Because the game timer is supposed to count up by 1 every frame, it's easy to tell if memory.readword() is reading the new value correctly or not. Each time it gets it wrong (and returns the value from the last frame), I increase a counter and make the screen flash black to make it obvious this is happening.
It doesn't matter if I try to get the value in gens.registerafter(), gens.registerbefore(), or in gui.register(), or even if I put hooks in when the memory is written to. I will still get a bad value from 1 frame ago sometimes.
Oddly, this seems to only happen when the screen is scrolling. If you stand Sonic still, it won't happen.
Furthermore, it's not just my Lua code. The RAM watch feature has the same issue, which can be seen if you watch an increasing value such as the timer and use frame advance, sometime it will not update.
I'm pretty much at my wits' end when it comes to this, because it prevents any kind of useful overlays on objects, making it a showstopping issue. Has anyone here ever experienced this, and do you know what might be the cause or the solution?
(It happens in Gens Rerecording v11a as well as the latest version at Google code.)


00