main.asm 196 KB
Newer Older
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
;
; **** 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
29 30 31 32
p22 = $22                       ;sprite to create: X lo
p24 = $24                       ;rows that trigger sprite class init
p26 = $26                       ;sprite to create: X hi
p28 = $28                       ;what sprite class to create at row
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
p2A = $2A
p5D = $5D
p5F = $5F
p83 = $83
pA9 = $A9
pD0 = $D0
pD2 = $D2
pF7 = $F7
pFB = $FB
pFC = $FC
pFD = $FD
;
; **** FIELDS ****
;
f0000 = $0000
f004B = $004B
f004C = $004C
f00A2 = $00A2
fD040 = $D040
fD99A = $D99A
fD9E9 = $D9E9
fDB48 = $DB48
fDB98 = $DB98
fDBDA = $DBDA
fE087 = $E087
fE19A = $E19A
fE1E9 = $E1E9
fE348 = $E348
fE398 = $E398
fE3F8 = $E3F8
fE6DC = $E6DC
fEFBA = $EFBA
;
; **** ABSOLUTE ADRESSES ****
;
a0014 = $0014
Ricardo Quesada's avatar
Ricardo Quesada committed
69
a0019 = $0019                   ;Stores current hero animation, but seems unused
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
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
a004E = $004E
a0053 = $0053
a0054 = $0054
a0055 = $0055
a0056 = $0056
a0057 = $0057
a0058 = $0058
a0059 = $0059
a005A = $005A
a00A7 = $00A7
a00A8 = $00A8
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
105 106 107
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
108
a0405 = $0405
109 110
IRQ_ADDR_LO = $0406
IRQ_ADDR_HI = $0407
Ricardo Quesada's avatar
Ricardo Quesada committed
111 112
GAME_TICK = $040A               ;Incremented from main loop
RASTER_TICK = $040B             ;Incremeted from raster routine
Ricardo Quesada's avatar
Ricardo Quesada committed
113 114 115 116 117 118 119 120
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
121 122
SPRITES_Y00 = $042D
SPRITES_Y01 = $042E
Ricardo Quesada's avatar
Ricardo Quesada committed
123 124
SPRITES_Y04 = $0431
SPRITES_Y05 = $0432
Ricardo Quesada's avatar
Ricardo Quesada committed
125 126
SPRITES_BKG_PRI00 = $043D
SPRITES_BKG_PRI01 = $043E
Ricardo Quesada's avatar
Ricardo Quesada committed
127 128
SPRITES_BKG_PRI04 = $0441
SPRITES_BKG_PRI05 = $0442
Ricardo Quesada's avatar
Ricardo Quesada committed
129
SPRITES_COLOR00 = $044D         ;primary color of sprite
Ricardo Quesada's avatar
Ricardo Quesada committed
130
SPRITES_COLOR01 = $044E
Ricardo Quesada's avatar
Ricardo Quesada committed
131 132
SPRITES_COLOR04 = $0451
SPRITES_COLOR05 = $0452
Ricardo Quesada's avatar
Ricardo Quesada committed
133
SPRITES_PTR00 = $045D           ;frame to be used by sprite
Ricardo Quesada's avatar
Ricardo Quesada committed
134
SPRITES_PTR01 = $045E
Ricardo Quesada's avatar
Ricardo Quesada committed
135 136
SPRITES_PTR04 = $0461
SPRITES_PTR05 = $0462
Ricardo Quesada's avatar
Ricardo Quesada committed
137
SPRITES_DELTA_X00 = $046D       ;pixels to move horizontally for hero (neg or pos)
Ricardo Quesada's avatar
Ricardo Quesada committed
138
SPRITES_DELTA_X01 = $046E
Ricardo Quesada's avatar
Ricardo Quesada committed
139 140
SPRITES_DELTA_X04 = $0471
SPRITES_DELTA_X05 = $0472
Ricardo Quesada's avatar
Ricardo Quesada committed
141
SPRITES_DELTA_Y00 = $047D       ;pixels to move vertically for hero (neg or pos)
Ricardo Quesada's avatar
Ricardo Quesada committed
142
SPRITES_DELTA_Y01 = $047E
Ricardo Quesada's avatar
Ricardo Quesada committed
143 144
SPRITES_DELTA_Y04 = $0481
SPRITES_DELTA_Y05 = $0482
Ricardo Quesada's avatar
Ricardo Quesada committed
145 146
SPRITES_CLASS00 = $048D
SPRITES_CLASS01 = $048E
Ricardo Quesada's avatar
Ricardo Quesada committed
147
SPRITES_CLASS04 = $0491
Ricardo Quesada's avatar
Ricardo Quesada committed
148
SPRITES_CLASS05 = $0492
Ricardo Quesada's avatar
Ricardo Quesada committed
149 150
SPRITES_COUNTER00 = $049D       ;TICK and COUNTER are the same, but using different names since they are not contiguous in memory
SPRITES_COUNTER03 = $04A0       ;referenced in throw grenade
Ricardo Quesada's avatar
Ricardo Quesada committed
151
a04A1 = $04A1                   ;Used to link sprites together
152
a04AC = $04AC
Ricardo Quesada's avatar
Ricardo Quesada committed
153
SPRITES_TICK05 = $04B7
154
a04C2 = $04C2
Ricardo Quesada's avatar
Ricardo Quesada committed
155
FIRE_COOLDOWN = $04DF           ;reset with $ff
Ricardo Quesada's avatar
Ricardo Quesada committed
156
HERO_ANIM_MOV_IDX = $04E0       ;Movement anim for hero: left,right,up,down,diagoanlly,etc.
Ricardo Quesada's avatar
Ricardo Quesada committed
157
                                ; See: SOLDIER_ANIM_FRAMES_HI/LO
158
a04E1 = $04E1
Ricardo Quesada's avatar
Ricardo Quesada committed
159 160 161
BKG_COLOR0 = $04E2
BKG_COLOR1 = $04E3
BKG_COLOR2 = $04E4
162
COUNTER1 = $04E6
163
a04E7 = $04E7
Ricardo Quesada's avatar
Ricardo Quesada committed
164
TRIGGER_ROW_IDX = $04E8         ;If equal to row index, create object
165 166 167 168
a04E9 = $04E9
a04EA = $04EA
a04EC = $04EC
a04ED = $04ED
Ricardo Quesada's avatar
Ricardo Quesada committed
169
a04EE = $04EE                   ;Hero is moving up (unused)
Ricardo Quesada's avatar
Ricardo Quesada committed
170
ENEMIES_IN_FORT = $04EF         ;How many enemies are inside the fort/warehouse
Ricardo Quesada's avatar
Ricardo Quesada committed
171 172 173
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
174
LEVEL_NR = $04F3
Ricardo Quesada's avatar
Ricardo Quesada committed
175
a04F4 = $04F4                   ;Seems to be a delay or something related to enemies inside
Ricardo Quesada's avatar
Ricardo Quesada committed
176 177
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
178 179 180 181 182 183 184
SCORE_LSB = $04F8
SCORE_MSB = $04F9
a04FD = $04FD
GRENADES = $04FF
LIVES = $0500
a0501 = $0501
a0502 = $0502
Ricardo Quesada's avatar
Ricardo Quesada committed
185
IS_HERO_DEAD = $0503            ;0: hero alive, 1:was shot, 2:fell down in trench
186 187
a0504 = $0504
a0505 = $0505
188
a0506 = $0506
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
a050F = $050F
a0510 = $0510
a0511 = $0511
a0512 = $0512
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
213
aFFC0 = $FFC0
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
;
; **** 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
        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
        JMP j0850

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
269
        ; TODO: unused, remove
270 271 272 273
        .BYTE $E0,$09,$D0,$F5,$20,$AD,$35,$20
        .BYTE $57,$0A,$20

j0850   SEI
274
        LDA #<NMI_HANDLER
275
        STA $0318    ;NMI
276
        LDA #>NMI_HANDLER
277 278 279
        STA $0319    ;NMI
        CLI
        LDX #$00     ;#%00000000
Ricardo Quesada's avatar
Ricardo Quesada committed
280
_L00    LDA RESET_ROUTINE,X
Ricardo Quesada's avatar
Ricardo Quesada committed
281
        STA $8000,X  ;Sets the reset routine (CBM80)
282 283
        INX
        CPX #$09     ;#%00001001
284
        BNE _L00
Ricardo Quesada's avatar
Ricardo Quesada committed
285 286

        JSR SETUP_VIC_BANK
Ricardo Quesada's avatar
Ricardo Quesada committed
287
        JSR SET_SIGHT_SPRITE
288 289
        JSR s401D
        LDX #$10     ;#%00010000
290
_L01    TXA
291 292
        STA f004B,b,X
        DEX
293
        BPL _L01
294 295 296
        LDA #$00     ;#%00000000
        STA a0502
        STA a0501
Ricardo Quesada's avatar
Ricardo Quesada committed
297
j0883   LDA #$A5     ;Set initial starting row
298
        STA V_SCROLL_ROW_IDX
Ricardo Quesada's avatar
Ricardo Quesada committed
299
        JSR SETUP_LEVEL
300
        JSR SETUP_SCREEN
301 302 303 304 305
        JSR SETUP_IRQ

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

Ricardo Quesada's avatar
Ricardo Quesada committed
308
        JSR s5006    ;Music stop?
309 310 311
        LDA #$00     ;#%00000000
        STA SCORE_LSB
        STA SCORE_MSB
312
        STA V_SCROLL_BIT_IDX
Ricardo Quesada's avatar
Ricardo Quesada committed
313
        STA LEVEL_NR
314 315 316 317 318 319
        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
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 346 347
        LDA #$00     ;#%00000000
        STA a04E9
        JSR s3D48
        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
353 354 355
        JSR s3D48
        JSR s3F24
        JSR TRY_THROW_GRENADE
Ricardo Quesada's avatar
Ricardo Quesada committed
356
        JSR ANIM_ENEMIES
Ricardo Quesada's avatar
actions  
Ricardo Quesada committed
357
        JSR PROCESS_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 s100F
Ricardo Quesada's avatar
Ricardo Quesada committed
366
_L01    LDA SPRITES_Y00
367
        CMP #$5A     ;#%01011010
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
Ricardo Quesada committed
379
        JSR s500F    ;SFX?
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 384
        JSR MUSIC_INIT
        JSR s1240
Ricardo Quesada's avatar
Ricardo Quesada committed
385 386
        INC LEVEL_NR
        LDA LEVEL_NR
387 388
        AND #$03     ;#%00000011
        CMP #$02     ;#%00000010
Ricardo Quesada's avatar
Ricardo Quesada committed
389
        BNE _L03
Ricardo Quesada's avatar
Ricardo Quesada committed
390
        INC LEVEL_NR
Ricardo Quesada's avatar
Ricardo Quesada committed
391
_L03    JMP START_LEVEL
392

Ricardo Quesada's avatar
Ricardo Quesada committed
393 394
        ; Animate hero "is dead"
HERO_DIED               ;b0953
Ricardo Quesada's avatar
Ricardo Quesada committed
395 396
        LDA IS_HERO_DEAD
        CMP #$02     ;Died of fall in trench/water?
Ricardo Quesada's avatar
Ricardo Quesada committed
397
        BNE _L01
Ricardo Quesada's avatar
Ricardo Quesada committed
398 399

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

Ricardo Quesada's avatar
Ricardo Quesada committed
410
_L00    LDA #$CB     ;Hero fall down in trench frame #0
Ricardo Quesada's avatar
Ricardo Quesada committed
411
        STA SPRITES_PTR00
Ricardo Quesada's avatar
Ricardo Quesada committed
412
        JMP GAME_LOOP
413

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

Ricardo Quesada's avatar
Ricardo Quesada committed
425
_L02    LDA #$DD     ;Hero was shot: frame #0
Ricardo Quesada's avatar
Ricardo Quesada committed
426
        STA SPRITES_PTR00
Ricardo Quesada's avatar
Ricardo Quesada committed
427
        JMP GAME_LOOP
428

Ricardo Quesada's avatar
Ricardo Quesada committed
429 430
        ; End of "died" animation. Decrease life.
_L03    DEC LIVES
431 432 433
        JSR SCREEN_REFRESH_LIVES
        LDA LIVES
        BEQ GAME_OVER
Ricardo Quesada's avatar
Ricardo Quesada committed
434
        JMP RESTART
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471

GAME_OVER
        LDX #$06     ;#%00000110
b09A6   TXA
        ASL A
        TAY
        LDA SCORE_MSB
        CMP HISCORE_MSB,Y
        BCC b09FD
        BNE b09BB
        LDA SCORE_LSB
        CMP HISCORE_LSB,Y
        BCC b09FD
b09BB   TXA
        ASL A
        TAY
        LDA HISCORE_MSB,Y
        STA f0F38,Y
        LDA HISCORE_LSB,Y
        STA f0F39,Y
        TXA
        ASL A
        ASL A
        ASL A
        TAY
b09CF   LDA f0EEE,Y
        STA f0EF6,Y
        INY
        TYA
        AND #$07     ;#%00000111
        BNE b09CF
        DEX
        BPL b09A6
        LDA SCORE_MSB
        STA HISCORE_MSB
        LDA SCORE_LSB
        STA HISCORE_LSB
Ricardo Quesada's avatar
Ricardo Quesada committed
472
        JSR SCREEN_ENTER_HI_SCORE
473
        LDY #$00     ;#%00000000
474
b09EF   LDA a0506,Y
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
        STA f0EEE,Y
        INY
        CPY #$08     ;#%00001000
        BNE b09EF
        JMP j0A2B

b09FD   TXA
        ASL A
        TAY
        LDA SCORE_MSB
        STA f0F38,Y
        LDA SCORE_LSB
        STA f0F39,Y
        CPX #$06     ;#%00000110
        BNE b0A13
        JMP j0883

b0A13   TXA
        PHA
Ricardo Quesada's avatar
Ricardo Quesada committed
494
        JSR SCREEN_ENTER_HI_SCORE
495 496 497 498 499 500
        PLA
        ASL A
        ASL A
        ASL A
        TAX
        LDY #$00     ;#%00000000
501
b0A1F   LDA a0506,Y
502 503 504 505 506
        STA f0EF6,X
        INX
        INY
        CPY #$08     ;#%00001000
        BNE b0A1F
Ricardo Quesada's avatar
Ricardo Quesada committed
507
j0A2B   JSR CLEANUP_SPRITES
508 509
        JSR s0E0F
        LDY #$64     ;#%01100100
Ricardo Quesada's avatar
delay  
Ricardo Quesada committed
510
        JSR DELAY
511
        LDA #$FF     ;#%11111111
512
        STA COUNTER1
513 514 515
b0A3B   LDA $DC00    ;CIA1: Data Port Register A  (riq: unk)
        CMP #$6F     ;#%01101111
        BEQ b0A4A
Ricardo Quesada's avatar
Ricardo Quesada committed
516
        JSR WAIT_RASTER_AT_BOTTOM
517
        DEC COUNTER1
518 519 520
        BNE b0A3B
b0A4A   JMP j0883

521 522
NMI_HANDLER
        RTI
523

Ricardo Quesada's avatar
Ricardo Quesada committed
524 525 526
        ;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
527
RESET_ROUTINE       ;$0A4E
Ricardo Quesada's avatar
Ricardo Quesada committed
528
        .ADDR j0850, j0850
Ricardo Quesada's avatar
Ricardo Quesada committed
529
        .BYTE $C3,$C2,$CD,$38,$30
530

Ricardo Quesada's avatar
Ricardo Quesada committed
531
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
Ricardo Quesada's avatar
Ricardo Quesada committed
532
; Sets the sight "()" sprite for high scores as sprite $41
Ricardo Quesada's avatar
Ricardo Quesada committed
533
SET_SIGHT_SPRITE    ;$0A57
534 535
        ;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
536
        LDA $DC0E    ;CIA1: CIA Control Register A
537
        AND #$FE     ;#%11111110 Stop timer
Ricardo Quesada's avatar
Ricardo Quesada committed
538
        STA $DC0E    ;Stop timer
539
        LDA a01
540
        AND #$FB     ;#%11111011    Enabling RAM at $D000 I guess
541
        STA a01
542

Ricardo Quesada's avatar
Ricardo Quesada committed
543 544 545
        LDX #$3F     ;size of sprite
_L00    LDA SIGHT_SPR_DATA,X
        STA fD040,X  ;It will be sprite $41
546
        DEX
Ricardo Quesada's avatar
Ricardo Quesada committed
547
        BPL _L00
548

549
        LDA a01
550
        ORA #$04     ;#%00000100    Enabling I/O at $D000 I guess
551 552
        STA a01
        LDA $DC0E    ;CIA1: CIA Control Register A
553
        ORA #$01     ;#%00000001 Start timer (why ?)
Ricardo Quesada's avatar
Ricardo Quesada committed
554
        STA $DC0E    ;Start Timer
555 556
        RTS

Ricardo Quesada's avatar
Ricardo Quesada committed
557
SIGHT_SPR_DATA      ;$0A7F
Ricardo Quesada's avatar
Ricardo Quesada committed
558
        .BYTE $00,$00,$00,$02,$AA,$00,$0A,$AA
559 560 561 562 563 564 565
        .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
566

Ricardo Quesada's avatar
Ricardo Quesada committed
567
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
568
s0ABE   LDA a0511
569
        BEQ _SKIP
570 571 572 573
        LDY #$00     ;#%00000000
        INC a0512
        LDA a0512
        CMP #$32     ;#%00110010
574
        BEQ _L02
575 576 577 578
        AND #$0F     ;#%00001111
        LSR A
        LSR A
        AND #$03     ;#%00000011
579
        BEQ _L00
580
        AND #$01     ;#%00000001
581
        BNE _L01
582 583 584 585 586 587
        LDA a0510
        CLC
        ADC #$20     ;#%00100000
        STA (pF7),Y
        RTS

588
_L00    LDA a0510
589 590 591
        STA (pF7),Y
        RTS

592
_L01    LDA #$79     ;#%01111001
593 594 595
        STA (pF7),Y
        RTS

596
_L02    LDA #$00     ;#%00000000
597 598 599
        STA a0511
        LDA a0510
        STA (pF7),Y
600
_SKIP   RTS
601

602
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
Ricardo Quesada's avatar
Ricardo Quesada committed
603
s0AFA   LDA SPRITES_X_LO05
604 605 606 607 608 609 610 611 612
        AND #$F0     ;#%11110000
        SEC
        SBC #$10     ;#%00010000
        PHP
        LSR A
        LSR A
        LSR A
        PLP
        BCC b0B11
Ricardo Quesada's avatar
Ricardo Quesada committed
613
        LDY SPRITES_X_HI05
614 615 616 617 618 619 620 621
        BEQ b0B11
        CLC
        ADC #$20     ;#%00100000
b0B11   STA a00FB,b
        LDA #$00     ;#%00000000
        STA a00FC,b
        STA a00FD,b
        STA a00FE,b
Ricardo Quesada's avatar
Ricardo Quesada committed
622
        LDA SPRITES_Y05
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 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
        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
        AND #$FD     ;#%11111101
        STA a01
        LDY #$00     ;#%00000000
        LDA (pFC),Y
        STA a0510
        LDA a01
        ORA #$02     ;#%00000010
        STA a01
        CLI
        RTS

s0B94   LDA #$64     ;#%01100100
        AND #$F0     ;#%11110000
Ricardo Quesada's avatar
Ricardo Quesada committed
680
        STA SPRITES_X_LO05
681 682
        LDA #$64     ;#%01100100
        AND #$F0     ;#%11110000
Ricardo Quesada's avatar
Ricardo Quesada committed
683
        STA SPRITES_Y05
684
        LDA #$00     ;#%00000000
Ricardo Quesada's avatar
Ricardo Quesada committed
685
        STA SPRITES_X_HI05
686
        LDA #$41     ;#%01000001
Ricardo Quesada's avatar
Ricardo Quesada committed
687
        STA SPRITES_PTR05
Ricardo Quesada's avatar
Ricardo Quesada committed
688
        LDA #$02     ;red
Ricardo Quesada's avatar
Ricardo Quesada committed
689
        STA SPRITES_COLOR05
690
        LDA #$FF     ;#%11111111
Ricardo Quesada's avatar
Ricardo Quesada committed
691
        STA SPRITES_BKG_PRI05
692
        LDA #$01     ;#%00000001
Ricardo Quesada's avatar
Ricardo Quesada committed
693
        STA SPRITES_CLASS05
Ricardo Quesada's avatar
Ricardo Quesada committed
694 695
        LDA SPRITES_X_LO05
        STA SPRITES_X_LO00
696
        LDA #$B4     ;#%10110100
Ricardo Quesada's avatar
Ricardo Quesada committed
697
        STA SPRITES_Y00
698
        LDA #$00     ;#%00000000
Ricardo Quesada's avatar
Ricardo Quesada committed
699
        STA SPRITES_X_HI00
700
        LDA #$98     ;#%10011000
Ricardo Quesada's avatar
Ricardo Quesada committed
701
        STA SPRITES_PTR00
Ricardo Quesada's avatar
Ricardo Quesada committed
702 703
        LDA #$06     ;blue
        STA SPRITES_COLOR00
704
        LDA #$00     ;#%00000000
Ricardo Quesada's avatar
Ricardo Quesada committed
705
        STA SPRITES_BKG_PRI00
706
        LDA #$01     ;#%00000001
Ricardo Quesada's avatar
Ricardo Quesada committed
707
        STA SPRITES_CLASS00
708 709
        LDX #$07     ;#%00000111
        LDA #$00     ;#%00000000
710
b0BE3   STA a0506,X
711 712 713 714 715 716
        DEX
        BPL b0BE3
        LDA #$00     ;#%00000000
        STA a0505
        STA a050F
        STA a0511
Ricardo Quesada's avatar
Ricardo Quesada committed
717
        LDA #<pE000  ;Screen RAM lo
718
        STA a00F7,b
Ricardo Quesada's avatar
Ricardo Quesada committed
719
        LDA #>pE000  ;Screen RAM hi
720 721 722 723 724 725 726 727 728 729 730 731
        STA a00F8,b
        LDA #$20     ;#%00100000
        STA a0510
        JSR s3D48
        JSR s3F24
        RTS

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
HISCORE_READ_JOY
        LDA $DC00    ;CIA1: Data Port Register A  (riq: enter high score)
        AND #$01     ;#%00000001
        BNE b0C1D
Ricardo Quesada's avatar
Ricardo Quesada committed
732
        LDA SPRITES_Y05
733 734 735
        CMP #$64     ;#%01100100
        BCC b0C1D
        LDA #$FE     ;#%11111110
Ricardo Quesada's avatar
Ricardo Quesada committed
736
        STA SPRITES_DELTA_Y05
737 738 739
b0C1D   LDA $DC00    ;CIA1: Data Port Register A (riq: enter high score)
        AND #$02     ;#%00000010
        BNE b0C30
Ricardo Quesada's avatar
Ricardo Quesada committed
740
        LDA SPRITES_Y05
741 742 743
        CMP #$78     ;#%01111000
        BCS b0C30
        LDA #$02     ;#%00000010
Ricardo Quesada's avatar
Ricardo Quesada committed
744
        STA SPRITES_DELTA_Y05
745 746 747
b0C30   LDA $DC00    ;CIA1: Data Port Register A (riq: enter high score)
        AND #$04     ;#%00000100
        BNE b0C43
Ricardo Quesada's avatar
Ricardo Quesada committed
748
        LDA SPRITES_X_LO05
749 750 751
        CMP #$64     ;#%01100100
        BCC b0C43
        LDA #$FE     ;#%11111110
Ricardo Quesada's avatar
Ricardo Quesada committed
752
        STA SPRITES_DELTA_X05
753 754 755
b0C43   LDA $DC00    ;CIA1: Data Port Register A (riq: enter high score)
        AND #$08     ;#%00001000
        BNE b0C56
Ricardo Quesada's avatar
Ricardo Quesada committed
756
        LDA SPRITES_X_LO05
757 758 759
        CMP #$F0     ;#%11110000
        BCS b0C56
        LDA #$02     ;#%00000010
Ricardo Quesada's avatar
Ricardo Quesada committed
760
        STA SPRITES_DELTA_X05
Ricardo Quesada's avatar
Ricardo Quesada committed
761 762
b0C56   LDA SPRITES_X_LO05
        STA SPRITES_X_LO00
763 764 765 766 767
        AND #$1F     ;#%00011111
        LSR A
        LSR A
        LSR A
        TAY
Ricardo Quesada's avatar
Ricardo Quesada committed
768
        LDA HERO_FRAMES_UP,Y
Ricardo Quesada's avatar
Ricardo Quesada committed
769
        STA SPRITES_PTR00
Ricardo Quesada's avatar
Ricardo Quesada committed
770 771
        LDA SPRITES_X_HI05
        STA SPRITES_X_HI00
772 773
        RTS

Ricardo Quesada's avatar
Ricardo Quesada committed
774
s0C6F   LDA SPRITES_X_LO05
775 776 777
        AND #$0F     ;#%00001111
        BNE b0C7B
        LDA #$00     ;#%00000000
Ricardo Quesada's avatar
Ricardo Quesada committed
778 779
        STA SPRITES_DELTA_X05
b0C7B   LDA SPRITES_Y05
780 781 782
        AND #$0F     ;#%00001111
        BNE b0C87
        LDA #$00     ;#%00000000
Ricardo Quesada's avatar
Ricardo Quesada committed
783
        STA SPRITES_DELTA_Y05
784 785
b0C87   RTS

Ricardo Quesada's avatar
Ricardo Quesada committed
786
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
Ricardo Quesada's avatar
Ricardo Quesada committed
787
SCREEN_ENTER_HI_SCORE   ;$0C88
Ricardo Quesada's avatar
Ricardo Quesada committed
788
        LDA #$01     ;Song to play (high scores)
789 790
        JSR MUSIC_INIT
        JSR s1334
Ricardo Quesada's avatar
Ricardo Quesada committed
791
        JSR CLEANUP_SPRITES
792
        LDA #$00     ;#%00000000
Ricardo Quesada's avatar
Ricardo Quesada committed
793
        STA V_SCROLL_DELTA
794
        STA V_SCROLL_BIT_IDX
Ricardo Quesada's avatar
Ricardo Quesada committed
795
        STA BKG_COLOR0
796
        LDA #$02     ;#%00000010
Ricardo Quesada's avatar
Ricardo Quesada committed
797
        STA LEVEL_NR
Ricardo Quesada's avatar
Ricardo Quesada committed
798
        LDA #<pE082  ;Screen RAM Lo
799
        STA a00FB,b
Ricardo Quesada's avatar
Ricardo Quesada committed
800
        LDA #>pE082  ;Screen RAM Hi
801
        STA a00FC,b
Ricardo Quesada's avatar
Ricardo Quesada committed
802
        LDA #<pD882  ;Color RAM Lo
803
        STA a00FD,b
Ricardo Quesada's avatar
Ricardo Quesada committed
804
        LDA #>pD882  ;Color RAM Hi
805 806 807 808
        STA a00FE,b
        LDX #$00     ;#%00000000
j0CB9   LDY #$00     ;#%00000000
j0CBB   LDA f0D09,X
Ricardo Quesada's avatar
Ricardo Quesada committed
809
        CMP #$FF     ;End of line?
810
        BEQ b0CD1
Ricardo Quesada's avatar
Ricardo Quesada committed
811
        CMP #$FE     ;Finish printing?
812 813 814 815 816 817 818 819 820 821 822
        BEQ b0CE9
        STA (pFB),Y
        LDA #$01     ;#%00000001
        STA (pFD),Y
        INX
        INY
        JMP j0CBB

b0CD1   INX
        LDA a00FB,b
        CLC
Ricardo Quesada's avatar
Ricardo Quesada committed
823
        ADC #$28     ;Put "cursor" in next line
824 825 826 827 828 829 830 831
        STA a00FB,b
        STA a00FD,b
        BCC b0CE6
        INC a00FC,b
        INC a00FE,b
b0CE6   JMP j0CB9

b0CE9   JSR s0B94
Ricardo Quesada's avatar
Ricardo Quesada committed
832
b0CEC   JSR WAIT_RASTER_AT_BOTTOM
833 834 835 836 837 838 839 840 841 842 843
        JSR HISCORE_READ_JOY
        JSR s0D59
        JSR s0ABE
        JSR s3D48
        JSR s3F24
        JSR s0C6F
        LDA a0510
        CMP #$78     ;#%01111000
        BNE b0CEC
        RTS

Ricardo Quesada's avatar
Ricardo Quesada committed
844
        ;Alphabet for hiscore
845 846 847 848 849 850 851 852 853 854 855
f0D09   .BYTE $20,$20,$20,$20,$20,$75,$75,$75
        .BYTE $75,$75,$75,$75,$75,$78,$FF,$FF
        .BYTE $FF,$5B,$20,$5C,$20,$5D,$20,$5E
        .BYTE $20,$5F,$20,$60,$20,$61,$20,$62
        .BYTE $20,$63,$20,$64,$FF,$FF,$65,$20
        .BYTE $66,$20,$67,$20,$68,$20,$69,$20
        .BYTE $6A,$20,$6B,$20,$6C,$20,$6D,$20
        .BYTE $6E,$FF,$FF,$6F,$20,$70,$20,$71
        .BYTE $20,$72,$20,$73,$20,$74,$20,$75
        .BYTE $20,$76,$20,$77,$20,$78,$FF,$FE

Ricardo Quesada's avatar
Ricardo Quesada committed
856
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;
857 858
s0D59   LDA a0505
        BEQ b0D81
Ricardo Quesada's avatar
Ricardo Quesada committed
859
        LDA SPRITES_Y01
Ricardo Quesada's avatar
Ricardo Quesada committed
860
        CMP SPRITES_COUNTER00
861 862 863 864
        BCC b0D67
        RTS

b0D67   LDA #$00     ;#%00000000
Ricardo Quesada's avatar
Ricardo Quesada committed
865
        STA SPRITES_CLASS01
866
        STA a0505
Ricardo Quesada's avatar
Ricardo Quesada committed
867 868
        LDA #$FF     ;Emtpy sprite
        STA SPRITES_PTR01
869 870 871 872 873 874 875 876 877 878 879 880 881
        LDA a0510
        CMP #$77     ;#%01110111
        BEQ b0D80
        LDA #$01     ;#%00000001
        STA a0511
b0D80   RTS

b0D81   LDA $DC00    ;CIA1: Data Port Register A (riq: enter high score - fire)
        AND #$10     ;#%00010000
        BEQ b0D89
        RTS

b0D89   LDA #$00     ;#%00000000
Ricardo Quesada's avatar
Ricardo Quesada committed
882
        STA SPRITES_DELTA_X01
883
        LDA #$FA     ;#%11111010
Ricardo Quesada's avatar
Ricardo Quesada committed
884
        STA SPRITES_DELTA_Y01
Ricardo Quesada's avatar
Ricardo Quesada committed
885 886
        LDA SPRITES_X_LO00
        STA SPRITES_X_LO01
Ricardo Quesada's avatar
Ricardo Quesada committed
887 888
        LDA SPRITES_Y00
        STA SPRITES_Y01
Ricardo Quesada's avatar
Ricardo Quesada committed
889 890
        LDA SPRITES_X_HI00
        STA SPRITES_X_HI01
891
        LDA #$01     ;#%00000001
Ricardo Quesada's avatar
Ricardo Quesada committed
892
        STA SPRITES_CLASS01
Ricardo Quesada's avatar
Ricardo Quesada committed
893 894
        LDA #$90     ;Bullet frame
        STA SPRITES_PTR01
Ricardo Quesada's avatar
Ricardo Quesada committed
895
        STA SPRITES_BKG_PRI01
Ricardo Quesada's avatar
Ricardo Quesada committed
896 897
        LDA #$01     ;white
        STA SPRITES_COLOR01
898
        STA a0505
Ricardo Quesada's avatar
Ricardo Quesada committed
899
        LDA SPRITES_Y05
Ricardo Quesada's avatar
Ricardo Quesada committed
900
        STA SPRITES_COUNTER00
901 902 903 904 905 906 907 908 909