Update MAME integration to support 0.227

This commit is contained in:
Jeremy Penner 2021-01-10 14:51:27 -05:00
parent 7baf9ffeaf
commit 3d69a3a1f9

View file

@ -62,18 +62,19 @@
(self:start-cpu-monitor)
(self:continue) ; debug mame starts paused
(self:done-msg))
(fn Machine.start-cpu-monitor [self ?last-addr]
(self.monitor:eval-input
"(let [?last-addr (tonumber (io.read))]
(run-periodic-job :cpu-monitor (fn []
(var last-addr ?last-addr)
(while (let [state (-> (manager:machine) (: :debugger) (. :execution_state))
addr (-> (manager:machine) (. :devices ::maincpu :state :PC :value))]
(while (let [state manager.machine.debugger.execution_state
addr (. manager.machine.devices ::maincpu :state :PC :value)]
(not (and (= state :stop) (not= addr ?last-addr))))
(when (= :run (-> (manager:machine) (: :debugger) (. :execution_state)))
(when (= :run manager.machine.debugger.execution_state)
(set last-addr nil))
(coroutine.yield))))
(-> (manager:machine) (. :devices ::maincpu :state :PC :value)))"
(. manager.machine.devices ::maincpu :state :PC :value))"
(tostring ?last-addr)
{:value (fn [nrepl output response]
(self:on-cpu-paused (tonumber output))
@ -88,20 +89,20 @@
(set self.breakpoints {}))
(fn Machine.write [self addr bytes]
(if (> (bytes:len) 0x1000)
(do (self:write addr (bytes:sub 1 0x1000))
(do (self:write addr (bytes:sub 1 0x1000))
(self:write (+ addr 0x1000) (bytes:sub 0x1001)))
(self:eval-input
"(let [bencode (require :bencode)
{: addr : bytes} (bencode.decode (io.read))
mem (-> (manager:machine) (. :devices ::maincpu :spaces :program))]
mem (. manager.machine.devices ::maincpu :spaces :program)]
(print :writing (bytes:len) :to addr)
(for [i 1 (bytes:len)]
(mem:write_u8 (+ addr i -1) (string.byte (bytes:sub i i)))))"
(bencode.encode {: addr : bytes}))))
(fn Machine.launch [self prg]
(self:eval "(: (manager:machine) :soft_reset)")
(self:eval "(manager.machine:soft_reset)")
(self:eval (string.format "(emu.keypost \"CALL-151\\n %xG\\n\")" (prg:lookup-addr prg.start-symbol))))
(fn Machine.reboot [self] (self:eval "(: (manager:machine) :hard_reset)"))
(fn Machine.reboot [self] (self:eval "(manager.machine:hard_reset)"))
(fn Machine.coro-eval [self code]
(var result nil)
(local append-to-result #(set result (.. (or result "") $2)))
@ -110,20 +111,21 @@
(coroutine.yield)
(or result "<no result>"))
(fn Machine.dbgcmd [self cmd ?handlers]
(self:eval (.. "(-> (manager:machine) (: :debugger) (: :command \"" cmd "\"))")) ?handlers)
(print "dbgcmd??" cmd)
(self:eval (.. "(manager.machine.debugger:command \"" cmd "\")")) ?handlers)
(fn Machine.continue [self] (self:dbgcmd :go))
(fn Machine.step [self] (self:dbgcmd :s))
(fn Machine.set-bp [self addr ?action]
; todo: handle setting the same breakpoint more than once?
(tset self.breakpoints addr {:action ?action})
(self:eval (.. "(-> (manager:machine) (. :devices ::maincpu) (: :debug) (: :bpset " (tostring addr) "))")
(self:eval (.. "(-> (. manager.machine.devices ::maincpu) (: :debug) (: :bpset " (tostring addr) "))")
{:value #(tset (. self.breakpoints addr) :id (tonumber $2))}))
(fn Machine.clear-bp [self addr]
(local bpid (-?> self.breakpoints (. addr) (. :id)))
(when bpid (self:dbgcmd (.. "bpclear " (string.format "%x" bpid))))
(tset self.breakpoints addr nil))
(fn Machine.jump [self addr]
(self:eval (.. "(tset (-> (manager:machine) (. :devices ::maincpu :state :PC)) :value " (tostring addr) ")")))
(self:eval (.. "(tset (. manager.machine.devices ::maincpu :state :PC) :value " (tostring addr) ")")))
(fn Machine.stub [self org post-check-jump ...]
(org:append :debug-stub [:jmp post-check-jump] :on-hotswap ...))
(fn Machine.hotswap [self prg-old prg-new]