0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-12-02 02:27:25 +00:00
uxn/projects/examples/devices/console.tal

109 lines
1.8 KiB
Tal
Raw Normal View History

2023-07-16 17:04:40 +00:00
( usage: uxncli console.rom arg1 arg2 arg3 Prints Hello Uxn!, and listens for incoming stdin events on enter. )
2021-02-20 23:00:34 +00:00
|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
2023-07-16 17:04:40 +00:00
|0000
2023-04-05 23:50:06 +00:00
@buf
2023-07-16 17:04:40 +00:00
|0100
2021-02-20 23:00:34 +00:00
2023-07-16 17:04:40 +00:00
@on-reset ( -> )
;on-argument .Console/vector DEO2
2023-12-05 19:55:46 +00:00
.Console/type DEI ?{ ;on-stdin .Console/vector DEO2 }
2023-07-16 17:04:40 +00:00
;dict/hello <print-str>
BRK
2021-02-20 23:00:34 +00:00
@on-argument ( -> )
2023-12-05 19:55:46 +00:00
.Console/read DEI .buf skey ?{ BRK }
<print-type>
;dict/yousent <print-str>
LIT "" #18 DEO
;buf <print-str>/
LIT "" #18 DEO
#0a18 DEO
;buf sclr/ .Console/type DEI #04 NEQ ?{
;dict/argend <print-str>
;on-stdin .Console/vector DEO2 }
2023-07-16 17:04:40 +00:00
BRK
@on-stdin ( -> )
2023-12-05 19:55:46 +00:00
.Console/read DEI .buf skey ?{ BRK }
;buf ;dict/quit scmp ?&quit
<print-type>
;dict/yousaid <print-str>
LIT "" #18 DEO
;buf <print-str>/
LIT "" #18 DEO
#0a18 DEO
;buf sclr/ BRK
2023-07-16 17:04:40 +00:00
&quit ( buf* -> )
2023-12-05 19:55:46 +00:00
#800f DEO
2023-07-16 17:04:40 +00:00
BRK
2023-07-16 17:04:40 +00:00
@<print-type> ( -- )
2023-12-05 19:55:46 +00:00
[ LIT2 00 -Console/type ] DEI #01 GTH DUP ADD ;types ADD2
( ) LDA2 !<print-str>/
(
@|stdlib )
2023-07-16 17:04:40 +00:00
@<print-str> ( str* -- )
2023-12-05 19:55:46 +00:00
&w ( -- )
LDAk #18 DEO
2023-12-05 19:55:46 +00:00
INC2 & LDAk ?&w
2023-07-16 17:04:40 +00:00
POP2 JMP2r
@sclr ( str* -- )
2023-12-05 19:55:46 +00:00
&w ( -- )
2023-07-16 17:04:40 +00:00
STH2k #00 STH2r STA
2023-12-05 19:55:46 +00:00
INC2 & LDAk ?&w
2023-07-16 17:04:40 +00:00
POP2 JMP2r
2023-12-05 19:55:46 +00:00
@skey ( key buf -- proc )
OVR #20 LTH ?{
#00 SWP sput #00 JMP2r }
POP2 #01 JMP2r
2023-07-16 17:04:40 +00:00
@scap ( str* -- end* )
2023-12-05 19:55:46 +00:00
&w ( -- )
INC2 & LDAk ?&w
2023-07-16 17:04:40 +00:00
JMP2r
@sput ( chr str* -- )
2023-12-05 19:55:46 +00:00
scap/ STA
2023-07-16 17:04:40 +00:00
JMP2r
@scmp ( a* b* -- f )
STH2
2023-12-05 19:55:46 +00:00
&l ( a* b* -- f )
LDAk LDAkr STHr NEQk ?&d
DUP EOR EQUk ?&d
POP2 INC2 INC2r !&l
&d ( a* c1 c2 b* -- f )
NIP2 POP2r EQU JMP2r
@<phex> ( short* -- )
SWP <phex>/b
&b ( -- )
DUP #04 SFT <phex>/c
&c ( -- )
#0f AND DUP #09 GTH #27 MUL ADD [ LIT "0 ] ADD #18 DEO
JMP2r
(
@|assets )
@types
2023-07-16 17:04:40 +00:00
=dict/std =dict/arg
@dict ( )
&hello "Welcome 20 "to 20 "Uxn! 0a $1
&yousaid "You 20 "said: 20 $1
&yousent "You 20 "sent: 20 $1
&std "(std) $1
&arg "(arg) $1
&quit "quit $1
&argend "(argend) 0a $1
2023-04-05 23:50:06 +00:00