... | ... |
@@ -1,7 +1,7 @@ |
1 |
-( Console: |
|
1 |
+( usage: uxncli console.rom arg1 arg2 arg3 |
|
2 | 2 |
Prints Hello Uxn!, and listens for incoming stdin events on enter. ) |
3 | 3 |
|
4 |
-|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1 |
|
4 |
+|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1 |
|
5 | 5 |
|
6 | 6 |
|00 |
7 | 7 |
|
... | ... |
@@ -10,38 +10,72 @@ |
10 | 10 |
|0100 ( -> ) |
11 | 11 |
|
12 | 12 |
( set vector ) |
13 |
- ;on-console .Console/vector DEO2 |
|
13 |
+ ;on-argument .Console/vector DEO2 |
|
14 | 14 |
( print hello ) |
15 |
- ;hello-txt print-str |
|
15 |
+ ;hello-txt pstr |
|
16 | 16 |
|
17 | 17 |
BRK |
18 | 18 |
|
19 |
-@on-console ( -> ) |
|
19 |
+@on-argument ( -> ) |
|
20 | 20 |
|
21 |
- .Console/read DEI .buf skey ?eval |
|
21 |
+ .Console/type DEI ?&no-argend |
|
22 |
+ ;on-stdin .Console/vector DEO2 |
|
23 |
+ BRK |
|
24 |
+ &no-argend |
|
25 |
+ .Console/read DEI .buf skey ?&eval |
|
22 | 26 |
|
23 | 27 |
BRK |
24 | 28 |
|
25 |
-@eval ( -> ) |
|
29 |
+&eval ( -> ) |
|
26 | 30 |
|
27 |
- ;buf |
|
28 |
- DUP2 ;quit-txt scmp ?quit |
|
31 |
+ print-type |
|
32 |
+ ;yousent-txt pstr |
|
33 |
+ LIT "" #18 DEO |
|
34 |
+ ;buf pstr |
|
35 |
+ LIT "" #18 DEO #0a18 DEO |
|
36 |
+ ;buf sclr |
|
37 |
+ |
|
38 |
+ .Console/type DEI #04 NEQ ?&no-close |
|
39 |
+ ;argend-txt pstr |
|
40 |
+ ;on-stdin .Console/vector DEO2 |
|
41 |
+ &no-close |
|
42 |
+ |
|
43 |
+BRK |
|
44 |
+ |
|
45 |
+@on-stdin ( -> ) |
|
46 |
+ |
|
47 |
+ .Console/read DEI .buf skey ?&eval |
|
48 |
+ |
|
49 |
+BRK |
|
50 |
+ |
|
51 |
+&eval ( -> ) |
|
29 | 52 |
|
30 |
- ;yousaid-txt print-str |
|
53 |
+ print-type |
|
54 |
+ ;buf ;quit-txt scmp ?quit |
|
55 |
+ ;yousaid-txt pstr |
|
31 | 56 |
LIT "" #18 DEO |
32 |
- DUP2 print-str |
|
57 |
+ ;buf pstr |
|
33 | 58 |
LIT "" #18 DEO #0a18 DEO |
34 |
- sclr |
|
59 |
+ ;buf sclr |
|
35 | 60 |
|
36 | 61 |
BRK |
37 | 62 |
|
63 |
+@print-type ( -- ) |
|
64 |
+ |
|
65 |
+ [ LIT2 00 -Console/type ] DEI #01 GTH DUP ADD ;types ADD2 LDA2 |
|
66 |
+ |
|
67 |
+!pstr |
|
68 |
+ |
|
38 | 69 |
@quit ( buf* -> ) |
39 | 70 |
|
40 | 71 |
POP2 #010f DEO |
41 | 72 |
|
42 | 73 |
BRK |
43 | 74 |
|
44 |
-@print-str ( str* -- ) |
|
75 |
+( |
|
76 |
+@|stdlib ) |
|
77 |
+ |
|
78 |
+@pstr ( str* -- ) |
|
45 | 79 |
|
46 | 80 |
&while |
47 | 81 |
LDAk #18 DEO |
... | ... |
@@ -55,8 +89,20 @@ JMP2r |
55 | 89 |
@scap ( str* -- end* ) LDAk ?&w JMP2r &w INC2 LDAk ?&w JMP2r |
56 | 90 |
@sput ( chr str* -- ) scap INC2k #00 ROT ROT STA STA JMP2r |
57 | 91 |
@scmp ( a* b* -- f ) STH2 &l LDAk LDAkr STHr ANDk #00 EQU ?&e NEQk ?&e POP2 INC2 INC2r !&l &e NIP2 POP2r EQU JMP2r |
92 |
+@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 |
|
93 |
+ |
|
94 |
+( |
|
95 |
+@|assets ) |
|
96 |
+ |
|
97 |
+@types |
|
98 |
+ =std-txt |
|
99 |
+ =arg-txt |
|
58 | 100 |
|
59 | 101 |
@hello-txt "Welcome 20 "to 20 "Uxn! 0a $1 |
60 | 102 |
@yousaid-txt "You 20 "said: 20 $1 |
103 |
+@yousent-txt "You 20 "sent: 20 $1 |
|
104 |
+@std-txt "(std) $1 |
|
105 |
+@arg-txt "(arg) $1 |
|
61 | 106 |
@quit-txt "quit $1 |
107 |
+@argend-txt "(argend) 0a $1 |
|
62 | 108 |
|
... | ... |
@@ -64,7 +64,7 @@ main(int argc, char **argv) |
64 | 64 |
for(i = 2; i < argc; i++) { |
65 | 65 |
char *p = argv[i]; |
66 | 66 |
while(*p) console_input(&u, *p++, CONSOLE_ARG); |
67 |
- console_input(&u, '\n', CONSOLE_EOA); |
|
67 |
+ console_input(&u, '\n', i == argc-1 ? CONSOLE_END : CONSOLE_EOA); |
|
68 | 68 |
} |
69 | 69 |
while(!u.dev[0x0f]) { |
70 | 70 |
int c = fgetc(stdin); |