Skip to content

Instantly share code, notes, and snippets.

@furious
Last active May 11, 2018 15:23
Show Gist options
  • Save furious/0c6b9793533473b85f52834e6faec927 to your computer and use it in GitHub Desktop.
Save furious/0c6b9793533473b85f52834e6faec927 to your computer and use it in GitHub Desktop.
BizHawk Lua Script to Export SNES Inputs
-- snes export inputs 1.0
-- by furious
--/byetUDLRaxlr0000
joymap = {"B", "Y", "Select", "Start", "Up", "Down", "Left", "Right", "A", "X", "L", "R"}
joypads = {"P1", "P2", "P5", "P6"}
file_suffix = "inputs.txt"
-- a movie needs to be playing to do anything
if movie.mode() ~= "PLAY" then
error("error movie not playing - run this script after movie started and paused")
end
-- get r16m filename
_, _, path, filename, ext = string.find(movie.filename(), "(.-)([^\\/]-%.?)([^%.\\/]*)$")
-- open for writing
fh, err = io.open(path..filename..file_suffix, "wb")
if not fh then
error("error opening output file: "..err)
end
print("dumping to "..path..filename..file_suffix)
dumpfile = fh
pollcount = 0
frame = 0
frame_lag = 0
fh = nil
err = nil
function bytes(x)
local b2=x%256 x=(x-x%256)/256
local b1=x%256 x=(x-x%256)/256
return string.char(b1,b2)
end
while true do
if dumpfile then
if movie.mode() ~= "PLAY" and dumpfile then
dumpfile:close()
dumpfile = nil
print("dumping completed")
elseif not emu.islagged() then
local inputs = movie.getinput(emu.framecount())
for x, pad in pairs(joypads) do
local input = 0
for i, btn in pairs(joymap) do
if inputs[pad.." "..btn] then
input = bit.bor(input, bit.lshift(1, 15 - i))
end
end
-- write bit data
dumpfile:write(bytes(input));
end
frame = frame + 1
elseif emu.islagged() then
frame_lag = frame_lag + 1
end
gui.pixelText(1, 1, string.format('frames: %04d - lag: %04d', frame, frame_lag), 0xFFFFFFFF, 0x99000000)
end
emu.frameadvance()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment