Advertisement
tikevin83

Bizhawk Cycle-Timestamp Inputs Lua Script

Apr 18th, 2018 (edited)
793
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local coreName = movie.getheader()["Core"]
  2. local gameName = string.gsub(movie.getheader()["GameName"], "%s+", "")
  3. local powerOnCycles = 0
  4. local inputlabels
  5. local powerButtonLabel
  6. local coreToGBAAudioSampleRatio
  7.  
  8. if coreName == "Gambatte" then
  9.   inputlabels = {"A", "B", "Select", "Start", "Right", "Left", "Up", "Down"}
  10.   powerButtonLabel = "Power"
  11.   coreToGBAAudioSampleRatio = 512
  12. elseif coreName == "GBHawk" or coreName == "SubGBHawk" then
  13.   inputlabels = {"P1 A", "P1 B", "P1 Select", "P1 Start", "P1 Right", "P1 Left", "P1 Up", "P1 Down"}
  14.   powerButtonLabel = "P1 Power"
  15.   coreToGBAAudioSampleRatio = 1024
  16. else
  17.   error("Unknown Emulator Core")
  18. end
  19.  
  20. function getinputbyte(t)
  21.   if not movie.isloaded() then
  22.     return 0
  23.   end
  24.  
  25.   local b = 0
  26.  
  27.   for i = 0, 7 do
  28.     if t[inputlabels[i + 1]] then
  29.       b = b + bit.lshift(1, i)
  30.     end
  31.   end
  32.  
  33.   return b
  34. end
  35.  
  36. function tryinput(file)
  37.   local t = movie.getinput(emu.framecount())
  38.   local input = getinputbyte(t)
  39.   local cycles = emu.totalexecutedcycles()
  40.   if t[powerButtonLabel] then
  41.     powerOnCycles = cycles
  42.   end
  43.  
  44.   if input ~= lastinput then
  45.       cycles = math.ceil((cycles - powerOnCycles) / coreToGBAAudioSampleRatio)
  46.     file:write(string.format("%08X %04X", cycles, input))
  47.     file:write("\n")
  48.     lastinput = input
  49.   end
  50. end
  51.  
  52. local timestamps = io.open(gameName .. ".txt", "w")
  53. local lastinput = -1
  54.  
  55. tryinput(timestamps)
  56.  
  57. while emu.framecount() <= movie.length() do
  58.  
  59.     tryinput(timestamps)
  60.  
  61.   emu.frameadvance()
  62. end
  63.  
  64. tryinput(timestamps)
  65. timestamps:close()
  66.  
  67. client.pause()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement