-- Per-instruction trace of a Namco custom's MB88xx MCU, out of MAME 0.285. -- -- Loaded with -autoboot_script; see ../../docs/mame-oracle.md for the whole -- command line, the verified numbers, and the gotchas. -- -- Environment: -- TRACE_MCU device tag of the MCU (default ":54xx:mcu"; ":51xx:mcu", -- ":50xx:mcu", ":52xx:mcu", ":53xx:mcu" on games that have -- them -- `mame -listdevices ` prints the tags) -- TRACE_FRAMES emulated frames to run before exiting (default 800) -- -- Output: one line per executed instruction appended to error.log IN THE -- CURRENT WORKING DIRECTORY (not -homepath), as -- PA PC A Y curflags totalcycles -- with PA/PC/A/Y in hex and the last two in decimal. Full program address -- is (PA << 6) | PC. curflags: bit0 ST, bit1 ZF, bit2 CF, bit3 VF, -- bit4 SF, bit5 IF. -- -- A file named FILE is written beside it holding MAME's disassembly of the -- same instructions. That is a listing of a copyrighted mask ROM: useful -- while debugging, never committed. local frames = tonumber(os.getenv("TRACE_FRAMES") or "800") local tag = os.getenv("TRACE_MCU") or ":54xx:mcu" local dbg = manager.machine.debugger if dbg == nil then error("no debugger: MAME must be started with -debug -debugger none") end local mcu = manager.machine.devices[tag] if mcu == nil then error("no device at tag " .. tag .. " (try mame -listdevices )") end -- The debugger traces the *visible* CPU, which defaults to maincpu. dbg.visible_cpu = mcu -- `noloop` stops MAME collapsing repeated loops into a summary line. -- The action's logerror is what lands in error.log; the format string is -- authoritative and extra values after the last specifier are dropped. dbg:command('trace FILE,,noloop,{logerror "%X %X %X %X %d %d\n",pa,pc,a,y,curflags,totalcycles}') dbg:command("go") -- Global on purpose: a notifier held in a local is garbage-collected and -- stops firing silently. trace_mcu_sub = emu.add_machine_frame_notifier(function () if manager.machine.screens[":screen"]:frame_number() >= frames then dbg:command("traceflush") -- or the last thousands of lines are lost manager.machine:exit() end end)