-- Per-instruction trace of R-Type's NEC V30 (Irem M72) from MAME 0.285. -- Used by scripts/mame/trace_rtype.sh; see docs/mame-oracle.md. -- -- The `trace` debugger command writes one disassembled line per instruction -- to the named file and evaluates the {logerror ...} action before each -- instruction, which lands in error.log under -homepath when -log is given. -- Register names are MAME's NEC names: PS:PC is CS:IP, AW/BW/CW/DW are -- AX/BX/CX/DX, IX/IY are SI/DI, DS0/DS1 are DS/ES, PSW is FLAGS. `curpc` -- is the 20-bit linear address (PS << 4) + PC; `pc` alone is the offset. local start_frame = tonumber(os.getenv("TRACE_START_FRAME") or "0") local stop_frame = tonumber(os.getenv("TRACE_STOP_FRAME") or "60") local disasm_file = os.getenv("TRACE_DISASM_FILE") or "trace_disasm.txt" local dbg = manager.machine.debugger dbg.visible_cpu = manager.machine.devices[":maincpu"] local fmt = '%05X %04X:%04X AW=%04X BW=%04X CW=%04X DW=%04X SP=%04X BP=%04X' .. ' IX=%04X IY=%04X DS0=%04X DS1=%04X SS=%04X PSW=%04X\\n' local regs = 'curpc,ps,pc,aw,bw,cw,dw,sp,bp,ix,iy,ds0,ds1,ss,psw' local trace_cmd = 'trace ' .. disasm_file .. ',,noloop,{logerror "' .. fmt .. '",' .. regs .. '}' if start_frame == 0 then dbg:command(trace_cmd) end dbg:command("go") local frames = 0 emu.register_frame_done(function() frames = frames + 1 if frames == start_frame then dbg:command(trace_cmd) end if frames >= stop_frame then dbg:command("trace off") manager.machine:exit() end end)