From 9ec998e128a8a975d647b4d49164a41191873ef3 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Tue, 28 Sep 2021 20:19:13 -0400 Subject: [PATCH] IT WORKS --- UdpDebug.dsk | Bin 143360 -> 143360 bytes asm/65816.fnl | 4 ++-- link/udpdebug.fnl | 20 +++++++++++--------- ssc/iigs/u2-debug.fnl | 9 +++++---- ssc/iigs/uthernet2.fnl | 38 ++++++++++++++++++++------------------ 5 files changed, 38 insertions(+), 33 deletions(-) diff --git a/UdpDebug.dsk b/UdpDebug.dsk index ed231ed9ee3c91e12a494918a7c0d41124f6a0ae..e43f4287ae924abeb1bc1f9e7d674103869a55b9 100644 GIT binary patch delta 1073 zcmZ`&O=uHQ5PrLxG${?#N~vk3c6KAuO`#U?put013qGk(s?eyHZmsDLrL8onhj+;m zh#q7wT`$FpWU25d3rhSs=%EOTwpHrALfeCvpok~E7-wIyk@~YNyzDnK-^}~IiMbOt zcft=phoynym++xea(kB@>eEgGK7>*yL<yRg$5X5A< zLTDiZUYcPW$*A4ecdIDLvQ(7M{%kn^vWF{Vug7}4hQB0IvYxE*PeA!WLg6Ve##<^F z@sgfllF^uep&O~W)OASDkI$qsyiH^*4Rs%4G{vE7VI8t;xC^$NOxxl{?Lm3(`WyTgV({q!MPA%L_E%0}mCsqW$ z1D|N6(62IH7!D3l7||G-R4!W^nxjyBp(&0CW2-ZTi0rvuXb=Z{)G)0kQHW@_<0Mxq z8}`7+iwk~pE~7h38Z#UPQ@4bg^~Awh_d1z*5m9L$I;b=A45D%s4HCF(Hzk`B_b||m zfj~775+vVrW<<`-XJ9s!PLEBd)H{Q#AZzGJZLq98nmioA1#zUxo-jL`Y|-mtxbKMs z6?Vav>TYPY0i(oyqf*y%bfVRMbtRry)SUY2zVh1U`gcQd3^yF3E^_j^Sado-@`3w= zJPJ@)wDrqJvg^1K*uSk!XyN5=*To3>;x6m8u0eu&iZ!v8b-<3wUmY>s$CQe$6@to^ p{F|7=JUf%dYH#+rM=)$TyRTvj_3eK_o~?@Ku6Y(5i)w+UmMxg^I+Z*kxf) zF<{QkL&OdyPZ>~_@Um`JhukEni%?$7Ll9fxwM)}Cv$JbL!@!&Q-uM09@ArMbm)!Lx zcfBh=y&RwY<*jMqcfy*dUDAfzpUrh2KWkvZjv|5|V@g>N71fs;457Vdb#3EKv%+fa zNS5PyF3Vs1~gNWsjvn+f@Q3r$^(D0Sr-}+6dVx?2<;0g z0j1gyYb=$cHiGYpl<1rq7j@2t92N=l0?Tn=X(UF)qB<%XF<4^O((>JlXi@;)iUVTA z#n6Pc4{97%Z3nFU_CdP4NN^{ny2n`s`&VK04iBZw!-Am)@r1MCB>G6AG zcq%$M6P;vpPNw$lYIWchW}_zw{*5UVtFw~UbFNMc@HLqpcZaE{pY!UMJbRBH@yV5CJOg7x=qYZ6)iI}9t?CwvZ@s0gG3Sr5MWzUXxxR; zuIC7?x(N13dX-~-R`D^YEWP+C_>bybZEXeV(Uyc@SjK={;qFF2!M3A1AX|t+8L@J) zAbn3R-7zMVXq6BS(>4{mTx;qLHUV=5dS7l(srQSGG (length data) 1400) (do (self:write addr (data:sub 1 1400)) (self:write (+ addr 1400) (data:sub 1401))) + (let [coro (coroutine.running)] + (self:send self.cmd.write (.. (int32-to-bytes addr) + (int16-to-bytes (length data)) + data) + #(coroutine.resume coro $3)) + (coroutine.yield)))) :launch (fn [self prg] (self:jump (prg:lookup-addr prg.start-symbol))) } diff --git a/ssc/iigs/u2-debug.fnl b/ssc/iigs/u2-debug.fnl index 07813a3..9e5943e 100644 --- a/ssc/iigs/u2-debug.fnl +++ b/ssc/iigs/u2-debug.fnl @@ -23,7 +23,6 @@ (require ssc.stdlib) (require ssc.iigs.toolbox) - (require ssc.iigs.uthernet2) (macro out [#(! (WriteLine (far-ref (pstr [$2]))))]) @@ -31,7 +30,9 @@ (fn printnum (num) (long! (ref hexbuf) (HexIt num)) (WriteCString (far-ref hexbuf))) - + + (require ssc.iigs.uthernet2) + (global word u2-debug-server-connected 0) (fn u2-init-debug-server () (out "Starting server") @@ -89,10 +90,10 @@ (far-fn u2-debug-server-poll () (let (size (u2-rx-begin)) - (when (> size 0) + (when size (let (msgid (u2-read) cmd (u2-read)) - (printnum msgid) (out "Got message!") + (printnum msgid) (printnum cmd) (out "Got message!") (u2-read-buf (ref u2-debug-buffer) (- size 2)) (u2-rx-complete) (when (not u2-debug-server-connected) diff --git a/ssc/iigs/uthernet2.fnl b/ssc/iigs/uthernet2.fnl index f6450ee..5787862 100644 --- a/ssc/iigs/uthernet2.fnl +++ b/ssc/iigs/uthernet2.fnl @@ -15,9 +15,9 @@ U2-ADDR-LO (reg 0xc086) U2-DATA (reg 0xc087)] #(compile $1 - (form u2-addr! [#($1:expr-poly [:word! [:ref U2-ADDR-HI] [:byteswap $2]])]) - (form u2-read [#($1:expr-poly [:byte-at [:ref U2-DATA]])]) - (form u2-write [#($1:expr-poly [:byte! [:ref U2-DATA] $2])]) + (macro u2-addr! [#[:word! [:ref U2-ADDR-HI] [:byteswap $2]]]) + (macro u2-read [#[:byte-at [:ref U2-DATA]]]) + (macro u2-write [#[:byte! [:ref U2-DATA] $2]]) (fn u2-read-word () (let (hi (u2-read) lo (u2-read)) @@ -89,39 +89,41 @@ (u2-addr! 0x0400) (u2-write 0x42) ; UDP, filter by MAC (u2-addr! 0x0404) ; set port - (u2-write (& (byteswap port) 0xff)) ; high byte first - (u2-write (& port 0xff)) + (u2-write-word port) (u2-addr! 0x0401) - (u2-write 0x01)) ; open socket + (u2-write 0x01) ; open socket + (u2-addr! 0x0403) + (printnum (u2-read)) (out ": Opened socket")) (fn u2-data-ready () (u2-addr! 0x0426) (u2-read-word)) + (define u2-buf-mask 0x1fff) (global long u2-udp-recv-ip 0) (global word u2-udp-recv-port 0) (global word u2-udp-recv-size 0) (global word u2-udp-recv-rxrd 0) - (fn u2-read-rxtx-ptr (base) (+ (& (u2-read-word) 0x1fff) base)) + (fn u2-rx-complete () + (u2-addr! 0x0428) + (u2-write-word (+ u2-udp-recv-rxrd 8 u2-udp-recv-size)) + (u2-addr! 0x0401) + (u2-write 0x40)) ; RECV command + + (fn u2-rxtx-ptr (rd base) (+ (& rd u2-buf-mask) base)) (fn u2-rx-begin () (if (u2-data-ready) (do (u2-addr! 0x0428) - (let (rxrd (u2-read-rxtx-ptr 0x4000)) - (set! u2-udp-recv-rxrd rxrd) + (set! u2-udp-recv-rxrd (u2-read-word)) + (let (rxrd (u2-rxtx-ptr u2-udp-recv-rxrd 0x6000)) (u2-addr! rxrd) (u2-read-buf (ref u2-udp-recv-ip) 8) ; convert from network order (set! u2-udp-recv-port (byteswap u2-udp-recv-port)) (set! u2-udp-recv-size (byteswap u2-udp-recv-size)) - (- u2-udp-recv-size 8))) + u2-udp-recv-size)) 0)) - (fn u2-rx-complete () - (u2-addr! 0x0428) - (u2-addr! (+ u2-udp-recv-rxrd u2-udp-recv-size)) - (u2-addr! 0x0401) - (u2-write 0x40)) ; RECV command - (fn u2-set-tx-dest ((long ip) port) (u2-addr! 0x040c) (u2-write-word (byteswap (loword ip))) ; ip is always network order @@ -130,12 +132,12 @@ (fn u2-tx-begin () (u2-addr! 0x0424) - (let (txwr (u2-read-rxtx-ptr 0x6000)) + (let (txwr (u2-rxtx-ptr (u2-read-word) 0x4000)) (u2-addr! txwr))) (fn u2-tx-complete (size) (u2-addr! 0x0424) - (let (txwr (u2-read-rxtx-ptr 0x6000)) + (let (txwr (u2-rxtx-ptr (u2-read-word) 0x4000)) (u2-addr! 0x0424) (u2-write-word (+ txwr size)) (u2-addr! 0x0401)