-- Per-instruction trace of Mortal Kombat's TMS34010 (Midway T-unit) from MAME 0.285. -- Used by scripts/mame/trace_mk.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; logerror output lands in error.log, which MAME opens in the -- process's CURRENT WORKING DIRECTORY (not beside -homepath -- verified). -- -- Every address printed here is a TMS34010 BIT address: byte = bit >> 3, -- 16-bit word index = bit >> 4. MAME's program space for this CPU reports -- data_width 16 and shift 3, i.e. it is addressed in bits. -- -- MAME's exposed state names for tms34010: PC GENPC CURPC SP ST CURFLAGS -- A0..A14 B0..B14. There is no state entry for the I/O register file at -- 0xC0000000; read those from the program space instead. local start_frame = tonumber(os.getenv("TRACE_START_FRAME") or "0") local stop_frame = tonumber(os.getenv("TRACE_STOP_FRAME") or "2") local disasm_file = os.getenv("TRACE_DISASM_FILE") or "trace_disasm.txt" local width = os.getenv("TRACE_REGS") or "full" -- "full" | "short" local cputag = os.getenv("TRACE_CPU") or ":maincpu" local dbg = manager.machine.debugger dbg.visible_cpu = manager.machine.devices[cputag] local fmt, regs if width == "short" then fmt = '%08X ST=%08X SP=%08X A0=%08X A1=%08X B0=%08X B1=%08X\\n' regs = 'curpc,st,sp,a0,a1,b0,b1' else local parts = { '%08X ST=%08X SP=%08X' } local names = { 'curpc', 'st', 'sp' } for i = 0, 14 do parts[#parts+1] = 'A' .. i .. '=%08X'; names[#names+1] = 'a' .. i end for i = 0, 14 do parts[#parts+1] = 'B' .. i .. '=%08X'; names[#names+1] = 'b' .. i end fmt = table.concat(parts, ' ') .. '\\n' regs = table.concat(names, ',') end 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)