Skip to content

Instantly share code, notes, and snippets.

@darrellenns
Created September 29, 2018 06:22
Show Gist options
  • Save darrellenns/489487aeb714c27197848af9e8f6566c to your computer and use it in GitHub Desktop.
Save darrellenns/489487aeb714c27197848af9e8f6566c to your computer and use it in GitHub Desktop.
FCEUX SMB3 Any% SpeedRun Auto Timer Lua Script
local flag_start=0
local old_flag_start=0
local flag_end=0
local old_flag_end=0
local pc_masked=0
local n=0
local t_stop=0
local attempt=0
local running=false
local framerate=60.098813897441
function fmt_time(t)
t_int=math.floor(t)
ms=1000*(t-t_int)
s=t_int%60
m=(t_int-s)/60
return(string.format("%3d:%02d.%03d",m,s,ms))
end
while true do
pc_masked=AND(0xFFF0,memory.getregister("pc"))
flag_start=AND(0xFFF0,memory.readword(0x1f8))
flag_end=memory.readbyte(0x7f2)
world_num=memory.readbyte(0x727)
if old_flag_start==0x2230 and pc_masked==0xa810 and flag_start==0xa810 then
n=0
running=true
attempt=attempt+1
end
if running==true and pc_masked==0xa810 and old_flag_end==0x3a and flag_end==0xc4 then
t_stop=t
running=false
end
t=n/framerate
gui.text(60,224,string.format("%d",attempt),"white","clear")
gui.text(190,224,fmt_time(t),"white","clear")
if running then
gui.text(100,224,fmt_time(t_stop),"white","clear")
else
gui.text(100,224,fmt_time(t_stop),"green","black")
end
emu.frameadvance()
old_flag_start=flag_start
old_flag_end=flag_end
n=n+1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment