honeylisp/ssc/iigs/u2-debug.fnl
Jeremy Penner ccfb52aeaa iigs: untested uthernet-ii debug stub
65816: support 8-bit immediate mode
repl: add re-run and clear buttons
ssc: fix returning false from an else clause
     add byteswap, byte reads / writes
     start stdlib with memcpy
2021-09-23 22:28:48 -04:00

86 lines
2.5 KiB
Fennel

(import-macros {:sss ! : compile} :ssc.macros)
(local {: cmd : response} (require :link.udpdebug))
(local Ssc (require :ssc))
(local ssc (Ssc))
(compile ssc
(require ssc.iigs.bootstub)
(require ssc.stdlib)
(require ssc.iigs.uthernet2)
(global word u2-debug-server-connected 0)
(fn u2-init-debug-server ()
(u2-reset)
(u2-udp-server-start 6502)
(set! u2-debug-server-connected 0))
(asm u2-debug-buffer (bytes [(string.rep "\x00" 1500)]))
(fn u2-debug-server-poll ()) ; predefine, will be overwritten. wastes a byte (rts).
(fn u2-debug-server-cmd-write (msgid)
(let (addr (long-at (ref u2-debug-buffer))
size (word-at (+ (ref u2-debug-buffer) 4)))
(memcpy (+ (far-ref u2-debug-buffer) 6) addr size)
(u2-tx-begin)
(u2-write msgid)
(u2-write [response.ack])
(u2-tx-complete 2)))
(fn u2-debug-server-cmd-read (msgid)
(let (addr (long-at (ref u2-debug-buffer))
size (word-at (+ (ref u2-debug-buffer) 4)))
(u2-tx-begin)
(u2-write msgid)
(u2-write [response.data])
(u2-write-farbuf addr size)
(u2-tx-complete (+ size 2))))
(fn u2-debug-server-cmd-jmp () (asm (jmp ((u2-debug-buffer)))))
(global word u2-debug-server-paused 0)
(fn u2-debug-server-cmd-pause (msgid)
(set! u2-debug-server-paused (not u2-debug-server-paused))
(u2-tx-begin)
(u2-write msgid)
(u2-write [response.ack])
(u2-write u2-debug-server-paused)
(u2-tx-complete 3)
(while u2-debug-server-paused
(u2-debug-server-poll)))
(fn u2-debug-server-cmd-ping (msgid)
(u2-tx-begin)
(u2-write msgid)
(u2-write [response.ack])
(u2-tx-complete 2))
(fn u2-debug-server-cmd (msgid cmd)
(if (= cmd [cmd.write]) (u2-debug-server-cmd-write msgid)
(= cmd [cmd.read]) (u2-debug-server-cmd-read msgid)
(= cmd [cmd.jmp]) (u2-debug-server-cmd-jmp)
(= cmd [cmd.pause]) (u2-debug-server-cmd-pause msgid)
(= cmd [cmd.ping]) (u2-debug-server-cmd-ping msgid)))
(fn u2-debug-server-poll ()
(let (size (u2-rx-begin))
(when (> size 0)
(let (msgid (u2-read)
cmd (u2-read))
(u2-read-buf (ref u2-debug-buffer) (- size 2))
(u2-rx-complete)
(when (not u2-debug-server-connected)
(u2-set-tx-dest u2-udp-recv-ip 6502)
(set! u2-debug-server-connected true))
(u2-debug-server-cmd msgid cmd)))))
(fn main ()
(u2-init-debug-server)
(while true (u2-debug-server-poll)))
)
ssc