summaryrefslogtreecommitdiffstats
path: root/hacks/images/m6502/sflake.asm
blob: cbb72e8908225c5b9e3e7c5d0bf365fdce449985 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
;; Jeremy English 01-December-2008
;; Snowflakes

;; Main loop Count
lda #7
sta $f

;; pattern number
lda #0
sta $10

;;Cells
lda #$00
sta $4
lda #$10
sta $5

;;Tmp
lda #$00
sta $6
lda #$11
sta $7

;;Init Cells Buffer
;;------------------------------------------------------------
ldy #$ff
initCells:
lda #0
sta ($4),y
sta ($6),y
dey
bne initCells

;;Set start position
ldy #115
lda #1
sta ($4),y
   
;;Setup offset
lda #15
sta $d
lda #16
sta $e

;;Start of main loop
;;------------------------------------------------------------
mainloop:

;;init indent
;;We want to indent every other line
lda #0
sta $a

lda #0
sta $9

;; Display Cells
;;------------------------------------------------------------
;; 248 is the total number of cells
ldy #248
display:

lda #0
sta $8

lda $a
beq stop16
lda #15
sta $b
lda #1
sta $8
jmp toggle
stop16:
lda #16
sta $b
toggle:
lda $a
eor #1
sta $a

;; Set the stop position
ldx $b
inner_display:
dex
txa
pha

dey
tya
pha
lda ($4),y

beq display_continue
ldx $8
ldy $9
lda #1
jsr paint
ldx $8
ldy $9
inx
jsr paint
ldx $8
ldy $9
iny
jsr paint
ldx $8
ldy $9
inx
iny
jsr paint
display_continue:
inc $8
inc $8

;;Life Cycle
;;------------------------------------------------------------
pla
tay
pha ;;Store y on the stack

tax
dey
lda ($4),y
iny
iny
clc
adc ($4),y
sta $c

txa
sec
sbc $d
tay
lda $c
clc
adc ($4),y
sta $c

txa
sec
sbc $e
tay
lda $c
clc
adc ($4),y
sta $c

txa
clc
adc $d
tay
lda $c
clc
adc ($4),y
sta $c

txa
clc
adc $e
tay
lda $c
clc
adc ($4),y
sta $c

pla
tay ;;Pull Y off of the stack

lda $c
and #1
beq dontset
sta ($6),y
dontset:
   
pla
tax ;;Pull x off of the stack   
beq exit_inner_display
jmp inner_display
exit_inner_display:
inc $9
inc $9
tya
beq display_exit
jmp display
display_exit:


;;Copy Temporary Buffer
;;------------------------------------------------------------
ldy #248
copybuf:
dey
lda ($6),y
sta ($4),y
tya
bne copybuf

dec $f
lda $f
beq reset_main
jmp mainloop

;;Reset main counter
;;------------------------------------------------------------
reset_main:
lda #7
sta $f

lda #$ff ;;Delay Count
sta $11
delay:
ldy #$a0
inner_delay:
nop
dey
bne inner_delay
dec $11
lda $11
bne delay

;; init buffer
;; and clear screen
clrscr:
lda $fe
and $f
cmp #1
beq clrscr ;We don't want a white background
ldy #$00
ldx #$0
cs_loop: 
sta $200,x
sta $300,x
sta $400,x
sta $500,x
pha
lda #0
sta ($6),y
sta ($4),y
pla
inx
dey
bne cs_loop

;; Setup new pattern
;;------------------------------------------------------------
inc $10
lda $10
and #3
sta $10
cmp #0
beq pattern1
cmp #1
beq pattern2
cmp #2
beq pattern3
cmp #3
beq pattern4

pattern1:
ldy #114
lda #1
sta ($4),y
ldy #115
lda #1
sta ($4),y
ldy #116
lda #1
sta ($4),y
jmp mainloop

pattern2:
ldy #113
lda #1
sta ($4),y
ldy #118
lda #1
sta ($4),y
jmp mainloop

pattern3:
ldy #115
lda #1
sta ($4),y
jmp mainloop

pattern4:
ldy #102
lda #1
sta ($4),y
ldy #128
lda #1
sta ($4),y
jmp mainloop

;;Paint subroutine
;;------------------------------------------------------------
paint:
   pha
   lda yl,y
   sta $2
   lda yh,y
   sta $3
   txa
   tay
   pla
   sta ($2),y
   rts

       ;; Y cord MSB   
yh:
       dcb $02, $02, $02, $02, $02, $02, $02, $02
       dcb $03, $03, $03, $03, $03, $03, $03, $03
       dcb $04, $04, $04, $04, $04, $04, $04, $04
       dcb $05, $05, $05, $05, $05, $05, $05, $05
       ;; Y cord LSB
yl:
       dcb $00, $20, $40, $60, $80, $a0, $c0, $e0
       dcb $00, $20, $40, $60, $80, $a0, $c0, $e0
       dcb $00, $20, $40, $60, $80, $a0, $c0, $e0
       dcb $00, $20, $40, $60, $80, $a0, $c0, $e0