-
Notifications
You must be signed in to change notification settings - Fork 2
/
scrollmode.s
379 lines (332 loc) · 8.5 KB
/
scrollmode.s
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
; Double Action Blaster Guys
;
; Copyright 2012-2014 NovaSquirrel
;
; This software is provided 'as-is', without any express or implied
; warranty. In no event will the authors be held liable for any damages
; arising from the use of this software.
;
; Permission is granted to anyone to use this software for any purpose,
; including commercial applications, and to alter it and redistribute it
; freely, subject to the following restrictions:
;
; 1. The origin of this software must not be misrepresented; you must not
; claim that you wrote the original software. If you use this software
; in a product, an acknowledgment in the product documentation would be
; appreciated but is not required.
; 2. Altered source versions must be plainly marked as such, and must not be
; misrepresented as being the original software.
; 3. This notice may not be removed or altered from any source distribution.
;
NewColumn = StatusRow2
.proc UpdateScrollColumn
WhichMetaColumn = 1
LevelBufIndex = 14
lda ScrollX+1
and #127
bne :+
jsr huge_rand
sta ScrollGenVars+0
jsr huge_rand
sta ScrollGenVars+1
lda #0
sta ScrollGenVars+2
sta ScrollGenVars+3
inc ScrollGenerator
lda ScrollGenerator
cmp #8
bne :+
lda #0
sta ScrollGenerator
:
; calculate PPU address to write the 28 byte buffer to
; (repurposed from being a status bar)
lda #$20
sta Update28Address+0
lda ScrollX+1
lsr
lsr
lsr
sta 0 ; nametable column used to determine what level column to update
add #64 ; start one block down
sta Update28Address+1
ldy #0 ; y will be Update28 index
sty WhichMetaColumn
lda 0
lsr ; get the LevelBuf index
sta LevelBufIndex
; we split the tasks for scrolling into different parts per frame
; partly to leave more CPU for other stuff and partly
ChooseTask:
lda ScrollX+1
and #15
cmp #8
jeq RenderRight
bcc :+
rts
: asl
tax
lda ScrollTasks+1,x
pha
lda ScrollTasks+0,x
pha
rts
RenderLeftGenerate:
; generate new level stuff here, if left column
jsr LaunchScrollGen1
tay
ldx #15
lda #0
: lda ScrollColumnTemplates,y
sta NewColumn,x
iny
dex
bpl :-
jsr LaunchScrollGen2
ldy #0
RenderLeft:
tya
lsr
tax
lda NewColumn,x
sta TempVal
lda LevelBufIndex ; step to next metatile
tax ; but for this iteration, use the previous value
add #16
sta LevelBufIndex
lda TempVal
sta LevelBuf+16,x ; find index into MetatileData
asl
asl
tax
lda MetatileTiledata,x
sta Update28+0,y
lda MetatileTiledata+2,x
sta Update28+1,y
iny
iny
cpy #28
bne RenderLeft
rts
RenderRight:
lda LevelBufIndex ; step to next metatile
tax ; but for this iteration, use the previous value
add #16
sta LevelBufIndex
lda LevelBuf+16,x ; find index into MetatileData
asl
asl
tax
lda MetatileTiledata+1,x
sta Update28+0,y
lda MetatileTiledata+3,x
sta Update28+1,y
iny
iny
cpy #28
bne RenderRight
rts
FixColors1:
ldx #0
ldy #FixColorSet2-FixColorSet1
bne FixColors
FixColors2:
ldx #FixColorSet2-FixColorSet1
ldy #FixColorSet3-FixColorSet2
bne FixColors
FixColors3:
ldx #FixColorSet3-FixColorSet1
ldy #FixColorSetEnd-FixColorSet3
FixColors:
ColorSetIndex = 12
ColorSetLoopCount = 13
stx ColorSetIndex
sty ColorSetLoopCount
FixColorsLoop:
ldx ColorSetIndex
inc ColorSetIndex
lda FixColorSet1,x ; what block to do currently
add LevelBufIndex
tay
sty 0
lda LevelBuf,y ; get tile we're going to be coloring
tay
lda MetatileFlags,y ; get the flags for this tile
and #3 ; mask off just the palette number
ldy 0
jsr ChangeBlockColor ; A = new palette, Y = LevelBuf index
dec ColorSetLoopCount
bne FixColorsLoop
rts
; two consecutive rows are going to share the same byte
; so I spread it out so we're not rewriting the same byte twice in one NMI
FixColorSet1: .byt 1*16, 3*16, 5*16, 7*16, 9*16
FixColorSet2: .byt 11*16, 13*16, 2*16, 4*16
FixColorSet3: .byt 6*16, 8*16, 10*16, 12*16, 14*16
FixColorSetEnd:
ScrollTasks:
.raddr RenderLeftGenerate
.raddr FixColors1
.raddr FixColors2
.raddr FixColors3
.raddr EmptyObject
.raddr EmptyObject
.raddr EmptyObject
.raddr EmptyObject
LaunchScrollGen1:
lda ScrollGenerator
asl
tax
lda ScrollGen1Table+1,x
pha
lda ScrollGen1Table+0,x
pha
DoLaunch:
lda LevelBufIndex
and #7
rts
LaunchScrollGen2:
lda ScrollGenerator
asl
tax
lda ScrollGen2Table+1,x
pha
lda ScrollGen2Table+0,x
pha
jmp DoLaunch
.endproc
.enum
SCROLLCOL_EMPTY
SCROLLCOL_GROUND
SCROLLCOL_MIDGROUND
SCROLLCOL_HIGHGROUND
SCROLLCOL_SPRINGGROUND
SCROLLCOL_ALLGROUND
SCROLLCOL_WALL_CYCLE_ON
SCROLLCOL_WALL_CYCLE_OFF
.endenum
.proc ScrollColumnTemplates ; backwards
.byt 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
.byt 0,0, METATILE_SOLID, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
.byt 0,0, METATILE_SOLID, METATILE_SOLID, METATILE_SOLID, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
.byt 0,0, METATILE_SOLID, METATILE_SOLID, METATILE_SOLID, METATILE_SOLID, METATILE_SOLID, 0, 0, 0, 0, 0, 0, 0, 0, 0
.byt 0,0, METATILE_SOLID, METATILE_SOLID, METATILE_SOLID, METATILE_SOLID, METATILE_SOLID, METATILE_SOLID, METATILE_SOLID, 0, 0, 0, 0, 0, 0, 0
.byt 0,0, METATILE_SOLID,METATILE_SOLID,METATILE_SOLID,METATILE_SOLID,METATILE_SOLID,METATILE_SOLID,METATILE_SOLID,METATILE_SOLID, METATILE_SOLID,METATILE_SOLID,METATILE_SOLID,METATILE_SOLID,METATILE_SOLID,METATILE_SOLID
.byt 0,0, METATILE_SOLID, METATILE_CYCLE_ON_SOLID, METATILE_CYCLE_ON_SOLID, METATILE_CYCLE_ON_SOLID, METATILE_CYCLE_ON_SOLID, METATILE_CYCLE_ON_SOLID, METATILE_CYCLE_ON_SOLID, METATILE_CYCLE_ON_SOLID, METATILE_CYCLE_ON_SOLID, METATILE_CYCLE_ON_SOLID, METATILE_CYCLE_ON_SOLID, METATILE_CYCLE_ON_SOLID, METATILE_CYCLE_ON_SOLID, METATILE_CYCLE_ON_SOLID
.byt 0,0, METATILE_SOLID, METATILE_CYCLE_OFF_SOLID, METATILE_CYCLE_OFF_SOLID, METATILE_CYCLE_OFF_SOLID, METATILE_CYCLE_OFF_SOLID, METATILE_CYCLE_OFF_SOLID, METATILE_CYCLE_OFF_SOLID, METATILE_CYCLE_OFF_SOLID, METATILE_CYCLE_OFF_SOLID, METATILE_CYCLE_OFF_SOLID, METATILE_CYCLE_OFF_SOLID, METATILE_CYCLE_OFF_SOLID, METATILE_CYCLE_OFF_SOLID, METATILE_CYCLE_OFF_SOLID
.byt 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
.byt 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
.endproc
.enum
SCROLLGEN_FLAT
SCROLLGEN_PLATFORM_FIELD
SCROLLGEN_GAP_THROUGH_SOLID
SCROLLGEN_STAIRGAP_THROUGH_SOLID
SCROLLGEN_SPRING_OVER_WALL
SCROLLGEN_FALL_UNDER_WALL
SCROLLGEN_SPRING_OVER_SPIKES
SCROLLGEN_SPRINGFIELD_OVER_SPIKES
.endenum
; gen 1 decides what column template to use
.proc ScrollGen1Table
.raddr ScrollGen1_Flat ;
.raddr ScrollGen1_PlatformField
.raddr ScrollGen1_GapThruSolid
.raddr ScrollGen1_CycleSwitchWalls ;
.raddr ScrollGen1_SpringOverWall
.raddr ScrollGen1_FallUnderWall ;
.raddr ScrollGen1_SpringOverSpikes
.raddr ScrollGen1_SpringFieldOverSpikes
.endproc
; gen 2 does additional changes
.proc ScrollGen2Table
.raddr ScrollGen2_Flat
.raddr ScrollGen2_PlatformField
.raddr ScrollGen2_GapThruSolid
.raddr ScrollGen2_CycleSwitchWalls
.raddr ScrollGen2_SpringOverWall
.raddr ScrollGen2_FallUnderWall
.raddr ScrollGen2_SpringOverSpikes
.raddr ScrollGen2_SpringFieldOverSpikes
.endproc
ScrollGen1_CycleSwitchWalls:
cmp #3
beq :+
cmp #7
beq :++
lda #SCROLLCOL_GROUND*16
rts
: lda #SCROLLCOL_WALL_CYCLE_ON*16
rts
: lda #SCROLLCOL_WALL_CYCLE_OFF*16
rts
ScrollGen1_GapThruSolid:
ScrollGen1_SpringOverWall:
lda #SCROLLCOL_GROUND*16
rts
ScrollGen1_FallUnderWall:
beq :+
lda #SCROLLCOL_ALLGROUND*16
rts
ScrollGen1_PlatformField:
: lda #SCROLLCOL_EMPTY*16
rts
ScrollGen1_Flat:
lda #SCROLLCOL_GROUND*16
rts
ScrollGen1_SpringOverSpikes:
ScrollGen1_SpringFieldOverSpikes:
lda #SCROLLCOL_GROUND*16
rts
ScrollGen2_CycleSwitchWalls:
and #3
cmp #2
bne :+
lda #METATILE_INSTANT_SWITCH
sta NewColumn+12
: rts
ScrollGen2_PlatformField:
lda #10
sub ScrollGenVars+2
tax
lda #METATILE_PLATFM
sta NewColumn,x
jsr huge_rand
and #7
sub #4
add ScrollGenVars+2
and #7
sta ScrollGenVars+2
rts
ScrollGen2_GapThruSolid:
ScrollGen2_SpringOverWall:
rts
ScrollGen2_FallUnderWall:
beq :+
lda #METATILE_SPIKES
sta NewColumn
lda ScrollGenVars
and #7
add #2
tax
lda #METATILE_EMPTY
sta NewColumn+0,x
sta NewColumn+1,x
: rts
ScrollGen2_Flat = EmptyObject
ScrollGen2_SpringOverSpikes:
bne :+
lda #METATILE_SPRING
sta NewColumn+12
rts
: lda #METATILE_SPIKES
sta NewColumn+12
rts
ScrollGen2_SpringFieldOverSpikes:
jsr huge_rand
and #7
add #2
tax
lda #METATILE_SPRING
sta NewColumn,x
rts