-- harness: reads cmds from file in env CMDS. lines: [args] -- cmds: press , snap , save , load , dump , exit, poke local path=os.getenv("CMDS") local cmds={} for l in io.lines(path) do if not l:match("^%s*#") and l:match("%S") then local t={} for w in l:gmatch("%S+") do t[#t+1]=w end t[1]=tonumber(t[1]); cmds[#cmds+1]=t end end local f=0; local i=1; local held={} local ports=manager.machine.ioport.ports local function field(pad,btn) local p=ports[":ctrl"..pad..":mdpad:PAD"] or ports[":ctrl"..pad..":md6button:PAD"]; return p.fields["P"..pad.." "..btn] end local mem=manager.machine.devices[":maincpu"].spaces["program"] local out=io.open(os.getenv("OUT") or "out.txt","w") emu.register_frame_done(function() f=f+1 for k,v in pairs(held) do if f>=v.until_ then v.fld:clear_value(); held[k]=nil end end while i<=#cmds and cmds[i][1]<=f do local c=cmds[i]; i=i+1 if c[2]=="press" then local fl=field(c[3],c[4]); fl:set_value(1); held[c[3]..c[4]]={fld=fl,until_=f+tonumber(c[5])} elseif c[2]=="snap" then manager.machine.video:snapshot() elseif c[2]=="save" then manager.machine:save(c[3]) elseif c[2]=="load" then manager.machine:load(c[3]) elseif c[2]=="dump" then local a=tonumber(c[3],16); local s={} for j=0,tonumber(c[4])-1 do s[#s+1]=string.format("%02x",mem:read_u8(a+j)) end out:write(f.." "..(c[5] or c[3]).." "..table.concat(s," ").."\n"); out:flush() elseif c[2]=="poke" then mem:write_u8(tonumber(c[3],16),tonumber(c[4],16)) elseif c[2]=="exit" then out:close(); manager.machine:exit() end end end) local gk=os.getenv("GK"); if gk and gk~="" then dofile(gk) end