-- vectrex-python: MAME 0.285 headless recorder for the `vectrex` driver. -- Driven by scripts/mame_trace.py, which sets VECTREX_TRACE (0/1) and -- VECTREX_SNAP_AT (emulated seconds, 0 = none). Writes, in the cwd: -- symbols.txt device tags and the CPU's register symbols, as MAME names them -- error.log one line per instruction (the debugger's trace -> logerror) -- via.log one line per CPU access to the VIA ($D000-$D7FF), with the -- E-cycle count since reset -- Taps and the file handle are globals on purpose: locals are collected. local machine = manager.machine cpu = machine.devices[":maincpu"] space = cpu.spaces["program"] dbg = machine.debugger local sym = io.open("symbols.txt", "w") sym:write("devices:\n") for tag, dev in pairs(machine.devices) do sym:write(string.format(" %s (%s)\n", tag, dev.shortname)) end sym:write("state symbols of :maincpu:\n") for name, entry in pairs(cpu.state) do sym:write(string.format(" %s = %X\n", name, entry.value)) end sym:write("screens:\n") for tag, screen in pairs(machine.screens) do sym:write(string.format(" %s %dx%d refresh %.6f Hz\n", tag, screen.width, screen.height, screen.refresh)) end sym:write("cartridge bytes $0000-$000F:") for a = 0, 15 do sym:write(string.format(" %02X", space:read_u8(a))) end sym:write("\n") sym:close() via_log = io.open("via.log", "w") local function cycles() -- E cycles since reset: MAME clocks the MC6809 device at the 6 MHz crystal -- and the device divides by four. return machine.time:as_ticks(1500000) end via_w = space:install_write_tap(0xd000, 0xd7ff, "via_w", function(offset, data, mask) via_log:write(string.format("%d W %X %02X\n", cycles(), offset & 0xf, data)) end) via_r = space:install_read_tap(0xd000, 0xd7ff, "via_r", function(offset, data, mask) via_log:write(string.format("%d R %X %02X\n", cycles(), offset & 0xf, data)) end) -- Vector fetches ($FFF2-$FFFD: SWI3, SWI2, FIRQ, IRQ, SWI, NMI): one line per -- read, so interrupt entries are counted without an instruction trace. vec_log = io.open("vectors.log", "w") vec_r = space:install_read_tap(0xfff2, 0xfffd, "vec_r", function(offset, data, mask) vec_log:write(string.format("%d %04X\n", cycles(), offset)) end) if os.getenv("VECTREX_TRACE") == "1" then dbg.visible_cpu = cpu dbg:command('trace /dev/null,,noloop,{logerror "%04X %02X %02X %04X %04X %04X %04X %02X %02X %d\\n",pc,a,b,x,y,u,s,dp,cc,totalcycles}') end local snap_at = tonumber(os.getenv("VECTREX_SNAP_AT") or "0") local snapped = false frame_sub = emu.add_machine_frame_notifier(function() if snap_at > 0 and not snapped and machine.time:as_double() >= snap_at then snapped = true machine.video:snapshot() end end) stop_sub = emu.add_machine_stop_notifier(function() via_log:close() vec_log:close() end)