Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local slot0 = savestate.object(1)
- local start_frame = 0
- local test_frame = 0
- local inited = false
- local testing = false
- local prev = nil
- local sum = 0
- local index = 0
- local lagCheck = true
- local freeFrame = 0
- local lagsChecked = 0
- local best = 123456789
- local worst = 0
- emu.speedmode("turbo") --It seems to work better when you click turbo from the menu.
- emu.setrenderplanes(false,false)
- emu.unpause()
- local function init()
- savestate.load(slot0)
- start_frame = emu.framecount()
- prev = "................"
- sum = 0
- index = 0
- testing = false
- lagCheck = false
- lagsChecked = 0
- freeFrame = 0
- inited = true
- end
- local function spacelessLen(str)
- local ans = 0
- for i=1,#str do
- if str:sub(i,i)~=" " then
- ans = ans + 1
- end
- end
- return ans
- end
- local function clampRight(str)
- local length = 0
- for i=1,#str do
- if str:sub(i,i) ~= ' ' then
- length = i
- end
- end
- return str:sub(1,length)
- end
- local function readWord()
- local word = memory.readbyterange(0x0448, 16)
- local ret = ""
- for i=1,#word do
- local c = word:sub(i,i):byte()
- if c == 0x28 then
- --emu.print(" ")
- ret = ret.." "
- elseif c>=0x0A and c<= 0x23 then
- --emu.print(string.char(c-0x0A+65))
- ret = ret..string.char(c-0x0A+65)
- else
- ret = ret.."." --dot for unknown characters, just like the hex editor
- end
- --emu.print(word:sub(i,i):byte()-0x0A+65)
- --emu.print(word:sub(i,i):byte())
- end
- --emu.print(ret)
- return clampRight(ret)
- end
- local function post_frame()
- if not inited then init() end
- if emu.framecount() - start_frame == test_frame then
- emu.print("Testing frame "..emu.framecount().."...")
- testing = true
- joypad.set(1,{start=true})
- return
- end
- if not testing then return end
- if freeFrame==0 and not lagCheck and emu.lagged() then
- lagCheck = true
- lagsChecked = lagsChecked + 1
- end
- if freeFrame==0 and lagCheck and not emu.lagged() then
- lagCheck = false
- if lagsChecked == 5 then
- --emu.print("Escaped lag at frame "..emu.framecount())
- freeFrame = emu.framecount()
- end
- end
- if AND(emu.framecount(),1) == 0 then
- joypad.set(1,{start=true})
- end
- local word = readWord()
- if word ~= prev then
- emu.print(word)
- sum = sum + spacelessLen(word)
- index = index + 1
- if index==6 then
- test_frame = test_frame + 1
- inited = false
- emu.print(sum.." characters + "..(freeFrame-1182).." frames of waiting.")
- if sum < best then
- emu.print("!!BEST SO FAR!!")
- best = sum
- elseif sum > worst then
- emu.print("...WORST SO FAR...")
- worst = sum
- end
- emu.print("________________________")
- end
- end
- prev = word
- end
- emu.registerafter(post_frame)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement