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

63 lines
1.1 KiB
Tal
Raw Normal View History

( Console:
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 $5 &write $1 &error $1
2023-04-05 23:50:06 +00:00
|00
@buf
2021-04-21 16:48:04 +00:00
|0100 ( -> )
2021-02-20 23:00:34 +00:00
( set vector )
;on-console .Console/vector DEO2
( print hello )
2023-04-05 23:50:06 +00:00
;hello-txt print-str
2021-07-28 22:41:07 +00:00
2021-05-13 15:47:18 +00:00
BRK
2021-02-20 23:00:34 +00:00
@on-console ( -> )
2023-04-05 23:50:06 +00:00
.Console/read DEI .buf skey ?eval
BRK
@eval ( -> )
;buf
DUP2 ;quit-txt scmp ?quit
2023-04-06 00:18:03 +00:00
2023-04-05 23:50:06 +00:00
;yousaid-txt print-str
2023-04-06 00:18:03 +00:00
LIT "" #18 DEO
DUP2 print-str
LIT "" #18 DEO #0a18 DEO
2023-04-05 23:50:06 +00:00
sclr
BRK
@quit ( buf* -> )
POP2 #010f DEO
BRK
@print-str ( str* -- )
&while
LDAk #18 DEO
2023-04-05 23:50:06 +00:00
INC2 LDAk ?&while
POP2
JMP2r
2023-04-06 00:18:03 +00:00
@skey ( key buf -- proc ) OVR #20 LTH ?&eval #00 SWP sput #00 JMP2r &eval POP2 #01 JMP2r
2023-04-05 23:50:06 +00:00
@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
@hello-txt "Welcome 20 "to 20 "Uxn! 0a $1
@yousaid-txt "You 20 "said: 20 $1
2023-04-05 23:50:06 +00:00
@quit-txt "quit $1