1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-12 10:07:00 +00:00
8bitworkshop/mame/debugger.lua

85 lines
1.7 KiB
Lua
Raw Normal View History

-- 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()
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
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
function mamedbg.runTo(addr)
2020-07-29 20:21:28 +00:00
debugger:command(string.format("g %x", addr))
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
print("parsed Lua debugger script")