main.asm 208 KB
Newer Older
Ricardo Quesada's avatar
Ricardo Quesada committed
1 2 3
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
; Main routine
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
Ricardo Quesada's avatar
Ricardo Quesada committed
4 5 6
; Note about levels:
; LVL0 -> Is "level 1" in the game
; LVL1 -> Is "level 2" in the game
7
; LVL2 -> Not present
Ricardo Quesada's avatar
Ricardo Quesada committed
8
; LVL3 -> Is "level 3" in the game
9 10 11 12 13 14 15 16 17 18 19 20
;
; LVL2:
; Apparently, four levels were designed for Commando.
; There is a lot of data/code that proves this, like:
; - Action table. See: LVL2_ACTION_TBL
; - Row trigger table. See: LVL2_TRIGGER_ROW_TBL
; - Sprites X pos. See: LVL2_SPRITE_X_LO_TBL / LVL2_SPRITE_HI_TBL
; - Charset mask. See: LVL2_CHARSET_MASK_TBL
; - The "main charset (included in co2.asm) was probably the one designed for
;   LVL2. Although part of it was overwritten with letters.
; What in theory is missing to have a working LVL2 is the map, and if fix the
; charset.
Ricardo Quesada's avatar
Ricardo Quesada committed
21

22 23 24 25 26
;
; **** ZP FIELDS ****
;
f4C = $4C
;
Ricardo Quesada's avatar
Ricardo Quesada committed
27
; **** ZP ABSOLUTE ADDRESSES ****
28 29
;
a01 = $01
30 31
a14 = $14
a41 = $41
32 33 34 35 36 37
a5D = $5D
a5E = $5E
a5F = $5F
a60 = $60
aA5 = $A5
aAE = $AE
38
aD7 = $D7
39 40 41 42
aDA = $DA
;
; **** ZP POINTERS ****
;
43 44
p19 = $19                       ;Stores current hero animation, but seems unused
p1A = $1A
Ricardo Quesada's avatar
Ricardo Quesada committed
45
p22 = $22                       ;sprite to create: X lo
46
p23 = $23
Ricardo Quesada's avatar
Ricardo Quesada committed
47
p24 = $24                       ;rows that trigger sprite type init
48
p25 = $25
Ricardo Quesada's avatar
Ricardo Quesada committed
49
p26 = $26                       ;sprite to create: X hi
50
p27 = $27
Ricardo Quesada's avatar
Ricardo Quesada committed
51
p28 = $28                       ;what sprite type to create at row
52
p29 = $29
53
p2A = $2A                       ;charset attributes: background priority, collision, etc.
54
p2B = $2B
55 56 57 58
p5D = $5D
p5F = $5F
p83 = $83
pF7 = $F7
Ricardo Quesada's avatar
Ricardo Quesada committed
59 60 61
pFB = $FB                       ;$FB/$FC: different meanings depending to the game state
pFC = $FC                       ; On Hiscore, it points to Screen RAM
                                ; During the game, it points to the Actions table
Ricardo Quesada's avatar
Ricardo Quesada committed
62 63 64
pFD = $FD                       ;But $FC/$FD is also used during the game to point
                                ; to the level data and is uses with $2A to determine
                                ; the sprite-background priority/collision
65 66 67 68 69 70 71 72 73 74 75 76
;
; **** FIELDS ****
;
f0000 = $0000
fD040 = $D040
fDB48 = $DB48
fDB98 = $DB98
fE087 = $E087
fE348 = $E348
fE398 = $E398
fE3F8 = $E3F8
;
Ricardo Quesada's avatar
Ricardo Quesada committed
77
; **** ABSOLUTE ADDRESSES ****
78 79 80
;
a003D = $003D
a003F = $003F
Ricardo Quesada's avatar
Ricardo Quesada committed
81
SPRITE_IDX_TBL = $004B                   ;$4B-$5A sprite index, used in raster multiplexer
82
a00A7 = $00A7
83
VIC_SPRITE_IDX = $00A8          ;Index used for sprite pos (e.g: $D000,idx) in raster intr.
84 85 86 87 88 89 90 91 92
a00C9 = $00C9
a00F7 = $00F7
a00F8 = $00F8
a00FB = $00FB
a00FC = $00FC
a00FD = $00FD
a00FE = $00FE
a0400 = $0400
a0401 = $0401
Ricardo Quesada's avatar
Ricardo Quesada committed
93 94 95
V_SCROLL_BIT_IDX = $0402        ;pixels scrolled vertically: 0-7
V_SCROLL_ROW_IDX = $0403        ;index to the row in the level: 0 means end of scroll (top of map)
V_SCROLL_DELTA = $0404          ;How many pixels needs to get scrolled. $0: no scroll needed, $ff: -1 one pixel
96
a0405 = $0405
97 98
IRQ_ADDR_LO = $0406
IRQ_ADDR_HI = $0407
Ricardo Quesada's avatar
Ricardo Quesada committed
99
GAME_TICK = $040A               ;Incremented from main loop
Ricardo Quesada's avatar
Ricardo Quesada committed
100
RASTER_TICK = $040B             ;Incremented from raster routine
Ricardo Quesada's avatar
Ricardo Quesada committed
101 102 103 104 105 106 107 108
SPRITES_X_HI00 = $040D          ;MSB for X pos
SPRITES_X_HI01 = $040E
SPRITES_X_HI04 = $0411
SPRITES_X_HI05 = $0412
SPRITES_X_LO00 = $041D          ;LSB for X pos
SPRITES_X_LO01 = $041E
SPRITES_X_LO04 = $0421
SPRITES_X_LO05 = $0422
Ricardo Quesada's avatar
Ricardo Quesada committed
109 110
SPRITES_Y00 = $042D
SPRITES_Y01 = $042E
Ricardo Quesada's avatar
Ricardo Quesada committed
111 112
SPRITES_Y04 = $0431
SPRITES_Y05 = $0432
Ricardo Quesada's avatar
Ricardo Quesada committed
113 114
SPRITES_BKG_PRI00 = $043D
SPRITES_BKG_PRI01 = $043E
Ricardo Quesada's avatar
Ricardo Quesada committed
115 116
SPRITES_BKG_PRI04 = $0441
SPRITES_BKG_PRI05 = $0442
Ricardo Quesada's avatar
Ricardo Quesada committed
117
SPRITES_COLOR00 = $044D         ;primary color of sprite
Ricardo Quesada's avatar
Ricardo Quesada committed
118
SPRITES_COLOR01 = $044E
Ricardo Quesada's avatar
Ricardo Quesada committed
119 120
SPRITES_COLOR04 = $0451
SPRITES_COLOR05 = $0452
Ricardo Quesada's avatar
Ricardo Quesada committed
121
SPRITES_PTR00 = $045D           ;frame to be used by sprite
Ricardo Quesada's avatar
Ricardo Quesada committed
122
SPRITES_PTR01 = $045E
Ricardo Quesada's avatar
Ricardo Quesada committed
123 124
SPRITES_PTR04 = $0461
SPRITES_PTR05 = $0462
Ricardo Quesada's avatar
Ricardo Quesada committed
125
SPRITES_DELTA_X00 = $046D       ;pixels to move horizontally for hero (neg or pos)
Ricardo Quesada's avatar
Ricardo Quesada committed
126
SPRITES_DELTA_X01 = $046E
Ricardo Quesada's avatar
Ricardo Quesada committed
127 128
SPRITES_DELTA_X04 = $0471
SPRITES_DELTA_X05 = $0472
Ricardo Quesada's avatar
Ricardo Quesada committed
129
SPRITES_DELTA_Y00 = $047D       ;pixels to move vertically for hero (neg or pos)
Ricardo Quesada's avatar
Ricardo Quesada committed
130
SPRITES_DELTA_Y01 = $047E
Ricardo Quesada's avatar
Ricardo Quesada committed
131 132
SPRITES_DELTA_Y04 = $0481
SPRITES_DELTA_Y05 = $0482
Ricardo Quesada's avatar
Ricardo Quesada committed
133 134 135 136
SPRITES_TYPE00 = $048D
SPRITES_TYPE01 = $048E
SPRITES_TYPE04 = $0491
SPRITES_TYPE05 = $0492
137 138 139 140 141
SPRITES_TMP_A01 = $049D         ;Used by different thigns. Only 15 slots (all but 0)
SPRITES_TMP_A04 = $04A0         ;referenced in throw grenade
SPRITES_TMP_A05 = $04A1         ;Used to link sprites together (?)
SPRITES_TMP_B05 = $04AC         ;Used as index to delta_tbl and more. Only 11 slots (enemies only)
SPRITES_TMP_C05 = $04B7         ;Used for timer: Only 11 slots (enemies only)
142 143
SPRITES_PREV_Y00 = $04C2        ;Used by raster interrupt. Is the Y value before applying delta.
                                ; Valid for all sprites expect for the Hero (SPRITE00)
Ricardo Quesada's avatar
Ricardo Quesada committed
144
FIRE_COOLDOWN = $04DF           ;reset with $ff
Ricardo Quesada's avatar
Ricardo Quesada committed
145
HERO_ANIM_MOV_IDX = $04E0       ;Movement anim for hero: left,right,up,down,diagonally,etc.
Ricardo Quesada's avatar
Ricardo Quesada committed
146
                                ; See: SOLDIER_ANIM_FRAMES_HI/LO
Ricardo Quesada's avatar
Ricardo Quesada committed
147
a04E1 = $04E1                   ;Bullet speed idx (???)
Ricardo Quesada's avatar
Ricardo Quesada committed
148 149 150
BKG_COLOR0 = $04E2
BKG_COLOR1 = $04E3
BKG_COLOR2 = $04E4
151
COUNTER1 = $04E6
152
a04E7 = $04E7
Ricardo Quesada's avatar
Ricardo Quesada committed
153
TRIGGER_ROW_IDX = $04E8         ;If equal to row index, create object
154
a04E9 = $04E9                   ;unused
155 156 157
a04EA = $04EA
a04EC = $04EC
a04ED = $04ED
Ricardo Quesada's avatar
Ricardo Quesada committed
158
a04EE = $04EE                   ;Hero is moving up (unused)
Ricardo Quesada's avatar
Ricardo Quesada committed
159
ENEMIES_IN_FORT = $04EF         ;How many enemies are inside the fort/warehouse
Ricardo Quesada's avatar
Ricardo Quesada committed
160 161 162
TMP_SPRITE_X_LO = $04F0         ;Temp sprite-X LSB for current sprite
TMP_SPRITE_Y = $04F1            ;ditto for Y
TMP_SPRITE_X_HI = $04F2         ;ditto for X MSB
Ricardo Quesada's avatar
Ricardo Quesada committed
163
LEVEL_NR = $04F3
Ricardo Quesada's avatar
Ricardo Quesada committed
164
a04F4 = $04F4                   ;Seems to be a delay or something related to enemies inside
Ricardo Quesada's avatar
Ricardo Quesada committed
165 166
IS_LEVEL_COMPLETE = $04F5       ;0: game in progress, 1:lvl complete. Exit animation finished (unused apparently)
IS_ANIM_EXIT_DOOR = $04F7       ;1: hero goes to exit door animation in progress
167 168 169 170 171 172 173
SCORE_LSB = $04F8
SCORE_MSB = $04F9
a04FD = $04FD
GRENADES = $04FF
LIVES = $0500
a0501 = $0501
a0502 = $0502
Ricardo Quesada's avatar
Ricardo Quesada committed
174
IS_HERO_DEAD = $0503            ;0: hero alive, 1:was shot, 2:fell down in trench
175
a0504 = $0504
Ricardo Quesada's avatar
Ricardo Quesada committed
176
HISCORE_IS_BULLET_ANIM = $0505  ;1: if the bullet in hiscore is being animated
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
177 178 179
HISCORE_NAME = $0506            ;8 chars reserved for the hiscore name ($0506-$050E)
HISCORE_NAME_IDX = $050F        ;Index to the hiscore name
HISCORE_SELECTED_CHAR = $0510   ;Selected char in hiscore
Ricardo Quesada's avatar
Ricardo Quesada committed
180 181
HISCORE_IS_CHAR_ANIM = $0511    ;1: if the selected char in hiscore is being animated
HISCORE_ANIM_CHAR_COUNTER = $0512       ;Counter to the selected char animation in hiscore
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
aE34E = $E34E
aE34F = $E34F
aE350 = $E350
aE351 = $E351
aE359 = $E359
aE35A = $E35A
aE361 = $E361
aE362 = $E362
aE36A = $E36A
aE36B = $E36B
aE36C = $E36C
aE36D = $E36D
aE3FA = $E3FA
aE3FB = $E3FB
aE3FF = $E3FF
197
aFFC0 = $FFC0
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
;
; **** POINTERS ****
;
pD800 = $D800
pD829 = $D829
pD882 = $D882
pE000 = $E000
pE029 = $E029
pE082 = $E082
;
; **** EXTERNAL JUMPS ****
;
e03F0 = $03F0
eF00A = $F00A
;
; **** PREDEFINED LABELS ****
;

        * = $0800

        .BYTE $00,$0B,$08,$0A,$00,$9E,$32,$30
        .BYTE $36,$31,$00,$00,$00
220

221 222 223 224 225 226 227
        LDA #$00     ;#%00000000
        TAY
        STA aA5
        STA aAE
        LDA #$09     ;#%00001001
        JSR s0828
        JSR s083D
228 229
        JSR eF00A       ;set charset: copy from e000-efff to d000-dfff
        JSR s083D       ; defined in "co2.asm"
230
        JSR s0828
231
        JMP BOOT
232

233
s0828   LDA #$01
234 235 236 237 238
        TAX
        TAY
        NOP
        NOP
        NOP
239
        LDA #$00
240 241 242
        NOP
        NOP
        NOP
243 244 245 246
        LDA #$00
        LDX #$FF
        LDY #$FF
        JMP e03F0       ;Load file. Defined in "commando.asm"
247 248 249 250 251 252 253

s083D   SEI
b083E   LDA a01
        EOR #$02     ;#%00000010
        STA a01
        RTS

254
        ; FIXME: unused, remove
255 256 257
        .BYTE $E0,$09,$D0,$F5,$20,$AD,$35,$20
        .BYTE $57,$0A,$20

258 259 260
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
BOOT    ;$0850
        SEI
261
        LDA #<NMI_HANDLER
262
        STA $0318    ;NMI
263
        LDA #>NMI_HANDLER
264 265
        STA $0319    ;NMI
        CLI
Ricardo Quesada's avatar
Ricardo Quesada committed
266 267

        ; FIXME: Probably this is not really needed. In fact, it generates
Ricardo Quesada's avatar
Ricardo Quesada committed
268
        ; a small artifact at the end of LVL1, since it is overwriting the
Ricardo Quesada's avatar
Ricardo Quesada committed
269
        ; data
270
        LDX #$00     ;#%00000000
Ricardo Quesada's avatar
Ricardo Quesada committed
271
_L00    LDA RESET_ROUTINE,X
Ricardo Quesada's avatar
Ricardo Quesada committed
272
        STA $8000,X  ;Sets the reset routine (CBM80)
273 274
        INX
        CPX #$09     ;#%00001001
275
        BNE _L00
Ricardo Quesada's avatar
Ricardo Quesada committed
276 277

        JSR SETUP_VIC_BANK
Ricardo Quesada's avatar
Ricardo Quesada committed
278
        JSR SET_SIGHT_SPRITE
Ricardo Quesada's avatar
random  
Ricardo Quesada committed
279
        JSR INIT_RANDOM
280 281 282

        ; Sprite Y pos used in raster multiplexer
        LDX #$10
283
_L01    TXA
Ricardo Quesada's avatar
Ricardo Quesada committed
284
        STA SPRITE_IDX_TBL,b,X
285
        DEX
286
        BPL _L01
287

288 289 290
        LDA #$00     ;#%00000000
        STA a0502
        STA a0501
291

Ricardo Quesada's avatar
Ricardo Quesada committed
292 293
START                   ;$0883
        LDA #$A5        ;Set initial starting row
294
        STA V_SCROLL_ROW_IDX
Ricardo Quesada's avatar
Ricardo Quesada committed
295
        JSR SETUP_LEVEL
296
        JSR SETUP_SCREEN
297 298 299
        JSR SETUP_IRQ

        ; Display main title screen
Ricardo Quesada's avatar
Ricardo Quesada committed
300
        LDA #$00        ;Song to play (main theme)
301
        JSR MUSIC_INIT
Ricardo Quesada's avatar
Ricardo Quesada committed
302
        JSR SCREEN_MAIN_TITLE
303

Ricardo Quesada's avatar
Ricardo Quesada committed
304 305
        JSR s5006       ;Music stop?
        LDA #$00        ;#%00000000
306 307
        STA SCORE_LSB
        STA SCORE_MSB
308
        STA V_SCROLL_BIT_IDX
Ricardo Quesada's avatar
Ricardo Quesada committed
309
        STA LEVEL_NR
310 311 312 313 314 315
        STA $D01D    ;Sprites Expand 2x Horizontal (X)
        STA $D017    ;Sprites Expand 2x Vertical (Y)
        LDA #$05     ;#%00000101
        STA GRENADES
        STA LIVES

Ricardo Quesada's avatar
Ricardo Quesada committed
316
        ;riq
Ricardo Quesada's avatar
Ricardo Quesada committed
317 318
        ;lda #3
        ;sta LEVEL_NR
Ricardo Quesada's avatar
Ricardo Quesada committed
319

Ricardo Quesada's avatar
Ricardo Quesada committed
320
START_LEVEL          ;$08B8
Ricardo Quesada's avatar
Ricardo Quesada committed
321
        LDA #$A5     ;#%10100101
322
        STA V_SCROLL_ROW_IDX
323 324
        LDA #$00     ;Song to play (main theme)
        JSR MUSIC_INIT
Ricardo Quesada's avatar
Ricardo Quesada committed
325 326

        ; Restart after life lost
Ricardo Quesada's avatar
Ricardo Quesada committed
327 328
RESTART
        JSR SETUP_LEVEL
329
        JSR SETUP_SCREEN
330
        JSR SETUP_IRQ
Ricardo Quesada's avatar
Ricardo Quesada committed
331 332

        ; Main loop
Ricardo Quesada's avatar
Ricardo Quesada committed
333
GAME_LOOP            ;$08CB
Ricardo Quesada's avatar
Ricardo Quesada committed
334
        JSR WAIT_RASTER_AT_BOTTOM
Ricardo Quesada's avatar
Ricardo Quesada committed
335 336
        LDA V_SCROLL_DELTA
        BEQ _L00
337
        CLC
338
        ADC V_SCROLL_BIT_IDX
339
        AND #$07     ;#%00000111
340
        STA V_SCROLL_BIT_IDX
341
        CMP #$07     ;#%00000111
Ricardo Quesada's avatar
Ricardo Quesada committed
342
        BNE _L00
343
        DEC V_SCROLL_ROW_IDX
344 345
        LDA #$00     ;#%00000000
        STA a04E9
Ricardo Quesada's avatar
Ricardo Quesada committed
346
        JSR APPLY_DELTA_MOV
347
        INC a04E9
Ricardo Quesada's avatar
Ricardo Quesada committed
348
        JSR LEVEL_DRAW_VIEWPORT
349
        INC a04E9
Ricardo Quesada's avatar
Ricardo Quesada committed
350
        JMP GAME_LOOP
351

Ricardo Quesada's avatar
Ricardo Quesada committed
352
_L00    INC GAME_TICK
Ricardo Quesada's avatar
Ricardo Quesada committed
353
        JSR APPLY_DELTA_MOV
Ricardo Quesada's avatar
Ricardo Quesada committed
354
        JSR SORT_SPRITES_BY_Y
355
        JSR TRY_THROW_GRENADE
Ricardo Quesada's avatar
Ricardo Quesada committed
356
        JSR ANIM_ENEMIES
357
        JSR RUN_ACTIONS
Ricardo Quesada's avatar
Ricardo Quesada committed
358
        JSR ANIM_HERO
Ricardo Quesada's avatar
Ricardo Quesada committed
359

Ricardo Quesada's avatar
Ricardo Quesada committed
360
        LDA IS_HERO_DEAD
Ricardo Quesada's avatar
Ricardo Quesada committed
361
        BNE HERO_DIED
362
        JSR HANDLE_JOY2
Ricardo Quesada's avatar
Ricardo Quesada committed
363
        LDA IS_ANIM_EXIT_DOOR
Ricardo Quesada's avatar
Ricardo Quesada committed
364
        BNE _L01
365
        JSR CHECK_COLLISION
Ricardo Quesada's avatar
Ricardo Quesada committed
366
_L01    LDA SPRITES_Y00
Ricardo Quesada's avatar
Ricardo Quesada committed
367
        CMP #$5A
Ricardo Quesada's avatar
Ricardo Quesada committed
368
        BNE GAME_LOOP
Ricardo Quesada's avatar
Ricardo Quesada committed
369 370

        LDA #$14     ;Points won after beating lvl
371
        JSR SCORE_ADD
Ricardo Quesada's avatar
Ricardo Quesada committed
372
        LDA LEVEL_NR
373 374
        AND #$03     ;#%00000011
        CMP #$03     ;#%00000011
Ricardo Quesada's avatar
Ricardo Quesada committed
375
        BNE _L02
Ricardo Quesada's avatar
Ricardo Quesada committed
376 377

        ;Play animation at end of Level 3
378
        LDA #$09     ;#%00001001
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
379
        JSR SFX_PLAY
Ricardo Quesada's avatar
Ricardo Quesada committed
380
        JSR SET_FORT_ON_FIRE
Ricardo Quesada's avatar
Ricardo Quesada committed
381

Ricardo Quesada's avatar
Ricardo Quesada committed
382
_L02    LDA #$02     ;Song to play (Level complete)
383
        JSR MUSIC_INIT
Ricardo Quesada's avatar
Ricardo Quesada committed
384
        JSR PRINT_LVL_COMPLETE
Ricardo Quesada's avatar
Ricardo Quesada committed
385
        INC LEVEL_NR
Ricardo Quesada's avatar
Ricardo Quesada committed
386 387 388

        ; Since LVL2 was removed from the game, when LVL2 is reached,
        ; the level is changed to LVL3.
Ricardo Quesada's avatar
Ricardo Quesada committed
389
        LDA LEVEL_NR
390 391
        AND #$03     ;#%00000011
        CMP #$02     ;#%00000010
Ricardo Quesada's avatar
Ricardo Quesada committed
392
        BNE _L03
Ricardo Quesada's avatar
Ricardo Quesada committed
393
        INC LEVEL_NR
Ricardo Quesada's avatar
Ricardo Quesada committed
394

Ricardo Quesada's avatar
Ricardo Quesada committed
395
_L03    JMP START_LEVEL
396

Ricardo Quesada's avatar
Ricardo Quesada committed
397 398
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
; Animate hero "is dead"
Ricardo Quesada's avatar
Ricardo Quesada committed
399
HERO_DIED               ;b0953
Ricardo Quesada's avatar
Ricardo Quesada committed
400 401
        LDA IS_HERO_DEAD
        CMP #$02     ;Died of fall in trench/water?
Ricardo Quesada's avatar
Ricardo Quesada committed
402
        BNE _L01
Ricardo Quesada's avatar
Ricardo Quesada committed
403 404

        ; Hero fell down in trench
405 406
        INC COUNTER1
        LDA COUNTER1
407
        CMP #$14     ;#%00010100
Ricardo Quesada's avatar
Ricardo Quesada committed
408
        BCC _L00
409
        CMP #$50     ;#%01010000
Ricardo Quesada's avatar
Ricardo Quesada committed
410
        BCS _L03
Ricardo Quesada's avatar
Ricardo Quesada committed
411 412
        LDA #$CC     ;Hero fall down in trench frame #1
        STA SPRITES_PTR00
Ricardo Quesada's avatar
Ricardo Quesada committed
413
        JMP GAME_LOOP
414

Ricardo Quesada's avatar
Ricardo Quesada committed
415
_L00    LDA #$CB     ;Hero fall down in trench frame #0
Ricardo Quesada's avatar
Ricardo Quesada committed
416
        STA SPRITES_PTR00
Ricardo Quesada's avatar
Ricardo Quesada committed
417
        JMP GAME_LOOP
418

Ricardo Quesada's avatar
Ricardo Quesada committed
419
        ; Hero was shot
Ricardo Quesada's avatar
Ricardo Quesada committed
420
_L01    INC COUNTER1
421
        LDA COUNTER1
422
        CMP #$14     ;#%00010100
Ricardo Quesada's avatar
Ricardo Quesada committed
423
        BCC _L02
424
        CMP #$50     ;#%01010000
Ricardo Quesada's avatar
Ricardo Quesada committed
425
        BCS _L03
Ricardo Quesada's avatar
Ricardo Quesada committed
426
        LDA #$B8     ;Hero was shot: frame #1
Ricardo Quesada's avatar
Ricardo Quesada committed
427
        STA SPRITES_PTR00
Ricardo Quesada's avatar
Ricardo Quesada committed
428
        JMP GAME_LOOP
429

Ricardo Quesada's avatar
Ricardo Quesada committed
430
_L02    LDA #$DD     ;Hero was shot: frame #0
Ricardo Quesada's avatar
Ricardo Quesada committed
431
        STA SPRITES_PTR00
Ricardo Quesada's avatar
Ricardo Quesada committed
432
        JMP GAME_LOOP
433

Ricardo Quesada's avatar
Ricardo Quesada committed
434 435
        ; End of "died" animation. Decrease life.
_L03    DEC LIVES
436 437 438
        JSR SCREEN_REFRESH_LIVES
        LDA LIVES
        BEQ GAME_OVER
Ricardo Quesada's avatar
Ricardo Quesada committed
439
        JMP RESTART
440

Ricardo Quesada's avatar
Ricardo Quesada committed
441
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
442 443
GAME_OVER
        LDX #$06     ;#%00000110
444
_L00    TXA
445 446 447
        ASL A
        TAY
        LDA SCORE_MSB
Ricardo Quesada's avatar
Ricardo Quesada committed
448
        CMP HISCORE_LSB00,Y
449 450
        BCC _L04
        BNE _L01
451
        LDA SCORE_LSB
Ricardo Quesada's avatar
Ricardo Quesada committed
452
        CMP HISCORE_MSB00,Y
453 454
        BCC _L04
_L01    TXA
455 456
        ASL A
        TAY
Ricardo Quesada's avatar
Ricardo Quesada committed
457 458 459 460
        LDA HISCORE_LSB00,Y
        STA HISCORE_LSB01,Y
        LDA HISCORE_MSB00,Y
        STA HISCORE_MSB01,Y
461 462 463 464 465
        TXA
        ASL A
        ASL A
        ASL A
        TAY
Ricardo Quesada's avatar
Ricardo Quesada committed
466 467
_L02    LDA HISCORE_NAME00,Y
        STA HISCORE_NAME01,Y
468 469 470
        INY
        TYA
        AND #$07     ;#%00000111
471
        BNE _L02
472
        DEX
473
        BPL _L00
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
474

475
        LDA SCORE_MSB
Ricardo Quesada's avatar
Ricardo Quesada committed
476
        STA HISCORE_LSB00
477
        LDA SCORE_LSB
Ricardo Quesada's avatar
Ricardo Quesada committed
478
        STA HISCORE_MSB00
Ricardo Quesada's avatar
Ricardo Quesada committed
479
        JSR SCREEN_ENTER_HI_SCORE
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
480 481 482

        LDY #$00
_L03    LDA HISCORE_NAME,Y
Ricardo Quesada's avatar
Ricardo Quesada committed
483
        STA HISCORE_NAME00,Y
484
        INY
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
485
        CPY #$08
486 487
        BNE _L03
        JMP _L07
488

489
_L04    TXA
490 491 492
        ASL A
        TAY
        LDA SCORE_MSB
Ricardo Quesada's avatar
Ricardo Quesada committed
493
        STA HISCORE_LSB01,Y
494
        LDA SCORE_LSB
Ricardo Quesada's avatar
Ricardo Quesada committed
495
        STA HISCORE_MSB01,Y
496
        CPX #$06     ;#%00000110
497 498
        BNE _L05
        JMP START
499

500
_L05    TXA
501
        PHA
Ricardo Quesada's avatar
Ricardo Quesada committed
502
        JSR SCREEN_ENTER_HI_SCORE
503 504 505 506 507 508
        PLA
        ASL A
        ASL A
        ASL A
        TAX
        LDY #$00     ;#%00000000
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
509
_L06    LDA HISCORE_NAME,Y
Ricardo Quesada's avatar
Ricardo Quesada committed
510
        STA HISCORE_NAME01,X
511 512 513
        INX
        INY
        CPY #$08     ;#%00001000
514 515 516
        BNE _L06

_L07    JSR CLEANUP_SPRITES
Ricardo Quesada's avatar
Ricardo Quesada committed
517
        JSR DISPLAY_HI_SCORES
518

519
        LDY #$64     ;#%01100100
Ricardo Quesada's avatar
delay  
Ricardo Quesada committed
520
        JSR DELAY
521 522 523

        ; Wait for 255 frames or joystick fire

524
        LDA #$FF     ;#%11111111
525
        STA COUNTER1
526
_L08    LDA $DC00    ;CIA1: Data Port Register A  (fire in Game Over scene)
527
        CMP #$6F     ;#%01101111
528
        BEQ _L09
Ricardo Quesada's avatar
Ricardo Quesada committed
529
        JSR WAIT_RASTER_AT_BOTTOM
530
        DEC COUNTER1
531 532
        BNE _L08
_L09    JMP START
533

534 535
NMI_HANDLER
        RTI
536

Ricardo Quesada's avatar
Ricardo Quesada committed
537
        ;TODO: This generates small garbage in the top row of the map.
538
        ;Can be safely removed once we don't care about the generating exactly
Ricardo Quesada's avatar
Ricardo Quesada committed
539
        ;the same binary.
Ricardo Quesada's avatar
Ricardo Quesada committed
540
RESET_ROUTINE       ;$0A4E
541
        .ADDR BOOT, BOOT
Ricardo Quesada's avatar
Ricardo Quesada committed
542
        .BYTE $C3,$C2,$CD,$38,$30
543

Ricardo Quesada's avatar
Ricardo Quesada committed
544
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
545
; Sets the sight "()" sprite for high scores as sprite $41 (@ $D040)
546 547 548
; Charset for LVL2 is located between D000-D7FF. Since LVL2 is not present
; it is safe to overwrite parts of $D000 as long you don't overwrite where
; the letters/numbers are located.
Ricardo Quesada's avatar
Ricardo Quesada committed
549
SET_SIGHT_SPRITE    ;$0A57
550 551
        ;TODO: probably it is safe to remove the stop/start timer since
        ;timer is not being used by code, and is already stop
Ricardo Quesada's avatar
Ricardo Quesada committed
552
        LDA $DC0E    ;CIA1: CIA Control Register A
553
        AND #$FE     ;#%11111110 Stop timer
Ricardo Quesada's avatar
Ricardo Quesada committed
554
        STA $DC0E    ;Stop timer
555
        LDA a01
556
        AND #$FB     ;#%11111011    Enabling RAM at $D000 I guess
557
        STA a01
558

Ricardo Quesada's avatar
Ricardo Quesada committed
559 560 561
        LDX #$3F     ;size of sprite
_L00    LDA SIGHT_SPR_DATA,X
        STA fD040,X  ;It will be sprite $41
562
        DEX
Ricardo Quesada's avatar
Ricardo Quesada committed
563
        BPL _L00
564

565
        LDA a01
566
        ORA #$04     ;#%00000100    Enabling I/O at $D000 I guess
567 568
        STA a01
        LDA $DC0E    ;CIA1: CIA Control Register A
569
        ORA #$01     ;#%00000001 Start timer (why ?)
Ricardo Quesada's avatar
Ricardo Quesada committed
570
        STA $DC0E    ;Start Timer
571 572
        RTS

Ricardo Quesada's avatar
Ricardo Quesada committed
573
SIGHT_SPR_DATA      ;$0A7F
Ricardo Quesada's avatar
Ricardo Quesada committed
574
        .BYTE $00,$00,$00,$02,$AA,$00,$0A,$AA
575 576 577 578 579 580 581
        .BYTE $80,$28,$20,$A0,$20,$20,$20,$20
        .BYTE $00,$20,$A0,$00,$28,$80,$00,$08
        .BYTE $80,$20,$08,$80,$20,$08,$A0,$A8
        .BYTE $28,$A0,$A8,$28,$80,$20,$08,$80
        .BYTE $20,$08,$80,$00,$08,$A0,$00,$28
        .BYTE $20,$00,$20,$20,$20,$20,$28,$20
        .BYTE $A0,$0A,$AA,$80,$02,$AA,$00
582

Ricardo Quesada's avatar
Ricardo Quesada committed
583
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
Ricardo Quesada's avatar
Ricardo Quesada committed
584 585 586
; Animates the selected char in hiscore
HISCORE_ANIM_CHAR       ;$0ABE
        LDA HISCORE_IS_CHAR_ANIM
587
        BEQ _SKIP
Ricardo Quesada's avatar
Ricardo Quesada committed
588

589
        LDY #$00     ;#%00000000
Ricardo Quesada's avatar
Ricardo Quesada committed
590 591
        INC HISCORE_ANIM_CHAR_COUNTER
        LDA HISCORE_ANIM_CHAR_COUNTER
592
        CMP #$32     ;#%00110010
593
        BEQ _L02
594 595 596
        AND #$0F     ;#%00001111
        LSR A
        LSR A
Ricardo Quesada's avatar
Ricardo Quesada committed
597
        AND #$03
598
        BEQ _L00
Ricardo Quesada's avatar
Ricardo Quesada committed
599
        AND #$01
600
        BNE _L01
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
601
        LDA HISCORE_SELECTED_CHAR
602
        CLC
Ricardo Quesada's avatar
Ricardo Quesada committed
603
        ADC #$20     ;Select the flipped char
604 605 606
        STA (pF7),Y
        RTS

Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
607
_L00    LDA HISCORE_SELECTED_CHAR
608 609 610
        STA (pF7),Y
        RTS

Ricardo Quesada's avatar
Ricardo Quesada committed
611
_L01    LDA #$79     ;Select the regular char
612 613 614
        STA (pF7),Y
        RTS

615
_L02    LDA #$00     ;#%00000000
Ricardo Quesada's avatar
Ricardo Quesada committed
616
        STA HISCORE_IS_CHAR_ANIM
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
617
        LDA HISCORE_SELECTED_CHAR
618
        STA (pF7),Y
619
_SKIP   RTS
620

621
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
Ricardo Quesada's avatar
Ricardo Quesada committed
622 623 624
; Get the selected char with the sight in the hiscore scene
HISCORE_GET_SELECTED_CHAR       ;$0AFA
        LDA SPRITES_X_LO05
625 626 627 628 629 630 631 632
        AND #$F0     ;#%11110000
        SEC
        SBC #$10     ;#%00010000
        PHP
        LSR A
        LSR A
        LSR A
        PLP
Ricardo Quesada's avatar
Ricardo Quesada committed
633
        BCC _L00
Ricardo Quesada's avatar
Ricardo Quesada committed
634
        LDY SPRITES_X_HI05
Ricardo Quesada's avatar
Ricardo Quesada committed
635
        BEQ _L00
636 637
        CLC
        ADC #$20     ;#%00100000
Ricardo Quesada's avatar
Ricardo Quesada committed
638
_L00    STA a00FB,b
639 640 641 642
        LDA #$00     ;#%00000000
        STA a00FC,b
        STA a00FD,b
        STA a00FE,b
Ricardo Quesada's avatar
Ricardo Quesada committed
643
        LDA SPRITES_Y05
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687
        AND #$F0     ;#%11110000
        SEC
        SBC #$2E     ;#%00101110
        LSR A
        LSR A
        LSR A
        PHA
        LSR A
        ROR a00FC,b
        LSR A
        ROR a00FC,b
        LSR A
        ROR a00FC,b
        STA a00FD,b
        PLA
        ASL A
        ROL a00FE,b
        ASL A
        ROL a00FE,b
        ASL A
        ROL a00FE,b
        CLC
        ADC a00FC,b
        STA a00FC,b
        LDA a00FD,b
        ADC a00FE,b
        STA a00FD,b
        LDA a00FC,b
        CLC
        ADC a00FB,b
        STA a00FC,b
        LDA a00FD,b
        ADC #$00     ;#%00000000
        STA a00FD,b
        LDA a00FD,b
        CLC
        ADC #$E0     ;#%11100000
        STA a00FD,b
        LDA a00FC,b
        STA a00F7,b
        LDA a00FD,b
        STA a00F8,b
        SEI
        LDA a01
Ricardo Quesada's avatar
Ricardo Quesada committed
688
        AND #$FD     ;Enable I/O to read from Screen RAM
689
        STA a01
Ricardo Quesada's avatar
Ricardo Quesada committed
690

691 692
        LDY #$00     ;#%00000000
        LDA (pFC),Y
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
693
        STA HISCORE_SELECTED_CHAR
Ricardo Quesada's avatar
Ricardo Quesada committed
694

695
        LDA a01
Ricardo Quesada's avatar
Ricardo Quesada committed
696
        ORA #$02
697
        STA a01
Ricardo Quesada's avatar
Ricardo Quesada committed
698

699 700 701
        CLI
        RTS

Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
702 703 704 705 706
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
; Sets up the hero and sight sprite, and cleans up name and other vars
HISCORE_SETUP_SPRITES   ;$0B94
        ; Sight sprite
        LDA #$64     ;#%01100100
707
        AND #$F0     ;#%11110000
Ricardo Quesada's avatar
Ricardo Quesada committed
708
        STA SPRITES_X_LO05
709 710
        LDA #$64     ;#%01100100
        AND #$F0     ;#%11110000
Ricardo Quesada's avatar
Ricardo Quesada committed
711
        STA SPRITES_Y05
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
712
        LDA #$00
Ricardo Quesada's avatar
Ricardo Quesada committed
713
        STA SPRITES_X_HI05
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
714
        LDA #$41     ;sight sprite
Ricardo Quesada's avatar
Ricardo Quesada committed
715
        STA SPRITES_PTR05
Ricardo Quesada's avatar
Ricardo Quesada committed
716
        LDA #$02     ;red
Ricardo Quesada's avatar
Ricardo Quesada committed
717
        STA SPRITES_COLOR05
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
718
        LDA #$FF
Ricardo Quesada's avatar
Ricardo Quesada committed
719
        STA SPRITES_BKG_PRI05
Ricardo Quesada's avatar
Ricardo Quesada committed
720
        LDA #$01            ;anim_type_01: bullet
Ricardo Quesada's avatar
Ricardo Quesada committed
721
        STA SPRITES_TYPE05
Ricardo Quesada's avatar
Ricardo Quesada committed
722
        LDA SPRITES_X_LO05
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
723 724

        ; Hero sprite
Ricardo Quesada's avatar
Ricardo Quesada committed
725
        STA SPRITES_X_LO00
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
726
        LDA #$B4
Ricardo Quesada's avatar
Ricardo Quesada committed
727
        STA SPRITES_Y00
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
728
        LDA #$00
Ricardo Quesada's avatar
Ricardo Quesada committed
729
        STA SPRITES_X_HI00
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
730
        LDA #$98     ;Hero going up
Ricardo Quesada's avatar
Ricardo Quesada committed
731
        STA SPRITES_PTR00
Ricardo Quesada's avatar
Ricardo Quesada committed
732 733
        LDA #$06     ;blue
        STA SPRITES_COLOR00
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
734
        LDA #$00
Ricardo Quesada's avatar
Ricardo Quesada committed
735
        STA SPRITES_BKG_PRI00
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
736
        LDA #$01
Ricardo Quesada's avatar
Ricardo Quesada committed
737
        STA SPRITES_TYPE00
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
738

Ricardo Quesada's avatar
Ricardo Quesada committed
739 740
        LDX #$07
        LDA #$00
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
741
_L00    STA HISCORE_NAME,X
742
        DEX
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
743 744
        BPL _L00

Ricardo Quesada's avatar
Ricardo Quesada committed
745 746
        LDA #$00
        STA HISCORE_IS_BULLET_ANIM
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
747
        STA HISCORE_NAME_IDX
Ricardo Quesada's avatar
Ricardo Quesada committed
748
        STA HISCORE_IS_CHAR_ANIM
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
749 750 751

        ; $F7/$F8 -> Screen RAM
        LDA #<pE000
752
        STA a00F7,b
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
753
        LDA #>pE000
754
        STA a00F8,b
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
755 756 757

        LDA #$20
        STA HISCORE_SELECTED_CHAR
Ricardo Quesada's avatar
Ricardo Quesada committed
758
        JSR APPLY_DELTA_MOV
Ricardo Quesada's avatar
Ricardo Quesada committed
759
        JSR SORT_SPRITES_BY_Y
760 761 762
        RTS

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
Ricardo Quesada's avatar
Ricardo Quesada committed
763 764 765 766
HISCORE_READ_JOY_MOV
        LDA $DC00
        AND #$01     ;#%00000001        up?
        BNE _L00
Ricardo Quesada's avatar
Ricardo Quesada committed
767
        LDA SPRITES_Y05
Ricardo Quesada's avatar