main.asm 208 KB
Newer Older
Ricardo Quesada's avatar
Ricardo Quesada committed
1 2 3 4
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
; Main routine
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;

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
;
; **** ZP FIELDS ****
;
f3C = $3C
f4C = $4C
f95 = $95
f96 = $96
f97 = $97
fFF = $FF
;
; **** ZP ABSOLUTE ADRESSES ****
;
a01 = $01
a05 = $05
a13 = $13
a3C = $3C
a5D = $5D
a5E = $5E
a5F = $5F
a60 = $60
aA5 = $A5
aAE = $AE
aC5 = $C5
aDA = $DA
aE6 = $E6
;
; **** ZP POINTERS ****
;
Ricardo Quesada's avatar
Ricardo Quesada committed
33
p22 = $22                       ;sprite to create: X lo
Ricardo Quesada's avatar
Ricardo Quesada committed
34
p24 = $24                       ;rows that trigger sprite type init
Ricardo Quesada's avatar
Ricardo Quesada committed
35
p26 = $26                       ;sprite to create: X hi
Ricardo Quesada's avatar
Ricardo Quesada committed
36
p28 = $28                       ;what sprite type to create at row
Ricardo Quesada's avatar
Ricardo Quesada committed
37
p2A = $2A                       ;256 bytes of Collision map?
38 39 40 41 42 43 44
p5D = $5D
p5F = $5F
p83 = $83
pA9 = $A9
pD0 = $D0
pD2 = $D2
pF7 = $F7
Ricardo Quesada's avatar
Ricardo Quesada committed
45 46 47
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
48 49 50
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
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
;
; **** FIELDS ****
;
f0000 = $0000
f00A2 = $00A2
fD040 = $D040
fDB48 = $DB48
fDB98 = $DB98
fDBDA = $DBDA
fE087 = $E087
fE348 = $E348
fE398 = $E398
fE3F8 = $E3F8
fE6DC = $E6DC
fEFBA = $EFBA
;
; **** ABSOLUTE ADRESSES ****
;
a0014 = $0014
Ricardo Quesada's avatar
Ricardo Quesada committed
70
a0019 = $0019                   ;Stores current hero animation, but seems unused
71 72 73 74 75 76 77 78 79 80 81 82 83 84
a001A = $001A
a0022 = $0022
a0023 = $0023
a0024 = $0024
a0025 = $0025
a0026 = $0026
a0027 = $0027
a0028 = $0028
a0029 = $0029
a002A = $002A
a002B = $002B
a003D = $003D
a003F = $003F
a0041 = $0041
85 86
a004B = $004B                   ;4b-5a Related to sprite Y pos, used in raster multiplexer
a004C = $004C
87 88 89 90 91 92 93 94 95 96
a004E = $004E
a0053 = $0053
a0054 = $0054
a0055 = $0055
a0056 = $0056
a0057 = $0057
a0058 = $0058
a0059 = $0059
a005A = $005A
a00A7 = $00A7
97
VIC_SPRITE_IDX = $00A8          ;Index used for sprite pos (e.g: $D000,idx) in raster intr.
98 99 100 101 102 103 104 105 106 107
a00C9 = $00C9
a00D7 = $00D7
a00F7 = $00F7
a00F8 = $00F8
a00FB = $00FB
a00FC = $00FC
a00FD = $00FD
a00FE = $00FE
a0400 = $0400
a0401 = $0401
Ricardo Quesada's avatar
Ricardo Quesada committed
108 109 110
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
111
a0405 = $0405
112 113
IRQ_ADDR_LO = $0406
IRQ_ADDR_HI = $0407
Ricardo Quesada's avatar
Ricardo Quesada committed
114 115
GAME_TICK = $040A               ;Incremented from main loop
RASTER_TICK = $040B             ;Incremeted from raster routine
Ricardo Quesada's avatar
Ricardo Quesada committed
116 117 118 119 120 121 122 123
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
124 125
SPRITES_Y00 = $042D
SPRITES_Y01 = $042E
Ricardo Quesada's avatar
Ricardo Quesada committed
126 127
SPRITES_Y04 = $0431
SPRITES_Y05 = $0432
Ricardo Quesada's avatar
Ricardo Quesada committed
128 129
SPRITES_BKG_PRI00 = $043D
SPRITES_BKG_PRI01 = $043E
Ricardo Quesada's avatar
Ricardo Quesada committed
130 131
SPRITES_BKG_PRI04 = $0441
SPRITES_BKG_PRI05 = $0442
Ricardo Quesada's avatar
Ricardo Quesada committed
132
SPRITES_COLOR00 = $044D         ;primary color of sprite
Ricardo Quesada's avatar
Ricardo Quesada committed
133
SPRITES_COLOR01 = $044E
Ricardo Quesada's avatar
Ricardo Quesada committed
134 135
SPRITES_COLOR04 = $0451
SPRITES_COLOR05 = $0452
Ricardo Quesada's avatar
Ricardo Quesada committed
136
SPRITES_PTR00 = $045D           ;frame to be used by sprite
Ricardo Quesada's avatar
Ricardo Quesada committed
137
SPRITES_PTR01 = $045E
Ricardo Quesada's avatar
Ricardo Quesada committed
138 139
SPRITES_PTR04 = $0461
SPRITES_PTR05 = $0462
Ricardo Quesada's avatar
Ricardo Quesada committed
140
SPRITES_DELTA_X00 = $046D       ;pixels to move horizontally for hero (neg or pos)
Ricardo Quesada's avatar
Ricardo Quesada committed
141
SPRITES_DELTA_X01 = $046E
Ricardo Quesada's avatar
Ricardo Quesada committed
142 143
SPRITES_DELTA_X04 = $0471
SPRITES_DELTA_X05 = $0472
Ricardo Quesada's avatar
Ricardo Quesada committed
144
SPRITES_DELTA_Y00 = $047D       ;pixels to move vertically for hero (neg or pos)
Ricardo Quesada's avatar
Ricardo Quesada committed
145
SPRITES_DELTA_Y01 = $047E
Ricardo Quesada's avatar
Ricardo Quesada committed
146 147
SPRITES_DELTA_Y04 = $0481
SPRITES_DELTA_Y05 = $0482
Ricardo Quesada's avatar
Ricardo Quesada committed
148 149 150 151
SPRITES_TYPE00 = $048D
SPRITES_TYPE01 = $048E
SPRITES_TYPE04 = $0491
SPRITES_TYPE05 = $0492
Ricardo Quesada's avatar
Ricardo Quesada committed
152 153
SPRITES_COUNTER00 = $049D       ;TICK and COUNTER are the same, but using different
                                ; names since they are not contiguous in memory
Ricardo Quesada's avatar
Ricardo Quesada committed
154
SPRITES_COUNTER03 = $04A0       ;referenced in throw grenade
Ricardo Quesada's avatar
Ricardo Quesada committed
155 156
a04A1 = $04A1                   ;Used to link sprites together (?)
a04AC = $04AC                   ;Used as index to delta_tbl, and index to anim frames (?)
Ricardo Quesada's avatar
Ricardo Quesada committed
157
SPRITES_TICK05 = $04B7
158
SPRITES_RASTER_Y00 = $04C2      ;Raster Intr. uses values from here instead of SPRITES_Y00
Ricardo Quesada's avatar
Ricardo Quesada committed
159
FIRE_COOLDOWN = $04DF           ;reset with $ff
Ricardo Quesada's avatar
Ricardo Quesada committed
160
HERO_ANIM_MOV_IDX = $04E0       ;Movement anim for hero: left,right,up,down,diagoanly,etc.
Ricardo Quesada's avatar
Ricardo Quesada committed
161
                                ; See: SOLDIER_ANIM_FRAMES_HI/LO
Ricardo Quesada's avatar
Ricardo Quesada committed
162
a04E1 = $04E1                   ;Bullet speed idx (???)
Ricardo Quesada's avatar
Ricardo Quesada committed
163 164 165
BKG_COLOR0 = $04E2
BKG_COLOR1 = $04E3
BKG_COLOR2 = $04E4
166
COUNTER1 = $04E6
167
a04E7 = $04E7
Ricardo Quesada's avatar
Ricardo Quesada committed
168
TRIGGER_ROW_IDX = $04E8         ;If equal to row index, create object
169
a04E9 = $04E9                   ;unused
170 171 172
a04EA = $04EA
a04EC = $04EC
a04ED = $04ED
Ricardo Quesada's avatar
Ricardo Quesada committed
173
a04EE = $04EE                   ;Hero is moving up (unused)
Ricardo Quesada's avatar
Ricardo Quesada committed
174
ENEMIES_IN_FORT = $04EF         ;How many enemies are inside the fort/warehouse
Ricardo Quesada's avatar
Ricardo Quesada committed
175 176 177
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
178
LEVEL_NR = $04F3
Ricardo Quesada's avatar
Ricardo Quesada committed
179
a04F4 = $04F4                   ;Seems to be a delay or something related to enemies inside
Ricardo Quesada's avatar
Ricardo Quesada committed
180 181
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
182 183 184 185 186 187 188
SCORE_LSB = $04F8
SCORE_MSB = $04F9
a04FD = $04FD
GRENADES = $04FF
LIVES = $0500
a0501 = $0501
a0502 = $0502
Ricardo Quesada's avatar
Ricardo Quesada committed
189
IS_HERO_DEAD = $0503            ;0: hero alive, 1:was shot, 2:fell down in trench
190
a0504 = $0504
Ricardo Quesada's avatar
Ricardo Quesada committed
191
HISCORE_IS_BULLET_ANIM = $0505  ;1: if the bullet in hiscore is being animated
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
192 193 194
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
195 196
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
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
aE34E = $E34E
aE34F = $E34F
aE350 = $E350
aE351 = $E351
aE359 = $E359
aE35A = $E35A
aE361 = $E361
aE362 = $E362
aE36A = $E36A
aE36B = $E36B
aE36C = $E36C
aE36D = $E36D
aE3F9 = $E3F9
aE3FA = $E3FA
aE3FB = $E3FB
aE3FC = $E3FC
aE3FD = $E3FD
aE3FE = $E3FE
aE3FF = $E3FF
aECEC = $ECEC
217
aFFC0 = $FFC0
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
;
; **** 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
240

241 242 243 244 245 246 247 248 249 250
        LDA #$00     ;#%00000000
        TAY
        STA aA5
        STA aAE
        LDA #$09     ;#%00001001
        JSR s0828
        JSR s083D
        JSR eF00A   ; set charset: copy from e000-efff to d000-dfff
        JSR s083D
        JSR s0828
251
        JMP BOOT
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273

s0828   LDA #$01     ;#%00000001
        TAX
        TAY
        NOP
        NOP
        NOP
        LDA #$00     ;#%00000000
        NOP
        NOP
        NOP
        LDA #$00     ;#%00000000
        LDX #$FF     ;#%11111111
        LDY #$FF     ;#%11111111
        JMP e03F0

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

Ricardo Quesada's avatar
Ricardo Quesada committed
274
        ; TODO: unused, remove
275 276 277
        .BYTE $E0,$09,$D0,$F5,$20,$AD,$35,$20
        .BYTE $57,$0A,$20

278 279 280
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
BOOT    ;$0850
        SEI
281
        LDA #<NMI_HANDLER
282
        STA $0318    ;NMI
283
        LDA #>NMI_HANDLER
284 285
        STA $0319    ;NMI
        CLI
Ricardo Quesada's avatar
Ricardo Quesada committed
286 287 288 289

        ; FIXME: Probably this is not really needed. In fact, it generates
        ; a small artifact at the end of LVL1, since it is overwritting the
        ; data
290
        LDX #$00     ;#%00000000
Ricardo Quesada's avatar
Ricardo Quesada committed
291
_L00    LDA RESET_ROUTINE,X
Ricardo Quesada's avatar
Ricardo Quesada committed
292
        STA $8000,X  ;Sets the reset routine (CBM80)
293 294
        INX
        CPX #$09     ;#%00001001
295
        BNE _L00
Ricardo Quesada's avatar
Ricardo Quesada committed
296 297

        JSR SETUP_VIC_BANK
Ricardo Quesada's avatar
Ricardo Quesada committed
298
        JSR SET_SIGHT_SPRITE
Ricardo Quesada's avatar
random  
Ricardo Quesada committed
299
        JSR INIT_RANDOM
300 301 302

        ; Sprite Y pos used in raster multiplexer
        LDX #$10
303
_L01    TXA
304
        STA a004B,b,X
305
        DEX
306
        BPL _L01
307

308 309 310
        LDA #$00     ;#%00000000
        STA a0502
        STA a0501
311

Ricardo Quesada's avatar
Ricardo Quesada committed
312 313
START                   ;$0883
        LDA #$A5        ;Set initial starting row
314
        STA V_SCROLL_ROW_IDX
Ricardo Quesada's avatar
Ricardo Quesada committed
315
        JSR SETUP_LEVEL
316
        JSR SETUP_SCREEN
317 318 319
        JSR SETUP_IRQ

        ; Display main title screen
Ricardo Quesada's avatar
Ricardo Quesada committed
320
        LDA #$00        ;Song to play (main theme)
321
        JSR MUSIC_INIT
Ricardo Quesada's avatar
Ricardo Quesada committed
322
        JSR SCREEN_MAIN_TITLE
323

Ricardo Quesada's avatar
Ricardo Quesada committed
324 325
        JSR s5006       ;Music stop?
        LDA #$00        ;#%00000000
326 327
        STA SCORE_LSB
        STA SCORE_MSB
328
        STA V_SCROLL_BIT_IDX
Ricardo Quesada's avatar
Ricardo Quesada committed
329
        STA LEVEL_NR
330 331 332 333 334 335
        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
336
        ;riq
Ricardo Quesada's avatar
Ricardo Quesada committed
337 338
        ;lda #3
        ;sta LEVEL_NR
Ricardo Quesada's avatar
Ricardo Quesada committed
339

Ricardo Quesada's avatar
Ricardo Quesada committed
340
START_LEVEL          ;$08B8
Ricardo Quesada's avatar
Ricardo Quesada committed
341
        LDA #$A5     ;#%10100101
342
        STA V_SCROLL_ROW_IDX
343 344
        LDA #$00     ;Song to play (main theme)
        JSR MUSIC_INIT
Ricardo Quesada's avatar
Ricardo Quesada committed
345 346

        ; Restart after life lost
Ricardo Quesada's avatar
Ricardo Quesada committed
347 348
RESTART
        JSR SETUP_LEVEL
349
        JSR SETUP_SCREEN
350
        JSR SETUP_IRQ
Ricardo Quesada's avatar
Ricardo Quesada committed
351 352

        ; Main loop
Ricardo Quesada's avatar
Ricardo Quesada committed
353
GAME_LOOP            ;$08CB
Ricardo Quesada's avatar
Ricardo Quesada committed
354
        JSR WAIT_RASTER_AT_BOTTOM
Ricardo Quesada's avatar
Ricardo Quesada committed
355 356
        LDA V_SCROLL_DELTA
        BEQ _L00
357
        CLC
358
        ADC V_SCROLL_BIT_IDX
359
        AND #$07     ;#%00000111
360
        STA V_SCROLL_BIT_IDX
361
        CMP #$07     ;#%00000111
Ricardo Quesada's avatar
Ricardo Quesada committed
362
        BNE _L00
363
        DEC V_SCROLL_ROW_IDX
364 365
        LDA #$00     ;#%00000000
        STA a04E9
Ricardo Quesada's avatar
Ricardo Quesada committed
366
        JSR APPLY_DELTA_MOV
367
        INC a04E9
Ricardo Quesada's avatar
Ricardo Quesada committed
368
        JSR LEVEL_DRAW_VIEWPORT
369
        INC a04E9
Ricardo Quesada's avatar
Ricardo Quesada committed
370
        JMP GAME_LOOP
371

Ricardo Quesada's avatar
Ricardo Quesada committed
372
_L00    INC GAME_TICK
Ricardo Quesada's avatar
Ricardo Quesada committed
373
        JSR APPLY_DELTA_MOV
374 375
        JSR s3F24
        JSR TRY_THROW_GRENADE
Ricardo Quesada's avatar
Ricardo Quesada committed
376
        JSR ANIM_ENEMIES
377
        JSR RUN_ACTIONS
Ricardo Quesada's avatar
Ricardo Quesada committed
378
        JSR ANIM_HERO
Ricardo Quesada's avatar
Ricardo Quesada committed
379

Ricardo Quesada's avatar
Ricardo Quesada committed
380
        LDA IS_HERO_DEAD
Ricardo Quesada's avatar
Ricardo Quesada committed
381
        BNE HERO_DIED
382
        JSR HANDLE_JOY2
Ricardo Quesada's avatar
Ricardo Quesada committed
383
        LDA IS_ANIM_EXIT_DOOR
Ricardo Quesada's avatar
Ricardo Quesada committed
384
        BNE _L01
385
        JSR CHECK_COLLISION
Ricardo Quesada's avatar
Ricardo Quesada committed
386
_L01    LDA SPRITES_Y00
Ricardo Quesada's avatar
Ricardo Quesada committed
387
        CMP #$5A
Ricardo Quesada's avatar
Ricardo Quesada committed
388
        BNE GAME_LOOP
Ricardo Quesada's avatar
Ricardo Quesada committed
389 390

        LDA #$14     ;Points won after beating lvl
391
        JSR SCORE_ADD
Ricardo Quesada's avatar
Ricardo Quesada committed
392
        LDA LEVEL_NR
393 394
        AND #$03     ;#%00000011
        CMP #$03     ;#%00000011
Ricardo Quesada's avatar
Ricardo Quesada committed
395
        BNE _L02
Ricardo Quesada's avatar
Ricardo Quesada committed
396 397

        ;Play animation at end of Level 3
398
        LDA #$09     ;#%00001001
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
399
        JSR SFX_PLAY
Ricardo Quesada's avatar
Ricardo Quesada committed
400
        JSR SET_FORT_ON_FIRE
Ricardo Quesada's avatar
Ricardo Quesada committed
401

Ricardo Quesada's avatar
Ricardo Quesada committed
402
_L02    LDA #$02     ;Song to play (Level complete)
403
        JSR MUSIC_INIT
Ricardo Quesada's avatar
Ricardo Quesada committed
404
        JSR PRINT_LVL_COMPLETE
Ricardo Quesada's avatar
Ricardo Quesada committed
405
        INC LEVEL_NR
Ricardo Quesada's avatar
Ricardo Quesada committed
406 407 408

        ; Since LVL2 was removed from the game, when LVL2 is reached,
        ; the level is changed to LVL3.
Ricardo Quesada's avatar
Ricardo Quesada committed
409
        LDA LEVEL_NR
410 411
        AND #$03     ;#%00000011
        CMP #$02     ;#%00000010
Ricardo Quesada's avatar
Ricardo Quesada committed
412
        BNE _L03
Ricardo Quesada's avatar
Ricardo Quesada committed
413
        INC LEVEL_NR
Ricardo Quesada's avatar
Ricardo Quesada committed
414

Ricardo Quesada's avatar
Ricardo Quesada committed
415
_L03    JMP START_LEVEL
416

Ricardo Quesada's avatar
Ricardo Quesada committed
417 418
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
; Animate hero "is dead"
Ricardo Quesada's avatar
Ricardo Quesada committed
419
HERO_DIED               ;b0953
Ricardo Quesada's avatar
Ricardo Quesada committed
420 421
        LDA IS_HERO_DEAD
        CMP #$02     ;Died of fall in trench/water?
Ricardo Quesada's avatar
Ricardo Quesada committed
422
        BNE _L01
Ricardo Quesada's avatar
Ricardo Quesada committed
423 424

        ; Hero fell down in trench
425 426
        INC COUNTER1
        LDA COUNTER1
427
        CMP #$14     ;#%00010100
Ricardo Quesada's avatar
Ricardo Quesada committed
428
        BCC _L00
429
        CMP #$50     ;#%01010000
Ricardo Quesada's avatar
Ricardo Quesada committed
430
        BCS _L03
Ricardo Quesada's avatar
Ricardo Quesada committed
431 432
        LDA #$CC     ;Hero fall down in trench frame #1
        STA SPRITES_PTR00
Ricardo Quesada's avatar
Ricardo Quesada committed
433
        JMP GAME_LOOP
434

Ricardo Quesada's avatar
Ricardo Quesada committed
435
_L00    LDA #$CB     ;Hero fall down in trench frame #0
Ricardo Quesada's avatar
Ricardo Quesada committed
436
        STA SPRITES_PTR00
Ricardo Quesada's avatar
Ricardo Quesada committed
437
        JMP GAME_LOOP
438

Ricardo Quesada's avatar
Ricardo Quesada committed
439
        ; Hero was shot
Ricardo Quesada's avatar
Ricardo Quesada committed
440
_L01    INC COUNTER1
441
        LDA COUNTER1
442
        CMP #$14     ;#%00010100
Ricardo Quesada's avatar
Ricardo Quesada committed
443
        BCC _L02
444
        CMP #$50     ;#%01010000
Ricardo Quesada's avatar
Ricardo Quesada committed
445
        BCS _L03
Ricardo Quesada's avatar
Ricardo Quesada committed
446
        LDA #$B8     ;Hero was shot: frame #1
Ricardo Quesada's avatar
Ricardo Quesada committed
447
        STA SPRITES_PTR00
Ricardo Quesada's avatar
Ricardo Quesada committed
448
        JMP GAME_LOOP
449

Ricardo Quesada's avatar
Ricardo Quesada committed
450
_L02    LDA #$DD     ;Hero was shot: frame #0
Ricardo Quesada's avatar
Ricardo Quesada committed
451
        STA SPRITES_PTR00
Ricardo Quesada's avatar
Ricardo Quesada committed
452
        JMP GAME_LOOP
453

Ricardo Quesada's avatar
Ricardo Quesada committed
454 455
        ; End of "died" animation. Decrease life.
_L03    DEC LIVES
456 457 458
        JSR SCREEN_REFRESH_LIVES
        LDA LIVES
        BEQ GAME_OVER
Ricardo Quesada's avatar
Ricardo Quesada committed
459
        JMP RESTART
460

Ricardo Quesada's avatar
Ricardo Quesada committed
461
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
462 463
GAME_OVER
        LDX #$06     ;#%00000110
464
_L00    TXA
465 466 467
        ASL A
        TAY
        LDA SCORE_MSB
Ricardo Quesada's avatar
Ricardo Quesada committed
468
        CMP HISCORE_LSB00,Y
469 470
        BCC _L04
        BNE _L01
471
        LDA SCORE_LSB
Ricardo Quesada's avatar
Ricardo Quesada committed
472
        CMP HISCORE_MSB00,Y
473 474
        BCC _L04
_L01    TXA
475 476
        ASL A
        TAY
Ricardo Quesada's avatar
Ricardo Quesada committed
477 478 479 480
        LDA HISCORE_LSB00,Y
        STA HISCORE_LSB01,Y
        LDA HISCORE_MSB00,Y
        STA HISCORE_MSB01,Y
481 482 483 484 485
        TXA
        ASL A
        ASL A
        ASL A
        TAY
Ricardo Quesada's avatar
Ricardo Quesada committed
486 487
_L02    LDA HISCORE_NAME00,Y
        STA HISCORE_NAME01,Y
488 489 490
        INY
        TYA
        AND #$07     ;#%00000111
491
        BNE _L02
492
        DEX
493
        BPL _L00
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
494

495
        LDA SCORE_MSB
Ricardo Quesada's avatar
Ricardo Quesada committed
496
        STA HISCORE_LSB00
497
        LDA SCORE_LSB
Ricardo Quesada's avatar
Ricardo Quesada committed
498
        STA HISCORE_MSB00
Ricardo Quesada's avatar
Ricardo Quesada committed
499
        JSR SCREEN_ENTER_HI_SCORE
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
500 501 502

        LDY #$00
_L03    LDA HISCORE_NAME,Y
Ricardo Quesada's avatar
Ricardo Quesada committed
503
        STA HISCORE_NAME00,Y
504
        INY
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
505
        CPY #$08
506 507
        BNE _L03
        JMP _L07
508

509
_L04    TXA
510 511 512
        ASL A
        TAY
        LDA SCORE_MSB
Ricardo Quesada's avatar
Ricardo Quesada committed
513
        STA HISCORE_LSB01,Y
514
        LDA SCORE_LSB
Ricardo Quesada's avatar
Ricardo Quesada committed
515
        STA HISCORE_MSB01,Y
516
        CPX #$06     ;#%00000110
517 518
        BNE _L05
        JMP START
519

520
_L05    TXA
521
        PHA
Ricardo Quesada's avatar
Ricardo Quesada committed
522
        JSR SCREEN_ENTER_HI_SCORE
523 524 525 526 527 528
        PLA
        ASL A
        ASL A
        ASL A
        TAX
        LDY #$00     ;#%00000000
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
529
_L06    LDA HISCORE_NAME,Y
Ricardo Quesada's avatar
Ricardo Quesada committed
530
        STA HISCORE_NAME01,X
531 532 533
        INX
        INY
        CPY #$08     ;#%00001000
534 535 536
        BNE _L06

_L07    JSR CLEANUP_SPRITES
Ricardo Quesada's avatar
Ricardo Quesada committed
537
        JSR DISPLAY_HI_SCORES
538

539
        LDY #$64     ;#%01100100
Ricardo Quesada's avatar
delay  
Ricardo Quesada committed
540
        JSR DELAY
541 542 543

        ; Wait for 255 frames or joystick fire

544
        LDA #$FF     ;#%11111111
545
        STA COUNTER1
546
_L08    LDA $DC00    ;CIA1: Data Port Register A  (fire in Game Over scene)
547
        CMP #$6F     ;#%01101111
548
        BEQ _L09
Ricardo Quesada's avatar
Ricardo Quesada committed
549
        JSR WAIT_RASTER_AT_BOTTOM
550
        DEC COUNTER1
551 552
        BNE _L08
_L09    JMP START
553

554 555
NMI_HANDLER
        RTI
556

Ricardo Quesada's avatar
Ricardo Quesada committed
557 558 559
        ;TODO: This generates small garbage in the top row of the map.
        ;Can be safely removed once we don't care about the generating exaclty
        ;the same binary.
Ricardo Quesada's avatar
Ricardo Quesada committed
560
RESET_ROUTINE       ;$0A4E
561
        .ADDR BOOT, BOOT
Ricardo Quesada's avatar
Ricardo Quesada committed
562
        .BYTE $C3,$C2,$CD,$38,$30
563

Ricardo Quesada's avatar
Ricardo Quesada committed
564
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
565
; Sets the sight "()" sprite for high scores as sprite $41 (@ $D040)
Ricardo Quesada's avatar
Ricardo Quesada committed
566
SET_SIGHT_SPRITE    ;$0A57
567 568
        ;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
569
        LDA $DC0E    ;CIA1: CIA Control Register A
570
        AND #$FE     ;#%11111110 Stop timer
Ricardo Quesada's avatar
Ricardo Quesada committed
571
        STA $DC0E    ;Stop timer
572
        LDA a01
573
        AND #$FB     ;#%11111011    Enabling RAM at $D000 I guess
574
        STA a01
575

Ricardo Quesada's avatar
Ricardo Quesada committed
576 577 578
        LDX #$3F     ;size of sprite
_L00    LDA SIGHT_SPR_DATA,X
        STA fD040,X  ;It will be sprite $41
579
        DEX
Ricardo Quesada's avatar
Ricardo Quesada committed
580
        BPL _L00
581

582
        LDA a01
583
        ORA #$04     ;#%00000100    Enabling I/O at $D000 I guess
584 585
        STA a01
        LDA $DC0E    ;CIA1: CIA Control Register A
586
        ORA #$01     ;#%00000001 Start timer (why ?)
Ricardo Quesada's avatar
Ricardo Quesada committed
587
        STA $DC0E    ;Start Timer
588 589
        RTS

Ricardo Quesada's avatar
Ricardo Quesada committed
590
SIGHT_SPR_DATA      ;$0A7F
Ricardo Quesada's avatar
Ricardo Quesada committed
591
        .BYTE $00,$00,$00,$02,$AA,$00,$0A,$AA
592 593 594 595 596 597 598
        .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
599

Ricardo Quesada's avatar
Ricardo Quesada committed
600
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
Ricardo Quesada's avatar
Ricardo Quesada committed
601 602 603
; Animates the selected char in hiscore
HISCORE_ANIM_CHAR       ;$0ABE
        LDA HISCORE_IS_CHAR_ANIM
604
        BEQ _SKIP
Ricardo Quesada's avatar
Ricardo Quesada committed
605

606
        LDY #$00     ;#%00000000
Ricardo Quesada's avatar
Ricardo Quesada committed
607 608
        INC HISCORE_ANIM_CHAR_COUNTER
        LDA HISCORE_ANIM_CHAR_COUNTER
609
        CMP #$32     ;#%00110010
610
        BEQ _L02
611 612 613
        AND #$0F     ;#%00001111
        LSR A
        LSR A
Ricardo Quesada's avatar
Ricardo Quesada committed
614
        AND #$03
615
        BEQ _L00
Ricardo Quesada's avatar
Ricardo Quesada committed
616
        AND #$01
617
        BNE _L01
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
618
        LDA HISCORE_SELECTED_CHAR
619
        CLC
Ricardo Quesada's avatar
Ricardo Quesada committed
620
        ADC #$20     ;Select the flipped char
621 622 623
        STA (pF7),Y
        RTS

Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
624
_L00    LDA HISCORE_SELECTED_CHAR
625 626 627
        STA (pF7),Y
        RTS

Ricardo Quesada's avatar
Ricardo Quesada committed
628
_L01    LDA #$79     ;Select the regular char
629 630 631
        STA (pF7),Y
        RTS

632
_L02    LDA #$00     ;#%00000000
Ricardo Quesada's avatar
Ricardo Quesada committed
633
        STA HISCORE_IS_CHAR_ANIM
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
634
        LDA HISCORE_SELECTED_CHAR
635
        STA (pF7),Y
636
_SKIP   RTS
637

638
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
Ricardo Quesada's avatar
Ricardo Quesada committed
639 640 641
; Get the selected char with the sight in the hiscore scene
HISCORE_GET_SELECTED_CHAR       ;$0AFA
        LDA SPRITES_X_LO05
642 643 644 645 646 647 648 649
        AND #$F0     ;#%11110000
        SEC
        SBC #$10     ;#%00010000
        PHP
        LSR A
        LSR A
        LSR A
        PLP
Ricardo Quesada's avatar
Ricardo Quesada committed
650
        BCC _L00
Ricardo Quesada's avatar
Ricardo Quesada committed
651
        LDY SPRITES_X_HI05
Ricardo Quesada's avatar
Ricardo Quesada committed
652
        BEQ _L00
653 654
        CLC
        ADC #$20     ;#%00100000
Ricardo Quesada's avatar
Ricardo Quesada committed
655
_L00    STA a00FB,b
656 657 658 659
        LDA #$00     ;#%00000000
        STA a00FC,b
        STA a00FD,b
        STA a00FE,b
Ricardo Quesada's avatar
Ricardo Quesada committed
660
        LDA SPRITES_Y05
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 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
        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
705
        AND #$FD     ;Enable I/O to read from Screen RAM
706
        STA a01
Ricardo Quesada's avatar
Ricardo Quesada committed
707

708 709
        LDY #$00     ;#%00000000
        LDA (pFC),Y
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
710
        STA HISCORE_SELECTED_CHAR
Ricardo Quesada's avatar
Ricardo Quesada committed
711

712
        LDA a01
Ricardo Quesada's avatar
Ricardo Quesada committed
713
        ORA #$02
714
        STA a01
Ricardo Quesada's avatar
Ricardo Quesada committed
715

716 717 718
        CLI
        RTS

Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
719 720 721 722 723
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
; Sets up the hero and sight sprite, and cleans up name and other vars
HISCORE_SETUP_SPRITES   ;$0B94
        ; Sight sprite
        LDA #$64     ;#%01100100
724
        AND #$F0     ;#%11110000
Ricardo Quesada's avatar
Ricardo Quesada committed
725
        STA SPRITES_X_LO05
726 727
        LDA #$64     ;#%01100100
        AND #$F0     ;#%11110000
Ricardo Quesada's avatar
Ricardo Quesada committed
728
        STA SPRITES_Y05
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
729
        LDA #$00
Ricardo Quesada's avatar
Ricardo Quesada committed
730
        STA SPRITES_X_HI05
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
731
        LDA #$41     ;sight sprite
Ricardo Quesada's avatar
Ricardo Quesada committed
732
        STA SPRITES_PTR05
Ricardo Quesada's avatar
Ricardo Quesada committed
733
        LDA #$02     ;red
Ricardo Quesada's avatar
Ricardo Quesada committed
734
        STA SPRITES_COLOR05
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
735
        LDA #$FF
Ricardo Quesada's avatar
Ricardo Quesada committed
736
        STA SPRITES_BKG_PRI05
Ricardo Quesada's avatar
Ricardo Quesada committed
737
        LDA #$01            ;anim_type_01: bullet
Ricardo Quesada's avatar
Ricardo Quesada committed
738
        STA SPRITES_TYPE05
Ricardo Quesada's avatar
Ricardo Quesada committed
739
        LDA SPRITES_X_LO05
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
740 741

        ; Hero sprite
Ricardo Quesada's avatar
Ricardo Quesada committed
742
        STA SPRITES_X_LO00
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
743
        LDA #$B4
Ricardo Quesada's avatar
Ricardo Quesada committed
744
        STA SPRITES_Y00
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
745
        LDA #$00
Ricardo Quesada's avatar
Ricardo Quesada committed
746
        STA SPRITES_X_HI00
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
747
        LDA #$98     ;Hero going up
Ricardo Quesada's avatar
Ricardo Quesada committed
748
        STA SPRITES_PTR00
Ricardo Quesada's avatar
Ricardo Quesada committed
749 750
        LDA #$06     ;blue
        STA SPRITES_COLOR00
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
751
        LDA #$00
Ricardo Quesada's avatar
Ricardo Quesada committed
752
        STA SPRITES_BKG_PRI00
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
753
        LDA #$01
Ricardo Quesada's avatar
Ricardo Quesada committed
754
        STA SPRITES_TYPE00
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
755

Ricardo Quesada's avatar
Ricardo Quesada committed
756 757
        LDX #$07
        LDA #$00
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
758
_L00    STA HISCORE_NAME,X
759
        DEX
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
760 761
        BPL _L00

Ricardo Quesada's avatar
Ricardo Quesada committed
762 763
        LDA #$00
        STA HISCORE_IS_BULLET_ANIM
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
764
        STA HISCORE_NAME_IDX
Ricardo Quesada's avatar
Ricardo Quesada committed
765
        STA HISCORE_IS_CHAR_ANIM
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
766 767 768

        ; $F7/$F8 -> Screen RAM
        LDA #<pE000
769
        STA a00F7,b
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
770
        LDA #>pE000
771
        STA a00F8,b
Ricardo Quesada's avatar
hiscore  
Ricardo Quesada committed
772 773 774

        LDA #$20
        STA HISCORE_SELECTED_CHAR
Ricardo Quesada's avatar
Ricardo Quesada committed
775
        JSR APPLY_DELTA_MOV
776 777 778 779
        JSR s3F24
        RTS

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
Ricardo Quesada's avatar
Ricardo Quesada committed
780 781 782 783
HISCORE_READ_JOY_MOV
        LDA $DC00
        AND #$01     ;#%00000001        up?
        BNE _L00
Ricardo Quesada's avatar
Ricardo Quesada committed
784
        LDA SPRITES_Y05
Ricardo Quesada's avatar
Ricardo Quesada committed
785 786 787
        CMP #$64     ;reached top?
        BCC _L00
        LDA #$FE     ;2 pixels up
Ricardo Quesada's avatar
Ricardo Quesada committed
788
        STA SPRITES_DELTA_Y05
Ricardo Quesada's avatar
Ricardo Quesada committed
789 790 791 792

_L00    LDA $DC00
        AND #$02     ;#%00000010        down?
        BNE _L01
Ricardo Quesada's avatar
Ricardo Quesada committed
793
        LDA SPRITES_Y05
Ricardo Quesada's avatar
Ricardo Quesada committed
794 795 796
        CMP #$78     ;reached bottom?
        BCS _L01
        LDA #$02     ;2 pixels down
Ricardo Quesada's avatar
Ricardo Quesada committed
797
        STA SPRITES_DELTA_Y05
Ricardo Quesada's avatar
Ricardo Quesada committed
798 799 800 801

_L01    LDA $DC00    ;CIA1: Data Port Register A (enter high score)
        AND #$04     ;#%00000100        left?
        BNE _L02
Ricardo Quesada's avatar
Ricardo Quesada committed
802
        LDA SPRITES_X_LO05
Ricardo Quesada's avatar
Ricardo Quesada committed
803 804 805
        CMP #$64     ;reached margin left?
        BCC _L02
        LDA #$FE     ;2 pixels to left
Ricardo Quesada's avatar
Ricardo Quesada committed
806
        STA SPRITES_DELTA_X05
Ricardo Quesada's avatar
Ricardo Quesada committed
807 808 809 810

_L02    LDA $DC00
        AND #$08     ;#%00001000        right?
        BNE _L03
Ricardo Quesada's avatar
Ricardo Quesada committed
811
        LDA SPRITES_X_LO05
Ricardo Quesada's avatar
Ricardo Quesada committed
812 813 814
        CMP #$F0     ;reached margin right?
        BCS _L03
        LDA #$02     ;2 pixels to right
Ricardo Quesada's avatar
Ricardo Quesada committed
815
        STA SPRITES_DELTA_X05
Ricardo Quesada's avatar
Ricardo Quesada committed
816 817

_L03    LDA SPRITES_X_LO05
Ricardo Quesada's avatar
Ricardo Quesada committed
818
        STA SPRITES_X_LO00