Repository navigation
Expand file tree
/
Copy pathrg_rampage.asm
More file actions
1886 lines (1508 loc) · 28.4 KB
/
Copy pathrg_rampage.asm
File metadata and controls
1886 lines (1508 loc) · 28.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
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
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
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;
; RG RAMPAGE
;
; Code, graphics and sound effects by Jason Kelk
; This source code is formatted for the ACME cross assembler from
; http://sourceforge.net/projects/acme-crossass/
; build.bat will call ACME to create an assembled file.
; MEMORY MAP
; $8000 - $9fff code and data
; $a000 - $a7ff character data (constructed)
; $a800 - $bbff sprite data (constructed)
; $bc00 - $bfff screen RAM
; $c000 - $c0ff multicolour bit pair flip table
; Select an output filename
!to "rg_rampage.prg",cbm
; If build is $00 then a BASIC startline is added, otherwise it isn't
build = $00
; Constants
level_max = $06 ; final level number (counts from $00)
rstr1p = $00
rstr2p = $f9
screen_col_off = $1c ; screen to colour RAM high byte offset
; Labels
rn = $82
sync = $83
hover_anim_tmr = $84
draw_stash_1 = $87
draw_stash_2 = $88
sprite_glow_tmr = $89
ply_run_tmr = $8a
ply_run_flag = $8b
char_glow_temp = $8c
char_glow_tmr = $8d
grav_power = $8e
grav_timer = $8f
grav_active = $90
respawn_x = $91
respawn_y = $92
level = $93
boxout_col = $94
boxout_len = $95
; Title zoom scroll stuff
scrl_cnt = $96
scrl_tmr = $97
scrl_buffer = $98 ; $07 bytes used
; Current sprite positions
sprite_pos = $a0 ; $10 bytes used
sprite_dp = $b0 ; $08 bytes used
sprite_flip = $b8 ; $08 bytes used
; Sprite movement positions
sprite_x1 = $c0 ; $06 bytes used
sprite_x2 = $c6 ; $06 bytes used
sprite_y1 = $cc ; $06 bytes used
sprite_y2 = $d2 ; $06 bytes used
sprite_dir = $d8 ; $06 bytes used
coll_temp = $e0 ; $04 bytes used
coll_flag = $e4
score = $f0 ; $06 bytes used
lives = $f6 ; $01 byte used
bonus = $f7 ; $04 bytes used
; Temporary storage
rt_store_1 = $fc
rt_store_2 = $fd
rt_store_3 = $fe
rt_store_4 = $ff
; Location to build a bit flip table to
bitflip_table = $c000 ; $100 bytes used
; Test :: add a BASIC startline if build is zero
!if build=$00 {
* = $0801
!word entry-2
!byte $00,$00,$9e
!text "32768"
!byte $00,$00,$00
}
; Main entry point
* = $8000
entry sei
lda #$33
sta $01
; Grab the alphanumeric part of the ROM character set
ldx #$00
ldy #$00
font_copy lda $d000,x
cpy #$02
bne *+$04
and #%00000000
sta $a000,x
eor #$ff
sta $a400,x
lda $d100,x
cpy #$02
bne *+$04
lda #$00
sta $a100,x
eor #$ff
sta $a500,x
iny
cpy #$08
bne *+$04
ldy #$00
inx
bne font_copy
; Pull down the custom tile characters
ldx #$00
font_modify lda char_data,x
sta $a200,x
inx
cpx #$88
bne font_modify
lda #$36
sta $01
cli
; Generate bit pair flip table for the sprites
ldx #$00
bitflip_gen txa
sta rt_store_1
lda #$00
asl rt_store_1
rol
asl rt_store_1
rol
sta rt_store_2
txa
and #%00110000
lsr
lsr
sta rt_store_3
txa
and #%00001100
asl
asl
sta rt_store_4
txa
sta rt_store_1
lda #$00
lsr rt_store_1
ror
lsr rt_store_1
ror
ora rt_store_2
ora rt_store_3
ora rt_store_4
sta bitflip_table,x
inx
bne bitflip_gen
; Copy sprites into their appropriate place in RAM
ldx #$00
sprite_copy lda sprite_data+$000,x
sta $aa00,x
lda sprite_data+$100,x
sta $a900,x
sta $ab00,x
lda sprite_data+$200,x
sta $ac00,x
inx
bne sprite_copy
; Generate flipped sprites
ldx #$00
sprite_flipper ldy sprite_data+$002,x
lda bitflip_table,y
sta $a800,x
ldy sprite_data+$001,x
lda bitflip_table,y
sta $a801,x
ldy sprite_data+$000,x
lda bitflip_table,y
sta $a802,x
ldy sprite_data+$042,x
lda bitflip_table,y
sta $a840,x
ldy sprite_data+$041,x
lda bitflip_table,y
sta $a841,x
ldy sprite_data+$040,x
lda bitflip_table,y
sta $a842,x
ldy sprite_data+$082,x
lda bitflip_table,y
sta $a880,x
ldy sprite_data+$081,x
lda bitflip_table,y
sta $a881,x
ldy sprite_data+$080,x
lda bitflip_table,y
sta $a882,x
ldy sprite_data+$0c2,x
lda bitflip_table,y
sta $a8c0,x
ldy sprite_data+$0c1,x
lda bitflip_table,y
sta $a8c1,x
ldy sprite_data+$0c0,x
lda bitflip_table,y
sta $a8c2,x
ldy sprite_data+$102,x
lda bitflip_table,y
sta $a900,x
ldy sprite_data+$101,x
lda bitflip_table,y
sta $a901,x
ldy sprite_data+$100,x
lda bitflip_table,y
sta $a902,x
ldy sprite_data+$142,x
lda bitflip_table,y
sta $a940,x
ldy sprite_data+$141,x
lda bitflip_table,y
sta $a941,x
ldy sprite_data+$140,x
lda bitflip_table,y
sta $a942,x
inx
inx
inx
cpx #$3f
beq *+$05
jmp sprite_flipper
; One shot video register inits
lda #$35
sta $dd00
lda #$18
sta $d016
lda #$f8
sta $d018
lda #$0b
sta $d020
lda #$00
sta $d021
lda #$0b
sta $d022
lda #$0f
sta $d023
lda #$0b
sta $d025
lda #$0e
sta $d026
; Stop interrupts, disable the ROMS and set up NMI and IRQ interrupt pointers
sei
lda #$01
sta rn
lda #<int
sta $fffe
lda #>int
sta $ffff
lda #<nmi
sta $fffa
lda #>nmi
sta $fffb
lda #$7f
sta $dc0d
sta $dd0d
lda #rstr1p
sta $d012
lda #$1b
sta $d011
lda #$01
sta $d019
sta $d01a
lda #$35
sta $01
cli
; Draw the status bar
ldx #$00
lda #$20
clr_status sta $bf98,x
inx
cpx #$50
bne clr_status
ldx #$00
set_status lda status_text+$00,x
sta $bf98,x
lda status_text_r,x
sta $bfa7,x
lda status_text+$05,x
sta $bfbb,x
lda status_text+$0a,x
sta $bfca,x
lda status_text+$0f,x
sta $bfd7,x
inx
cpx #$05
bne set_status
ldx #$00
set_status_col lda #$06
sta $db98,x
sta $dbc0,x
lda #$03
sta $dba7,x
lda #$02
sta $dbb6,x
sta $dbde,x
lda #$05
sta $dbca,x
lda #$04
sta $dbd4,x
inx
cpx #$0a
bne set_status_col
; Reset the label space
jsr nuke_labels
; Initialise titles page
title_init jsr screen_clear
jsr fire_debounce
; Reset the sound effect driver
jsr sfx_init
; Set colour RAM for the titles page
ldx #$00
ttl_colset lda #$0d
sta $d918,x
lda #$0c
sta $d9b8,x
inx
cpx #$a0
bne ttl_colset
; Main title loop
title_loop jsr sync_wait
; Move the big scroller
ldx #$00
ttl_scrl lda $bd41,x
sta $bd40,x
lda $bd69,x
sta $bd68,x
lda $bd91,x
sta $bd90,x
lda $bdb9,x
sta $bdb8,x
lda $bde1,x
sta $bde0,x
lda $be09,x
sta $be08,x
lda $be31,x
sta $be30,x
inx
cpx #$27
bne ttl_scrl
; See if we need a new character for the scroller
ldx scrl_tmr
dex
bpl ttl_st_xb
ldx scrl_cnt
ldy scrolltext,x
dey
tya
asl
asl
asl
tay
; Copy the character definition
ldx #$00
ttl_read_char lda $a008,y
sta scrl_buffer,x
iny
inx
cpx #$07
bne ttl_read_char
ldx scrl_cnt
inx
cpx #$19
bne *+$04
ldx #$00
stx scrl_cnt
ldx #$07
ttl_st_xb stx scrl_tmr
; Get some bits from the character buffer (skips the blank third row)
lda #$50
ldy #$20
asl scrl_buffer+$00
bcc *+$03
tay
sty $bd67
ldy #$20
asl scrl_buffer+$01
bcc *+$03
tay
sty $bd8f
; ldy #$20 ; this line of the char is always blank!
; asl scrl_buffer+$02
; bcc *+$03
; tay
; sty $bdb7
ldy #$20
asl scrl_buffer+$03
bcc *+$03
tay
sty $bddf
ldy #$20
asl scrl_buffer+$04
bcc *+$03
tay
sty $be07
ldy #$20
asl scrl_buffer+$05
bcc *+$03
tay
sty $be2f
ldy #$20
asl scrl_buffer+$06
bcc *+$03
tay
sty $be57
; Check the fire button to see if the game needs to start
lda $dc00
and #$10
beq ttl_exit
jmp title_loop
ttl_exit jsr screen_clear
jsr fire_debounce
; Falling through into the game itself
jsr nuke_labels
lda #$00
sta level
lda #<level_data
sta screen_init_rd+$01
lda #>level_data
sta screen_init_rd+$02
lda #$03
sta lives
; Initialise main game - called when each new life starts
main_init jsr screen_clear
jsr level_init
lda #$02
sta bonus+$00
lda #$05
sta bonus+$01
lda #$00
sta bonus+$02
sta bonus+$03
; Reset the sprite flip table
ldx #$00
txa
flip_reset sta sprite_flip,x
inx
cpx #$08
bne flip_reset
; Player spawn
main_respawn lda respawn_x
sta sprite_pos+$00
lda respawn_y
sta sprite_pos+$01
lda #$a0
sta sprite_dp+$00
lda #$b0
sta sprite_dp+$07
lda #$00
sta sprite_flip+$00
sta sprite_flip+$07
sta grav_power
sta grav_timer
sta grav_active
; Trigger the player spawn sound
ldx #$10
jsr sfx_call
; Main loop start
main_loop jsr sync_wait
jsr player_move
jsr enemy_move
; Decrease the bonus
jsr bonus_down
jsr player_colls
; Check for and process fatal collisions
lda coll_flag
cmp #$01
beq death_init
; Check for and process player to collectable object
cmp #$02
bne mb_skip
jsr score_bump_100
jsr score_bump_100
jsr score_bump_100
; Detect the end of a level
jsr screen_init_rd
cmp #$ff
bne *+$05
jmp levdun_init
sta sprite_pos+$0e
jsr screen_init_rd
sta sprite_pos+$0f
; Trigger the object collection sound
ldx #$08
jsr sfx_call
mb_skip jsr bgnd_manage
jmp main_loop
; Initialise death sequence
death_init
; Trigger the player death sound
ldx #$1c
jsr sfx_call
ldx #$20
jsr sfx_call
lda #$a1
sta sprite_dp
ldy #$0c
; Death sequence main loop
death_loop jsr sync_wait
jsr sync_wait
jsr sync_wait
jsr sync_wait
lda sprite_flip
eor #$08
sta sprite_flip
dey
bne death_loop
; Hide the player sprite and wait a second
lda #$00
sta sprite_pos+$00
jsr sync_wait_50
; Decrease the lives, check for zero and call the game over routine
dec lives
lda lives
beq gover_init
; Respawn the player for the next life
jmp main_respawn
; Initialise game over sequence
gover_init lda #$02
sta boxout_col
ldx #$0d ; X position of box
ldy #$00 ; start of message in status text
lda #$0e ; end of message in status text
jsr boxout_draw
; Trigger the game over sound
ldx #$14
jsr sfx_call
ldx #$18
jsr sfx_call
; Wait for three seconds, then bail to the titles page
jsr sync_wait_50
jsr sync_wait_50
jsr sync_wait_50
jmp title_init
; Initialise level completion sequence
levdun_init ldx #$00
ld_copy lda $bfae,x
sta boxout_bonus,x
inx
cpx #$03
bne ld_copy
lda #$04
sta boxout_col
ldx #$0c ; X position of box
ldy #$0c ; start of message in status text
lda #$1c ; end of message in status text
jsr boxout_draw
; Trigger the level completion sound
ldx #$0c
jsr sfx_call
; Level completion loop
levdun_loop jsr sync_wait
lda bonus+$00
ora bonus+$01
ora bonus+$02
beq ld_loop_out
; Add five points for each second on the bonus clock
jsr bonus_down_3
jsr score_bump_1
jsr score_bump_1
jsr score_bump_1
jsr score_bump_1
jsr score_bump_1
jmp levdun_loop
; Exit level completion sequence
ld_loop_out jsr sync_wait_50
ldx level
inx
cpx #level_max
beq gamedun_init
stx level
jmp main_init
; Initialise completion sequence
gamedun_init ldy lives
gd_lives_bonus jsr score_bump_1000
dey
bne gd_lives_bonus
; Completion sequence loop
gamedun_loop jsr sync_wait
jsr sync_wait
inc char_glow_tmr
lda char_glow_tmr
and #$0f
tax
lda char_glow,x
sta boxout_col
ldx #$07 ; X position of box
ldy #$1a ; start of message in status text
lda #$34 ; end of message in status text
jsr boxout_draw
lda char_glow_tmr
and #$0f
cmp #$0f
bne gd_no_sfx
; Trigger the game completion sound
ldx #$24
jsr sfx_call
; Modify the end sound data to make things more interesting
lda sd_data_end+$00
sec
sbc #$08
sta sd_data_end+$00
inc sd_data_end+$01
lda sd_data_end+$02
eor #$30
sta sd_data_end+$02
gd_no_sfx lda $dc00
and #$10
bne gamedun_loop
jmp title_init
; General purpose screen clear (doesn't clear the bottom two lines)
screen_clear ldx #$00
lda #$20
sc_loop sta $bc00,x
sta $bd00,x
sta $be00,x
sta $bee8-$50,x
inx
bne sc_loop
rts
; Zero all the sprite positions
sprite_reset ldx #$00
txa
sr_loop sta sprite_pos,x
inx
cpx #$10
bne sr_loop
rts
; Draw a text boxout (Y contains start of text)
boxout_draw sta boxout_len
bd_loop lda #$a0
sta $bd90,x
sta $bde0,x
lda boxout_text,y
ora #$80
sta $bdb8,x
lda boxout_col
sta $d990,x
sta $d9b8,x
sta $d9e0,x
inx
iny
cpy boxout_len
bne bd_loop
jsr sprite_reset
rts
; Shared debounce routine for the fire button
fire_debounce lda $dc00
and #$10
beq fire_debounce
rts
; Nuke the label space
nuke_labels ldx #$83
lda #$00
nl_loop sta $00,x
inx
bne nl_loop
rts
; IRQ interrupt
int pha
txa
pha
tya
pha
lda $d019
and #$01
sta $d019
bne ya
jmp ea31
ya lda rn
cmp #$02
beq rout2
; Raster split 1
rout1
; Set up for the second raster split
lda #$02
sta rn
lda #rstr2p
sta $d012
lda #$ff
sta $d015
lda #$7f
sta $d01c
; Set up the current sprite positions
ldx #$00
ldy #$00
xplode lda sprite_pos,y
asl
ror $d010
sta $d000,y
lda sprite_pos+$01,y
sta $d001,y
lda sprite_dp,x
clc
adc sprite_flip,x
sta $bff8,x
lda sprite_col,x
sta $d027,x
inx
iny
iny
cpx #$08
bne xplode
; Update the sound effect driver
jsr sfx_update
; Exit the interrupt
jmp ea31
; Raster split 2
rout2 lda #$14
sta $d011
; Wait for the lower border (upper/lower border opening code)
lda #$fc
cmp $d012
bne *-$05
lda #$1b
sta $d011
lda #$00
sta $d015
; Set up for the first raster split
lda #$01
sta rn
lda #rstr1p
sta $d012
lda #$01
sta sync
; Status bar updates
ldx #$00
stats_update lda score+$01,x
ora #$30
sta $bfc0,x
lda high_score+$01,x
ora #$30
sta $bfe3,x
inx
cpx #$05
bne stats_update
ldx #$00
stats_upd_2 lda bonus,x
ora #$30
sta $bfae,x
inx
cpx #$03
bne stats_upd_2
lda lives
ora #$30
sta $bfd0
lda level
clc
adc #$31
sta $bfdd
; Exit interrupt
ea31 pla
tay
pla
tax
pla
nmi rti
; 50 frame wait and screen mask for exiting segments of the game
sync_wait_50 ldx #$32
sw50_loop jsr sync_wait
dex
bne sw50_loop
rts
; Raster synchronisation wait
sync_wait lda #$00
sta sync
sw_loop cmp sync
beq sw_loop
rts
; Background event management
bgnd_manage lda sprite_glow_tmr
clc
adc #$01
and #$1f
sta sprite_glow_tmr
lsr
tax
lda sprite_glow,x
sta sprite_col+$07
; Redefine the conveyor belt characters
convey_rl_1 lda $a240
asl
bcc convey_rl_1a
ora #$01
convey_rl_1a asl
bcc convey_rl_1b
ora #$01
convey_rl_1b sta $a240
sta $a248
sta $a257
sta $a25f
convey_rl_2 lda $a250
lsr
bcc convey_rl_2a
ora #$80
convey_rl_2a lsr
bcc convey_rl_2b
ora #$80
convey_rl_2b sta $a250
sta $a258
sta $a247
sta $a24f
; Sprite animation - hover droid 2
inc hover_anim_tmr
lda hover_anim_tmr
lsr