tikevin83

Bizhawk Cycle-Timestamp Inputs Lua Script

Apr 18th, 2018
262
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local inputlabels = {"A", "B", "Select", "Start", "Right", "Left", "Up", "Down"}
  2.  
  3. function getinputbyte()
  4.   if not movie.isloaded() then
  5.     return 0
  6.   end
  7.  
  8.   local t = movie.getinput(emu.framecount())
  9.   local b = 0
  10.  
  11.   for i = 0, 7 do
  12.     if t[inputlabels[i + 1]] then
  13.       b = b + bit.lshift(1, i)
  14.     end
  15.   end
  16.  
  17.   return b
  18. end
  19.  
  20. function tryinput(file)
  21.   local input = getinputbyte()
  22.  
  23.   if input ~= lastinput then
  24.     local cycles = emu.totalexecutedcycles();
  25.     cycles = (cycles + 485376) / 512;
  26.    
  27.     file:write(string.format("%08X %04X", cycles, input))
  28.     file:write("\n")
  29.     lastinput = input
  30.   end
  31. end
  32.  
  33. local timestamps = io.open("timestamps.txt", "w")
  34. local lastinput = -1
  35.  
  36. tryinput(timestamps)
  37.  
  38. while emu.framecount() <= movie.length() do
  39.  
  40.   tryinput(timestamps)
  41.  
  42.   emu.frameadvance()
  43. end
  44.  
  45. tryinput(timestamps)
  46. timestamps:close()
  47.  
  48. client.pause()
RAW Paste Data