-
Notifications
You must be signed in to change notification settings - Fork 0
/
bank5.inc
3016 lines (2917 loc) · 68.3 KB
/
bank5.inc
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
ORG $8000, $00
; =============== S U B R O U T I N E =======================================
; start to display the copyright message, then start the main title attract
; event with logos, title and hi-score table
;
_attract_display:
LDA #$FF
STA _pad_block_mask
LDA #SND_MTITLE_
JSR _far_apu_mus_load_prg5_safe ; init title mus
JSR _star_field_init
LDA #4
JSR _screen_display ; disables ppu as well
PRINTF _res_copyrights ; display copyrights
.do_music_and_delay:
LDA #$81
STA _PPU_CTRL ; enable NMI back, select scroll high nt bit
LDA #1
STA _event_reload_idx ; set dummy reload nmi
LDX #$FF
.copyright_screen_dealy:
LDA _event_idx ; wait for nmi, don't call events, just sync
BEQ .copyright_screen_dealy
LDA #0
STA _event_idx ; clear back
TXA
PHA
JSR _star_field_animate
PLA
TAX
DEX
BNE .copyright_screen_dealy
LDA #0
STA _event_idx
STA _delay_counter ; init delay counters
STA _delay_counter+1
STA _screen_idx
LDA #2
STA _event_reload_idx ; set actual title event session index
LDA #$80
STA _PPU_CTRL ; do actual event, not it's NMI-based
JMP _event_exec
; =============== S U B R O U T I N E =======================================
; start a new game, display the initial intro sequence before the common
; level briefing messages
;
_intro_display:
LDA #0
STA _event_idx
STA _tmp_idx0
STA _tmp_idx1
STA _tmp_idx2
STA _delay_counter
LDA #$FF
STA _pad_block_mask
LDA #3
STA _event_reload_idx
JSR _log_clear_buf
LDA #4
JSR _screen_display
LDA #$81
STA _PPU_CTRL
JMP _event_exec
; =============== S U B R O U T I N E =======================================
; draw an ending screen, set manual sprite overlays and wait
;
_ending_display:
LDA #0
STA _event_idx
STA _hi_score_entry_display_lock
STA _delay_counter
STA _delay_counter+1
STA _continues ; to prevent game continue after the completion
STA _title_menu_idx ; to disable the title menu change
LDA #$FF
STA _pad_block_mask
LDA #4
STA _event_reload_idx
LDA #SND_MENDING
JSR _far_apu_mus_load_prg5_safe
LDA #7
JSR _screen_display
LDA #$81
STA _PPU_CTRL
JMP _event_exec
; =============== S U B R O U T I N E =======================================
; draw the repair lab, fix the tilemaps according to current damage
; run an input event
;
_repair_lab_display:
LDA #0
STA _event_idx
LDA #5
STA _event_reload_idx
LDA #$A8
STA _repair_cursor_spr_y_pos
LDA #$40
STA _repair_cursor_spr_x_pos
LDA #$FF
STA _pad_block_mask
LDA #2
STA _repair_body_index
STA _repair_body_index_request
JSR _player_percents_backup ; save current to be able to repeat repair
LDA _repair_tanks
STA _repair_tanks_backup
LDA #SND_MREPAIR
JSR _far_apu_mus_load_prg5_safe
LDA #8
JSR _screen_display
JSR _repair_ppu_head_upgrade_display
JSR _repair_ppu_body_upgrade_display
JSR _repair_ppu_arms_upgrade_display
JSR _repair_ppu_legs_upgrade_display
LDA #6
STA _PPU_MASK
LDA #$80
STA _PPU_CTRL
JMP _event_exec
; =============== S U B R O U T I N E =======================================
; go to the Game Overs screen, test for continues, etc..
;
_game_over_display:
LDA #0
STA _event_idx
STA _tmp_idx0
STA _tmp_idx1
STA _tmp_idx2
STA _delay_counter
STA _delay_counter+1
LDA #$FF
STA _pad_block_mask
LDA #6
STA _event_reload_idx
LDA _lvl_idx ; test is level > 1
BNE loc_442AB0
STA _continues ; if = 0, disable continues
BEQ loc_442AB
loc_442AB0:
LDA _continues ; test for player continues
BEQ loc_442AB
LDA #1
loc_442AB:
STA _title_menu_idx ; or to START and disable continues
JSR _log_clear_buf
JSR _star_field_init
LDA #SND_MGMOVER
JSR _far_apu_mus_load_prg5_safe
LDA #4
JSR _screen_display ; draw regular frame tilemap
PRINTF _res_game_over ; display game over
LDA #$81
STA _PPU_CTRL
JMP _event_exec
; =============== S U B R O U T I N E =======================================
_event_exec:
LDA _event_idx
BEQ _event_exec
ASL
TAX
LDA _events_lib,X
STA _tptr0
LDA _events_lib+1,X
STA _tptr0+1
LDA #0
STA _event_idx
JMP (_tptr0)
_events_lib:
.WORD _event_exec
.WORD _event_exec
.WORD _event2_title
.WORD _event3_intro
.WORD _event4_ending
.WORD _event5_repair
.WORD _event6_game_over
.WORD _event7_log_msg
; =============== S U B R O U T I N E =======================================
_event2_title:
LDX _screen_idx ; this idx is always +1 of the current screen here,
LDA _delays_list_hi,X ; so we can ckek next timer value
CMP _delay_counter+1
BNE .do_title_generic_handlers ; and then switch to next screen
LDA #0
CMP _delay_counter
BNE .do_title_generic_handlers
LDX _screen_idx ; yep, reached. check for title loop or skip
CPX #4
BCC loc_443B5
DEX ; if jumped over hi-score (3 + 1), jump back to title (2)
DEX
STX _screen_idx ; reload timers
JSR _reload_counters
loc_443B5:
LDA _screen_idx ; redisplay a new screen by index
JSR _screen_display_ex
LDA _screen_idx
CMP #3
BNE loc_4444F
JSR _star_field_init ; special init case for hi-score screen
JSR _draw_hiscore_table
loc_4444F:
LDA #$81 ; re-enable ppu again
STA _PPU_CTRL
INC _screen_idx ; set ptr to next value in delays list to wait for
.do_title_generic_handlers:
ADD16 _delay_counter, 1 ; do idle timers roll on every screen
LDA _screen_idx
CMP #4
BNE loc_44491 ; check for special case, a hi-score screen
JSR _star_field_animate
LDA _pad_edge ; at hi-score screen do check for input lol
BEQ loc_4448B ; while no one ever read the pads here, this only
LDX #4 ; works when any button is held at the title
STX _screen_idx ; while it switching to the next screen
JSR _reload_counters ; do skip to the title screen
loc_4448B:
JMP _event_exec
loc_44491:
LDA _disp_spr0hit_use
BNE loc_444AD
JMP _event_exec
loc_444AD:
LDY _title_menu_idx ; select menu item for blink
LDX _title_menu_spr_ofs_list,Y
LDA _title_menu_spr_num_list,Y
STA _title_menu_spr_num_tmp
LDA _pad_edge
AND #$24
BEQ loc_44526
loc_44510:
LDA _title_menu_idx ; select or down pressed here
CLC
ADC #1
JMP loc_445260
loc_44526:
LDA _pad_edge
AND #8
BEQ .title_menu_update
LDA _title_menu_idx
SEC
SBC #1
loc_445260:
AND #3
STA _title_menu_idx
JSR _reload_title_counters
LDA #0
STA _generic_nmi_over_counter
.title_menu_update:
LDA _generic_nmi_over_counter ; check nmi counter, first 20 frames do show all menu items
AND #$1F
CMP #$15
BCC loc_444DA ; from 21th to 31 frames do menu hide. this code is called
LDA #$F0 ; continuosly on every frame after 20th
BNE .title_menu_update_ex ; item visible time is longer than not visible
loc_444DA:
LDA _title_menu_pos_list,Y ; get the menu Y value to restore
.title_menu_update_ex:
STA _spr_buf,X ; force it to the screen
INX
INX
INX
INX
DEC _title_menu_spr_num_tmp ; previously saved size of menu item in sprites
BNE .title_menu_update_ex
LDA _apu_enable
AND #APU_SND_ENABLE
BEQ .menu_sound_off ; if SOUND is on
LDA #$4F ; draw "N " sprite
STA [_spr_buf+_m2onoff]
LDA #1
STA [_spr_buf+_m2onoff+4]
BNE loc_44569
.menu_sound_off:
LDA #$3F ; else, draw "FF"
STA [_spr_buf+_m2onoff]
STA [_spr_buf+_m2onoff+4]
loc_44569:
LDA _apu_enable
AND #APU_MUS_ENABLE
BEQ .menu_music_off
LDA #$4F
STA [_spr_buf+_m3onoff]
LDA #1
STA [_spr_buf+_m3onoff+4]
BNE loc_44583
.menu_music_off:
LDA #$3F
STA [_spr_buf+_m3onoff]
STA [_spr_buf+_m3onoff+4]
loc_44583:
LDA _title_menu_idx ; test for title menu idx
BNE loc_4459F
LDA _pad_edge ; start menu idx, test A or Start
AND #$90
BEQ loc_4459F
JSR _player_vars_init ; start new game, reset all players params
JMP _intro_display ; begin intro always, one-player code too
loc_4459F:
LDA _title_menu_idx
CMP #1
BNE loc_445C3 ; continue option
LDA _pad_edge
AND #$90
BEQ loc_445C3
LDA _continues ; recheck the continues for first player
BNE loc_445BD
LDA #0
STA _tmp_idx0
JMP .wait_for_midscreen_change ; do nothing, reset counters
loc_445BD:
LDA #0 ; clear the hi-scores before continue
STA _score_hex
STA _score_hex+1 ; just exit and begin a new game without intro
STA _weapon0_idx ; clear weapon if continue too
STA _weapon1_idx
STA _weapon_type
RTS
loc_445C3:
LDA _title_menu_idx
CMP #2
BNE loc_445E7
LDA _pad_edge
AND #$90
BEQ loc_445E7
JSR _reload_title_counters
LDA _apu_enable
EOR #APU_SND_ENABLE
STA _apu_enable
loc_445E7:
LDA _title_menu_idx
CMP #3
BNE .wait_for_midscreen_change
LDA _pad_edge
AND #$90
BEQ .wait_for_midscreen_change
JSR _reload_title_counters
LDA _apu_enable
EOR #APU_MUS_ENABLE
STA _apu_enable
AND #APU_MUS_ENABLE
BEQ loc_44615
LDA #SND_MTITLE_
loc_44615:
JSR _far_apu_mus_load_prg5_safe
.wait_for_midscreen_change:
BIT _PPU_STATUS
BMI loc_44620
BVC .wait_for_midscreen_change
LDX #$11
JSR _delayx ; delay 97 clocks
LDA #$1A ; call 48 clocks
JSR _mmc1_chr0
loc_44620:
JMP _event_exec
; offset of the menu item sprites from the beginning of the sprite buffer
;
_title_menu_spr_ofs_list:
.BYTE [_spr2_title_menu0 - _spr2_title]
.BYTE [_spr2_title_menu1 - _spr2_title]
.BYTE [_spr2_title_menu2 - _spr2_title]
.BYTE [_spr2_title_menu3 - _spr2_title]
; a number of sprites in given menu item string
;
_title_menu_spr_num_list:
.BYTE [[_spr2_title_menu1 - _spr2_title_menu0] >> 2]
.BYTE [[_spr2_title_menu2 - _spr2_title_menu1] >> 2]
.BYTE [[_spr2_title_menu3 - _spr2_title_menu2] >> 2]
.BYTE [[_spr2_title_end - _spr2_title_menu3] >> 2]
; fixed constants of the Y position of the menu items on the screen
;
_m0p EQU $87
_m1p EQU $97
_m2p EQU $A7
_m3p EQU $B7
_title_menu_pos_list:
.BYTE _m0p,_m1p,_m2p,_m3p
; sprite ram offset of the first modified on/off tile of the menu items 2 and 3
; 6 sprites * 4 + 1 (SOUND_O/MUSIC_O)
;
_m2onoff EQU [[_spr2_title_menu2 - _spr2_title] + 25]
_m3onoff EQU [[_spr2_title_menu3 - _spr2_title] + 25]
; =============== S U B R O U T I N E =======================================
_reload_counters:
LDA _delays_list_hi,X
STA _delay_counter+1
LDA #0
STA _delay_counter
RTS
; =============== S U B R O U T I N E =======================================
_reload_title_counters:
LDA _delays_list_hi+2
STA _delay_counter+1
LDA #0
STA _delay_counter
RTS
_delays_list_hi:
.BYTE 0, 1, 2, 6, $A
; =============== S U B R O U T I N E =======================================
_event3_intro:
LDA _pad_edge
AND #$90
BEQ loc_44684 ; test if button is pressed to skip
.i_cmdFA_break:
RTS
loc_44684:
LDA _tmp_idx0 ; 3B4 screen index temp value
ASL
TAX
LDA _lvl0_intro_log_lib,X
STA _txt_ptr
INX
LDA _lvl0_intro_log_lib,X
STA _txt_ptr+1
LDY _tmp_idx1 ; cur message pos temp value
LDA (_txt_ptr),Y ; check for special symbols
CMP #$FF
BEQ .i_cmdFF_next_screen ; $FF - next screen code
CMP #$FE
BEQ .i_cmdFE_scroll_up ; $FE - scroll buffer up
;loc_446A8:
CMP #$FC
BEQ .i_cmdFC_delay ; $FC - long delay
CMP #$FB
BEQ .i_cmdFB_clear_buf ; $FB - clear current buf
CMP #$FA
BEQ .i_cmdFA_break ; $FA code - end of messages
LDX _tmp_idx2 ; output buf pos temp value
STA _log_msg_buf+$54,X ; start to display at the bottom line of the buf
INC _tmp_idx1
INC _tmp_idx2
LDA #0
STA _generic_nmi_over_counter
.j_event_exec0:
JMP _event_exec
; --------------------------------
.i_cmdFF_next_screen:
INC _tmp_idx0
LDA #0
STA _tmp_idx2
STA _tmp_idx1
INC _screen_idx
LDA _screen_idx
JSR _screen_display_ex
LDA #$81
STA _PPU_CTRL
JMP _event_exec
; --------------------------------
.i_cmdFE_scroll_up:
LDA _generic_nmi_over_counter
AND #$F
BNE .j_event_exec0
JSR _log_msg_buf_scroll_up
INC _tmp_idx1
LDA #0
STA _tmp_idx2
JMP _event_exec
; --------------------------------
.i_cmdFB_clear_buf:
LDX #$6F
LDA #0
loc_446FF:
STA _log_msg_buf,X
DEX
BPL loc_446FF
INC _tmp_idx1
LDA #0
STA _tmp_idx2
JMP _event_exec
; --------------------------------
.i_cmdFC_delay:
LDA _delay_counter
CLC
ADC #1
STA _delay_counter
CMP #$3F
BCC .j_event_exec0
INC _tmp_idx1
LDA #0
STA _tmp_idx2
STA _delay_counter
JMP _event_exec
; =============== S U B R O U T I N E =======================================
_event4_ending:
LDA #$7D
STA _spr_buf
LDA #$30
STA _spr_buf+1
LDA #$FF
STA _spr_buf+2
LDA #0
STA _spr_buf+3
ADD16 _delay_counter, 1
LDA _delay_counter+1
CMP #3
BCC loc_44858
CMP #$D
BCS _title_screen_display
JMP _hi_score_entry_event
loc_44858:
LDA _pad_edge
AND #$80
BEQ loc_44871
LDA #3
STA _delay_counter+1
loc_44871:
BIT _PPU_STATUS
BMI loc_448B8
BVC loc_44871
LDX #7
JSR _delayx ; delay 48 clocks
LDA #$1F ; call 48 clocks
JSR _mmc1_chr0
loc_448B8:
JMP _event_exec
; =============== S U B R O U T I N E =======================================
; used to redisplay the title screen after the game over or ending sequences
; as well after the hi-score entry screen
;
_title_screen_display:
LDA #0
STA _event_idx
LDA #2
STA _event_reload_idx
LDA #$FF
STA _pad_block_mask
JSR _reload_title_counters
LDA #SND_MTITLE_
JSR _far_apu_mus_load_prg5_safe
LDA #2
JSR _screen_display
LDA #$80
STA _PPU_CTRL
JMP _event_exec
; =============== S U B R O U T I N E =======================================
_hi_score_entry_event:
LDA _hi_score_entry_display_lock
BNE loc_44965
LDA #$FF
STA _hi_score_entry_display_lock
JSR _sort_hiscore_test
LDA _hi_score_line_idx
CMP #6
BCS _title_screen_display
LDA #0
STA _tmp_idx2
JSR _star_field_init
LDA #3
JSR _screen_display
JSR _draw_hiscore_table
LDA #$81
STA _PPU_CTRL
loc_44965:
JSR _star_field_animate
LDX _hi_score_line_idx
LDA _hi_score_ram_name_ofs_list,X
CLC
ADC _tmp_idx2
TAX
LDA _pad_edge
BNE loc_44992
LDA _generic_nmi_over_counter ; if button is held nmi counter is reset to 3 here
AND #$1F ; so we auto-repear back after 17 frames every time
BEQ loc_44992
BNE .j_event_exec3
loc_44992:
LDA _pad_last
AND #4
BEQ loc_449B3
LDA _ram_score_tbl,X
CLC
ADC #1
CMP #$25
BCC .update_char
LDA #0
BEQ .update_char
loc_449B3:
LDA _pad_last
AND #8
BEQ loc_449D2
LDA _ram_score_tbl,X
SEC
SBC #1
BCS .update_char
LDA #$24
.update_char:
STA _ram_score_tbl,X
JMP .reset_counters
loc_449D2:
LDA _pad_last
AND #1
BEQ loc_449EE
LDA _tmp_idx2
CMP #9
BCS .wait_for_start
INC _tmp_idx2
BCC .reset_counters
loc_449EE:
LDA _pad_last
AND #2
BEQ .wait_for_start
LDA _tmp_idx2
BEQ .wait_for_start
DEC _tmp_idx2
.reset_counters:
LDA #3
STA _delay_counter+1
STA _generic_nmi_over_counter
.wait_for_start:
LDA _pad_edge
AND #$90
BEQ .j_event_exec3
JMP _title_screen_display
.j_event_exec3:
JMP _event_exec
; =============== S U B R O U T I N E =======================================
_sort_hiscore_test:
LDA #0
STA _hex2str_tile_delta
STA _hi_score_pos_count
STA _hi_score_line_idx
LDX #$E
loc_45A21:
STA _score_cmp_buf,X
DEX
BPL loc_45A21
U16TOS _score_hex, _score_cmp_buf
loc_45A3B:
LDY _hi_score_pos_count ; read cur score line idx to test
CPY #6
BCS locret_45A7A ; check if no more lines
LDX _hi_score_ram_score_ofs_list,Y ; table calc of score data offset
LDY #0
.test_loop:
LDA _score_cmp_buf,Y ; compare
CMP _ram_score_tbl,X
BCC .hiscore_no_swap
BNE .hiscore_swap
INX
INY
CPY #5
BNE .test_loop
.hiscore_no_swap:
INC _hi_score_line_idx ; player position in the list
loc_45A55:
INC _hi_score_pos_count ; next line
JMP loc_45A3B
.hiscore_swap:
LDY _hi_score_pos_count ; return score data offset to the begining
LDX _hi_score_ram_score_ofs_list,Y
LDY #0
loc_45A69:
JSR _do_swap
CPY #5
BNE loc_45A69
LDY _hi_score_pos_count ; get the name offset
LDX _hi_score_ram_name_ofs_list,Y
LDY #5
loc_45A690:
JSR _do_swap
CPY #$F
BNE loc_45A690
BEQ loc_45A55
locret_45A7A:
RTS
; =============== S U B R O U T I N E =======================================
_do_swap:
LDA _ram_score_tbl,X
PHA
LDA _score_cmp_buf,Y
STA _ram_score_tbl,X
PLA
STA _score_cmp_buf,Y
INX
INY
RTS
_hi_score_ram_score_ofs_list:
.BYTE 0,5,10,15,20,25
_hi_score_ram_name_ofs_list:
.BYTE _hi0_name-_ram_score_tbl
.BYTE _hi1_name-_ram_score_tbl
.BYTE _hi2_name-_ram_score_tbl
.BYTE _hi3_name-_ram_score_tbl
.BYTE _hi4_name-_ram_score_tbl
.BYTE _hi5_name-_ram_score_tbl
; =============== S U B R O U T I N E =======================================
; draws an actual hi-score table data from RAM at the fixed position
; on the screen
;
_draw_hiscore_table:
PRINTF _res_ram_scores ; _res_hi_score_header
BIT _PPU_STATUS
LDA #$21
STA _PPU_ADDR
LDA #$47
STA _PPU_ADDR
LDX #0
loc_45AEE:
LDY _hi0_score,X
LDA _nums_table,Y
STA _PPU_DATA
INX
CPX #5
BCC loc_45AEE
LDA #$F
STA _PPU_DATA
STA _PPU_DATA
LDA #$21
STA _PPU_ADDR
LDA #$87
STA _PPU_ADDR
LDX #0
loc_45B26:
LDY _hi1_score,X
LDA _nums_table,Y
STA _PPU_DATA
INX
CPX #5
BCC loc_45B26
LDA #$F
STA _PPU_DATA
STA _PPU_DATA
LDA #$21
STA _PPU_ADDR
LDA #$C7
STA _PPU_ADDR
LDX #0
loc_45B5E:
LDY _hi2_score,X
LDA _nums_table,Y
STA _PPU_DATA
INX
CPX #5
BCC loc_45B5E
LDA #$F
STA _PPU_DATA
STA _PPU_DATA
LDA #$22
STA _PPU_ADDR
LDA #7
STA _PPU_ADDR
LDX #0
loc_45B96:
LDY _hi3_score,X
LDA _nums_table,Y
STA _PPU_DATA
INX
CPX #5
BCC loc_45B96
LDA #$F
STA _PPU_DATA
STA _PPU_DATA
LDA #$22
STA _PPU_ADDR
LDA #$47
STA _PPU_ADDR
LDX #0
loc_45BCE:
LDY _hi4_score,X
LDA _nums_table,Y
STA _PPU_DATA
INX
CPX #5
BCC loc_45BCE
LDA #$F
STA _PPU_DATA
STA _PPU_DATA
LDA #$22
STA _PPU_ADDR
LDA #$87
STA _PPU_ADDR
LDX #0
loc_45C06:
LDY _hi5_score,X
LDA _nums_table,Y
STA _PPU_DATA
INX
CPX #5
BCC loc_45C06
LDA #$F
STA _PPU_DATA
STA _PPU_DATA
RTS
_nums_table:
.BYTE _O,_1,_2,_3,_4,_5,_6,_7,_8,_9
; =============== S U B R O U T I N E =======================================
_event5_repair:
LDA _repair_cursor_spr_x_pos ; update cursor position
STA _spr_buf+4
CLC
ADC #8
STA _spr_buf+8
LDA _repair_cursor_spr_y_pos
STA _spr_buf+7
STA _spr_buf+$B
LDA #$E6
STA _hex2str_tile_delta
LDX _repair_body_index_request
LDY _repair_update_flag_list,X
LDA _percents,Y
U8TOS _repair_percent_disp_buf_tmp
LDA _pad_edge
AND #$10
BEQ loc_44AB8
LDA #0
STA _event_reload_idx
LDA #7
JMP _bios_msg_display_no_skip
loc_44AB8:
LDA _repair_tanks ; draw only single digit of tanks if more than 9, draw always 9
CMP #$A ; there were original bug, drawing % instead, since you doubtly
BCC loc_44AC1 ; obtain more than 10 at once and this case never tested
LDA #9
loc_44AC1:
CLC
ADC #$E6
STA _repair_tanks_number_tile_tmp
LDA _pad_edge
AND #$80
BEQ loc_44AF1
LDA _repair_tanks
BEQ loc_44AF1
LDX _repair_body_index_request
LDY _repair_update_flag_list,X
LDA _percents,Y
CMP #MAX_PERCENT_VALUE
BCS loc_44AF1
CLC
ADC #DEF_PERCENT_REPAIR
CMP #MAX_PERCENT_VALUE
BCC loc_44AF10
LDA #MAX_PERCENT_VALUE ; clamp to max
loc_44AF10:
STA _percents,Y
DEC _repair_tanks
loc_44AF1:
BIT _PPU_STATUS
BMI loc_44B2B
BVC loc_44AF1
LDX #6
JSR _delayx ; 43 clocks delay
LDA #$17 ; 48 clocks call
JSR _mmc1_chr0
loc_44B2B:
JSR _repair_cursor_input
JSR _repair_cursor_animate
JMP _event_exec
; =============== S U B R O U T I N E =======================================
_repair_cursor_input:
LDA _repair_cursor_animate_in_progress
BNE locret_45C98
LDA _pad_edge
AND #$F
TAX
LDY _dpad_conv_tbl,X
BNE loc_45C39
RTS
loc_45C39:
DEY
STY _tptr0
LDA _repair_body_index
ASL
ASL
CLC
ADC _tptr0
TAY
LDA _repair_cursor_allow_table,Y
BMI locret_45C98
CMP _repair_body_index_request
BEQ locret_45C98
STA _repair_body_index_request
LDA #1
STA _repair_cursor_animate_in_progress
locret_45C98:
RTS
UP EQU 1
RT EQU 2
DN EQU 3
LT EQU 4
_dpad_conv_tbl:
.BYTE 0,RT,LT,0,DN,0,0,0,UP,0,0,0,0,0,0,0
HEAD EQU 0
RHAND EQU 1
BODY EQU 2
LHAND EQU 3
LEGS EQU 4
STOP EQU $FF
_repair_cursor_allow_table:
; UP RT DN LT
.BYTE STOP ,LHAND,BODY ,RHAND ; HEAD
.BYTE HEAD ,BODY ,LEGS ,STOP ; RHAND
.BYTE HEAD ,LHAND,LEGS ,RHAND ; BODY
.BYTE HEAD ,STOP ,LEGS ,BODY ; LHAND
.BYTE BODY ,LHAND,STOP ,RHAND ; LEGS
; =============== S U B R O U T I N E =======================================
_repair_cursor_animate:
LDA _repair_cursor_animate_in_progress
BNE loc_45CD4
RTS
loc_45CD4:
INC _repair_cursor_animate_tmp
LDA _repair_cursor_animate_tmp
CMP #2
BEQ loc_45CDF
RTS
loc_45CDF:
LDA #0
STA _repair_cursor_animate_tmp
LDA _repair_body_index_request
ASL
TAX
LDA _repair_cursor_anim_data,X
STA _repair_cursor_pos_dest
LDA _repair_cursor_anim_data+1,X
STA _repair_cursor_pos_dest+1
LDA _repair_cursor_spr_y_pos
CMP _repair_cursor_pos_dest
BCS loc_45D1D
LDA _repair_cursor_pos_dest
SEC
SBC _repair_cursor_spr_y_pos
LSR
LSR
STA _repair_cursor_pos_dest
LDA _repair_cursor_spr_y_pos
CLC
ADC _repair_cursor_pos_dest
STA _repair_cursor_spr_y_pos
JMP loc_45D33
loc_45D1D:
LDA _repair_cursor_spr_y_pos
SEC
SBC _repair_cursor_pos_dest
LSR
LSR
STA _repair_cursor_pos_dest
LDA _repair_cursor_spr_y_pos
SEC
SBC _repair_cursor_pos_dest
STA _repair_cursor_spr_y_pos
loc_45D33:
LDA _repair_cursor_spr_x_pos
CMP _repair_cursor_pos_dest+1
BCS loc_45D54
LDA _repair_cursor_pos_dest+1
SEC
SBC _repair_cursor_spr_x_pos
LSR
LSR
STA _repair_cursor_pos_dest+1
LDA _repair_cursor_spr_x_pos
CLC
ADC _repair_cursor_pos_dest+1
STA _repair_cursor_spr_x_pos
JMP loc_45D6A
loc_45D54:
LDA _repair_cursor_spr_x_pos
SEC
SBC _repair_cursor_pos_dest+1
LSR
LSR
STA _repair_cursor_pos_dest+1
LDA _repair_cursor_spr_x_pos
SEC
SBC _repair_cursor_pos_dest+1
STA _repair_cursor_spr_x_pos
loc_45D6A:
LDA _repair_cursor_pos_dest