local machine = manager.machine local dbg = machine.debugger local main = machine.devices[":maincpu"] local audio = machine.devices[":audiocpu"] local screen = machine.screens[":screen"] local facts = io.open("facts.txt", "w") facts:write("machine " .. machine.system.name .. "\n") for tag, device in pairs(machine.devices) do local clock = "" pcall(function() clock = tostring(device.clock) end) facts:write("device " .. tag .. " | " .. device.shortname .. " | " .. device.name .. " | clock " .. clock .. "\n") end facts:write(string.format("screen %dx%d refresh %.6f Hz (attoseconds %s)\n", screen.width, screen.height, screen.refresh, tostring(screen.refresh_attoseconds))) for _, cpu in ipairs({main, audio}) do local names = {} for name, _ in pairs(cpu.state) do names[#names + 1] = name end table.sort(names) facts:write("symbols " .. cpu.tag .. ": " .. table.concat(names, " ") .. "\n") end facts:flush() -- Per-instruction traces. An unknown symbol drops the whole command silently, -- so the symbol lists above are written first. dbg:command('trace cpu.trace,maincpu,noloop,{logerror "M %06X %04X %08X %08X %08X %08X %d %d %d\\n",pc,sr,d0,d1,a0,sp,totalcycles,beamy,beamx}') dbg.visible_cpu = audio -- trace expressions are parsed against the visible CPU's symbols dbg:command('trace z80.trace,audiocpu,noloop,{logerror "Z %04X %04X %04X %04X %04X %d\\n",pc,af,bc,hl,sp,totalcycles}') -- Register and sound-latch writes for the whole run. The taps are globals: -- a collected tap stops firing. dbg.visible_cpu = main local program = main.spaces["program"] local regs = io.open("regs.log", "w") -- emu.print_error goes to the console, not to error.log tap_regs = program:install_write_tap(0x800100, 0x80017f, "cps_regs", function(offset, data, mask) regs:write(string.format("W %06X %04X %04X f%d y%d x%d\n", offset, data, mask, screen:frame_number(), screen:vpos(), screen:hpos())) end) tap_sound = program:install_write_tap(0x800180, 0x80018f, "cps_sound", function(offset, data, mask) regs:write(string.format("S %06X %04X %04X f%d y%d x%d\n", offset, data, mask, screen:frame_number(), screen:vpos(), screen:hpos())) end) local trace_frames = 2 local last = 180 frame_sub = emu.add_machine_frame_notifier(function() local frame = screen:frame_number() if frame == trace_frames then dbg:command('trace off,maincpu') dbg:command('trace off,audiocpu') end if frame == last then screen:snapshot("final.png") facts:write(string.format("frames %d emulated_time %s\n", frame, tostring(machine.time))) facts:close() regs:close() machine:exit() end end)