-- Execution coverage: every executed PC with M/X flag state and hit count. Env: -- TBG_LIB, TBG_LOAD, TBG_END, TBG_OUT (file), TBG_PLAN local L = dofile(os.getenv("TBG_LIB")) local out = os.getenv("TBG_OUT") local last = tonumber(os.getenv("TBG_END") or "600") local plan = L.inputPlan(os.getenv("TBG_PLAN")) local cov, frame = {}, 0 if os.getenv("TBG_LOAD") then L.load(os.getenv("TBG_LOAD")) end emu.addMemoryCallback(function(addr) local s = emu.getState() local key = (addr << 4) | ((s["cpu.ps"] >> 4) & 3) | (s["cpu.emulationMode"] and 4 or 0) cov[key] = (cov[key] or 0) + 1 end, emu.callbackType.exec, 0x000000, 0xFFFFFF, emu.cpuType.snes) emu.addEventCallback(function() local pressed = {[0] = {}, [1] = {}} for _, e in ipairs(plan) do if frame >= e.f and frame < e.f + e.hold then for b in e.b:gmatch("[^+]+") do pressed[e.port][b] = true end end end emu.setInput(pressed[0], 0); emu.setInput(pressed[1], 1) end, emu.eventType.inputPolled) emu.addEventCallback(function() frame = frame + 1 if frame >= last then local h = io.open(out, "w") for k, n in pairs(cov) do local f = k & 15 h:write(string.format("%06X m%d x%d e%d %d\n", k >> 4, (f >> 1) & 1, f & 1, (f >> 2) & 1, n)) end h:close() emu.stop(0) end end, emu.eventType.endFrame)