1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,23 +0,0 @@ |
1 |
-( dev/console ) |
|
2 |
- |
|
3 |
-( |
|
4 |
- Copies data from stdin to both stdout and stderr. |
|
5 |
-) |
|
6 |
- |
|
7 |
-|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ] |
|
8 |
- |
|
9 |
-( init ) |
|
10 |
- |
|
11 |
-|0100 ( -> ) |
|
12 |
- |
|
13 |
- ;on-stdin .Console/vector DEO2 |
|
14 |
- |
|
15 |
-BRK |
|
16 |
- |
|
17 |
-@on-stdin ( -> ) |
|
18 |
- |
|
19 |
- .Console/read DEI |
|
20 |
- DUP .Console/write DEO |
|
21 |
- .Console/error DEO |
|
22 |
- |
|
23 |
-BRK |
24 | 0 |
deleted file mode 100644 |
... | ... |
@@ -1,94 +0,0 @@ |
1 |
-( dev/console ) |
|
2 |
- |
|
3 |
-%RTN { JMP2r } |
|
4 |
-%PRINT { ;print JSR2 } |
|
5 |
-%BR { #0a .Console/write DEO } |
|
6 |
- |
|
7 |
-( devices ) |
|
8 |
- |
|
9 |
-|10 @Console [ &pad $8 &write $1 ] |
|
10 |
- |
|
11 |
-( variables ) |
|
12 |
- |
|
13 |
-|0000 |
|
14 |
- |
|
15 |
-@number [ &started $1 ] |
|
16 |
- |
|
17 |
-( init ) |
|
18 |
- |
|
19 |
-|0100 ( -> ) |
|
20 |
- |
|
21 |
- ;char-txt PRINT #42 .Console/write DEO BR |
|
22 |
- ;byte-txt PRINT #ab ;print-byte JSR2 BR |
|
23 |
- ;short-txt PRINT #cdef ;print-short JSR2 BR |
|
24 |
- ;string-txt PRINT ;hello-word ;print JSR2 BR |
|
25 |
- |
|
26 |
- ;hello-word ;print JSR2 |
|
27 |
- #ffff ;print-short JSR2 |
|
28 |
- ;is-word ;print JSR2 |
|
29 |
- #ffff ;print-short-decimal JSR2 |
|
30 |
- |
|
31 |
-BRK |
|
32 |
- |
|
33 |
-@print ( addr* -- ) |
|
34 |
- |
|
35 |
- &loop |
|
36 |
- ( send ) LDAk .Console/write DEO |
|
37 |
- ( incr ) INC2 |
|
38 |
- ( loop ) LDAk ,&loop JCN |
|
39 |
- POP2 |
|
40 |
- |
|
41 |
-RTN |
|
42 |
- |
|
43 |
-@print-short ( short* -- ) |
|
44 |
- LIT '0 .Console/write DEO |
|
45 |
- LIT 'x .Console/write DEO |
|
46 |
- OVR #04 SFT ,&hex JSR |
|
47 |
- SWP #0f AND ,&hex JSR |
|
48 |
- DUP #04 SFT ,&hex JSR |
|
49 |
- #0f AND ,&hex JMP |
|
50 |
- |
|
51 |
- &hex |
|
52 |
- #30 ADD DUP #3a LTH ,¬-alpha JCN |
|
53 |
- #27 ADD |
|
54 |
- ¬-alpha |
|
55 |
- .Console/write DEO |
|
56 |
-RTN |
|
57 |
- |
|
58 |
-@print-byte ( byte -- ) |
|
59 |
- LIT '0 .Console/write DEO |
|
60 |
- LIT 'x .Console/write DEO |
|
61 |
- DUP #04 SFT ,&hex JSR |
|
62 |
- #0f AND ,&hex JMP |
|
63 |
- |
|
64 |
- &hex |
|
65 |
- #30 ADD DUP #39 GTH #27 MUL ADD .Console/write DEO |
|
66 |
-RTN |
|
67 |
- |
|
68 |
-@print-short-decimal ( short -- ) |
|
69 |
- #00 .number/started STZ |
|
70 |
- DUP2 #2710 DIV2 DUP2 ,&digit JSR #2710 MUL2 SUB2 |
|
71 |
- DUP2 #03e8 DIV2 DUP2 ,&digit JSR #03e8 MUL2 SUB2 |
|
72 |
- DUP2 #0064 DIV2 DUP2 ,&digit JSR #0064 MUL2 SUB2 |
|
73 |
- DUP2 #000a DIV2 DUP2 ,&digit JSR #000a MUL2 SUB2 |
|
74 |
- ,&digit JSR |
|
75 |
- .number/started LDZ ,&end JCN |
|
76 |
- LIT '0 .Console/write DEO |
|
77 |
- &end |
|
78 |
-RTN |
|
79 |
- |
|
80 |
- &digit |
|
81 |
- NIP |
|
82 |
- DUP .number/started LDZ ORA #02 JCN |
|
83 |
- POP JMP2r |
|
84 |
- LIT '0 ADD .Console/write DEO |
|
85 |
- #01 .number/started STZ |
|
86 |
-RTN |
|
87 |
- |
|
88 |
-@char-txt "char: 20 $1 |
|
89 |
-@byte-txt "byte: 20 $1 |
|
90 |
-@short-txt "short: 20 $1 |
|
91 |
-@string-txt "string: 20 $1 |
|
92 |
- |
|
93 |
-@hello-word "hello 20 "World! 0a 00 |
|
94 |
-@is-word 20 "is 20 00 |
... | ... |
@@ -1,19 +1,37 @@ |
1 |
-( dev/console ) |
|
1 |
+( Console: |
|
2 |
+ Prints Hello Uxn!, and listens for incoming stdin events on enter. ) |
|
2 | 3 |
|
3 |
-%HALT { #010f DEO } |
|
4 |
-%EMIT { #18 DEO } |
|
5 |
- |
|
6 |
-( init ) |
|
4 |
+|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1 |
|
7 | 5 |
|
8 | 6 |
|0100 ( -> ) |
9 | 7 |
|
10 |
- ;hello-word |
|
8 |
+ ( set vector ) |
|
9 |
+ ;on-console .Console/vector DEO2 |
|
10 |
+ ( print hello ) |
|
11 |
+ ;hello-txt |
|
11 | 12 |
&while |
12 |
- ( send ) LDAk EMIT |
|
13 |
+ LDAk .Console/write DEO |
|
13 | 14 |
INC2 LDAk ,&while JCN |
14 | 15 |
POP2 |
15 |
- ( stop ) HALT |
|
16 | 16 |
|
17 | 17 |
BRK |
18 | 18 |
|
19 |
-@hello-word "Hello 20 "Uxn! $1 |
|
20 | 19 |
\ No newline at end of file |
20 |
+@on-console ( -> ) |
|
21 |
+ |
|
22 |
+ ;yousaid-txt ,print-str JSR |
|
23 |
+ .Console/read DEI .Console/write DEO |
|
24 |
+ #0a .Console/write DEO |
|
25 |
+ |
|
26 |
+BRK |
|
27 |
+ |
|
28 |
+@print-str ( str* -- ) |
|
29 |
+ |
|
30 |
+ &while |
|
31 |
+ LDAk #18 DEO |
|
32 |
+ INC2 LDAk ,&while JCN |
|
33 |
+ POP2 |
|
34 |
+ |
|
35 |
+JMP2r |
|
36 |
+ |
|
37 |
+@hello-txt "Hello 20 "Uxn! $1 |
|
38 |
+@yousaid-txt "You 20 "said: 20 $1 |
... | ... |
@@ -1,58 +1,35 @@ |
1 |
-( dev/controller/keys ) |
|
1 |
+( Controller: |
|
2 |
+ Buttons should highlight on press and display the button and key bytes. ) |
|
2 | 3 |
|
3 |
-%+ { ADD } %- { SUB } %/ { DIV } |
|
4 |
-%< { LTH } %> { GTH } %= { EQU } %! { NEQ } |
|
5 |
-%++ { ADD2 } %-- { SUB2 } %// { DIV2 } |
|
6 |
-%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 } |
|
7 |
- |
|
8 |
-%RTN { JMP2r } |
|
9 |
-%TOS { #00 SWP } |
|
10 |
-%LTS2 { #8000 ++ SWP2 #8000 ++ >> } |
|
11 |
-%AUTO-NONE { #00 .Screen/auto DEO } |
|
12 |
-%AUTO-X { #01 .Screen/auto DEO } |
|
13 |
- |
|
14 |
-( devices ) |
|
15 |
- |
|
16 |
-|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] |
|
17 |
-|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 |
|
18 |
-|80 @Controller [ &vector $2 &button $1 &key $1 ] |
|
19 |
- |
|
20 |
-( variables ) |
|
4 |
+|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 |
|
5 |
+|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 |
|
6 |
+|80 @Controller &vector $2 &button $1 &key $1 |
|
21 | 7 |
|
22 | 8 |
|0000 |
23 | 9 |
|
24 | 10 |
@center |
25 |
- &x $2 |
|
26 |
- &y $2 |
|
11 |
+ &x $2 &y $2 |
|
27 | 12 |
@frame |
28 |
- &w $2 &h $2 |
|
29 |
- &x0 $2 &y0 $2 |
|
30 |
- &x1 $2 &y1 $2 |
|
31 |
- |
|
32 |
-( init ) |
|
13 |
+ &w $2 &h $2 &x0 $2 &y0 $2 &x1 $2 &y1 $2 |
|
33 | 14 |
|
34 | 15 |
|0100 ( -> ) |
35 | 16 |
|
36 |
- ( theme ) |
|
37 |
- #0ff7 .System/r DEO2 |
|
38 |
- #0f07 .System/g DEO2 |
|
17 |
+ ( theme ) |
|
18 |
+ #0ff7 .System/r DEO2 |
|
19 |
+ #0f07 .System/g DEO2 |
|
39 | 20 |
#0f07 .System/b DEO2 |
40 |
- |
|
41 | 21 |
( find center ) |
42 | 22 |
.Screen/width DEI2 #01 SFT2 .center/x STZ2 |
43 | 23 |
.Screen/height DEI2 #01 SFT2 .center/y STZ2 |
44 |
- |
|
45 | 24 |
( place controller ) |
46 | 25 |
#0068 .frame/w STZ2 |
47 | 26 |
#0030 .frame/h STZ2 |
48 |
- .center/x LDZ2 .frame/w LDZ2 #0002 // -- .frame/x0 STZ2 |
|
49 |
- .center/y LDZ2 .frame/h LDZ2 #0002 // -- .frame/y0 STZ2 |
|
50 |
- .frame/x0 LDZ2 .frame/w LDZ2 ++ .frame/x1 STZ2 |
|
51 |
- .frame/y0 LDZ2 .frame/h LDZ2 ++ .frame/y1 STZ2 |
|
52 |
- |
|
53 |
- ( vectors ) |
|
27 |
+ .center/x LDZ2 .frame/w LDZ2 #01 SFT2 SUB2 .frame/x0 STZ2 |
|
28 |
+ .center/y LDZ2 .frame/h LDZ2 #01 SFT2 SUB2 .frame/y0 STZ2 |
|
29 |
+ .frame/x0 LDZ2 .frame/w LDZ2 ADD2 .frame/x1 STZ2 |
|
30 |
+ .frame/y0 LDZ2 .frame/h LDZ2 ADD2 .frame/y1 STZ2 |
|
31 |
+ ( vectors ) |
|
54 | 32 |
;on-button .Controller/vector DEO2 |
55 |
- |
|
56 | 33 |
( frame ) |
57 | 34 |
.frame/x0 LDZ2 .frame/y0 LDZ2 |
58 | 35 |
.frame/x1 LDZ2 .frame/y1 LDZ2 |
... | ... |
@@ -67,7 +44,7 @@ BRK |
67 | 44 |
,draw-controller JSR |
68 | 45 |
|
69 | 46 |
( print stack on start button ) |
70 |
- .Controller/button DEI #08 = JMP BRK #010e DEO |
|
47 |
+ .Controller/button DEI #08 EQU JMP BRK #010e DEO |
|
71 | 48 |
|
72 | 49 |
BRK |
73 | 50 |
|
... | ... |
@@ -76,74 +53,74 @@ BRK |
76 | 53 |
.Controller/button DEI STH |
77 | 54 |
|
78 | 55 |
( d-pad ) |
79 |
- .frame/x0 LDZ2 #0010 ++ .Screen/x DEO2 |
|
80 |
- .frame/y0 LDZ2 #0010 ++ .Screen/y DEO2 |
|
56 |
+ .frame/x0 LDZ2 #0010 ADD2 .Screen/x DEO2 |
|
57 |
+ .frame/y0 LDZ2 #0010 ADD2 .Screen/y DEO2 |
|
81 | 58 |
;controller-icn/dpad-up .Screen/addr DEO2 |
82 |
- #03 [ STHkr #04 SFT #01 AND DUP + - ] .Screen/sprite DEO |
|
83 |
- .Screen/y DEI2 #0010 ++ .Screen/y DEO2 |
|
59 |
+ #03 [ STHkr #04 SFT #01 AND DUP ADD SUB ] .Screen/sprite DEO |
|
60 |
+ .Screen/y DEI2 #0010 ADD2 .Screen/y DEO2 |
|
84 | 61 |
;controller-icn/dpad-down .Screen/addr DEO2 |
85 |
- #03 [ STHkr #05 SFT #01 AND DUP + - ] .Screen/sprite DEO |
|
86 |
- .Screen/y DEI2 #0008 -- .Screen/y DEO2 |
|
87 |
- .Screen/x DEI2 #0008 -- .Screen/x DEO2 |
|
62 |
+ #03 [ STHkr #05 SFT #01 AND DUP ADD SUB ] .Screen/sprite DEO |
|
63 |
+ .Screen/y DEI2 #0008 SUB2 .Screen/y DEO2 |
|
64 |
+ .Screen/x DEI2 #0008 SUB2 .Screen/x DEO2 |
|
88 | 65 |
;controller-icn/dpad-left .Screen/addr DEO2 |
89 |
- #03 [ STHkr #06 SFT #01 AND DUP + - ] .Screen/sprite DEO |
|
90 |
- .Screen/x DEI2 #0010 ++ .Screen/x DEO2 |
|
66 |
+ #03 [ STHkr #06 SFT #01 AND DUP ADD SUB ] .Screen/sprite DEO |
|
67 |
+ .Screen/x DEI2 #0010 ADD2 .Screen/x DEO2 |
|
91 | 68 |
;controller-icn/dpad-right .Screen/addr DEO2 |
92 |
- #03 [ STHkr #07 SFT #01 AND DUP + - ] .Screen/sprite DEO |
|
93 |
- .Screen/x DEI2 #0008 -- .Screen/x DEO2 |
|
69 |
+ #03 [ STHkr #07 SFT #01 AND DUP ADD SUB ] .Screen/sprite DEO |
|
70 |
+ .Screen/x DEI2 #0008 SUB2 .Screen/x DEO2 |
|
94 | 71 |
;controller-icn/dpad .Screen/addr DEO2 |
95 | 72 |
#03 .Screen/sprite DEO |
96 | 73 |
|
97 | 74 |
( options ) |
98 |
- .center/y LDZ2 #0009 ++ .Screen/y DEO2 |
|
99 |
- .center/x LDZ2 #0009 -- .Screen/x DEO2 |
|
75 |
+ .center/y LDZ2 #0009 ADD2 .Screen/y DEO2 |
|
76 |
+ .center/x LDZ2 #0009 SUB2 .Screen/x DEO2 |
|
100 | 77 |
;controller-icn/option .Screen/addr DEO2 |
101 |
- #03 [ STHkr #02 SFT #01 AND DUP + - ] .Screen/sprite DEO |
|
102 |
- .center/x LDZ2 #0004 ++ .Screen/x DEO2 |
|
78 |
+ #03 [ STHkr #02 SFT #01 AND DUP ADD SUB ] .Screen/sprite DEO |
|
79 |
+ .center/x LDZ2 #0004 ADD2 .Screen/x DEO2 |
|
103 | 80 |
;controller-icn/option .Screen/addr DEO2 |
104 |
- #03 [ STHkr #03 SFT #01 AND DUP + - ] .Screen/sprite DEO |
|
81 |
+ #03 [ STHkr #03 SFT #01 AND DUP ADD SUB ] .Screen/sprite DEO |
|
105 | 82 |
|
106 | 83 |
( buttons ) |
107 |
- .center/y LDZ2 #0000 ++ .Screen/y DEO2 |
|
108 |
- .center/x LDZ2 #0018 ++ .Screen/x DEO2 |
|
84 |
+ .center/y LDZ2 #0000 ADD2 .Screen/y DEO2 |
|
85 |
+ .center/x LDZ2 #0018 ADD2 .Screen/x DEO2 |
|
109 | 86 |
;controller-icn/button .Screen/addr DEO2 |
110 |
- #03 [ STHkr #01 SFT #01 AND - ] .Screen/sprite DEO |
|
111 |
- .Screen/y DEI2 #000a ++ .Screen/y DEO2 |
|
112 |
- ;font-hex #000b #30 SFT2 ++ .Screen/addr DEO2 |
|
87 |
+ #03 [ STHkr #01 SFT #01 AND SUB ] .Screen/sprite DEO |
|
88 |
+ .Screen/y DEI2 #000a ADD2 .Screen/y DEO2 |
|
89 |
+ ;font-hex #000b #30 SFT2 ADD2 .Screen/addr DEO2 |
|
113 | 90 |
#03 .Screen/sprite DEO |
114 | 91 |
|
115 |
- .center/y LDZ2 #0000 ++ .Screen/y DEO2 |
|
116 |
- .center/x LDZ2 #0024 ++ .Screen/x DEO2 |
|
92 |
+ .center/y LDZ2 #0000 ADD2 .Screen/y DEO2 |
|
93 |
+ .center/x LDZ2 #0024 ADD2 .Screen/x DEO2 |
|
117 | 94 |
;controller-icn/button .Screen/addr DEO2 |
118 |
- #03 [ STHr #01 AND - ] .Screen/sprite DEO |
|
119 |
- .Screen/y DEI2 #000a ++ .Screen/y DEO2 |
|
120 |
- ;font-hex #000a #30 SFT2 ++ .Screen/addr DEO2 |
|
95 |
+ #03 [ STHr #01 AND SUB ] .Screen/sprite DEO |
|
96 |
+ .Screen/y DEI2 #000a ADD2 .Screen/y DEO2 |
|
97 |
+ ;font-hex #000a #30 SFT2 ADD2 .Screen/addr DEO2 |
|
121 | 98 |
#03 .Screen/sprite DEO |
122 | 99 |
|
123 |
- .center/x LDZ2 #0010 -- .Screen/x DEO2 |
|
124 |
- .center/y LDZ2 #0010 -- .Screen/y DEO2 |
|
125 |
- AUTO-X |
|
126 |
- .Controller/button DEI2 #03 ;draw-short JSR2 |
|
127 |
- AUTO-NONE |
|
100 |
+ .center/x LDZ2 #0010 SUB2 .Screen/x DEO2 |
|
101 |
+ .center/y LDZ2 #0010 SUB2 .Screen/y DEO2 |
|
102 |
+ #01 .Screen/auto DEO |
|
103 |
+ .Controller/button DEI2 ,draw-short JSR |
|
104 |
+ #00 .Screen/auto DEO |
|
128 | 105 |
|
129 |
-RTN |
|
106 |
+JMP2r |
|
130 | 107 |
|
131 | 108 |
( generics ) |
132 | 109 |
|
133 |
-@draw-short ( short* color -- ) |
|
110 |
+@draw-short ( short* -- ) |
|
134 | 111 |
|
135 |
- STH SWP STHkr ,draw-byte JSR STHr |
|
112 |
+ SWP ,draw-byte JSR |
|
136 | 113 |
|
137 |
-@draw-byte ( byte color -- ) |
|
114 |
+@draw-byte ( byte -- ) |
|
138 | 115 |
|
139 |
- STH DUP #04 SFT STHkr ,draw-hex JSR STHr |
|
116 |
+ DUP #04 SFT ,draw-hex JSR |
|
140 | 117 |
|
141 |
-@draw-hex ( char color -- ) |
|
118 |
+@draw-hex ( char -- ) |
|
142 | 119 |
|
143 |
- #00 ROT #0f AND #30 SFT2 ;font-hex ++ .Screen/addr DEO2 |
|
144 |
- .Screen/sprite DEO |
|
120 |
+ #00 SWP #0f AND #30 SFT2 ;font-hex ADD2 .Screen/addr DEO2 |
|
121 |
+ #03 .Screen/sprite DEO |
|
145 | 122 |
|
146 |
-RTN |
|
123 |
+JMP2r |
|
147 | 124 |
|
148 | 125 |
@line-rect ( x1* y1* x2* y2* color -- ) |
149 | 126 |
|
... | ... |
@@ -170,7 +147,7 @@ RTN |
170 | 147 |
POP2 POP2 |
171 | 148 |
POPr |
172 | 149 |
|
173 |
-RTN |
|
150 |
+JMP2r |
|
174 | 151 |
|
175 | 152 |
@controller-icn |
176 | 153 |
&dpad ffff ffff ffff ffff |
... | ... |
@@ -181,12 +158,12 @@ RTN |
181 | 158 |
&option 0000 7eff ff7e 0000 |
182 | 159 |
&button 3c7e ffff ffff 7e3c |
183 | 160 |
|
184 |
-@font-hex |
|
185 |
- 003c 4242 4242 3c00 0018 0808 0808 1c00 |
|
186 |
- 003c 4202 3c40 7e00 003c 421c 0242 3c00 |
|
187 |
- 000c 1424 447e 0400 007e 407c 0242 3c00 |
|
188 |
- 003c 407c 4242 3c00 007e 0204 0810 1000 |
|
189 |
- 003c 423c 4242 3c00 003c 4242 3e02 3c00 |
|
190 |
- 003c 4242 7e42 4200 007c 427c 4242 7c00 |
|
191 |
- 003c 4240 4042 3c00 007c 4242 4242 7c00 |
|
192 |
- 007e 4078 4040 7e00 007e 4078 4040 4000 |
|
161 |
+@font-hex |
|
162 |
+ 007c 8282 8282 827c 0030 1010 1010 1010 |
|
163 |
+ 007c 8202 7c80 80fe 007c 8202 1c02 827c |
|
164 |
+ 000c 1424 4484 fe04 00fe 8080 7c02 827c |
|
165 |
+ 007c 8280 fc82 827c 00fe 0202 0408 1010 |
|
166 |
+ 007c 8282 7c82 827c 007c 8282 7e02 827c |
|
167 |
+ 007c 8202 7e82 827e 00fc 8282 fc82 82fc |
|
168 |
+ 007c 8280 8080 827c 00fc 8282 8282 82fc |
|
169 |
+ 00fe 8080 fe80 80fe 00fe 8080 f080 8080 |
193 | 170 |
deleted file mode 100644 |
... | ... |
@@ -1,133 +0,0 @@ |
1 |
-( simple Dev/File reading example ) |
|
2 |
- |
|
3 |
-( devices ) |
|
4 |
- |
|
5 |
-|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] |
|
6 |
-|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] |
|
7 |
-|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] |
|
8 |
- |
|
9 |
-( variables ) |
|
10 |
- |
|
11 |
-|0000 |
|
12 |
- |
|
13 |
-( program ) |
|
14 |
- |
|
15 |
-|0100 ( -> ) |
|
16 |
- ;try-load JSR2 |
|
17 |
- BRK |
|
18 |
- |
|
19 |
-@try-load ( -- ) |
|
20 |
- ( load contents from file ) |
|
21 |
- #1000 .File/length DEO2 |
|
22 |
- ;filename .File/name DEO2 |
|
23 |
- ;contents .File/read DEO2 |
|
24 |
- |
|
25 |
- .File/success DEI2 ORA ,&success JCN |
|
26 |
- ( failed to read: bright yellow background ) |
|
27 |
- #f0f7 .System/r DEO2 |
|
28 |
- #f0f7 .System/g DEO2 |
|
29 |
- #00f7 .System/b DEO2 |
|
30 |
- JMP2r |
|
31 |
- |
|
32 |
- &success |
|
33 |
- ( read successful: dark blue background, show contents ) |
|
34 |
- #00f7 .System/r DEO2 |
|
35 |
- #00f7 .System/g DEO2 |
|
36 |
- #40f7 .System/b DEO2 |
|
37 |
- ;contents DUP2 .File/success DEI2 ADD2 SWP2 ;draw JSR2 |
|
38 |
- JMP2r |
|
39 |
- |
|
40 |
-@draw ( end-ptr* ptr* -- ) |
|
41 |
- EQU2k ,&end JCN |
|
42 |
- LDAk |
|
43 |
- DUP #0a EQU ,&linefeed JCN |
|
44 |
- #0005 SFT2 ;font ADD2 |
|
45 |
- .Screen/addr DEO2 |
|
46 |
- #09 .Screen/sprite DEO |
|
47 |
- .Screen/x DEI2 #0008 ADD2 .Screen/x DEO2 |
|
48 |
- &next |
|
49 |
- INC2 |
|
50 |
- ,draw JMP |
|
51 |
- |
|
52 |
- &linefeed |
|
53 |
- POP |
|
54 |
- #0000 .Screen/x DEO2 |
|
55 |
- .Screen/y DEI2 #0008 ADD2 .Screen/y DEO2 |
|
56 |
- ,&next JMP |
|
57 |
- |
|
58 |
- &end |
|
59 |
- POP2 POP2 |
|
60 |
- JMP2r |
|
61 |
- |
|
62 |
-@get-x-advance ( font-char-addr* -- advance* ) |
|
63 |
- ( Save two 00 bytes for later use ) |
|
64 |
- #0000 SWP2 |
|
65 |
- ( First, load the eight bytes that make up the character ) |
|
66 |
- LDA2k SWP2 #0002 ADD2 |
|
67 |
- LDA2k SWP2 #0002 ADD2 |
|
68 |
- LDA2k SWP2 #0002 ADD2 |
|
69 |
- LDA2 |
|
70 |
- ( OR all the bytes together, so we know which columns contain filled pixels ) |
|
71 |
- ORA2 ORA2 ORA2 ORA |
|
72 |
- ( Find the lowest set bit (using one of the 00 bytes at the top, but not consuming it) ) |
|
73 |
- SUBk AND |
|
74 |
- ( Convert the nine possible values (00-80) into an offset into the magic table (00-08). ) |
|
75 |
- ( They get jumbled up with these two operations, but each possible value remains unique ) |
|
76 |
- #a3 MUL #16 DIV |
|
77 |
- ( Load the byte from the magic table, return a short (consuming/returning the 00 bytes at the top) ) |
|
78 |
- ;&magic ADD2 LDA |
|
79 |
- JMP2r |
|
80 |
- ( The magic table performs the last bit of arithmetic we want: |
|
81 |
- * the advance in x should be one more than the number of columns with filled pixels, |
|
82 |
- * with a maximum of 8, and |
|
83 |
- * a minimum of 3. ) |
|
84 |
- &magic |
|
85 |
- 03 ( lowest set bit is 00, 0 columns wide ) |
|
86 |
- 06 ( lowest set bit is 08, 5 columns wide ) |
|
87 |
- 05 ( lowest set bit is 10, 4 columns wide ) |
|
88 |
- 08 ( lowest set bit is 02, 7 columns wide ) |
|
89 |
- 04 ( lowest set bit is 20, 3 columns wide ) |
|
90 |
- 03 ( lowest set bit is 80, 1 column wide ) |
|
91 |
- 07 ( lowest set bit is 04, 6 columns wide ) |
|
92 |
- 08 ( lowest set bit is 01, 8 columns wide ) |
|
93 |
- 03 ( lowest set bit is 40, 2 columns wide ) |
|
94 |
- |
|
95 |
-@font ( spectrum-zx font ) |
|
96 |
-[ |
|
97 |
- 0000 0000 0000 0000 0000 2400 7e3c 0000 0000 2400 3c42 0000 0000 6c7c 7c38 1000 |
|
98 |
- 0010 387c 7c38 1000 0038 387c 6c10 3800 0010 387c 7c10 3800 0000 0018 1800 0000 |
|
99 |
- 007e 4242 4242 7e00 0000 1824 2418 0000 0018 2442 4224 1800 001e 063a 4a48 3000 |
|
100 |
- 0038 446c 107c 1000 000c 0808 0838 3800 003e 2222 2266 6600 0000 0822 0022 0800 |
|
101 |
- 0000 1018 1c18 1000 0000 0818 3818 0800 0008 1c00 001c 0800 0028 2828 2800 2800 |
|
102 |
- 003e 4a4a 3a0a 0a00 000c 3046 620c 3000 0000 0000 0000 ffff 0010 3800 3810 0038 |
|
103 |
- 0008 1c2a 0808 0800 0008 0808 2a1c 0800 0000 0804 7e04 0800 0000 1020 7e20 1000 |
|
104 |
- 0000 4040 7e00 0000 0000 0024 6624 0000 0000 1038 7c00 0000 0000 007c 3810 0000 |
|
105 |
- 0000 0000 0000 0000 0008 0808 0800 0800 0014 1400 0000 0000 0024 7e24 247e 2400 |
|
106 |
- 0008 1e28 1c0a 3c08 0042 0408 1020 4200 0030 4832 4c44 3a00 0008 1000 0000 0000 |
|
107 |
- 0004 0808 0808 0400 0010 0808 0808 1000 0000 1408 3e08 1400 0000 0808 3e08 0800 |
|
108 |
- 0000 0000 0008 0810 0000 0000 3c00 0000 0000 0000 0000 0800 0000 0204 0810 2000 |
|
109 |
- 003c 464a 5262 3c00 0018 2808 0808 3e00 003c 4202 3c40 7e00 003c 421c 0242 3c00 |
|
110 |
- 0008 1828 487e 0800 007e 407c 0242 3c00 003c 407c 4242 3c00 007e 0204 0810 1000 |
|
111 |
- 003c 423c 4242 3c00 003c 4242 3e02 3c00 0000 0008 0000 0800 0000 0800 0008 0810 |
|
112 |
- 0000 0810 2010 0800 0000 003e 003e 0000 0000 1008 0408 1000 003c 4202 0c00 0800 |
|
113 |
- 003c 425a 5442 3c00 0018 2442 7e42 4200 007c 427c 4242 7c00 003c 4240 4042 3c00 |
|
114 |
- 0078 4442 4244 7800 007e 407c 4040 7e00 003e 4040 7c40 4000 003c 4240 4e42 3c00 |
|
115 |
- 0042 427e 4242 4200 003e 0808 0808 3e00 0002 0202 4242 3c00 0044 4870 4844 4200 |
|
116 |
- 0040 4040 4040 7e00 0042 665a 4242 4200 0042 6252 4a46 4200 003c 4242 4242 3c00 |
|
117 |
- 007c 4242 7c40 4000 003c 4242 524a 3c00 007c 4242 7c44 4200 003c 403c 0242 3c00 |
|
118 |
- 00fe 1010 1010 1000 0042 4242 4242 3c00 0042 4242 4224 1800 0042 4242 5a66 4200 |
|
119 |
- 0042 2418 1824 4200 0082 4428 1010 1000 007e 0408 1020 7e00 000c 0808 0808 0c00 |
|
120 |
- 0040 2010 0804 0200 0018 0808 0808 1800 0008 1422 0000 0000 0000 0000 0000 7e00 |
|
121 |
- 0008 0400 0000 0000 0000 1c02 1e22 1e00 0020 203c 2222 3c00 0000 1e20 2020 1e00 |
|
122 |
- 0002 021e 2222 1e00 0000 1c22 3c20 1e00 000c 101c 1010 1000 0000 1c22 221e 021c |
|
123 |
- 0020 202c 3222 2200 0008 0018 0808 0400 0008 0008 0808 4830 0020 2428 3028 2400 |
|
124 |
- 0010 1010 1010 0c00 0000 6854 5454 5400 0000 5864 4444 4400 0000 3844 4444 3800 |
|
125 |
- 0000 7844 4478 4040 0000 3c44 443c 0406 0000 2c30 2020 2000 0000 3840 3804 7800 |
|
126 |
- 0010 103c 1010 0c00 0000 4444 4444 3800 0000 4444 2828 1000 0000 4454 5454 2800 |
|
127 |
- 0000 4428 1028 4400 0000 4444 443c 0438 0000 7c08 1020 7c00 000c 0810 1008 0c00 |
|
128 |
- 0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c |
|
129 |
-] |
|
130 |
- |
|
131 |
-@filename "hello.txt 00 |
|
132 |
-@contents |
|
133 |
- |
134 | 0 |
deleted file mode 100644 |
... | ... |
@@ -1,41 +0,0 @@ |
1 |
-( simple Dev/File writing example ) |
|
2 |
- |
|
3 |
-( devices ) |
|
4 |
- |
|
5 |
-|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] |
|
6 |
-|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] |
|
7 |
- |
|
8 |
-( variables ) |
|
9 |
- |
|
10 |
-|0000 |
|
11 |
- |
|
12 |
-( init ) |
|
13 |
- |
|
14 |
-|0100 ( -> ) |
|
15 |
- ;try-save JSR2 |
|
16 |
- BRK |
|
17 |
- |
|
18 |
-@try-save ( -- ) |
|
19 |
- ( save contents to file ) |
|
20 |
- ;contents/end ;contents SUB2 .File/length DEO2 |
|
21 |
- ;filename .File/name DEO2 |
|
22 |
- ;contents .File/write DEO2 |
|
23 |
- |
|
24 |
- .File/success DEI2 ORA ,&success JCN |
|
25 |
- ( failed to write: bright yellow background ) |
|
26 |
- #f0f7 .System/r DEO2 |
|
27 |
- #f0f7 .System/g DEO2 |
|
28 |
- #00f7 .System/b DEO2 |
|
29 |
- JMP2r |
|
30 |
- |
|
31 |
- &success |
|
32 |
- ( write successful: dark blue background ) |
|
33 |
- #00f7 .System/r DEO2 |
|
34 |
- #00f7 .System/g DEO2 |
|
35 |
- #40f7 .System/b DEO2 |
|
36 |
- JMP2r |
|
37 |
- |
|
38 |
-@filename "hello.txt 00 |
|
39 |
-@contents "Hello 20 "world, 0a "how 20 "are 20 "you? 0a |
|
40 |
- &end |
|
41 |
- |
... | ... |
@@ -1,78 +1,92 @@ |
1 |
-( Dev/File ) |
|
1 |
+( File: |
|
2 |
+ Creates a temporary file called file-output.txt, |
|
3 |
+ then read it back in console, print length and delete it. ) |
|
2 | 4 |
|
3 |
-%8+ { #0008 ADD2 } |
|
4 |
-%MEMORY { #1000 } |
|
5 |
+|a0 @File0 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 |
|
6 |
+|b0 @File1 &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 |
|
5 | 7 |
|
6 |
-( devices ) |
|
8 |
+|0100 ( -> ) |
|
7 | 9 |
|
8 |
-|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ] |
|
9 |
-|10 @Console [ &pad $8 &write $1 ] |
|
10 |
-|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] |
|
11 |
-|a0 @File [ &vector $2 &success $2 &stat $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2 ] |
|
10 |
+ ( write a file with file0 ) |
|
11 |
+ ;filepath-txt .File0/name DEO2 |
|
12 |
+ ;part1 ,append JSR |
|
13 |
+ ;part2 ,append JSR |
|
14 |
+ ( read a file with file1 ) |
|
15 |
+ ;filepath-txt .File1/name DEO2 |
|
16 |
+ ,stream JSR |
|
17 |
+ ( delete file with file0 ) |
|
18 |
+ ;filepath-txt .File0/delete DEO2 |
|
12 | 19 |
|
13 |
-( variables ) |
|
20 |
+BRK |
|
14 | 21 |
|
15 |
-|0000 |
|
22 |
+@append ( part* -- ) |
|
16 | 23 |
|
17 |
-( init ) |
|
24 |
+ DUP2 ;print-str JSR2 |
|
25 |
+ DUP2 ;slen JSR2 STH2k .File0/length DEO2 |
|
26 |
+ .File0/write DEO2 |
|
27 |
+ ( print result ) |
|
28 |
+ ;saved-txt ;print-str JSR2 |
|
29 |
+ STH2r ;print JSR2 #2018 DEO |
|
30 |
+ ;bytes-txt ;print-str JSR2 #0a18 DEO |
|
18 | 31 |
|
19 |
-|0100 ( -> ) |
|
32 |
+JMP2r |
|
20 | 33 |
|
21 |
- ( theme ) |
|
22 |
- #0efc .System/r DEO2 |
|
23 |
- #03cc .System/g DEO2 |
|
24 |
- #03ac .System/b DEO2 |
|
34 |
+@stream ( -- ) |
|
25 | 35 |
|
26 |
- ( load file ) |
|
27 |
- #1000 .File/length DEO2 |
|
28 |
- ;srcpath .File/name DEO2 |
|
29 |
- MEMORY .File/read DEO2 |
|
36 |
+ #0001 .File1/length DEO2 |
|
37 |
+ LIT2r 0000 |
|
38 |
+ &stream |
|
39 |
+ ;&buf DUP2 .File1/read DEO2 LDA #18 DEO INC2r |
|
40 |
+ .File1/success DEI2 #0000 NEQ2 ,&stream JCN |
|
41 |
+ ( print result ) |
|
42 |
+ ;loaded-txt ;print-str JSR2 |
|
43 |
+ STH2r ;print JSR2 #2018 DEO |
|
44 |
+ ;bytes-txt ;print-str JSR2 #0a18 DEO |
|
30 | 45 |
|
31 |
- .File/success DEI2 ORA ;on-success JCN2 |
|
46 |
+JMP2r |
|
47 |
+ &buf $1 |
|
32 | 48 |
|
33 |
- ;failedtxt ;print-string JSR2 |
|
49 |
+@slen ( str* -- len* ) |
|
34 | 50 |
|
35 |
-BRK |
|
51 |
+ DUP2 ,scap JSR SWP2 SUB2 |
|
36 | 52 |
|
37 |
-@on-success ( -> ) |
|
38 |
- |
|
39 |
- ;successtxt ;print-string JSR2 |
|
40 |
- |
|
41 |
- ( draw image ) |
|
42 |
- MEMORY .Screen/addr DEO2 |
|
43 |
- #0000 #0080 |
|
44 |
- &ver |
|
45 |
- ( save ) OVR2 .Screen/y DEO2 |
|
46 |
- #0000 #0080 |
|
47 |
- &hor |
|
48 |
- ( save ) OVR2 .Screen/x DEO2 |
|
49 |
- ( draw ) #81 .Screen/sprite DEO |
|
50 |
- ( incr ) .Screen/addr DEI2 #0010 ADD2 .Screen/addr DEO2 |
|
51 |
- ( incr ) SWP2 8+ SWP2 |
|
52 |
- LTH2k ,&hor JCN |
|
53 |
- POP2 POP2 |
|
54 |
- ( incr ) SWP2 8+ SWP2 |
|
55 |
- LTH2k ,&ver JCN |
|
56 |
- POP2 POP2 |
|
57 |
- |
|
58 |
- ( save file ) |
|
59 |
- #1000 .File/length DEO2 |
|
60 |
- ;dstpath .File/name DEO2 |
|
61 |
- MEMORY .File/write DEO2 |
|
53 |
+JMP2r |
|
62 | 54 |
|
63 |
-BRK |
|
55 |
+@scap ( str* -- end* ) |
|
56 |
+ |
|
57 |
+ LDAk #00 NEQ JMP JMP2r |
|
58 |
+ &while INC2 LDAk ,&while JCN |
|
59 |
+ |
|
60 |
+JMP2r |
|
61 |
+ |
|
62 |
+@print ( short* -- ) |
|
63 |
+ |
|
64 |
+ &short ( short* -- ) SWP ,&byte JSR |
|
65 |
+ &byte ( byte -- ) DUP #04 SFT ,&char JSR |
|
66 |
+ &char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO |
|
67 |
+ |
|
68 |
+JMP2r |
|
69 |
+ |
|
70 |
+@print-str ( str* -- ) |
|
71 |
+ |
|
72 |
+ &while |
|
73 |
+ LDAk #18 DEO |
|
74 |
+ INC2 LDAk ,&while JCN |
|
75 |
+ POP2 |
|
64 | 76 |
|
65 |
-@print-string ( ptr* -- ) |
|
66 |
- LDAk DUP ,&keep-going JCN |
|
67 |
- POP POP2 JMP2r |
|
77 |
+JMP2r |
|
68 | 78 |
|
69 |
- &keep-going |
|
70 |
- .Console/write DEO |
|
71 |
- INC2 |
|
72 |
- ,print-string JMP |
|
79 |
+@saved-txt "Saved 20 $1 |
|
80 |
+@loaded-txt "Loaded 20 $1 |
|
81 |
+@bytes-txt "bytes. $1 |
|
82 |
+@filepath-txt "file-output.txt $1 |
|
73 | 83 |
|
74 |
-@successtxt "Success! 09 $1 |
|
75 |
-@failedtxt "Failed. 09 $1 |
|
84 |
+@part1 |
|
85 |
+ 476f 6420 6865 6c70 2074 6865 2064 7265 |
|
86 |
+ 616d 6572 2077 686f 7365 206d 6164 2076 |
|
87 |
+ 6973 696f 6e73 2073 6865 770a 00 |
|
76 | 88 |
|
77 |
-@srcpath "projects/pictures/ako10x10.chr $1 |
|
78 |
-@dstpath "bin/image-copy.chr $1 |
|
89 |
+@part2 |
|
90 |
+ 5468 6f73 6520 6465 6164 2065 7965 7320 |
|
91 |
+ 7365 7420 696e 2063 7279 7374 616c 2067 |
|
92 |
+ 756c 6673 2062 656c 6f77 210a 00 |
... | ... |
@@ -1,4 +1,5 @@ |
1 |
-( Screen ) |
|
1 |
+( Screen: |
|
2 |
+ Draws a table of all possible sprite arrangements. ) |
|
2 | 3 |
|
3 | 4 |
|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 |
4 | 5 |
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 |