View difference between Paste ID: NbTRNePD and LPN9E85G
SHOW: | | - or go back to the newest paste.
1-
local inputlabels = {"A", "B", "Select", "Start", "Right", "Left", "Up", "Down"}
1+
local coreName = movie.getheader()["Core"]
2
local gameName = string.gsub(movie.getheader()["GameName"], "%s+", "")
3-
function getinputbyte()
3+
local powerOnCycles = 0
4
local modeSwitchGBAToGBCDelay = 948.84375
5
local inputlabels
6
local powerButtonLabel
7
local coreToGBAAudioSampleRatio
8
9
if coreName == "Gambatte" then
10
  inputlabels = {"A", "B", "Select", "Start", "Right", "Left", "Up", "Down"}
11
  powerButtonLabel = "Power"
12
  coreToGBAAudioSampleRatio = 512
13
elseif coreName == "GBHawk" or coreName == "SubGBHawk" then
14
  inputlabels = {"P1 A", "P1 B", "P1 Select", "P1 Start", "P1 Right", "P1 Left", "P1 Up", "P1 Down"}
15
  powerButtonLabel = "P1 Power"
16
  coreToGBAAudioSampleRatio = 1024
17
else
18
  error("Unknown Emulator Core")
19
end
20-
function tryinput()
20+
21-
  local input = getinputbyte()
21+
function getinputbyte(t)
22
  if not movie.isloaded() then
23
    return 0
24-
    io.write(string.format("%08X %02X", emu.totalexecutedcycles(), input))
24+
25
  
26
  local b = 0
27
  
28
  for i = 0, 7 do
29-
local timestamps = io.open("timestamps.txt", "w")
29+
30
      b = b + bit.lshift(1, i)
31
    end
32-
io.output(timestamps)
32+
33-
tryinput()
33+
34
  return b
35
end
36-
  if emu.getregister("PC") == 0x40 then
36+
37-
    tryinput()
37+
function tryinput(file)
38
  local t = movie.getinput(emu.framecount())
39
  local input = getinputbyte(t)
40
  local cycles = emu.totalexecutedcycles()
41
  if t[powerButtonLabel] then
42
    powerOnCycles = cycles
43-
tryinput()
43+
44-
io.close()
44+
45
  if input ~= lastinput then
46
	  cycles = math.ceil(((cycles - powerOnCycles) / coreToGBAAudioSampleRatio) + modeSwitchGBAToGBCDelay)
47
    file:write(string.format("%08X %04X", cycles, input))
48
    file:write("\n")
49
    lastinput = input
50
  end
51
end
52
53
local timestamps = io.open(gameName .. ".txt", "w")
54
local lastinput = -1
55
56
tryinput(timestamps)
57
58
while emu.framecount() <= movie.length() do
59
60
    tryinput(timestamps)
61
  
62
  emu.frameadvance()
63
end
64
65
tryinput(timestamps)
66
timestamps:close()
67
68
client.pause()