Skip to content

Instantly share code, notes, and snippets.

@sumeet
Created September 26, 2023 21:39
Show Gist options
  • Save sumeet/95d8e559e2424de5f30f91830a659c31 to your computer and use it in GitHub Desktop.
Save sumeet/95d8e559e2424de5f30f91830a659c31 to your computer and use it in GitHub Desktop.
@on-stdin ( -> )
( increment num-bytes-read )
;incoming/num-bytes-read LDA2 ( =: count )
INC2 ( =: count )
( count &> ) DUP2 ;incoming/num-bytes-read STA2
( first 4 bytes are the IP )
( count &> ) DUP2 #0001 EQU2 #00 EQU ?{ LIT "< draw-char }
( count &> ) DUP2 #0005 LTH2 #00 EQU ?{
.Console/read DEI draw-hex-char
}
( count &> ) DUP2 #0004 LTH2 #00 EQU ?{ LIT ". draw-char }
( count &> ) DUP2 #0004 EQU2 #00 EQU ?{ LIT "> draw-char }
( count &> ) DUP2 #0005 LTH2 #00 EQU ?{ BRK }
( next 2 bytes are the payload length )
( count &> ) DUP2 #0005 EQU2 #00 EQU ?{
.Console/read DEI ;incoming/payload-len STA
BRK
}
( count &> ) DUP2 #0006 EQU2 #00 EQU ?{
.Console/read DEI #0001 ;incoming/payload-len ADD2 STA
( and then draw a space )
#20 draw-char
BRK
}
( print out the char from the payload )
.Console/read DEI draw-char
( if count - 6 == payload-len then draw newline and reset )
( count -> ) #0006 SUB2 ;incoming/payload-len LDA2 EQU2 #00 EQU ?{
draw-next-line
#0000 ;incoming/num-bytes-read STA2
}
BRK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment