-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameMain.asm
382 lines (286 loc) · 9.31 KB
/
gameMain.asm
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
380
381
382
;===============================================================================
; BASIC Loader
*=$0801 ; 10 SYS (2064)
byte $0E, $08, $0A, $00, $9E, $20, $28, $32
byte $30, $36, $34, $29, $00, $00, $00
; Our code starts at $0810 (2064 decimal)
; after the 15 bytes for the BASIC loader
jmp $8000
;===============================================================================
; Initialize
*=$8000
; Turn off interrupts to stop LIBSCREEN_WAIT failing every so
; often when the kernal interrupt syncs up with the scanline test
;sei
; Disable run/stop + restore keys
lda #$FC
sta $0328
; disable BASIC ROM
lda $01
and #%11111110
sta $01
; Set multicolor background mode
LIBSCREEN_SETMULTICOLORMODE
; Set border and background colors
; The last 3 parameters are not used yet
LIBSCREEN_SETCOLORS Black, Black, Black, Black, Black
; Fill 1000 bytes (40x25) of screen memory
LIBSCREEN_SET1000 SCREENRAMONE, SpaceCharacter
; Fill 1000 bytes (40x25) of screen memory
LIBSCREEN_SET1000 SCREENRAMTWO, SpaceCharacter
; Fill 1000 bytes (40x25) of color memory
LIBSCREEN_SET1000 COLORRAM, Black
; Set sprite multicolors
LIBSPRITE_SETMULTICOLORS_VV MediumGray, Black
; Set the memory location of the custom character set
LIBSCREEN_SETCHARMEMORY 14
; Set 38 column screen mode
LIBSCREEN_SET38COLUMNMODE
; Set 24 row screen mode
;LIBSCREEN_SET24ROWMODE
lda #1
sta screenOneActive
lda #0
sta screenTwoActive
lda #1
sta flipScreenCounter
; set up raster interrupt
lda #%01111111
sta $DC0D
and $D011
sta $D011
lda #255
sta $D012
lda #<Irq3
sta $0314
lda #>Irq3
sta $0315
lda #%00000001
sta $D01A
; initialize the music
jsr libMusicInit
; initialize the sound
jsr libSoundInit
; Initialize the game
jsr gamePlayerInit
jsr gameBaronInit
; Initialize the game
jsr gameMapInit
mainLoop
jmp mainLoop
;===============================================================================
; Update
gMLoop1
; Update the library
lda #13
sta EXTCOL
jsr libInputUpdate
; Update the game
lda #8
sta EXTCOL
jsr gamePlayerUpdate
; End code timer reset border color
lda #0
sta EXTCOL
rts
gMLoop2
lda #3
sta EXTCOL
jsr gameBulletsUpdate
lda #8
sta EXTCOL
jsr gameBombUpdate
; End code timer reset border color
lda #0
sta EXTCOL
rts
gmLoop3
lda #11
sta EXTCOL
jsr gameBaronUpdate
; End code timer reset border color
lda #0
sta EXTCOL
rts
Irq ; fires at raster line 10
LIBSCREEN_SETCOLORS Black, LightBlue, Brown, White, Black
LIBSCREEN_SCROLLTOBACKGROUND
lda #5
sta EXTCOL
SCREEN_UPDATE_SCROLLING_AVVAA screenScrollXValue, 6, 6, gameMapUpdateBottom, gameMapUpdateBottom
;SCREEN_UPDATE_SCROLLING_AVVAA screenScrollXValue, 0, 6, gameColorUpdateBottom, gameColorUpdateBottom
SCREEN_UPDATE_SCROLLING_AVVAA screenScrollXValue, 0, 0, gameMapUpdateBottomExtra, gameMapUpdateBottomExtra
;lda #9
;sta EXTCOL
SCREEN_UPDATE_SCROLLING_AVVAA backgroundScrollXValue, 1, 1, gameMapUpdateTop, gameMapUpdateTop
SCREEN_UPDATE_SCROLLING_AVVAA backgroundScrollXValue, 5, 5, gameMapUpdateTop, gameMapUpdateTop
;SCREEN_UPDATE_SCROLLING_AVVAA backgroundScrollXValue, 6, 0, gameColorUpdateTop, gameColorUpdateTop
SCREEN_UPDATE_SCROLLING_AVVAA backgroundScrollXValue, 2, 2, gameMapUpdateTopExtra, gameMapUpdateTopExtra
SCREEN_UPDATE_SCROLLING_AVVAA backgroundScrollXValue, 6, 6, gameMapUpdateTopExtra, gameMapUpdateTopExtra
lda #15
sta EXTCOL
; play a music frame only if the player is not alive
lda playerActive
bne @skipMusic
jsr libMusicUpdate
@skipMusic
jsr libSoundUpdate
jsr libSpritesUpdate
lda #0
sta EXTCOL
jsr gMLoop3
lda #<Irq2
sta $0314
lda #>Irq2
sta $0315
lda #146
sta $D012
lsr $D019
jmp $EA81
Irq2 ; fires at raster line 146
LIBSCREEN_SETCOLORS Black, Brown, Green, White, Black
lda #5
sta EXTCOL
LIBSCREEN_SCROLLTOFOREGROUND
;SCREEN_UPDATE_SCROLLING_AVVAA screenScrollXValue, 2, 4, gameMapUpdateBottomExtra, gameMapUpdateBottomExtra
;SCREEN_UPDATE_SCROLLING_AVVAA screenScrollXValue, 0, 6, gameColorUpdateBottomExtra, gameColorUpdateBottomExtra
;SCREEN_UPDATE_SCROLLING_AVVAA screenScrollXValue, 4, 2, gameMapUpdateTopExtra, gameMapUpdateTopExtra
;SCREEN_UPDATE_SCROLLING_AVVAA screenScrollXValue, 6, 0, gameColorUpdateTopExtra, gameColorUpdateTopExtra
jsr gMLoop2
lda #<Irq3
sta $0314
lda #>Irq3
sta $0315
lda #234
sta $D012
lsr $D019
jmp $EA81
Irq3 ; fires at raster line 234
LIBSCREEN_SETCOLORS Black, Red, Green, White, Red
lda #2
sta EXTCOL
LIBSCREEN_SCROLLTOSCOREBOARD
SCREEN_UPDATE_SCROLLING_AVVAA screenScrollXValue, 6, 0, flipScreenLeft, flipScreenRight
SCREEN_UPDATE_SCROLLING_AVVAA backgroundScrollXValue, 4, 4, flipBackgroundLeft, flipBackgroundRight
jsr gMLoop1
lda #30
sta ZeroPageTemp
lda #23
sta ZeroPageTemp2
LIBSCREEN_DRAWDECIMAL_AAAVV ZeroPageTemp, ZeroPageTemp2, screenDebugZero, 1, 0
LIBSCREEN_DRAWDECIMAL_AAAVV ZeroPageTemp, ZeroPageTemp2, screenDebugZero, 1, 1
lda #30
sta ZeroPageTemp
lda #24
sta ZeroPageTemp2
LIBSCREEN_DRAWDECIMAL_AAAVV ZeroPageTemp, ZeroPageTemp2, screenDebugOne, 1, 0
LIBSCREEN_DRAWDECIMAL_AAAVV ZeroPageTemp, ZeroPageTemp2, screenDebugOne, 1, 1
lda #<Irq
sta $0314
lda #>Irq
sta $0315
lda #10
sta $D012
lsr $D019
jmp $EA81
;===============================================================================
defm SCREEN_UPDATE_SCROLLING_AVVAA
lda ScreenScrollingRight
bne @scrollNegative
lda ScreenScrollingLeft
bne @scrollPositive
jmp @finished
@scrollNegative
lda /1
cmp #/2
bne @finished
jsr /4
jmp @finished
@scrollPositive
lda /1
cmp #/3
bne @finished
jsr /5
@finished
endm
;===============================================================================
flipScreen
lda screenOneActive
beq @flipSecondary
@flipPrimary
lda $D018
and #%00001111
ora #%10000000 ; set active screen RAM to SCREENRAMTWO/$2000
sta $D018
lda #1
sta screenTwoActive
lda #0
sta screenOneActive
jmp @finished
@flipSecondary
lda $D018
and #%00001111
ora #%00010000 ; set active screen RAM to SCREENRAMONE/$0400
sta $D018
lda #0
sta screenTwoActive
lda #1
sta screenOneActive
@finished
rts
;===============================================================================
flipScreenRight
inc flipScreenCounter
lda flipScreenCounter
cmp #2
bcc @flipDone
lda #1
sta flipScreenCounter
jsr flipScreen
@flipDone
inc screenColumn
lda screenColumn
cmp #MapLastColumn
bcc @screenColumnResetDone
lda #0
sta screenColumn
@screenColumnResetDone
rts
;===============================================================================
flipBackgroundRight
inc backgroundColumn
lda backgroundColumn
cmp #MapLastColumn
bcc @finished
lda #0
sta backgroundColumn
@finished
rts
;===============================================================================
flipScreenLeft
dec flipScreenCounter
lda flipScreenCounter
cmp #1
bcs @flipDone
lda #1
sta flipScreenCounter
jsr flipScreen
@flipDone
dec screenColumn
lda screenColumn
cmp #1
bcs @screenColumnResetDone
lda #MapLastColumn
sta screenColumn
@screenColumnResetDone
rts
;===============================================================================
flipBackgroundLeft
dec backgroundColumn
lda backgroundColumn
cmp #1
bcs @finished
lda #MapLastColumn
sta backgroundColumn
@finished
rts