BizHawk
BizHawk copied to clipboard
MAME .inp importer
Pearl made a MAME+libTAS movie, which I used to create a MAME replay file (-record file.inp
/ -playback file.inp
). I ran that file in actual MAME while running a script that dumps bizhawk inputs:
fields = {
{ name = "|"},
{ tag = ":COIN", mask = 0x1, name = "Coin 1", value = ".", mnemonic = "C" },
{ tag = ":COIN", mask = 0x2, name = "Coin 2", value = ".", mnemonic = "C" },
{ tag = ":SYSTEM", mask = 0x1, name = "1 Player Start", value = ".", mnemonic = "1" },
{ tag = ":SYSTEM", mask = 0x2, name = "2 Players Start", value = ".", mnemonic = "2" },
{ tag = ":SYSTEM", mask = 0x8, name = "Service 1", value = ".", mnemonic = "s" },
{ tag = ":SYSTEM", mask = 0x4, name = "Service Mode", value = ".", mnemonic = "S" },
{ name = "|"},
{ tag = ":INPUTS", mask = 0x10, name = "P1 Button 1", value = ".", mnemonic = "1" },
{ tag = ":INPUTS", mask = 0x20, name = "P1 Button 2", value = ".", mnemonic = "2" },
{ tag = ":INPUTS", mask = 0x40, name = "P1 Button 3", value = ".", mnemonic = "3" },
{ tag = ":INPUTS", mask = 0x2, name = "P1 Down", value = ".", mnemonic = "D" },
{ tag = ":INPUTS", mask = 0x4, name = "P1 Left", value = ".", mnemonic = "L" },
{ tag = ":INPUTS", mask = 0x8, name = "P1 Right", value = ".", mnemonic = "R" },
{ tag = ":INPUTS", mask = 0x1, name = "P1 Up", value = ".", mnemonic = "U" },
{ name = "|"},
{ tag = ":INPUTS", mask = 0x1000, name = "P2 Button 1", value = ".", mnemonic = "1" },
{ tag = ":INPUTS", mask = 0x2000, name = "P2 Button 2", value = ".", mnemonic = "2" },
{ tag = ":INPUTS", mask = 0x4000, name = "P2 Button 3", value = ".", mnemonic = "3" },
{ tag = ":INPUTS", mask = 0x200, name = "P2 Down", value = ".", mnemonic = "D" },
{ tag = ":INPUTS", mask = 0x400, name = "P2 Left", value = ".", mnemonic = "L" },
{ tag = ":INPUTS", mask = 0x800, name = "P2 Right", value = ".", mnemonic = "R" },
{ tag = ":INPUTS", mask = 0x100, name = "P2 Up", value = ".", mnemonic = "U" },
{ name = "|"}
}
local function getscreen()
for k,v in pairs(manager.machine.screens) do return v end
end
local screen = getscreen()
local curframe = -1
local function log(s, name)
logfile = io.open(name, "ab")
logfile:write(s)
logfile:close()
end
function framecount()
if curframe == screen:frame_number() then return end
local line = ""
for i = 1, #fields do
local char0 = "!"
if fields[i].name ~= "|" then
local state = manager.machine.ioport.ports[fields[i].tag]:read()
char0 = (state & fields[i].mask == 0) and fields[i].mnemonic or "_"
end
line = line .. char0
end
log(line .. "\n", "log.txt")
curframe = screen:frame_number()
end
emu.register_frame_done(framecount)
And barring a single place where a frame had to be inserted, it also synced on MAMEHawk. Which made me think it'd be not too hard to come up with a Hawk side .inp importer, because MAME replays use to sync across versions quite well.
The main advantage of such an importer is crazy amounts of existing MAME replays over the internet, so one could use them as a foundation for a TAS, or any kind of project that could benefit from Hawk tools. Also easier to encode them with Hawk than with MAME, that only dumps uncompressed. All that would be a good selling point of MAMEHawk IMO.
https://github.com/mamedev/mame/blob/dd355e4d68d77fa47a07ee26170a21f3d517ee22/src/emu/ioport.cpp#L2806
Bonus points if MAME-RR replays could also be imported.
https://github.com/TASEmulators/mame-rr/blob/14cc1b04768c56d0b98b0f0f506b72b711238f31/mame-rr/src/emu/inptport.c#L4352