2018-06-18 08:12:52 +00:00
|
|
|
-- JS debug support for MAME using -debugger none
|
|
|
|
|
|
|
|
mamedbg = {}
|
|
|
|
|
|
|
|
local debugging = false
|
|
|
|
local stopped = false
|
|
|
|
|
|
|
|
function mamedbg.init()
|
|
|
|
cpu = manager:machine().devices[":maincpu"]
|
|
|
|
mem = cpu.spaces["program"]
|
2020-07-29 20:21:28 +00:00
|
|
|
machine = manager:machine()
|
|
|
|
debugger = machine:debugger()
|
2018-06-18 08:12:52 +00:00
|
|
|
mamedbg.reset()
|
|
|
|
emu.register_periodic(function ()
|
2020-07-29 20:21:28 +00:00
|
|
|
if debugging and not stopped then
|
|
|
|
--print(debugger.execution_state)
|
|
|
|
lastBreakState = machine.buffer_save()
|
|
|
|
emu.pause()
|
|
|
|
stopped = true
|
2018-06-18 08:12:52 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
function mamedbg.reset()
|
|
|
|
debugging = false
|
|
|
|
stopped = false
|
|
|
|
end
|
|
|
|
|
|
|
|
function mamedbg.start()
|
|
|
|
debugging = true
|
|
|
|
stopped = false
|
|
|
|
end
|
|
|
|
|
|
|
|
function mamedbg.is_stopped()
|
|
|
|
return debugging and stopped
|
|
|
|
end
|
|
|
|
|
2020-07-29 20:21:28 +00:00
|
|
|
function mamedbg.continue()
|
|
|
|
debugger:command("g")
|
|
|
|
end
|
|
|
|
|
2018-06-18 08:12:52 +00:00
|
|
|
function mamedbg.runTo(addr)
|
2020-07-29 20:21:28 +00:00
|
|
|
debugger:command(string.format("g %x", addr))
|
2018-06-18 08:12:52 +00:00
|
|
|
mamedbg.start()
|
|
|
|
end
|
|
|
|
|
|
|
|
function mamedbg.runToVsync(addr)
|
|
|
|
debugger:command("gv")
|
|
|
|
mamedbg.start()
|
|
|
|
end
|
|
|
|
|
|
|
|
function mamedbg.runUntilReturn(addr)
|
|
|
|
debugger:command("out")
|
|
|
|
mamedbg.start()
|
|
|
|
end
|
|
|
|
|
|
|
|
function mamedbg.step()
|
|
|
|
debugger:command("step")
|
|
|
|
mamedbg.start()
|
|
|
|
end
|
|
|
|
|
2020-07-29 20:21:28 +00:00
|
|
|
function string.fromhex(str)
|
|
|
|
return (str:gsub('..', function (cc)
|
|
|
|
return string.char(tonumber(cc, 16))
|
|
|
|
end))
|
|
|
|
end
|
|
|
|
|
|
|
|
function string.tohex(str)
|
|
|
|
return (str:gsub('.', function (c)
|
|
|
|
return string.format('%02X', string.byte(c))
|
|
|
|
end))
|
|
|
|
end
|
|
|
|
|
2021-07-31 14:52:25 +00:00
|
|
|
function table.tojson(t)
|
|
|
|
local result = {}
|
|
|
|
for key, value in pairs(t) do
|
|
|
|
-- prepare json key-value pairs and save them in separate table
|
|
|
|
table.insert(result, string.format("\"%s\":\"%s\"", key, value))
|
|
|
|
end
|
|
|
|
-- get simple json string
|
|
|
|
return "{" .. table.concat(result, ",") .. "}"
|
|
|
|
end
|
|
|
|
|
2018-06-18 08:12:52 +00:00
|
|
|
print("parsed Lua debugger script")
|