0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-01 03:52:39 +00:00
uxn/projects/examples/devices/console.tal
2023-04-17 11:27:54 -07:00

113 lines
2 KiB
Tal

( usage: uxncli console.rom arg1 arg2 arg3
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
|00
@buf
|0100 ( -> )
( set vector )
;on-argument .Console/vector DEO2
( print hello )
;hello-txt pstr
( when arguments are queued )
.Console/type DEI #00 EQU ?&no-queue
;queue-txt pstr
&no-queue
BRK
@on-argument ( -> )
.Console/type DEI ?&no-argend
;on-stdin .Console/vector DEO2
BRK
&no-argend
.Console/read DEI .buf skey ?&eval
BRK
&eval ( -> )
print-type
;yousent-txt pstr
LIT "" #18 DEO
;buf pstr
LIT "" #18 DEO #0a18 DEO
;buf sclr
.Console/type DEI #04 NEQ ?&no-close
;argend-txt pstr
;on-stdin .Console/vector DEO2
&no-close
BRK
@on-stdin ( -> )
.Console/read DEI .buf skey ?&eval
BRK
&eval ( -> )
print-type
;buf ;quit-txt scmp ?&quit
;yousaid-txt pstr
LIT "" #18 DEO
;buf pstr
LIT "" #18 DEO #0a18 DEO
;buf sclr
BRK
&quit ( buf* -> )
#010f DEO
BRK
@print-type ( -- )
[ LIT2 00 -Console/type ] DEI #01 GTH DUP ADD ;types ADD2 LDA2
!pstr
(
@|stdlib )
@pstr ( str* -- )
&while
LDAk #18 DEO
INC2 LDAk ?&while
POP2
JMP2r
@skey ( key buf -- proc ) OVR #20 LTH ?&eval #00 SWP sput #00 JMP2r &eval POP2 #01 JMP2r
@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
@sput ( chr str* -- ) scap INC2k #00 ROT ROT STA STA JMP2r
@scmp ( a* b* -- f ) STH2 &l LDAk LDAkr STHr ANDk #00 EQU ?&e NEQk ?&e POP2 INC2 INC2r !&l &e NIP2 POP2r EQU JMP2r
@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
(
@|assets )
@types
=std-txt
=arg-txt
@hello-txt "Welcome 20 "to 20 "Uxn! 0a $1
@yousaid-txt "You 20 "said: 20 $1
@yousent-txt "You 20 "sent: 20 $1
@std-txt "(std) $1
@arg-txt "(arg) $1
@quit-txt "quit $1
@argend-txt "(argend) 0a $1
@queue-txt "(queue) 0a $1