1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,286 @@ |
1 |
+( a simple calculator ) |
|
2 |
+ |
|
3 |
+%+ { ADD } %- { SUB } %/ { DIV } |
|
4 |
+%< { LTH } %> { GTH } %= { EQU } %! { NEQ } |
|
5 |
+%++ { ADD2 } %-- { SUB2 } %// { DIV2 } |
|
6 |
+%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 } |
|
7 |
+ |
|
8 |
+%4/ { #02 SFT } |
|
9 |
+%2** { #10 SFT2 } %2// { #01 SFT2 } |
|
10 |
+%8** { #30 SFT2 } %8// { #03 SFT2 } |
|
11 |
+%10** { #40 SFT2 } |
|
12 |
+ |
|
13 |
+%4MOD { #03 AND } |
|
14 |
+ |
|
15 |
+%DEBUG { ;print-hex/byte JSR2 #0a .Console/write DEO } |
|
16 |
+%DEBUG2 { ;print-hex/short JSR2 #0a .Console/write DEO } |
|
17 |
+ |
|
18 |
+%RTN { JMP2r } |
|
19 |
+%SWP2? { #01 JCN SWP2 } |
|
20 |
+%BRK? { #01 JCN BRK } |
|
21 |
+%TOS { #00 SWP } |
|
22 |
+ |
|
23 |
+( devices ) |
|
24 |
+ |
|
25 |
+|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ] |
|
26 |
+|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ] |
|
27 |
+|20 @Screen [ &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ] |
|
28 |
+|30 @Audio0 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] |
|
29 |
+|40 @Audio1 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] |
|
30 |
+|50 @Audio2 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] |
|
31 |
+|60 @Audio3 [ &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ] |
|
32 |
+|80 @Controller [ &vector $2 &button $1 &key $1 ] |
|
33 |
+|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] |
|
34 |
+|a0 @File [ &vector $2 &success $2 &offset-hs $2 &offset-ls $2 &name $2 &length $2 &load $2 &save $2 ] |
|
35 |
+|b0 @DateTime [ &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 ] |
|
36 |
+ |
|
37 |
+( variables ) |
|
38 |
+ |
|
39 |
+|0000 |
|
40 |
+ |
|
41 |
+@center |
|
42 |
+ &x $2 &y $2 |
|
43 |
+@rect |
|
44 |
+ &x1 $2 &y1 $2 &x2 $2 &y2 $2 |
|
45 |
+@pointer |
|
46 |
+ &x $2 &y $2 &lastx $2 &lasty $2 &state $1 |
|
47 |
+@keypad-frame |
|
48 |
+ &x $2 &y $2 &x2 $2 &y2 $2 |
|
49 |
+@modpad-frame |
|
50 |
+ &x $2 &y $2 |
|
51 |
+ |
|
52 |
+( program ) |
|
53 |
+ |
|
54 |
+|0100 ( -> ) |
|
55 |
+ |
|
56 |
+ ( theme ) |
|
57 |
+ #0fef .System/r DEO2 |
|
58 |
+ #0fc5 .System/g DEO2 |
|
59 |
+ #0f25 .System/b DEO2 |
|
60 |
+ |
|
61 |
+ ( center ) |
|
62 |
+ .Screen/width DEI2 2// .center/x STZ2 |
|
63 |
+ .Screen/height DEI2 2// .center/y STZ2 |
|
64 |
+ |
|
65 |
+ .center/x LDZ2 #0028 -- |
|
66 |
+ DUP2 .keypad-frame/x STZ2 |
|
67 |
+ #0040 ++ .keypad-frame/x2 STZ2 |
|
68 |
+ .center/y LDZ2 #0020 -- |
|
69 |
+ DUP2 .keypad-frame/y STZ2 |
|
70 |
+ #0040 ++ .keypad-frame/y2 STZ2 |
|
71 |
+ |
|
72 |
+ .keypad-frame/x LDZ2 #0040 ++ .modpad-frame/x STZ2 |
|
73 |
+ .keypad-frame/y LDZ2 .modpad-frame/y STZ2 |
|
74 |
+ |
|
75 |
+ ;on-mouse .Mouse/vector DEO2 |
|
76 |
+ |
|
77 |
+ ;redraw JSR2 |
|
78 |
+ |
|
79 |
+BRK |
|
80 |
+ |
|
81 |
+@on-mouse ( -> ) |
|
82 |
+ |
|
83 |
+ ;pointer_icn .Screen/addr DEO2 |
|
84 |
+ ( clear last cursor ) |
|
85 |
+ .pointer/x LDZ2 .Screen/x DEO2 |
|
86 |
+ .pointer/y LDZ2 .Screen/y DEO2 |
|
87 |
+ #40 .Screen/sprite DEO |
|
88 |
+ |
|
89 |
+ ( record pointer positions ) |
|
90 |
+ .Mouse/x DEI2 .pointer/x STZ2 |
|
91 |
+ .Mouse/y DEI2 .pointer/y STZ2 |
|
92 |
+ |
|
93 |
+ ( draw new cursor ) |
|
94 |
+ .pointer/x LDZ2 .Screen/x DEO2 |
|
95 |
+ .pointer/y LDZ2 .Screen/y DEO2 |
|
96 |
+ #41 .Mouse/state DEI #01 = + .Screen/sprite DEO |
|
97 |
+ |
|
98 |
+ .Mouse/state DEI BRK? |
|
99 |
+ |
|
100 |
+ .Mouse/x DEI2 |
|
101 |
+ .Mouse/y DEI2 |
|
102 |
+ .keypad-frame |
|
103 |
+ ;within-rect JSR2 ;click-keypad JCN2 |
|
104 |
+ |
|
105 |
+BRK |
|
106 |
+ |
|
107 |
+@click-keypad ( -> ) |
|
108 |
+ |
|
109 |
+ #00 .Mouse/state DEO |
|
110 |
+ #aa DEBUG |
|
111 |
+ |
|
112 |
+BRK |
|
113 |
+ |
|
114 |
+@redraw ( -- ) |
|
115 |
+ |
|
116 |
+ ;draw-keypad JSR2 |
|
117 |
+ ;draw-modpad JSR2 |
|
118 |
+ |
|
119 |
+RTN |
|
120 |
+ |
|
121 |
+@draw-keypad ( -- ) |
|
122 |
+ |
|
123 |
+ ( auto x addr ) #05 .Screen/auto DEO |
|
124 |
+ #10 #00 |
|
125 |
+ &loop |
|
126 |
+ ( color ) DUP TOS ;keypad/color ++ LDA STH |
|
127 |
+ ( layout ) DUP TOS ;keypad/layout ++ LDA |
|
128 |
+ ( layout addr ) TOS 8** ;font-hex ++ STH2 |
|
129 |
+ ( x ) DUP 4MOD TOS 10** STH2 |
|
130 |
+ ( y ) DUP 4/ TOS 10** |
|
131 |
+ ( origin-x ) STH2r .keypad-frame/x LDZ2 ++ SWP2 |
|
132 |
+ ( origin-y ) .keypad-frame/y LDZ2 ++ |
|
133 |
+ STH2r STHr ;draw-key JSR2 |
|
134 |
+ INC GTHk ,&loop JCN |
|
135 |
+ POP2 |
|
136 |
+ ( auto none ) #00 .Screen/auto DEO |
|
137 |
+ |
|
138 |
+RTN |
|
139 |
+ |
|
140 |
+@draw-modpad ( -- ) |
|
141 |
+ |
|
142 |
+ ( auto x addr ) #05 .Screen/auto DEO |
|
143 |
+ #04 #00 |
|
144 |
+ &loop |
|
145 |
+ ( color ) DUP TOS ;modpad/color ++ LDA STH |
|
146 |
+ ( layout ) DUP TOS 8** ;mod-icns ++ STH2 |
|
147 |
+ ( x ) #0000 STH2 |
|
148 |
+ ( y ) DUP TOS 10** |
|
149 |
+ ( origin-x ) STH2r .modpad-frame/x LDZ2 ++ SWP2 |
|
150 |
+ ( origin-y ) .modpad-frame/y LDZ2 ++ |
|
151 |
+ STH2r STHr ;draw-key JSR2 |
|
152 |
+ INC GTHk ,&loop JCN |
|
153 |
+ POP2 |
|
154 |
+ ( auto none ) #00 .Screen/auto DEO |
|
155 |
+ |
|
156 |
+RTN |
|
157 |
+ |
|
158 |
+@draw-key ( x* y* glyph* color -- ) |
|
159 |
+ |
|
160 |
+ ( frame ) |
|
161 |
+ STH STH2 ROTr |
|
162 |
+ .Screen/y DEO2 |
|
163 |
+ .Screen/x DEO2 |
|
164 |
+ ;key-icns/bg .Screen/addr DEO2 |
|
165 |
+ STHkr .Screen/sprite DEO |
|
166 |
+ STHkr .Screen/sprite DEO |
|
167 |
+ .Screen/x DEI2 #0010 -- .Screen/x DEO2 |
|
168 |
+ .Screen/y DEI2 #0008 ++ .Screen/y DEO2 |
|
169 |
+ STHkr .Screen/sprite DEO |
|
170 |
+ STHkr .Screen/sprite DEO |
|
171 |
+ ( glyph ) |
|
172 |
+ ROTr ROTr STH2r .Screen/addr DEO2 |
|
173 |
+ .Screen/x DEI2 #000c -- .Screen/x DEO2 |
|
174 |
+ .Screen/y DEI2 #0005 -- .Screen/y DEO2 |
|
175 |
+ STHr #04 MUL .Screen/sprite DEO |
|
176 |
+ |
|
177 |
+RTN |
|
178 |
+ |
|
179 |
+@within-rect ( x* y* rect -- flag ) |
|
180 |
+ |
|
181 |
+ STH |
|
182 |
+ ( y < rect.y1 ) DUP2 STHkr #02 ADD LDZ2 LTH2 ,&skip JCN |
|
183 |
+ ( y > rect.y2 ) DUP2 STHkr #06 ADD LDZ2 GTH2 ,&skip JCN |
|
184 |
+ SWP2 |
|
185 |
+ ( x < rect.x1 ) DUP2 STHkr LDZ2 LTH2 ,&skip JCN |
|
186 |
+ ( x > rect.x2 ) DUP2 STHkr #04 ADD LDZ2 GTH2 ,&skip JCN |
|
187 |
+ POP2 POP2 POPr |
|
188 |
+ #01 |
|
189 |
+RTN |
|
190 |
+ &skip |
|
191 |
+ POP2 POP2 POPr |
|
192 |
+ #00 |
|
193 |
+ |
|
194 |
+RTN |
|
195 |
+ |
|
196 |
+@line-rect ( rect color -- ) |
|
197 |
+ |
|
198 |
+ STH STH |
|
199 |
+ ( y2 ) STHkr #06 + LDZ2 |
|
200 |
+ ( y1 ) STHkr #02 + LDZ2 #0001 -- ( flip sign ) GTH2k SWP2? |
|
201 |
+ &ver |
|
202 |
+ ( save ) DUP2 .Screen/y DEO2 |
|
203 |
+ ( x1 ) STHkr LDZ2 #0001 -- .Screen/x DEO2 |
|
204 |
+ OVRr STHr .Screen/pixel DEO |
|
205 |
+ ( x2 ) STHkr #04 + LDZ2 .Screen/x DEO2 |
|
206 |
+ OVRr STHr .Screen/pixel DEO |
|
207 |
+ ( incr ) |
|
208 |
+ INC2 GTH2k ,&ver JCN |
|
209 |
+ POP2 |
|
210 |
+ ( x2 ) STHkr #04 + LDZ2 |
|
211 |
+ ( x1 ) STHkr LDZ2 #0001 -- ( flip sign ) GTH2k SWP2? |
|
212 |
+ &hor |
|
213 |
+ ( save ) DUP2 .Screen/x DEO2 |
|
214 |
+ ( y1 ) STHkr #02 + LDZ2 #0001 -- .Screen/y DEO2 |
|
215 |
+ OVRr STHr .Screen/pixel DEO |
|
216 |
+ ( y2 ) STHkr #06 + LDZ2 .Screen/y DEO2 |
|
217 |
+ OVRr STHr .Screen/pixel DEO |
|
218 |
+ ( incr ) |
|
219 |
+ INC2 GTH2k ,&hor JCN |
|
220 |
+ POP2 |
|
221 |
+ POPr |
|
222 |
+ .Screen/x DEO2 |
|
223 |
+ .Screen/y DEO2 |
|
224 |
+ STHr .Screen/pixel DEO |
|
225 |
+ |
|
226 |
+RTN |
|
227 |
+ |
|
228 |
+@print-hex ( value* -- ) |
|
229 |
+ |
|
230 |
+ &short ( value* -- ) |
|
231 |
+ SWP ,&echo JSR |
|
232 |
+ &byte ( value -- ) |
|
233 |
+ ,&echo JSR |
|
234 |
+ RTN |
|
235 |
+ |
|
236 |
+ &echo ( value -- ) |
|
237 |
+ STHk #04 SFT ,&parse JSR .Console/write DEO |
|
238 |
+ STHr #0f AND ,&parse JSR .Console/write DEO |
|
239 |
+ RTN |
|
240 |
+ &parse ( value -- char ) |
|
241 |
+ DUP #09 GTH ,&above JCN #30 + RTN &above #09 - #60 + RTN |
|
242 |
+ |
|
243 |
+RTN |
|
244 |
+ |
|
245 |
+@keypad |
|
246 |
+ &layout |
|
247 |
+ 0708 090f |
|
248 |
+ 0405 060e |
|
249 |
+ 0102 030d |
|
250 |
+ 000a 0b0c |
|
251 |
+ &color |
|
252 |
+ 0101 0102 |
|
253 |
+ 0101 0102 |
|
254 |
+ 0101 0102 |
|
255 |
+ 0102 0202 |
|
256 |
+ |
|
257 |
+@modpad |
|
258 |
+ &color |
|
259 |
+ 0303 0303 |
|
260 |
+ 0303 0303 |
|
261 |
+ |
|
262 |
+@font-hex |
|
263 |
+ 007c 8282 8282 827c 0030 1010 1010 1010 |
|
264 |
+ 007c 8202 7c80 80fe 007c 8202 1c02 827c |
|
265 |
+ 000c 1424 4484 fe04 00fe 8080 7c02 827c |
|
266 |
+ 007c 8280 fc82 827c 007c 8202 1e02 0202 |
|
267 |
+ 007c 8282 7c82 827c 007c 8282 7e02 827c |
|
268 |
+ 007c 8202 7e82 827e 00fc 8282 fc82 82fc |
|
269 |
+ 007c 8280 8080 827c 00fc 8282 8282 82fc |
|
270 |
+ 007c 8280 f080 827c 007c 8280 f080 8080 |
|
271 |
+ |
|
272 |
+@mod-icns |
|
273 |
+ 0010 1010 fe10 1010 |
|
274 |
+ 0000 0000 fe00 0000 |
|
275 |
+ 0010 5428 c628 5410 |
|
276 |
+ 0010 0000 fe00 0010 |
|
277 |
+ |
|
278 |
+@key-icns |
|
279 |
+ &bg |
|
280 |
+ 3f7f ffff ffff ffff |
|
281 |
+ f8fc fefe fefe fefe |
|
282 |
+ ffff ffff ff7f 3f00 |
|
283 |
+ fefe fefe fefc f800 |
|
284 |
+ |
|
285 |
+@pointer_icn |
|
286 |
+ 80c0 e0f0 f8e0 1000 |