/[projet1]/public/oric/demos/AlchimieX/effect_game_of_life.s
Defence Force logotype

Contents of /public/oric/demos/AlchimieX/effect_game_of_life.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 970 - (show annotations)
Tue Nov 12 20:07:47 2013 UTC (5 years, 10 months ago) by dbug
File size: 5963 byte(s)
Source code for the AlchimieGarden demo
1
2 .zero
3
4 _ptr_buffer1 .dsb 2
5 _ptr_buffer2 .dsb 2
6
7 NeighbourCount .dsb 1
8
9
10 .text
11
12 #define GOL_WIDTH 32
13 #define GOL_HEIGHT 8 // 32*8=256...
14
15
16 _GOL_RedefineCharacters
17 .(
18 ldx #8*4
19 loop
20 lda GOL_Charset-1,x
21 sta $b400+36*8-1,x ; $
22 dex
23 bne loop
24 rts
25 .)
26
27
28 GOL_Charset
29 ; 2
30 .byt %000000
31 .byt %000000
32 .byt %000000
33 .byt %001100
34 .byt %001100
35 .byt %000000
36 .byt %000000
37 .byt %000000
38
39 ; 3
40 .byt %000000
41 .byt %000000
42 .byt %001100
43 .byt %011110
44 .byt %011110
45 .byt %001100
46 .byt %000000
47 .byt %000000
48
49 ; 4
50 .byt %000000
51 .byt %011100
52 .byt %111110
53 .byt %111110
54 .byt %111110
55 .byt %111110
56 .byt %011100
57 .byt %000000
58
59 ; 5
60 .byt %000000
61 .byt %011110
62 .byt %111111
63 .byt %111111
64 .byt %111111
65 .byt %111111
66 .byt %111111
67 .byt %011110
68
69
70
71
72 /*
73 unsigned char x,y;
74 unsigned char* screen;
75
76 unsigned char* ptr=ptr_buffer1;
77 screen=(unsigned char*)0xbb80+(40*4)+5;
78 for (y=0;y<GOL_HEIGHT;y++)
79 {
80 for (x=0;x<GOL_WIDTH;x++)
81 {
82 if (*ptr++)
83 {
84 screen[x]=32+4;
85 }
86 else
87 {
88 if (screen[x]>' ')
89 {
90 screen[x]--;
91 }
92 }
93 }
94 screen+=40;
95 }
96 */
97
98 ; #define GOL_WIDTH 32
99 ; #define GOL_HEIGHT 8
100 ; 32*8 => 256 bytes
101
102 _GOL_ShowBuffer
103 .(
104 lda _ptr_buffer1+0
105 sta tmp0+0
106 lda _ptr_buffer1+1
107 sta tmp0+1
108
109 lda #<$bb80+(40*11)+5
110 sta tmp1+0
111 lda #>$bb80+(40*11)+5
112 sta tmp1+1
113
114 lda #<$bb80+(40*27)+5
115 sta tmp2+0
116 lda #>$bb80+(40*27)+5
117 sta tmp2+1
118
119 ldx #GOL_HEIGHT
120 loop_y
121
122 ldy #0
123 loop_x
124 lda (tmp0),y
125 beq fade_out
126 new
127 lda #39
128 sta (tmp1),y
129 jmp end
130
131 fade_out
132 lda (tmp1),y
133 cmp #32
134 beq end
135 sec
136 sbc #1
137 cmp #35 ; the # is destroyed by the character redefinition, so we need to skip it
138 bne no_end
139 lda #32
140 no_end
141 sta (tmp1),y
142 sta (tmp2),y
143
144 end
145 iny
146 cpy #GOL_WIDTH
147 bne loop_x
148
149
150 .(
151 clc
152 lda tmp0+0
153 adc #32
154 sta tmp0+0
155 bcc skip
156 inc tmp0+1
157 skip
158 .)
159
160 .(
161 clc
162 lda tmp1+0
163 adc #40
164 sta tmp1+0
165 bcc skip
166 inc tmp1+1
167 skip
168 .)
169
170 .(
171 clc
172 lda tmp2+0
173 sbc #40
174 sta tmp2+0
175 lda tmp2+1
176 sbc #0
177 sta tmp2+1
178 skip
179 .)
180
181 dex
182 bne loop_y
183
184 rts
185 .)
186
187
188 NeighbourTable
189 .byt 0,1,31,32,33,223,224,225,255 ; Last value (backward) is the reference cell
190
191 _GOL_Evolve
192 ;jmp _GOL_Evolve_ASM
193 .(
194 lda _ptr_buffer1+0
195 sta __read_cell+1+0
196 lda _ptr_buffer1+1
197 sta __read_cell+1+1
198
199 ; Destination is automodified
200 lda _ptr_buffer2+0
201 sta __write_cell+1+0
202 lda _ptr_buffer2+1
203 sta __write_cell+1+1
204
205 loop_cell
206 lda #0
207 sta NeighbourCount
208
209 ldy #0
210 ldx #9
211 loop_neighbour
212 clc
213 lda __write_cell+1
214 adc NeighbourTable-1,x
215 tay
216 __read_cell
217 lda _GameOfLifeBuffer1,y
218 .(
219 beq skip
220 inc NeighbourCount
221 skip
222 .)
223 dex
224 bne loop_neighbour
225
226 ; A contains the state of the center cell
227 cmp #0
228 bne cell_is_alive
229
230 cell_is_dead
231 ; Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
232 lda NeighbourCount
233 cmp #3
234 beq new_cell
235 lda #0
236 jmp __write_cell
237
238 cell_is_alive
239 ; Any live cell with fewer than two live neighbours dies, as if caused by under-population.
240 ; Any live cell with two or three live neighbours lives on to the next generation.
241 ; Any live cell with more than three live neighbours dies, as if by overcrowding.
242 lda NeighbourCount ; This one includes the alive cell itself, so need to add one when testing
243 cmp #2+1
244 beq new_cell
245 cmp #3+1
246 beq new_cell
247 lda #0
248 jmp __write_cell
249
250 new_cell
251 lda #1
252
253 __write_cell
254 sta _GameOfLifeBuffer2
255
256 inc __write_cell+1
257 bne loop_cell
258
259 rts
260 .)
261
262
263 BlueRasters
264 .byt 16+0
265 .byt 16+0
266 .byt 16+0
267 .byt 16+4
268 .byt 16+0
269 .byt 16+0
270 .byt 16+4
271 .byt 16+4
272 .byt 16+0
273 .byt 16+4
274 .byt 16+4
275 .byt 16+4
276 .byt 16+6
277 .byt 16+4
278 .byt 16+4
279 .byt 16+6
280 .byt 16+6
281 .byt 16+4
282 .byt 16+6
283 .byt 16+6
284 .byt 16+6
285 .byt 16+7
286 .byt 16+6
287 .byt 16+6
288 .byt 16+7
289 .byt 16+7
290 .byt 16+6
291 .byt 16+7
292 .byt 16+7
293 .byt 16+7
294 .byt 16+6
295 .byt 16+7
296 .byt 16+7
297 .byt 16+6
298 .byt 16+6
299 .byt 16+7
300 .byt 16+6
301 .byt 16+6
302 .byt 16+6
303 .byt 16+4
304 .byt 16+6
305 .byt 16+6
306 .byt 16+4
307 .byt 16+4
308 .byt 16+6
309 .byt 16+4
310 .byt 16+4
311 .byt 16+4
312 .byt 16+0
313 .byt 16+4
314 .byt 16+4
315 .byt 16+0
316 .byt 16+0
317 .byt 16+4
318 .byt 16+0
319 .byt 16+0
320 .byt 16+0
321 .byt 16+0
322 .byt 16+0
323 .byt 16+0
324 .byt 16+0
325 .byt 16+0
326 .byt 16+0
327 .byt 16+0
328
329 RedRasters
330 .byt 5
331 .byt 5
332 .byt 5
333 .byt 1
334 .byt 5
335 .byt 5
336 .byt 1
337 .byt 1
338 .byt 5
339 .byt 1
340 .byt 1
341 .byt 1
342 .byt 3
343 .byt 1
344 .byt 1
345 .byt 3
346 .byt 3
347 .byt 1
348 .byt 3
349 .byt 3
350 .byt 3
351 .byt 2
352 .byt 3
353 .byt 3
354 .byt 2
355 .byt 2
356 .byt 3
357 .byt 2
358 .byt 2
359 .byt 2
360 .byt 3
361 .byt 2
362 .byt 2
363 .byt 3
364 .byt 3
365 .byt 2
366 .byt 3
367 .byt 3
368 .byt 3
369 .byt 1
370 .byt 3
371 .byt 3
372 .byt 1
373 .byt 1
374 .byt 3
375 .byt 1
376 .byt 1
377 .byt 1
378 .byt 5
379 .byt 1
380 .byt 1
381 .byt 5
382 .byt 5
383 .byt 1
384 .byt 5
385 .byt 5
386 .byt 5
387 .byt 5
388 .byt 5
389 .byt 5
390 .byt 5
391 .byt 5
392 .byt 5
393 .byt 5
394
395
396 BlueRastersPos
397 .byt 0
398
399 BlueRastersCurPos
400 .byt 0
401
402 RedRastersPos
403 .byt 0
404
405 RedRastersCurPos
406 .byt 0
407
408 _GOL_Rasters
409 .(
410 lda #<$a000+1+40*32
411 sta tmp0+0
412 lda #>$a000+1+40*32
413 sta tmp0+1
414
415 lda BlueRastersPos
416 inc BlueRastersPos
417 sta BlueRastersCurPos
418
419 lda RedRastersPos
420 dec RedRastersPos
421 sta RedRastersCurPos
422
423 ldx #64
424 loop
425 inc BlueRastersCurPos
426 lda BlueRastersCurPos
427 and #63
428 tay
429
430 lda BlueRasters,y
431 ldy #1
432 sta (tmp0),y
433
434 dec RedRastersCurPos
435 lda RedRastersCurPos
436 and #63
437 tay
438
439 lda RedRasters,y
440 ldy #0
441 sta (tmp0),y
442
443 .(
444 clc
445 lda tmp0+0
446 adc #40
447 sta tmp0+0
448 bcc skip
449 inc tmp0+1
450 skip
451 .)
452
453 dex
454 bne loop
455 rts
456 .)
457
458
459
460 .dsb 256-(*&255)
461 ; These two arrays MUST be alligned on a page boundary
462 _GameOfLifeBuffer1 .dsb GOL_WIDTH*GOL_HEIGHT
463 _GameOfLifeBuffer2 .dsb GOL_WIDTH*GOL_HEIGHT
464

  ViewVC Help
Powered by ViewVC 1.1.26