Improved console device examples

This commit is contained in:
Devine Lu Linvega 2023-07-16 10:04:40 -07:00
parent 7f35e1863a
commit 8508fd3dec
2 changed files with 97 additions and 81 deletions

View File

@ -0,0 +1,16 @@
( usage: uxncli console.read.rom )
|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
|0100
@on-reset ( -> )
;on-console .Console/vector DEO2
( type something in the console )
BRK
@on-console ( -> )
.Console/read DEI .Console/write DEO
#0a .Console/write DEO
BRK

View File

@ -1,113 +1,113 @@
( usage: uxncli console.rom arg1 arg2 arg3 ( usage: uxncli console.rom arg1 arg2 arg3 Prints Hello Uxn!, and listens for incoming stdin events on enter. )
Prints Hello Uxn!, and listens for incoming stdin events on enter. )
|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1 |10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
|00 |0000
@buf @buf
|0100 ( -> ) |0100
( set vector ) @on-reset ( -> )
;on-argument .Console/vector DEO2 ;on-argument .Console/vector DEO2
( print hello ) ;dict/hello <print-str>
;hello-txt pstr .Console/type DEI ?&has-arg
( when arguments are queued ) BRK
.Console/type DEI #00 EQU ?&no-queue &has-arg ( -> )
;queue-txt pstr ;dict/queue <print-str>
&no-queue BRK
BRK
@on-argument ( -> ) @on-argument ( -> )
.Console/type DEI ?&>no-argend
.Console/type DEI ?&no-argend
;on-stdin .Console/vector DEO2 ;on-stdin .Console/vector DEO2
BRK BRK &>no-argend
&no-argend
.Console/read DEI .buf skey ?&eval .Console/read DEI .buf skey ?&eval
BRK
BRK &eval ( -> )
<print-type>
&eval ( -> ) ;dict/yousent <print-str>
print-type
;yousent-txt pstr
LIT "" #18 DEO LIT "" #18 DEO
;buf pstr ;buf <print-str>
LIT "" #18 DEO #0a18 DEO LIT "" #18 DEO
;buf sclr #0a18 DEO
;buf sclr .Console/type DEI #04 NEQ ?&>no-close
.Console/type DEI #04 NEQ ?&no-close ;dict/argend <print-str>
;argend-txt pstr ;on-stdin .Console/vector DEO2 &>no-close
;on-stdin .Console/vector DEO2 BRK
&no-close
BRK
@on-stdin ( -> ) @on-stdin ( -> )
.Console/read DEI .buf skey ?&eval .Console/read DEI .buf skey ?&eval
BRK
BRK &eval ( -> )
<print-type>
&eval ( -> ) ;buf ;dict/quit scmp ?&quit
;dict/yousaid <print-str>
print-type
;buf ;quit-txt scmp ?&quit
;yousaid-txt pstr
LIT "" #18 DEO LIT "" #18 DEO
;buf pstr ;buf <print-str>
LIT "" #18 DEO #0a18 DEO LIT "" #18 DEO
;buf sclr #0a18 DEO
;buf sclr BRK
BRK &quit ( buf* -> )
&quit ( buf* -> )
#010f DEO #010f DEO
BRK
BRK @<print-type> ( -- )
[ LIT2 00 -Console/type ] DEI #01 GTH DUP ADD ;types ADD2 LDA2 !<print-str>
@print-type ( -- )
[ LIT2 00 -Console/type ] DEI #01 GTH DUP ADD ;types ADD2 LDA2
!pstr
( (
@|stdlib ) @|stdlib )
@pstr ( str* -- ) @<print-str> ( str* -- )
!&
&while &while ( -- )
LDAk #18 DEO LDAk #18 DEO
INC2 LDAk ?&while INC2 & LDAk ?&while
POP2 POP2 JMP2r
JMP2r @skey ( key buf -- proc )
OVR #20 LTH ?&eval
#00 SWP sput #00 JMP2r
&eval POP2 #01 JMP2r
@skey ( key buf -- proc ) OVR #20 LTH ?&eval #00 SWP sput #00 JMP2r &eval POP2 #01 JMP2r @sclr ( str* -- )
@sclr ( str* -- ) LDAk ?&w POP2 JMP2r &w STH2k #00 STH2r STA INC2 LDAk ?&w POP2 JMP2r !&
@scap ( str* -- end* ) LDAk ?&w JMP2r &w INC2 LDAk ?&w JMP2r &while ( -- )
@sput ( chr str* -- ) scap INC2k #00 ROT ROT STA STA JMP2r STH2k #00 STH2r STA
@scmp ( a* b* -- f ) STH2 &l LDAk LDAkr STHr ANDk #00 EQU ?&e NEQk ?&e POP2 INC2 INC2r !&l &e NIP2 POP2r EQU JMP2r INC2 & LDAk ?&while
@phex ( short* -- ) SWP phex/b &b ( byte -- ) DUP #04 SFT phex/c &c ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO JMP2r POP2 JMP2r
@scap ( str* -- end* )
!&
&while ( -- )
INC2 & LDAk ?&while
JMP2r
@sput ( chr str* -- )
scap INC2k #00 ROT ROT STA
STA
JMP2r
@scmp ( a* b* -- f )
STH2
&loop ( -- )
LDAk LDAkr STHr ANDk #00 EQU ?&e
NEQk ?&e
POP2 INC2 INC2r !&loop
&e NIP2 POP2r EQU JMP2r
( (
@|assets ) @|assets )
@types @types
=std-txt =dict/std =dict/arg
=arg-txt
@hello-txt "Welcome 20 "to 20 "Uxn! 0a $1 @dict ( )
@yousaid-txt "You 20 "said: 20 $1 &hello "Welcome 20 "to 20 "Uxn! 0a $1
@yousent-txt "You 20 "sent: 20 $1 &yousaid "You 20 "said: 20 $1
@std-txt "(std) $1 &yousent "You 20 "sent: 20 $1
@arg-txt "(arg) $1 &std "(std) $1
@quit-txt "quit $1 &arg "(arg) $1
@argend-txt "(argend) 0a $1 &quit "quit $1
@queue-txt "(queue) 0a $1 &argend "(argend) 0a $1
&queue "(queue) 0a $1