User File #638445157573692183

Upload All User Files

#638445157573692183 (unlisted) - BizHawk script - Log replay file intput frame, emulator-cycle frame, and polling-for-input info

movie-frame-list.lua
19 downloads
Uploaded 2/26/2024 3:42 AM by Deadcode (see all 13)
As far as GameBoy emulation goes, the polling-for-input data from emu.islagged() seems only to be useful with Gambatte core, not GBHawk core.
function formatInput(input)
    local formattedString = ""
    for key, value in pairs(input) do
        if value then
            if formattedString ~= "" then
                formattedString = formattedString + ", "
            end
            formattedString = formattedString .. key
        end
    end
    return formattedString
end

function logFrame(logfile, movieCore)
    local emuFrame = emu.framecount()
    local emuCycle = emu.totalexecutedcycles()
    if movieCore == "Gambatte" then
        emuFrame = emuFrame - 15
        emuCycle = emuCycle * 2 - 755716
    end
    logfile:write(string.format("%6d, %12.6f: %s %s\n", emuFrame, emuCycle / 70224, emu.islagged() and " " or "!", formatInput(joypad.getwithmovie())))
    logfile:flush()
end

local logfile = nil
local movieCore
local lastFrame
local lastMovie = nil
local finished
while true do
    if movie.isloaded() and movie.mode() ~= "FINISHED" then
        if emu.framecount() == 0 and (finished or lastFrame ~= 0 or movie.filename() ~= lastMovie) then
            if logfile ~= nil then
                logfile:close()
            end
            lastMovie = movie.filename()
            logfile = io.open(lastMovie .. ".frame-list.txt", "w")
            movieCore = movie.getheader()["Core"]
            finished = false
        elseif logfile ~= nil and emu.framecount() ~= lastFrame then
            logFrame(logfile, movieCore)
        end
        lastFrame = emu.framecount()
    elseif logfile ~= nil then
        if movie.isloaded() and emu.framecount() ~= lastFrame and not finished then
            logFrame(logfile, movieCore)
            finished = true
        end
        if not movie.isloaded() or finished then
            logfile:close()
            logfile = nil
        end
    end
    emu.yield()
end