Repository navigation
Expand file tree
/
Copy pathsync.asm
More file actions
319 lines (260 loc) · 5.94 KB
/
Copy pathsync.asm
File metadata and controls
319 lines (260 loc) · 5.94 KB
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
ILineSync: subroutine
lda #-22
sta LineCycles
; TODO: reflection and the latter 20 tiles should also be translated
lda #2
bit VSYNC
beq .nvsync
inc $201 ; frame counter
lda $202 ; how many frames did this one frame take?
sta $203
lda #0
sta $202
lda #$ec
sta FreeSprite
lda #-37
sta ScanLine
lda #3 ; sets the counter so the colors for each section are read halfway through
sta PaletteCounter
lda #1
sta ColorSection
inc ScanLine
jmp InterruptDone
.nvsync
ldy ScanLine
; we don't do anything if in vblank
cpy #192
bcc .screen
inc ScanLine
jmp InterruptDone
.screen
; visible scanlines 0-191
ldx FreeSprite
lda GRP0
beq .nsprite0
sta $201,x
tya
clc
adc #39
sta $200,x
lda REFP0
and #$8
asl
asl
asl
std $202,x
lda Sprite0H
sta $203,x
dex
dex
dex
dex
bne .nwrap
ldx #$ec
.nwrap
.nsprite0
lda GRP1
beq .nsprite1
sta $201,x
tya
clc
adc #39
sta $200,x
lda Sprite1H
sta $203,x
dex
dex
dex
dex
bne .nwrap1
ldx #$ec
.nwrap1
.nsprite1
stx FreeSprite
tya
lsr
bcs .odd ; only odd scanlines are processed and drawn
inc ScanLine
jmp InterruptDone
.odd
; read the rest of the line since the PFx bytes aren't gonna change
jsr FinishLine
lda ScanLine
and #$7
cmp #7 ; have we read a entire row of tiles?
beq .rowcomplete
inc ScanLine
jmp InterruptDone
.rowcomplete
; after 8 scanlines, copy the converted playfield data to buffer
bit DrawBuffer0
bne .n0
FILL_BUFFER 0
jmp .buffdone
.n0 bit DrawBuffer1
bne .n1
;FILL_BUFFER 1
jmp .buffdone
.n1
.buffdone
ldx PaletteCounter
dex
bne .paldone
; after 6 tiles (48 scanlines) set the palettes
lda COLUBK
jsr ConvertColor
sta BGColor
lda COLUPF
jsr ConvertColor
sta PFColor
ldx ColorSection
stx UpdateColor
inx
stx ColorSection
ldx #5
.paldone
stx PaletteCounter
.syncdone
inc ScanLine
jmp InterruptDone
IPlayfieldChange: subroutine
lda ScanLine
lsr
bcc CopyOld
lda LineCycles
bmi CopyOld
; multiply by 3 and divide by 4
asl
clc
adc LineCycles
sec
lsr
lsr
tay
cpy LastDrawnPixel
bcs .nwrap
tya
pha
jsr FinishLine
pla
tay
.nwrap
ldx LastDrawnPixel
sty LastDrawnPixel
; now that x and y are set with the correct pixel numbers, this subroutine reads
; pixels in that range and updates the playfield buffer bytes
jsr ReadPlayfieldRange
CopyOld
lda PF0
sta PF0old
lda PF1
sta PF1old
lda PF2
sta PF2old
jmp InterruptDone
; finish drawing the last scanline, clear buffers for the next
FinishLine: subroutine
ldx LastDrawnPixel
ldy #39
jsr ReadPlayfieldRange
lda #0
sta LastDrawnPixel
UPDATE_TILES_LEFT
lda CTRLPF
ror
bcc .nmirror
UPDATE_TILES_RIGHT_MIRRORED
jmp .linedone
.nmirror
UPDATE_TILES_RIGHT
.linedone
lda #0
sta PFRight0
sta PFRight1
sta PFRight2
sta PFLeft0
sta PFLeft1
sta PFLeft2
rts
; these subroutines read the playfield data after x and y are set
ReadPlayfieldRange: subroutine
cpy #20
bcc .left
cpx #20
bcc .split
; both points are in the right
txa
sec
sbc #20
tax
tya
sec
sbc #20
tay
jsr ReadPlayfieldRight
rts
.split
; it's split if we're here
tya
sec
sbc #20
tay
stx var2
ldx #0
jsr ReadPlayfieldRight
ldx var2
ldy #19
.left
; both points are in the left
ReadPlayfieldLeft: subroutine
lda PF0Masks,y
eor PF0Masks,x
and PF0old
ora PFLeft0
sta PFLeft0
lda PF1Masks,y
eor PF1Masks,x
and PF1old
ora PFLeft1
sta PFLeft1
lda PF2Masks,y
eor PF2Masks,x
and PF2old
ora PFLeft2
sta PFLeft2
rts
ReadPlayfieldRight: subroutine
lda PF0Masks,y
eor PF0Masks,x
and PF0old
ora PFRight0
sta PFRight0
lda PF1Masks,y
eor PF1Masks,x
and PF1old
ora PFRight1
sta PFRight1
lda PF2Masks,y
eor PF2Masks,x
and PF2old
ora PFRight2
sta PFRight2
rts
PF0Masks:
.byte %00000000, %00010000, %00110000, %01110000
.byte %11110000, %11110000, %11110000, %11110000
.byte %11110000, %11110000, %11110000, %11110000
.byte %11110000, %11110000, %11110000, %11110000
.byte %11110000, %11110000, %11110000, %11110000
PF1Masks:
.byte %00000000, %00000000, %00000000, %00000000
.byte %00000000, %10000000, %11000000, %11100000
.byte %11110000, %11111000, %11111100, %11111110
.byte %11111111, %11111111, %11111111, %11111111
.byte %11111111, %11111111, %11111111, %11111111
PF2Masks:
.byte %00000000, %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000, %00000000
.byte %00000001, %00000011, %00000111, %00001111
.byte %00011111, %00111111, %01111111, %11111111