local inputlabels = {"A", "B", "Select", "Start", "Right", "Left", "Up", "Down"} function get_lcd_status() memory.usememorydomain("System Bus") return memory.readbyte(0xFF40) end function determine_lcd_status() return bit.band(get_lcd_status(), (0x80)) end function getinputbyte() if not movie.isloaded() then return 0 end local t = movie.getinput(emu.framecount()) local b = 0 for i = 0, 7 do if t[inputlabels[i + 1]] then b = b + bit.lshift(1, i) end end return b end function tryinput(file) local input = getinputbyte() file:write(string.char(input)) lastinput = input end local demo = io.open("bgb.dem", "wb") local lastinput = -1 tryinput(demo) while emu.framecount() <= movie.length() do if determine_lcd_status() ~= 0 then tryinput(demo) end emu.frameadvance() end tryinput(demo) demo:close() client.pause()