-- Start 1 frame after the first up input in each level, because reasons.
local startFrame = emu.framecount()
local prevJoy = {}
local prevY = -1
local firstTime06 = true
print(string.format("Starting on frame %d", startFrame))
emu.registerafter(function()
local joy = joypad.get(1)
local y = memory.readbyte(0x0664) -- Upper 4 bits is screen, lower 4 is tile Y.
gui.text(10, 10, string.format("%02X", y))
if (emu.framecount() - startFrame) % 2 == 0 and emu.lagged() then
print("Level complete.")
emu.pause()
return
end
-- There is an anomaly at the end of each stage. When you hit 06 for the first time, your next movement is going to
-- nudge you down by 01, invisibly. Seems like they're accounting for some hideous fencepost error.
-- This statement counters that nudge so the validation still works.
if prevY == 0x06 and firstTime06 then
prevY = 0x07
end
if (emu.framecount() - startFrame) % 4 == 0 then
if not joy.up or prevJoy.up then
print(string.format("%d - Why aren't you pressing up!?", emu.framecount()))
emu.pause()
elseif y >= prevY then
print(string.format("%d - You're not moving!", emu.framecount()))
emu.pause()
end
end
prevJoy = joy
prevY = y
end)