User File #638406822164178639

Upload All User Files

#638406822164178639 - script for use with FCEUX to dump to the .r08 format

r08-fceux.lua
29 downloads
Uploaded 1/12/2024 6:50 PM by feos (see all 184)

--local inspect = require("inspect")
local char = string.char

local movie_loaded = false
local handle = nil

local frame = 0

local playerKeys = {
    {"right", "left", "down", "up", "start", "select", "B", "A"},
    {"right", "left", "down", "up", "start", "select", "B", "A"}
}

function writeFrame()
    local input = {}
    input[1] = joypad.get(1)
    input[2] = joypad.get(2)
    
    local chunk = {0, 0}
    
    for i = 1, 2 do
        for k = 7, 0, -1 do
            local key = playerKeys[i][k + 1]
            if input[i][key] == true then
                chunk[i] = bit.bor(chunk[i], bit.lshift(1, k))
            end
        end
        handle:write(char(chunk[i]))
    end
end

emu.speedmode("turbo")

while (true) do
    if movie.active() == true then
        if movie_loaded == false then
            movie.playbeginning()
            
            local movie_filename = movie.getname()
            local output_filename = string.sub(movie_filename, 0, #movie_filename - 4) .. ".r08"
            
            print("Writing to " .. output_filename .. "...")
            
            handle = io.open(output_filename, "wb+")
            
            if (handle == nil) then
                print("Error opening dump file!")
            else
                movie_loaded = true
                emu.unpause()
            end
        end
        
        
        if movie.framecount() > 0 and movie.mode() ~= "finished" and emu.lagged() == false then
            writeFrame();
            frame = frame + 1;
        end
        
        
    end
    
    if movie_loaded == true and movie.mode() == "finished" then
        handle:close()
        
        print("DONE Frames written: "..tostring(frame))
        movie_loaded = false
        frame = 0
        movie.stop()
        emu.pause()
    end
    
    emu.frameadvance();
end