local dbg = manager.machine.debugger local gsu_tag = nil for tag, dev in pairs(manager.machine.devices) do if dev.shortname == "superfx1" or dev.shortname == "superfx2" then gsu_tag = tag end end if gsu_tag == nil then print("NOGSU"); manager.machine:exit(); return end print("GSU " .. gsu_tag .. " " .. manager.machine.devices[gsu_tag].shortname) dbg.visible_cpu = manager.machine.devices[gsu_tag] if false then dbg:command('dasm /data/emu/gsu-python/tests/mame_traces/Doom_replay/program.dasm,0,0,1,' .. gsu_tag) for _, line in ipairs(dbg.consolelog) do print("CON " .. line) end manager.machine:exit() return end local function watch(start, length, kind, cond, tag) dbg:command('wpset ' .. start .. ':maincpu,' .. length .. ',' .. kind .. ',' .. cond .. ',{logerror "' .. tag .. ' %X %X %d\\n",wpaddr,wpdata,totalcycles; g}') end -- The GSU's registers and cache RAM in the banks the S-CPU uses (all of -- 00-3F/80-BF with --all-banks: slower, every ROM read there meets the tap). for _, bank in ipairs({"00", "80"}) do watch(bank .. "3000", "500", "r", "1", "R") watch(bank .. "3000", "500", "w", "1", "W") end if true then watch("013000", "3F0500", "r", "(wpaddr & ffff) >= 3000 && (wpaddr & ffff) < 3500 && (wpaddr & ff0000) != 0", "R") watch("013000", "3F0500", "w", "(wpaddr & ffff) >= 3000 && (wpaddr & ffff) < 3500 && (wpaddr & ff0000) != 0", "W") watch("813000", "3F0500", "r", "(wpaddr & ffff) >= 3000 && (wpaddr & ffff) < 3500 && (wpaddr & ff0000) != 800000", "R") watch("813000", "3F0500", "w", "(wpaddr & ffff) >= 3000 && (wpaddr & ffff) < 3500 && (wpaddr & ff0000) != 800000", "W") end if true then watch("700000", "20000", "w", "1", "W") watch("006000", "400000", "w", "(wpaddr & e000) == 6000", "W") watch("806000", "400000", "w", "(wpaddr & e000) == 6000", "W") end if false then watch("002116", "3", "w", "1", "V") end local function start() dbg.visible_cpu = manager.machine.devices[gsu_tag] dbg:command('trace /dev/null,' .. gsu_tag .. ',noloop,{' .. 'logerror "G %X %X %X %X %X %X %X %X %X %X %X %X %X %d\\n",pc,r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,totalcycles; ' .. 'logerror "H %X %X %X %X %X %X %X %X %X %X %X %X %d\\n",r12,r13,r14,r15,sfr,pbr,rombr,rambr,cbr,colr,por,ramaddr,totalcycles}') for _, line in ipairs(dbg.consolelog) do print("CON " .. line) end end -- --arm-on-start: begin at the S-CPU's first $301F write (a GSU start) at or after the -- start frame, so the trace opens with the GSU idle, and dump the Game Pak RAM (the GSU's -- 70:0000-71:FFFF) at that moment for the replay (rung 4). A Lua write tap sees the write. local armed_taps = {} local armed_frame = nil local screen = manager.machine.screens[":screen"] local function arm() local space = manager.machine.devices[":maincpu"].spaces["program"] local gsu_space = manager.machine.devices[gsu_tag].spaces["program"] local function fire(offset, data, mask) if #armed_taps == 0 then return data end local out = io.open("/data/emu/gsu-python/tests/mame_traces/Doom_replay/ram_at_start.bin", "wb") local chunk = {} for a = 0x700000, 0x71FFFF do chunk[#chunk + 1] = string.char(gsu_space:read_u8(a)) if #chunk == 4096 then out:write(table.concat(chunk)); chunk = {} end end out:close() for _, tap in ipairs(armed_taps) do tap:remove() end armed_taps = {} print("ARMED " .. screen:frame_number()) armed_frame = screen:frame_number() start() return data end armed_taps[#armed_taps + 1] = space:install_write_tap(0x00301F, 0x00301F, "arm00", fire) armed_taps[#armed_taps + 1] = space:install_write_tap(0x80301F, 0x80301F, "arm80", fire) end local started = false local function begin() if true then arm() else start() end end if not started and 1200 == 0 then begin(); started = true end for _, line in ipairs(dbg.consolelog) do print("CON " .. line) end dbg:command("go") -- Button presses: {frame, field name, frames held}, matched against every input field's name. local presses = {} local fields = {} for ptag, port in pairs(manager.machine.ioport.ports) do for fname, fld in pairs(port.fields) do fields[fname] = fld if false then print("INPUT " .. ptag .. " | " .. fname) end end end for _, p in ipairs(presses) do if fields[p[2]] == nil then print("NOINPUT " .. p[2]) end end sub = emu.add_machine_frame_notifier(function() local frame = screen:frame_number() for _, p in ipairs(presses) do local fld = fields[p[2]] if fld ~= nil then if frame == p[1] then fld:set_value(1) end if frame == p[1] + p[3] then fld:clear_value() end end end if not started and frame >= 1200 then started = true; begin() end if 0 > 0 and frame % 0 == 0 then manager.machine.video:snapshot() end -- With --arm-on-start the window is --frames long from the start that armed it; the -- search for one gives up 600 frames after --start-frame. if true then if armed_frame ~= nil and frame >= armed_frame + 2 then manager.machine:exit() end if armed_frame == nil and frame >= 1200 + 600 then manager.machine:exit() end elseif frame >= 1202 then manager.machine:exit() end end)