Browse code

Improved console device examples

Devine Lu Linvega authored on 16/07/2023 17:04:40
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,16 @@
1
+( usage: uxncli console.read.rom )
2
+
3
+|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
4
+
5
+|0100
6
+
7
+@on-reset ( -> )
8
+	;on-console .Console/vector DEO2
9
+	( type something in the console ) 
10
+	BRK
11
+
12
+@on-console ( -> )
13
+	.Console/read DEI .Console/write DEO
14
+	#0a .Console/write DEO
15
+	BRK
16
+
... ...
@@ -1,113 +1,113 @@
1
-( usage: uxncli console.rom arg1 arg2 arg3
2
-	Prints Hello Uxn!, and listens for incoming stdin events on enter. )
1
+( usage: uxncli console.rom arg1 arg2 arg3 Prints Hello Uxn!, and listens for incoming stdin events on enter. )
3 2
 
4 3
 |10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
5 4
 
6
-|00
5
+|0000
7 6
 
8 7
 	@buf
9 8
 
10
-|0100 ( -> )
9
+|0100
11 10
 
12
-	( set vector )
11
+@on-reset ( -> )
13 12
 	;on-argument .Console/vector DEO2
14
-	( print hello )
15
-	;hello-txt pstr
16
-	( when arguments are queued )
17
-	.Console/type DEI #00 EQU ?&no-queue
18
-		;queue-txt pstr
19
-		&no-queue
20
-
21
-BRK
13
+	;dict/hello <print-str>
14
+	.Console/type DEI ?&has-arg
15
+	BRK
16
+	&has-arg ( -> )
17
+		;dict/queue <print-str>
18
+		BRK
22 19
 
23 20
 @on-argument ( -> )
24
-
25
-	.Console/type DEI ?&no-argend
21
+	.Console/type DEI ?&>no-argend
26 22
 		;on-stdin .Console/vector DEO2
27
-		BRK
28
-		&no-argend
23
+		BRK &>no-argend
29 24
 	.Console/read DEI .buf skey ?&eval
30
-
31
-BRK
32
-
33
-&eval ( -> )
34
-
35
-	print-type
36
-	;yousent-txt pstr
25
+	BRK
26
+	&eval ( -> )
27
+		<print-type>
28
+		;dict/yousent <print-str>
37 29
 		LIT "" #18 DEO
38
-		;buf pstr
39
-		LIT "" #18 DEO #0a18 DEO
40
-		;buf sclr
41
-
42
-	.Console/type DEI #04 NEQ ?&no-close
43
-		;argend-txt pstr
44
-		;on-stdin .Console/vector DEO2
45
-		&no-close
46
-
47
-BRK
30
+		;buf <print-str>
31
+		LIT "" #18 DEO
32
+		#0a18 DEO
33
+		;buf sclr .Console/type DEI #04 NEQ ?&>no-close
34
+			;dict/argend <print-str>
35
+			;on-stdin .Console/vector DEO2 &>no-close
36
+		BRK
48 37
 
49 38
 @on-stdin ( -> )
50
-
51 39
 	.Console/read DEI .buf skey ?&eval
52
-
53
-BRK
54
-
55
-&eval ( -> )
56
-
57
-	print-type
58
-	;buf ;quit-txt scmp ?&quit
59
-	;yousaid-txt pstr
40
+	BRK
41
+	&eval ( -> )
42
+		<print-type>
43
+		;buf ;dict/quit scmp ?&quit
44
+		;dict/yousaid <print-str>
60 45
 		LIT "" #18 DEO
61
-		;buf pstr
62
-		LIT "" #18 DEO #0a18 DEO
63
-		;buf sclr
64
-
65
-BRK
66
-
67
-&quit ( buf* -> )
68
-
69
-	#010f DEO
70
-
71
-BRK
72
-
73
-@print-type ( -- )
74
-
75
-	[ LIT2 00 -Console/type ] DEI #01 GTH DUP ADD ;types ADD2 LDA2
46
+		;buf <print-str>
47
+		LIT "" #18 DEO
48
+		#0a18 DEO
49
+		;buf sclr BRK
50
+	&quit ( buf* -> )
51
+		#010f DEO
52
+		BRK
76 53
 
77
-!pstr
54
+@<print-type> ( -- )
55
+	[ LIT2 00 -Console/type ] DEI #01 GTH DUP ADD ;types ADD2 LDA2 !<print-str>
78 56
 
79 57
 (
80 58
 @|stdlib )
81 59
 
82
-@pstr ( str* -- )
83
-
84
-	&while
60
+@<print-str> ( str* -- )
61
+	!&
62
+	&while ( -- )
85 63
 		LDAk #18 DEO
86
-		INC2 LDAk ?&while
87
-	POP2
88
-
89
-JMP2r
90
-
91
-@skey ( key buf -- proc ) OVR #20 LTH ?&eval #00 SWP sput #00 JMP2r &eval POP2 #01 JMP2r
92
-@sclr ( str* -- ) LDAk ?&w POP2 JMP2r &w STH2k #00 STH2r STA INC2 LDAk ?&w POP2 JMP2r
93
-@scap ( str* -- end* ) LDAk ?&w JMP2r &w INC2 LDAk ?&w JMP2r
94
-@sput ( chr str* -- ) scap INC2k #00 ROT ROT STA STA JMP2r
95
-@scmp ( a* b* -- f ) STH2 &l LDAk LDAkr STHr ANDk #00 EQU ?&e NEQk ?&e POP2 INC2 INC2r !&l &e NIP2 POP2r EQU JMP2r
96
-@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
64
+		INC2 & LDAk ?&while
65
+	POP2 JMP2r
66
+
67
+@skey ( key buf -- proc )
68
+	OVR #20 LTH ?&eval
69
+	#00 SWP sput #00 JMP2r
70
+	&eval POP2 #01 JMP2r
71
+
72
+@sclr ( str* -- )
73
+	!&
74
+	&while ( -- )
75
+		STH2k #00 STH2r STA
76
+		INC2 & LDAk ?&while
77
+	POP2 JMP2r
78
+
79
+@scap ( str* -- end* )
80
+	!&
81
+	&while ( -- )
82
+		INC2 & LDAk ?&while
83
+	JMP2r
84
+
85
+@sput ( chr str* -- )
86
+	scap INC2k #00 ROT ROT STA
87
+	STA
88
+	JMP2r
89
+
90
+@scmp ( a* b* -- f )
91
+	STH2
92
+	&loop ( -- )
93
+		LDAk LDAkr STHr ANDk #00 EQU ?&e
94
+		NEQk ?&e
95
+		POP2 INC2 INC2r !&loop
96
+	&e NIP2 POP2r EQU JMP2r
97 97
 
98 98
 (
99 99
 @|assets )
100 100
 
101 101
 @types
102
-	=std-txt
103
-	=arg-txt
104
-
105
-@hello-txt "Welcome 20 "to 20 "Uxn! 0a $1
106
-@yousaid-txt "You 20 "said: 20 $1
107
-@yousent-txt "You 20 "sent: 20 $1
108
-@std-txt "(std) $1
109
-@arg-txt "(arg) $1
110
-@quit-txt "quit $1
111
-@argend-txt "(argend) 0a $1
112
-@queue-txt "(queue) 0a $1
102
+	=dict/std =dict/arg
103
+
104
+@dict ( )
105
+	&hello "Welcome 20 "to 20 "Uxn! 0a $1
106
+	&yousaid "You 20 "said: 20 $1
107
+	&yousent "You 20 "sent: 20 $1
108
+	&std "(std) $1
109
+	&arg "(arg) $1
110
+	&quit "quit $1
111
+	&argend "(argend) 0a $1
112
+	&queue "(queue) 0a $1
113 113