-- m6809-python: MAME 0.285 instruction-trace script for Williams robotron/joust. -- Run via scripts/mame_trace.sh; see docs/mame-oracle.md for what it produces. -- -- Prints the state names MAME's mc6809e exposes and the vector table to -- stdout, presses Advance once the fresh-CMOS ROM starts waiting for it (so -- that IRQs are ever enabled), and traces every instruction of :maincpu. -- The disassembly goes to .trace in the cwd; the register log goes to -- error.log in the cwd (MAME's -log output), one line per instruction: -- pc a b x y u s dp cc totalcycles frame beamy (hex, hex..., dec, dec, dec) local game = emu.romname() local cpu = manager.machine.devices[":maincpu"] local names = {} for k, _ in pairs(cpu.state) do names[#names + 1] = k end table.sort(names) print("STATE NAMES: " .. table.concat(names, " ")) local mem = cpu.spaces["program"] local vec = {} for a = 0xFFF0, 0xFFFE, 2 do vec[#vec + 1] = string.format("%04X=%04X", a, mem:read_u16(a)) end print("VECTORS: " .. table.concat(vec, " ")) -- Where each supported ROM spins on PIA1 port A bit 1 (Advance) with IRQs masked. local wait_loop = { robotron = { 0x74EB, 0x74F7 }, joust = { 0x3D69, 0x3D73 } } local range = wait_loop[game] if range then local advance = manager.machine.ioport.ports[":IN2"].fields["Advance"] local frames, pressed_at = 0, nil emu.register_frame_done(function() frames = frames + 1 local pc = cpu.state["PC"].value if pressed_at == nil and pc >= range[1] and pc <= range[2] then pressed_at = frames advance:set_value(1) print("Advance pressed at frame " .. frames) elseif pressed_at ~= nil and frames == pressed_at + 10 then advance:set_value(0) print("Advance released at frame " .. frames) end end) end local dbg = manager.machine.debugger dbg.visible_cpu = cpu dbg:command('trace ' .. game .. '.trace,,noloop,{logerror "%X %X %X %X %X %X %X %X %X %d %d %d\\n",pc,a,b,x,y,u,s,dp,cc,totalcycles,frame,beamy}') dbg:command("go")