mirror of
https://git.sr.ht/~rabbits/uxn
synced 2025-01-05 07:01:20 +00:00
(console.tal) Modernized example
This commit is contained in:
parent
dbb111376d
commit
1733ebca0f
1 changed files with 52 additions and 72 deletions
|
@ -1,108 +1,88 @@
|
||||||
( usage: uxncli console.rom arg1 arg2 arg3 Prints Hello Uxn!, and listens for incoming stdin events on enter. )
|
( usage: uxncli console.rom foo "bar baz"
|
||||||
|
| Prints Welcome to 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
|
||||||
|
|
||||||
|0000
|
|000
|
||||||
|
|
||||||
@buf
|
@arg $40
|
||||||
|
@std $40
|
||||||
|
|
||||||
|0100
|
|100
|
||||||
|
|
||||||
@on-reset ( -> )
|
@on-reset ( -> )
|
||||||
|
;Dict/hello <print-str>
|
||||||
|
.Console/type DEI ?{
|
||||||
|
( | no arguments )
|
||||||
|
;on-stdin .Console/vector DEO2
|
||||||
|
BRK }
|
||||||
;on-argument .Console/vector DEO2
|
;on-argument .Console/vector DEO2
|
||||||
.Console/type DEI ?{ ;on-stdin .Console/vector DEO2 }
|
|
||||||
;dict/hello <print-str>
|
|
||||||
BRK
|
BRK
|
||||||
|
|
||||||
@on-argument ( -> )
|
@on-argument ( -> )
|
||||||
.Console/read DEI .buf skey ?{ BRK }
|
[ LIT2 02 -Console/type ] DEI NEQ ?{
|
||||||
<print-type>
|
.Console/read DEI [ LIT2 00 &ptr -arg ] INCk ,&ptr STR
|
||||||
;dict/yousent <print-str>
|
STZ2
|
||||||
LIT "" #18 DEO
|
BRK }
|
||||||
;buf <print-str>/
|
;arg ;Dict/yousent <print-result>
|
||||||
LIT "" #18 DEO
|
[ LIT2 04 -Console/type ] DEI NEQ ?{ ;on-stdin .Console/vector DEO2 }
|
||||||
#0a18 DEO
|
[ LIT2 -arg _&ptr ] STR
|
||||||
;buf sclr/ .Console/type DEI #04 NEQ ?{
|
|
||||||
;dict/argend <print-str>
|
|
||||||
;on-stdin .Console/vector DEO2 }
|
|
||||||
BRK
|
BRK
|
||||||
|
|
||||||
@on-stdin ( -> )
|
@on-stdin ( -> )
|
||||||
.Console/read DEI .buf skey ?{ BRK }
|
[ LIT2 0a -Console/read ] DEI EQU ?{
|
||||||
;buf ;dict/quit scmp ?&quit
|
.Console/read DEI [ LIT2 00 &ptr -std ] INCk ,&ptr STR
|
||||||
<print-type>
|
STZ2
|
||||||
;dict/yousaid <print-str>
|
BRK }
|
||||||
LIT "" #18 DEO
|
;std DUP2 ;Dict/yousaid <print-result>
|
||||||
;buf <print-str>/
|
;Dict/quit scmp ?quit
|
||||||
LIT "" #18 DEO
|
[ LIT2 -std _&ptr ] STR
|
||||||
#0a18 DEO
|
BRK
|
||||||
;buf sclr/ BRK
|
|
||||||
&quit ( buf* -> )
|
@quit ( buf* -> )
|
||||||
#800f DEO
|
#800f DEO
|
||||||
BRK
|
BRK
|
||||||
|
|
||||||
@<print-type> ( -- )
|
@<print-result> ( buf* name* -- )
|
||||||
[ LIT2 00 -Console/type ] DEI #01 GTH DUP ADD ;types ADD2
|
<print-str>
|
||||||
( ) LDA2 !<print-str>/
|
[ LIT2 "" 18 ] DEO
|
||||||
|
<print-str>/
|
||||||
|
[ LIT2 "" 18 ] DEO
|
||||||
|
[ LIT2 00 -Console/type ] DEI DUP ADD ;Types ADD2 LDA2 <print-str>/
|
||||||
|
#0a18 DEO
|
||||||
|
JMP2r
|
||||||
|
|
||||||
(
|
(
|
||||||
@|stdlib )
|
@|stdlib )
|
||||||
|
|
||||||
@<print-str> ( str* -- )
|
@<print-str> ( str* -- )
|
||||||
&w ( -- )
|
|
||||||
LDAk #18 DEO
|
LDAk #18 DEO
|
||||||
INC2 & LDAk ?&w
|
INC2 & LDAk ?<print-str>
|
||||||
POP2 JMP2r
|
POP2 JMP2r
|
||||||
|
|
||||||
@sclr ( str* -- )
|
|
||||||
&w ( -- )
|
|
||||||
STH2k #00 STH2r STA
|
|
||||||
INC2 & LDAk ?&w
|
|
||||||
POP2 JMP2r
|
|
||||||
|
|
||||||
@skey ( key buf -- proc )
|
|
||||||
OVR #20 LTH ?{
|
|
||||||
#00 SWP sput #00 JMP2r }
|
|
||||||
POP2 #01 JMP2r
|
|
||||||
|
|
||||||
@scap ( str* -- end* )
|
|
||||||
&w ( -- )
|
|
||||||
INC2 & LDAk ?&w
|
|
||||||
JMP2r
|
|
||||||
|
|
||||||
@sput ( chr str* -- )
|
|
||||||
scap/ STA
|
|
||||||
JMP2r
|
|
||||||
|
|
||||||
@scmp ( a* b* -- f )
|
@scmp ( a* b* -- f )
|
||||||
STH2
|
STH2
|
||||||
&l ( a* b* -- f )
|
&l ( a* b* -- f )
|
||||||
LDAk LDAkr STHr NEQk ?&d
|
LDAk LDAkr STHr NEQk ?&d
|
||||||
DUP EOR EQUk ?&d
|
DUP EOR EQUk ?&d
|
||||||
POP2 INC2 INC2r !&l
|
POP2 INC2 INC2r !&l
|
||||||
|
|
||||||
&d ( a* c1 c2 b* -- f )
|
&d ( a* c1 c2 b* -- f )
|
||||||
NIP2 POP2r EQU JMP2r
|
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 )
|
@|assets )
|
||||||
|
|
||||||
@types
|
@Types =Dict/arg-none =Dict/arg-stdin =Dict/arg-data =Dict/arg-spacer =Dict/arg-end
|
||||||
=dict/std =dict/arg
|
|
||||||
|
|
||||||
@dict ( )
|
@Dict
|
||||||
&hello "Welcome 20 "to 20 "Uxn! 0a $1
|
&hello "Welcome 20 "to 20 "Uxn! 0a $1
|
||||||
&yousaid "You 20 "said: 20 $1
|
&yousaid "You 20 "said: 20 $1
|
||||||
&yousent "You 20 "sent: 20 $1
|
&yousent "You 20 "sent: 20 $1
|
||||||
&std "(std) $1
|
|
||||||
&arg "(arg) $1
|
|
||||||
&quit "quit $1
|
&quit "quit $1
|
||||||
&argend "(argend) 0a $1
|
&arg-none "<none> $1
|
||||||
|
&arg-stdin "<stdin> $1
|
||||||
|
&arg-data "<data> $1
|
||||||
|
&arg-spacer "<spacer> $1
|
||||||
|
&arg-end "<end> $1
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue