SHOW:
|
|
- or go back to the newest paste.
1 | lda #0 | |
2 | sta $0 | |
3 | lda #2 | |
4 | sta $1 | |
5 | ||
6 | lda #0 ;debug counter | |
7 | sta $11 | |
8 | lda #2 | |
9 | sta $12 | |
10 | ||
11 | ;==================================================== | |
12 | loopOne: | |
13 | lda $FE | |
14 | and #1 | |
15 | sta ($0),y | |
16 | ||
17 | clc | |
18 | lda $0 | |
19 | adc #1 | |
20 | sta $0 | |
21 | lda $1 | |
22 | adc #0 | |
23 | sta $1 | |
24 | cmp #6 | |
25 | beq memoryFilled | |
26 | jmp loopOne | |
27 | ||
28 | ||
29 | ;==================================================== | |
30 | memoryFilled: | |
31 | jsr resetEverything | |
32 | notDoneYet: | |
33 | jsr countLife ;count life around cell | |
34 | lda ($0),y | |
35 | cmp #1 | |
36 | beq cellWasAlive | |
37 | ;otherwise, the cell is NOT living | |
38 | jsr currentCellDead | |
39 | jmp cellChecked | |
40 | ||
41 | cellWasAlive: | |
42 | jsr currentCellAlive | |
43 | jmp cellChecked | |
44 | ||
45 | ||
46 | cellChecked: | |
47 | ;jsr debug | |
48 | sta ($4),y ;Store final cell checked value in the buffer | |
49 | ||
50 | jsr incrementPointers | |
51 | ||
52 | lda $1 | |
53 | cmp #6 | |
54 | ||
55 | beq doneNow | |
56 | ;it was not equal, jump back | |
57 | jmp notDoneYet | |
58 | ||
59 | doneNow: ;here lies the rub, done now is not jumping here properly | |
60 | ||
61 | jsr resetEverything | |
62 | jsr copyNewBuffer | |
63 | jmp memoryFilled | |
64 | ||
65 | ||
66 | ;reset stuff, including $10 | |
67 | ||
68 | ;==================================================== | |
69 | resetEverything: | |
70 | lda #0 ;screen pointer | |
71 | sta $0 | |
72 | lda #2 | |
73 | sta $1 | |
74 | ||
75 | lda #0 ;screen reading pointer | |
76 | sta $2 | |
77 | lda #2 | |
78 | sta $3 | |
79 | ||
80 | lda #0 ;buffer pointer | |
81 | sta $4 | |
82 | lda #$10 | |
83 | sta $5 | |
84 | ||
85 | ||
86 | lda #0 ;life count | |
87 | sta $10 | |
88 | rts | |
89 | ||
90 | ||
91 | ||
92 | ;==================================================== | |
93 | countLife: | |
94 | ;center screen reading pointer | |
95 | lda $0 | |
96 | sta $2 | |
97 | lda $1 | |
98 | sta $3 | |
99 | ||
100 | ;TODO!! | |
101 | ;since the data is all in one stream, we need to account for the fact that | |
102 | ;the map is 2d, and wraps around every 32 pixels. | |
103 | ;if cell is far left, don't calculate up left, left, or down left | |
104 | ;if cell is far right, don't calculate up right, right, or down right | |
105 | ldx #0 | |
106 | ||
107 | ;x-- | |
108 | ;--- | |
109 | ;--- | |
110 | sec | |
111 | lda $2 | |
112 | sbc #33 ;move up one row, left a column | |
113 | sta $2 | |
114 | lda $3 | |
115 | sbc #0 ;carry subtract | |
116 | sta $3 | |
117 | jsr addLife | |
118 | ||
119 | ;-x- | |
120 | ;--- | |
121 | ;--- | |
122 | clc | |
123 | lda $2 | |
124 | adc #1 ;move right one | |
125 | sta $2 | |
126 | lda $3 | |
127 | adc #0 | |
128 | sta $3 | |
129 | jsr addLife | |
130 | ||
131 | ;--x | |
132 | ;--- | |
133 | ;--- | |
134 | clc | |
135 | lda $2 | |
136 | adc #1 ;move right one | |
137 | sta $2 | |
138 | lda $3 | |
139 | adc #0 | |
140 | sta $3 | |
141 | jsr addLife | |
142 | ||
143 | ;center screen reading pointer | |
144 | lda $0 | |
145 | sta $2 | |
146 | lda $1 | |
147 | sta $2 | |
148 | ||
149 | ;--- | |
150 | ;x-- | |
151 | ;--- | |
152 | sec | |
153 | lda $2 | |
154 | sbc #1 ;move left one | |
155 | sta $2 | |
156 | lda $3 | |
157 | sbc #0 ;carry subtract | |
158 | sta $3 | |
159 | jsr addLife | |
160 | ||
161 | ;--- | |
162 | ;--x | |
163 | ;--- | |
164 | clc | |
165 | lda $2 | |
166 | adc #2 ;move right two | |
167 | sta $2 | |
168 | lda $3 | |
169 | adc #0 | |
170 | sta $3 | |
171 | jsr addLife | |
172 | ||
173 | ||
174 | ;center screen reading pointer | |
175 | lda $0 | |
176 | sta $2 | |
177 | lda $1 | |
178 | sta $2 | |
179 | ||
180 | ;--- | |
181 | ;--- | |
182 | ;x-- | |
183 | clc | |
184 | lda $2 | |
185 | adc #31 ;move down one, left one | |
186 | sta $2 | |
187 | lda $3 | |
188 | adc #0 | |
189 | sta $3 | |
190 | jsr addLife | |
191 | ||
192 | ;--- | |
193 | ;--- | |
194 | ;-x- | |
195 | clc | |
196 | lda $2 | |
197 | adc #1 ;move right one | |
198 | sta $2 | |
199 | lda $3 | |
200 | adc #0 | |
201 | sta $3 | |
202 | jsr addLife | |
203 | ||
204 | ;--- | |
205 | ;--- | |
206 | ;--x | |
207 | clc | |
208 | lda $2 | |
209 | adc #1 ;move right one | |
210 | sta $2 | |
211 | lda $3 | |
212 | adc #0 | |
213 | sta $3 | |
214 | jsr addLife | |
215 | ||
216 | rts | |
217 | ||
218 | ||
219 | ||
220 | ;==================================================== | |
221 | addLife: | |
222 | lda ($2),y | |
223 | cmp #1 | |
224 | bne noLife | |
225 | inc $10 | |
226 | noLife: | |
227 | rts | |
228 | ||
229 | ||
230 | ||
231 | ;==================================================== | |
232 | currentCellDead: | |
233 | ; If there are 3 neighboring cells, it is alive | |
234 | ; Any other case, it is dead. | |
235 | lda $10 | |
236 | cmp #3 | |
237 | beq deadCellAlive | |
238 | ;no? then it's dead. | |
239 | lda #0 | |
240 | jmp currentCellDeadEnd | |
241 | ||
242 | deadCellAlive: | |
243 | lda #1 | |
244 | jmp currentCellDeadEnd | |
245 | ||
246 | currentCellDeadEnd: | |
247 | rts | |
248 | ||
249 | ||
250 | ||
251 | ;==================================================== | |
252 | currentCellAlive: | |
253 | lda $10 | |
254 | ;useless notes - cmp actually compares and sets flags as if | |
255 | ;subtract had taken place... so if it's equal, carry flag will | |
256 | ;be set, and the equal flag will be set. If it's more than, | |
257 | ;just the carry flag will be set. If it's less than, none | |
258 | ;of the flags will be set. | |
259 | ||
260 | ; Any live cell with fewer than two live neighbours dies, | |
261 | ; Any live cell with two or three live neighbours lives | |
262 | ; Any live cell with more than three live neighbours dies | |
263 | ||
264 | cmp #2 | |
265 | bcs cellEQGT2 | |
266 | ;less than 2, cell dies | |
267 | lda #0 | |
268 | jmp currentCellAliveEnd | |
269 | ||
270 | cellEQGT2: | |
271 | BNE cellGT2 | |
272 | ;equal to 2, cell lives | |
273 | lda #1 | |
274 | jmp currentCellAliveEnd | |
275 | ||
276 | cellGT2: | |
277 | cmp #3 | |
278 | bne cellGT3 | |
279 | ;equal to 3, cell lives | |
280 | lda #1 | |
281 | jmp currentCellAliveEnd | |
282 | ||
283 | cellGT3: | |
284 | ;greater than 3, cell dies | |
285 | lda #0 | |
286 | jmp currentCellAliveEnd | |
287 | ||
288 | currentCellAliveEnd: | |
289 | rts | |
290 | ||
291 | ||
292 | ||
293 | ;==================================================== | |
294 | incrementPointers: | |
295 | clc | |
296 | lda $0 ;increment screen pointer | |
297 | adc #1 | |
298 | sta $0 | |
299 | lda $1 | |
300 | adc #0 | |
301 | sta $1 | |
302 | ||
303 | clc | |
304 | lda $4 ;increment buffer pointer | |
305 | adc #1 | |
306 | sta $4 | |
307 | lda $5 | |
308 | adc #0 | |
309 | sta $5 | |
310 | rts | |
311 | ||
312 | ||
313 | ;==================================================== | |
314 | copyNewBuffer: | |
315 | lda ($4),y | |
316 | sta ($0),y | |
317 | jsr incrementPointers | |
318 | lda $1 | |
319 | cmp #6 | |
320 | bne copyNewBuffer | |
321 | rts | |
322 | ||
323 | debug: | |
324 | lda #$d | |
325 | sta ($11),y | |
326 | inc $11 | |
327 | rts |