1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,287 @@ |
1 |
+( Copy of demos/life.tal, but with in infinite loop in the Screen vector ) |
|
2 |
+ |
|
3 |
+( Game Of Life: |
|
4 |
+ Any live cell with fewer than two live neighbours dies, as if by underpopulation. |
|
5 |
+ Any live cell with two or three live neighbours lives on to the next generation. |
|
6 |
+ Any live cell with more than three live neighbours dies, as if by overpopulation. |
|
7 |
+ Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. ) |
|
8 |
+ |
|
9 |
+|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 |
|
10 |
+|10 @Console &vector $2 &read $1 &pad $5 &write $1 &error $1 |
|
11 |
+|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 |
|
12 |
+|30 @Audio0 &vector $2 &position $2 &output $1 &pad $3 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 |
|
13 |
+|80 @Controller &vector $2 &button $1 &key $1 |
|
14 |
+|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &wheel $1 |
|
15 |
+ |
|
16 |
+|0000 |
|
17 |
+ |
|
18 |
+@world &frame $1 &count $2 |
|
19 |
+@anchor &x $2 &y $2 &x2 $2 &y2 $2 |
|
20 |
+@pointer &x $2 &y $2 |
|
21 |
+ |
|
22 |
+|0100 ( -> ) |
|
23 |
+ |
|
24 |
+ ( theme ) |
|
25 |
+ #02cf .System/r DEO2 |
|
26 |
+ #02ff .System/g DEO2 |
|
27 |
+ #024f .System/b DEO2 |
|
28 |
+ ( resize ) |
|
29 |
+ #00c0 .Screen/width DEO2 |
|
30 |
+ #00c0 .Screen/height DEO2 |
|
31 |
+ ( vectors ) |
|
32 |
+ ;on-frame .Screen/vector DEO2 |
|
33 |
+ ;on-mouse .Mouse/vector DEO2 |
|
34 |
+ ;on-control .Controller/vector DEO2 |
|
35 |
+ ( glider ) |
|
36 |
+ #07 #03 ;set-cell JSR2 |
|
37 |
+ #07 #04 ;set-cell JSR2 |
|
38 |
+ #05 #04 ;set-cell JSR2 |
|
39 |
+ #07 #05 ;set-cell JSR2 |
|
40 |
+ #06 #05 ;set-cell JSR2 |
|
41 |
+ ( center ) |
|
42 |
+ .Screen/width DEI2 #01 SFT2 #0040 SUB2 |
|
43 |
+ DUP2 .anchor/x STZ2 |
|
44 |
+ #007e ADD2 .anchor/x2 STZ2 |
|
45 |
+ .Screen/height DEI2 #01 SFT2 #0040 SUB2 |
|
46 |
+ DUP2 .anchor/y STZ2 |
|
47 |
+ #007e ADD2 .anchor/y2 STZ2 |
|
48 |
+ |
|
49 |
+BRK |
|
50 |
+ |
|
51 |
+@on-frame ( -> ) |
|
52 |
+ ( Because an interrupted infinite loop will (almost certainly) leave |
|
53 |
+ items on the stacks, clear both stacks here. ) |
|
54 |
+ #00 .System/wst DEO |
|
55 |
+ #00 .System/rst DEO |
|
56 |
+ |
|
57 |
+ .Mouse/state DEI #00 EQU #01 JCN [ BRK ] |
|
58 |
+ #0000 .world/count STZ2 |
|
59 |
+ .world/frame LDZ INC |
|
60 |
+ DUP .world/frame STZ |
|
61 |
+ #03 AND #00 EQU #01 JCN [ BRK ] |
|
62 |
+ &infinite-loop |
|
63 |
+ ;run JSR2 |
|
64 |
+ ,&infinite-loop JMP |
|
65 |
+ &paused |
|
66 |
+ |
|
67 |
+BRK |
|
68 |
+ |
|
69 |
+@on-mouse ( -> ) |
|
70 |
+ |
|
71 |
+ ( clear last cursor ) |
|
72 |
+ ;cursor .Screen/addr DEO2 |
|
73 |
+ .pointer/x LDZ2 .Screen/x DEO2 |
|
74 |
+ .pointer/y LDZ2 .Screen/y DEO2 |
|
75 |
+ #40 .Screen/sprite DEO |
|
76 |
+ ( record pointer positions ) |
|
77 |
+ .Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2 |
|
78 |
+ .Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2 |
|
79 |
+ ( colorize on state ) |
|
80 |
+ #42 [ .Mouse/state DEI #00 NEQ ] ADD .Screen/sprite DEO |
|
81 |
+ ( on touch in rect ) |
|
82 |
+ .Mouse/state DEI #00 NEQ #01 JCN [ BRK ] |
|
83 |
+ .Mouse/x DEI2 .Mouse/y DEI2 .anchor ;within-rect JSR2 JMP [ BRK ] |
|
84 |
+ ( paint ) |
|
85 |
+ .Mouse/x DEI2 .anchor/x LDZ2 SUB2 #01 SFT NIP |
|
86 |
+ .Mouse/y DEI2 .anchor/y LDZ2 SUB2 #01 SFT NIP |
|
87 |
+ ;set-cell JSR2 |
|
88 |
+ ( draw ) |
|
89 |
+ ;draw-grid JSR2 |
|
90 |
+ |
|
91 |
+BRK |
|
92 |
+ |
|
93 |
+@on-control ( -> ) |
|
94 |
+ |
|
95 |
+ ( toggle play ) |
|
96 |
+ .Controller/key DEI #20 NEQ ,&no-toggle JCN |
|
97 |
+ ;on-frame |
|
98 |
+ .Screen/vector DEI2 ;on-frame/paused EQU2 ,&swap JCN |
|
99 |
+ POP2 ;on-frame/paused |
|
100 |
+ &swap |
|
101 |
+ .Screen/vector DEO2 |
|
102 |
+ &no-toggle |
|
103 |
+ ( clear on home ) |
|
104 |
+ .Controller/button DEI #08 NEQ ,&no-reset JCN |
|
105 |
+ ;bank1 #0400 ;mclr JSR2 |
|
106 |
+ &no-reset |
|
107 |
+ |
|
108 |
+BRK |
|
109 |
+ |
|
110 |
+@run ( -- ) |
|
111 |
+ |
|
112 |
+ ( clear buffer ) |
|
113 |
+ ;bank2 #1000 ;mclr JSR2 |
|
114 |
+ ( run grid ) |
|
115 |
+ #4000 |
|
116 |
+ &ver |
|
117 |
+ STHk |
|
118 |
+ #4000 |
|
119 |
+ &hor |
|
120 |
+ DUP STHkr ,run-cell JSR |
|
121 |
+ INC GTHk ,&hor JCN |
|
122 |
+ POP2 |
|
123 |
+ POPr |
|
124 |
+ INC GTHk ,&ver JCN |
|
125 |
+ POP2 |
|
126 |
+ ( move buffer ) |
|
127 |
+ ;bank2 ;bank1 #1000 ;mcpy JSR2 |
|
128 |
+ ( draw ) |
|
129 |
+ ;draw-grid JSR2 |
|
130 |
+ |
|
131 |
+JMP2r |
|
132 |
+ |
|
133 |
+@run-cell ( x y -- ) |
|
134 |
+ |
|
135 |
+ ( x y ) DUP2 |
|
136 |
+ ( neighbours ) DUP2 ;get-neighbours JSR2 |
|
137 |
+ ( state ) ROT ROT ;get-cell JSR2 |
|
138 |
+ #00 EQU ,&dead JCN |
|
139 |
+ DUP #02 LTH ,&dies JCN |
|
140 |
+ DUP #03 GTH ,&dies JCN |
|
141 |
+ POP ,&save JSR JMP2r |
|
142 |
+ &dies POP POP2 JMP2r |
|
143 |
+ &dead |
|
144 |
+ DUP #03 EQU ,&birth JCN POP POP2 JMP2r |
|
145 |
+ &birth POP ,&save JSR JMP2r |
|
146 |
+ |
|
147 |
+JMP2r |
|
148 |
+ &save ( x y -- ) |
|
149 |
+ STH2 #01 STH2r ,get-index JSR [ #1000 ADD2 ] STA |
|
150 |
+ .world/count LDZ2 INC2 .world/count STZ2 |
|
151 |
+ JMP2r |
|
152 |
+ |
|
153 |
+@get-index ( x y -- index* ) |
|
154 |
+ |
|
155 |
+ ( y ) #3f AND #00 SWP #60 SFT2 |
|
156 |
+ ( x ) ROT #3f AND #00 SWP ADD2 |
|
157 |
+ ;bank1 ADD2 |
|
158 |
+ |
|
159 |
+JMP2r |
|
160 |
+ |
|
161 |
+@set-cell ( x y -- ) |
|
162 |
+ |
|
163 |
+ STH2 #01 STH2r ,get-index JSR STA |
|
164 |
+ |
|
165 |
+JMP2r |
|
166 |
+ |
|
167 |
+@get-cell ( x y -- cell ) |
|
168 |
+ |
|
169 |
+ ,get-index JSR LDA |
|
170 |
+ |
|
171 |
+JMP2r |
|
172 |
+ |
|
173 |
+@get-neighbours ( x y -- neighbours ) |
|
174 |
+ |
|
175 |
+ ,&origin STR2 |
|
176 |
+ LITr 00 |
|
177 |
+ #0800 |
|
178 |
+ &loop |
|
179 |
+ #00 OVR #10 SFT2 ;&mask ADD2 LDA2 [ LIT2 &origin $2 ] |
|
180 |
+ ROT ADD STH ADD STHr ;get-cell JSR2 STH ADDr |
|
181 |
+ INC GTHk ,&loop JCN |
|
182 |
+ POP2 |
|
183 |
+ STHr |
|
184 |
+ |
|
185 |
+JMP2r |
|
186 |
+ &mask ffff 00ff 01ff ff00 0100 ff01 0001 0101 |
|
187 |
+ |
|
188 |
+@draw-grid ( -- ) |
|
189 |
+ |
|
190 |
+ ( draw cell count ) |
|
191 |
+ .anchor/x LDZ2 .Screen/x DEO2 |
|
192 |
+ .anchor/y2 LDZ2 #0008 ADD2 .Screen/y DEO2 |
|
193 |
+ #01 .Screen/auto DEO |
|
194 |
+ .world/count LDZ2 ;draw-short JSR2 |
|
195 |
+ #00 .Screen/auto DEO |
|
196 |
+ #4000 |
|
197 |
+ &ver |
|
198 |
+ #00 OVR #10 SFT2 .anchor/y LDZ2 ADD2 .Screen/y DEO2 |
|
199 |
+ STHk |
|
200 |
+ #4000 |
|
201 |
+ &hor |
|
202 |
+ #00 OVR #10 SFT2 .anchor/x LDZ2 ADD2 .Screen/x DEO2 |
|
203 |
+ DUP STHkr ;get-cell JSR2 INC .Screen/pixel DEO |
|
204 |
+ INC GTHk ,&hor JCN |
|
205 |
+ POP2 |
|
206 |
+ POPr |
|
207 |
+ INC GTHk ,&ver JCN |
|
208 |
+ POP2 |
|
209 |
+ |
|
210 |
+JMP2r |
|
211 |
+ |
|
212 |
+@draw-short ( short* -- ) |
|
213 |
+ |
|
214 |
+ SWP ,draw-byte JSR |
|
215 |
+ |
|
216 |
+@draw-byte ( byte color -- ) |
|
217 |
+ |
|
218 |
+ DUP #04 SFT ,draw-hex JSR #0f AND |
|
219 |
+ |
|
220 |
+@draw-hex ( char color -- ) |
|
221 |
+ |
|
222 |
+ #00 SWP #30 SFT2 ;font-hex ADD2 .Screen/addr DEO2 |
|
223 |
+ #03 .Screen/sprite DEO |
|
224 |
+ |
|
225 |
+JMP2r |
|
226 |
+ |
|
227 |
+@within-rect ( x* y* rect -- flag ) |
|
228 |
+ |
|
229 |
+ STH |
|
230 |
+ ( y < rect.y1 ) DUP2 STHkr #02 ADD LDZ2 LTH2 ,&skip JCN |
|
231 |
+ ( y > rect.y2 ) DUP2 STHkr #06 ADD LDZ2 GTH2 ,&skip JCN |
|
232 |
+ SWP2 |
|
233 |
+ ( x < rect.x1 ) DUP2 STHkr LDZ2 LTH2 ,&skip JCN |
|
234 |
+ ( x > rect.x2 ) DUP2 STHkr #04 ADD LDZ2 GTH2 ,&skip JCN |
|
235 |
+ POP2 POP2 POPr |
|
236 |
+ #01 |
|
237 |
+JMP2r |
|
238 |
+ &skip |
|
239 |
+ POP2 POP2 POPr |
|
240 |
+ #00 |
|
241 |
+ |
|
242 |
+JMP2r |
|
243 |
+ |
|
244 |
+@mclr ( addr* len* -- ) |
|
245 |
+ |
|
246 |
+ OVR2 ADD2 SWP2 |
|
247 |
+ &loop |
|
248 |
+ STH2k #00 STH2r STA |
|
249 |
+ INC2 GTH2k ,&loop JCN |
|
250 |
+ POP2 POP2 |
|
251 |
+ |
|
252 |
+JMP2r |
|
253 |
+ |
|
254 |
+@mcpy ( src* dst* len* -- ) |
|
255 |
+ |
|
256 |
+ SWP2 STH2 |
|
257 |
+ OVR2 ADD2 SWP2 |
|
258 |
+ &loop |
|
259 |
+ LDAk STH2kr STA INC2r |
|
260 |
+ INC2 GTH2k ,&loop JCN |
|
261 |
+ POP2 POP2 |
|
262 |
+ POP2r |
|
263 |
+ |
|
264 |
+JMP2r |
|
265 |
+ |
|
266 |
+@cursor |
|
267 |
+ 80c0 e0f0 f8e0 1000 |
|
268 |
+ |
|
269 |
+@font-hex |
|
270 |
+ 7c82 8282 8282 7c00 |
|
271 |
+ 3010 1010 1010 3800 |
|
272 |
+ 7c82 027c 8080 fe00 |
|
273 |
+ 7c82 021c 0282 7c00 |
|
274 |
+ 2242 82fe 0202 0200 |
|
275 |
+ fe80 807c 0282 7c00 |
|
276 |
+ 7c82 80fc 8282 7c00 |
|
277 |
+ fe82 0408 0810 1000 |
|
278 |
+ 7c82 827c 8282 7c00 |
|
279 |
+ 7c82 827e 0202 0200 |
|
280 |
+ 7c82 82fe 8282 8200 |
|
281 |
+ fc82 82fc 8282 fc00 |
|
282 |
+ 7c82 8080 8082 7c00 |
|
283 |
+ fc82 8282 8282 fc00 |
|
284 |
+ fe80 80f0 8080 fe00 |
|
285 |
+ fe80 80f0 8080 8000 |
|
286 |
+ |
|
287 |
+@bank1 $1000 @bank2 |