-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbank1.inc
2802 lines (2720 loc) · 85.8 KB
/
bank1.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 $A000
BANK_START $F1
; ---------------------------------------------------------------------------
; -------------G-A-M-E--S-E-T-U-P--A-N-D--I-N-I-T--S-T-U-F-F-----------------
; ---------------------------------------------------------------------------
SECTION_START F0E
; =============== S U B R O U T I N E =======================================
_game_setup:
LDA #_MUS_IDX_STOP
STA _apu_mus_idx_req ; stop music
JSR _wait_for_nmi
LDA #_MUS_IDX_SETUP
STA _apu_mus_idx_req ; load degault setup music idx
LDA #$00
STA _tmp6D5
STA _tmp6D2
STA _tmp6D3
LDA _scenario_result_idx ; when return from scenario mode
BNE loc_2402A ; do not load_cur_game_mode, jump directly
LDY _cur_game_mode ; to new scenario select
; BNE loc_24024 ; REDUNDANT, weird, we already stop music inside
; LDA #_MUS_IDX_STOP ; continue handlers
; STA _apu_mus_idx_req
;loc_24024:
LDA _game_setup_subs_list,Y ; load actual game mode setup sub
STA _game_setup_sub_idx
loc_2402A:
JSR _wait_for_nmi ; do loop until you complete corresponding settings
JSR _game_setup_sub_exec
LDA _main_sub_idx
CMP #$01
BEQ loc_2402A
RTS
_game_setup_subs_list:
.BYTE $03,$00,$05,$09
; =============== S U B R O U T I N E =======================================
_game_setup_sub_exec:
LDA _game_setup_sub_idx
JSR _switch
.WORD _game_setup00_new_city_gen ; city gen start
.WORD _game_setup01_name_input_init ; city gen
.WORD _game_setup02_name_input_input ; city gen jump 0D
.WORD _game_setup03_continue_init ; continue start
.WORD _game_setup04_continue_input ; continue stop
.WORD _game_setup05_scenario_init ; scenario start
.WORD _game_setup06_scenario_select_input ; scenario
.WORD _game_setup07_scenario_intro_init ; scenario
.WORD _game_setup08_scenario_intro_draw ; scenario stop
.WORD _game_setup09_practice_msg_init ; practice start
.WORD _game_setup0A_practice_msg_draw ; practice stop
.WORD _game_setup0B_scenario_over_init ; game over start
.WORD _game_setup0C_scenario_over_input ; game over jump 05/0F
.WORD _game_setup0D_difficult_init ; city gen continues
.WORD _game_setup0E_difficult_input ; city gen stop
.WORD _game_setup0F_all_complete_init ; game won start
.WORD _game_setup10_all_complete_input ; game won jump 05
; REDUNDANT
; LDY _game_setup_sub_idx
; LDA _game_setup_lib_lo,Y
; STA _ptr0
; LDA _game_setup_lib_hi,Y
; STA _ptr0+1
; JMP (_ptr0)
;_game_setup_lib_lo:
; .BYTE <[_game_setup00_new_city_gen]
; .BYTE <[_game_setup01_name_input_init]
; .BYTE <[_game_setup02_name_input_input]
; .BYTE <[_game_setup03_continue_init]
; .BYTE <[_game_setup04_continue_input]
; .BYTE <[_game_setup05_scenario_init]
; .BYTE <[_game_setup06_scenario_select_input]
; .BYTE <[_game_setup07_scenario_intro_init]
; .BYTE <[_game_setup08_scenario_intro_draw]
; .BYTE <[_game_setup09_practice_msg_init]
; .BYTE <[_game_setup0A_practice_msg_draw]
; .BYTE <[_game_setup0B_scenario_over_init]
; .BYTE <[_game_setup0C_scenario_over_input]
; .BYTE <[_game_setup0D_difficult_init]
; .BYTE <[_game_setup0E_difficult_input]
; .BYTE <[_game_setup0F_all_complete_init]
; .BYTE <[_game_setup10_all_complete_input]
;_game_setup_lib_hi:
; .BYTE >[_game_setup00_new_city_gen]
; .BYTE >[_game_setup01_name_input_init]
; .BYTE >[_game_setup02_name_input_input]
; .BYTE >[_game_setup03_continue_init]
; .BYTE >[_game_setup04_continue_input]
; .BYTE >[_game_setup05_scenario_init]
; .BYTE >[_game_setup06_scenario_select_input]
; .BYTE >[_game_setup07_scenario_intro_init]
; .BYTE >[_game_setup08_scenario_intro_draw]
; .BYTE >[_game_setup09_practice_msg_init]
; .BYTE >[_game_setup0A_practice_msg_draw]
; .BYTE >[_game_setup0B_scenario_over_init]
; .BYTE >[_game_setup0C_scenario_over_input]
; .BYTE >[_game_setup0D_difficult_init]
; .BYTE >[_game_setup0E_difficult_input]
; .BYTE >[_game_setup0F_all_complete_init]
; .BYTE >[_game_setup10_all_complete_input]
; OPTIMIZED, merged
; =============== S U B R O U T I N E =======================================
_game_setup_screen_init:
JSR _ppu_queues_reset ; reset queue buffers
JSR _pal_fade_out ; fade out
JSR _render_off ; render off
LDY #$80 ; prepare vars
STY _game_wnd_spr_mode_flag
STY _ppu_ctrl_shadow
LDY #$01
STY _scr_mode_idx ; set screen modes
INY
STY _scr_res_idx
DEC _mmc5_operation_in_progress_flag; enter critical section
LDA #$08
STA _mmc5_nt_mode_shadow ; set mode
STA _MMC5_NT_MODE
JMP _spr_clear ; ready to ppu unpack
; =============== S U B R O U T I N E =======================================
_game_setup05_scenario_init:
; JSR _ppu_queues_reset ; REDUNDANT
; JSR _pal_fade_out
; JSR _render_off
; LDY #$80
; STY _game_wnd_spr_mode_flag
; STY _ppu_ctrl_shadow
; LDY #$01
; STY _scr_mode_idx
; INY
; STY _scr_res_idx
; DEC _mmc5_operation_in_progress_flag
; LDA #$08
; STA _mmc5_nt_mode_shadow
; STA _MMC5_NT_MODE
; JSR _spr_clear
; -
JSR _game_setup_screen_init ; OPTIMIZED
; -
LDA _city._all_scenarios_are_clear_ram_flag
BNE .extra_scenarios ; all scenarios are beaten, unlock full screen
JSRXY _res_ppu_lz_unpack,_tlm_res_lz_scenario_normal
LDY #$03 ; or load the regular one with 6 scenarios
BNE loc_240B2
.extra_scenarios:
LDXY _tlm_res_lz_scenario_complete ; tlm for this scenario is in extra bank
FJSRA _res_ppu_lz_unpack,PRG6,PRG6 ; the only extarnal tlm data here for now
LDY #$04
loc_240B2:
STY _tmp6D4 ; tmp var for number or icons per row
; JSR _ppu_queues_reset ; REDUNDANT, already clear
LDA #$02
STA _MMC5_CHR_MODE
JSR _scenario_closed_screen_update ; draw "CLOSED" icons on beaten scenarios
LDA #$01
STA _MMC5_CHR_MODE
LDA #$00
STA _tmp6D0
STA _tmp6D0+1
LDA #$08
STA _screen_pal_cur_bg_idx
LDA #$02
STA _screen_pal_cur_spr_idx
; !FALLTHROUGH!
; =============== S U B R O U T I N E =======================================
_game_setup_screen_start:
INC _game_setup_sub_idx ; switch to the next sub
JSR _render_on ; render on again
INC _mmc5_operation_in_progress_flag; exit critical section
JMP _pal_fade_in ; fade out screen
; =============== S U B R O U T I N E =======================================
_scenario_closed_screen_update:
LDY #$00 ; icons counter init
; LDX #$06 ; REDUNDANT, icons counter max
LDA _city._all_scenarios_are_clear_ram_flag
BNE locret_2411B ; FIX: lets just exit here
; BEQ loc_240FA
; REDUNDANT: by this logic, when you complete all scenarios, the extra scenario
; screen reset all cleared pictures and planned to draw a new ones only for
; two extra scenarios lol, BUT, there are no offsets not only for a rearranged
; icons set (4x2 instead of 3x2), but there are no 7th and 8th offsets in
; table. if you ever manage to beat all scenarios, then beat one of the extra
; scenarios, you'll get an error screen. but you actually just can't beat
;
; FIX: disable extra code for this special options, anyway they aren't working
;
; LDY #$06
; LDX #$08
; LDA _city._scenarios_clear_flags
; LSR
; LSR
; LSR
; LSR
; LSR
; LSR
; BPL loc_240FD
;loc_240FA:
LDA _city._scenarios_clear_flags
loc_240FD:
; STX _tmp3 ; REDUNDANT, store cycle max idx
; BUG: _tmp2 here used as a cycle counter, also used inside the draw
; routine but nothing is modify it there as against _tmp3 which is
; used in this loop as max counts number, but also used inside draw
; routine as temporary var so erased inside it and loop will run for
; extra 250 cycles because of that.
;
; REDUNDANT: it seems, they save wrong var before drawing routines: pushes
; _tmp2 instead of _tmp3 lol, no need anymore, removed it
;
loc_240FF:
STY _tmp2 ; store for convinience
LSR ; here is the bitflags in A
BCC loc_2411A ; skip if flag clear
PHA ; save current shifted flags
; PUSHB _tmp3 ; REDUNDANT, save cycles max idx
JSR _scenario_closed_icon_draw ; draw
;loc_2410B:
; JSR _ppu_dequeue ; REDUNDANT, merged
; JSR _extnt_dequeue
; JSR _buffers_test_flush
; BNE loc_2410B
JSR _buffers_force_flush ; OPTIMIZED
; POPB _tmp3 ; REDUNDANT, restore cycle max count
PLA
loc_2411A:
LDY _tmp2 ; get cur cycle idx
INY ; next (will be saved at the loop start)
; CPY _tmp3 ; REDUNDANT
CPY #$06 ; OPTIMIZED, fixed now to single value
BNE loc_240FF ; test if loops is over
locret_2411B:
RTS
; =============== S U B R O U T I N E =======================================
_scenario_closed_icon_draw:
PPUQSTART
LDA _scenario_closed_ppu_ofs_hi,Y ; get the "CLOSED" ppu ofs for
STA _ptr0+1 ; particular icon
PHA
LDA _scenario_closed_ppu_ofs_lo,Y
STA _ptr0
PHA
LDY #$00
loc_24130:
PPUQMOVB _ptr0,OP_NOP,0 ; queue ofs, and 6 bytes (one line)
PPUQMOVB _ptr0+1,OP_NOP,0 ; at once
PPUQMOVB #$06,OP_NOP,0
STA _tmp3
loc_24144:
LDA _tlm_scenario_closed_nt,Y
INY
PPUQMOVA
DEC _tmp3
BNE loc_24144 ; go to the next line, draw up to 6x6 bytes
ADDWB _ptr0,#$20
CPY #$24
BNE loc_24130
PPUQEND
LDY _tmp2
EXTQSTART
; REDUNDANT
; LDA _scenario_closed_ppu_ofs_hi,Y
; CLC
; ADC #$3C
; STA _ptr0+1
; LDA _scenario_closed_ppu_ofs_lo,Y
; STA _ptr0
; OPTIMIZED
; -
PLA
STA _ptr0
PLA
CLC
ADC #$3C
STA _ptr0+1
; -
LDY #$00
loc_24174:
EXTQMOVB _ptr0,OP_NOP,0 ; exactly the same for extnt data
EXTQMOVB _ptr0+1,OP_NOP,0
EXTQMOVB #$06,OP_NOP,0
STA _tmp3
loc_24188:
LDA _tlm_scenario_closed_extnt,Y
INY
EXTQMOVA
DEC _tmp3
BNE loc_24188
ADDWB _ptr0,#$20
CPY #$24
BNE loc_24174
EXTQEND
RTS
_scenario_closed_ppu_ofs_lo:
.BYTE $E5,$ED,$F5,$05,$0D,$15
_scenario_closed_ppu_ofs_hi:
.BYTE $20,$20,$20,$22,$22,$22
_tlm_scenario_closed_nt:
.BYTE $E0,$E1,$A1,$A1,$E4,$E5
.BYTE $F0,$F1,$F2,$F3,$F4,$F5
.BYTE $B0,$E6,$E7,$E8,$E9,$B2
.BYTE $B0,$F6,$F7,$F8,$F9,$B2
.BYTE $EA,$EB,$EC,$ED,$EE,$EF
.BYTE $FA,$FB,$C1,$C1,$FE,$FF
_tlm_scenario_closed_extnt:
.BYTE $0B,$0B,$01,$01,$0B,$0B
.BYTE $0B,$0B,$0B,$0B,$0B,$0B
.BYTE $01,$0B,$0B,$0B,$0B,$01
.BYTE $01,$0B,$0B,$0B,$0B,$01
.BYTE $0B,$0B,$0B,$0B,$0B,$0B
.BYTE $0B,$0B,$01,$01,$0B,$0B
; =============== S U B R O U T I N E =======================================
_game_setup06_scenario_select_input:
JSR _scenario_select_input
BIT _pad0_press ; test B button
BVC loc_2420C
LDA #$02
STA _title_sub_idx ; if pressed, return back to the title menu
DEC _main_sub_idx
JMP _pal_fade_out
loc_2420C:
JMP _common_select_cursor_control ; or else draw regular cursor
; =============== S U B R O U T I N E =======================================
_scenario_select_input:
LDA _pad0_autorep ; test if any d-pad pressed
AND #$0F
BEQ .no_dpad_pressed
APUA_SE _SE_IDX_SELECT ; then do sound
.no_dpad_pressed:
LDX _tmp6D2 ; column idx selector
LDA _pad0_autorep
LSR
BCC loc_24229
INX ; dpad RIGHT pressed
CPX _tmp6D4 ; increment idx, compare with number of icons per row
BNE loc_24229
LDX #$00 ; wrap to 0 if more than needed
loc_24229:
LSR
BCC loc_24233
DEX ; the same for LEFT button
BPL loc_24233
LDX _tmp6D4 ; wrap to max instead
DEX
loc_24233:
AND #$03
BEQ .no_up_down_pressed
LDA _tmp6D3 ; up-down very simple, just toggle low bit
EOR #$01 ; of column selector idx
STA _tmp6D3
.no_up_down_pressed:
STX _tmp6D2 ; get cursor position of current row/col idxes
LDY _tmp6D3
LDA _scenario_cursor_col_list,Y ; two columns always
STA _tmp6CE
LDA _scenario_cursor_row_list3,X ; may be either 3 rows...
LDY _city._all_scenarios_are_clear_ram_flag
BEQ loc_24256
LDA _scenario_cursor_row_list4,X ; ...or 4 if all scenarios cleared
loc_24256:
STA _tmp6CC
LDA _pad0_press ; store cursor pos tmp
BPL locret_24273 ; test for A button now
LDA _tmp6D3 ; calc scenarios list ofs
ASL
ASL
ADC _tmp6D2
TAY
LDA _scenatios_list,Y ; get an actual scenario idx
STA _scenario_idx
APUA_SE _SE_IDX_CLICK
INC _game_setup_sub_idx
locret_24273:
RTS
_scenario_cursor_row_list3:
.BYTE $4D,$8D,$CD
_scenario_cursor_row_list4:
.BYTE $45,$75,$A5,$DD
_scenario_cursor_col_list:
.BYTE $5D,$A5
_scenatios_list:
.BYTE $00,$01,$02,$06
.BYTE $03,$04,$05,$07
; =============== S U B R O U T I N E =======================================
_game_setup07_scenario_intro_init:
JSR _ppu_queues_reset ; prepare scenario intro screen
JSR _pal_fade_out
JSR _render_off
DEC _mmc5_operation_in_progress_flag
JSR _spr_clear ; common full-screen window draw
JSRXY _res_ppu_lz_unpack,_tlm_res_lz_fullscreen_wnd
LDY _scenario_idx ; scenario name header draw
; NOTE, scenario headers drawn by tilemap method, however they used the same
; font as in PRG3 for ingame message headers draw. for ingame messages are
; headers are ASCII encoded and converted to full 3-line fonts automatically
; here we have a lot of redundancy because may use the same conversion routines
; as for ingame menus and keep all scenario headers in ASCII as well
; the problem is, the ingame window functions are more complex, they need to
; calculate screen offsets on the fly. this code doesn't...
; TODO: check if merging both codes worth it.
LDA _tlm_res_scenario_hdr_lib_lo,Y
; STA _ptr0
TAX
LDA _tlm_res_scenario_hdr_lib_hi,Y
; STA _ptr0+1
TAY
JSR _res_ppu_unpack
; OPTIMIZED, common lib, indexes 0-7 for scenarios
LDA _scenario_idx ; now load scenario message data
JSR _msg_lib_load ; for printout routine
; LDA _scenario_msg_lib_lo,Y
; STA _tmp6D6
; LDA _scenario_msg_lib_hi,Y
; STA _tmp6D6+1
; LDY #$00
; STY _tmp6DA
; STY _tmp6D9
; DEY
; STY _tmp6D8
LDA #$11
STA _screen_pal_cur_bg_idx
; REDUNDANT
; INC _game_setup_sub_idx ; skip to the next sub
; JSR _render_on
; INC _mmc5_operation_in_progress_flag
; JMP _pal_fade_in
JMP _game_setup_screen_start
; =============== S U B R O U T I N E =======================================
_game_setup08_scenario_intro_draw:
JSR _msg_print_out_handler ; do pritnout letter by letter
BIT _pad0_press ; all this tile wait for A button
BPL loc_242EC
APUA_SE _SE_IDX_CLICK ; skip scenario intro if pressed
JSR _scenario_map_load ; load scenario map from PPU ROM
INC _main_sub_idx ; go to the main game
LDA #_MUS_IDX_STOP
STA _apu_mus_idx_req ; stop the music, already fade out by map load
RTS
loc_242EC:
BVC locret_242F7 ; test if B pressed
DEC _game_setup_sub_idx ; then cancel to _game_setup05_scenario_init
DEC _game_setup_sub_idx ; to select scenario again
DEC _game_setup_sub_idx
locret_242F7:
RTS
; =============== S U B R O U T I N E =======================================
_msg_print_out_handler:
JSR _msg_print_out ; print two chars at a time
; !FALLTHROUGH!
; =============== S U B R O U T I N E =======================================
_msg_print_out:
LDY _tmp6D8 ; _tmp6D8 initialized with FF at the beginning
CPY #$FF ; so this means we not in dict mode
BEQ .skip_dictionary
INC _tmp6D8 ; or else this is a dictionary char pos
LDA _msg_dictionary,Y ; load it, pos already incremented
BPL .put_msg_char ; if not FF, print char as is, if FF
STA _tmp6D8 ; store it, this means end of dict word
.skip_dictionary:
LDA _tmp6D6+1 ; cur message char ptr, if high nibble is FF
CMP #$FF ; the end of message occured
BEQ locret_2436F ; so just skip
STA _ptr0+1 ; if not, store to the tmp ptr
LDA _tmp6D6
STA _ptr0
INCW _tmp6D6 ; increment ptr
LDY #$00
LDA (_ptr0),Y ; then load cur char
BPL loc_24330 ; hi-bit is clear, then regular chars
AND #$7F ; if set, this is a dictionary char offset
STA _tmp6D8 ; mask it, dic max size if 127 bytes including
BPL _msg_print_out ; eofs, jump recursively to char fetch
loc_24330:
CMP #$0A ; regular special symbol CR/LF
BNE loc_2433D
LDA #$00 ; reset row pos, increment column pos
STA _tmp6D9 ; nothing to draw there
INC _tmp6DA
RTS
loc_2433D:
CMP #$5B
BNE .put_msg_char ; end of msg special code
LDA #$FF
STA _tmp6D6+1 ; set end msg flag
RTS
.put_msg_char:
PHA ; backup actual print symbol
PPUQSTART
LDY _tmp6DA ; line ppu ofs already calculated for this screen
LDA _msg_print_out_ppu_pos_list_lo,Y; just load them and queue current char
CLC
ADC _tmp6D9
PPUQMOVA
LDA _msg_print_out_ppu_pos_list_hi,Y
PPUQMOVA
PPUQMOVB #$01,OP_NOP,0 ; one char queue
PLA ; restore symbol to print
PPUQMOVA
PPUQEND
INC _tmp6D9 ; next row.
locret_2436F:
RTS
_msg_print_out_ppu_pos_list_lo:
.BYTE $04,$24,$44,$64,$84,$A4,$C4,$E4,$04,$24,$44,$64,$84,$A4,$C4,$E4,$04
_msg_print_out_ppu_pos_list_hi:
.BYTE $21,$21,$21,$21,$21,$21,$21,$21,$22,$22,$22,$22,$22,$22,$22,$22,$23
; =============== S U B R O U T I N E =======================================
_msg_lib_load:
TAY
LDA _msg_lib_lo,Y ; unificated mag data load routine
STA _tmp6D6
LDA _msg_lib_hi,Y
STA _tmp6D6+1
LDY #$00
STY _tmp6DA ; as well as init the msg variables
STY _tmp6D9
DEY
STY _tmp6D8
RTS
; =============== S U B R O U T I N E =======================================
_scenario_map_load:
JSR _pal_fade_out ; to load a map, we need access to PPU ROM
JSR _render_off ; shut down the screen then
DEC _mmc5_operation_in_progress_flag
JSR _city_map_init ; init map buf with BULLDOZERED_GROUND
LDA #$01
STA _MMC5_CHR_SIZE ; set CHR bank size 4K
JSR _apu_dpcm_forbid ; somehow dpcm may interfer with process, disable it
LDY _scenario_idx
LDX _scenario_data_chr_bank,Y ; load PPU ROM banks containing a map data
STX _MMC5_CHR_BANKSA+3
INX
STX _MMC5_CHR_BANKSA+7
LDA _PPU_STATUS
LDA _scenario_data_ppu_hi,Y ; also we have list of offsets there
AND #$0F
STA _PPU_ADDR
LDA _scenario_data_ppu_lo,Y
STA _PPU_ADDR ; setup address
LDA _PPU_DATA ; dummy read, now ready
LDA _scenario_map_dicts_lib_lo,Y ; load ptr to current map dictionary
STA _tmp2 ; of two-tile sctructures used as packing
LDA _scenario_map_dicts_lib_hi,Y
STA _tmp3
MOVWO _tmp4,_city_map ; load city map buf ptr as dst ptr
JSR _sram_write_enable ; enable wram bank
JSR _scenario_map_unpack ; do unpack
JSR _sram_write_disable ; disable back
LDA #$03
STA _MMC5_CHR_SIZE ; restore CHR bank size 1K
JSR _apu_dpcm_allow ; allow dpcm back
; REDUNDANT
; LDY _scenario_idx
; LDX _scenario_titles_ofs_lib,Y ; load predefined town name for scenario
; LDY #$01
;loc_243F1:
; LDA _scenario_town_names_list,X ; copy data
; BMI loc_243FD
; STA _city._name,Y
; INX
; INY
; BNE loc_243F1
;loc_243FD:
; STY _city._name ; store name buf len
; -
LDX _scenario_idx ; OPTIMIZED, default city name, scenario name
LDY #$00
JSR _set_default_name
; -
LDA _mmc5_chr_banks_shadow+3 ; restore CHR3 BANK
STA _MMC5_CHR_BANKSA+3
INC _mmc5_operation_in_progress_flag; restart ppu
JMP _render_on
; =============== S U B R O U T I N E =======================================
_scenario_map_unpack:
LDY #$00
LDA _PPU_DATA ; read code
STA _tmp6
AND #$F0
CMP #$80
BNE .raw_tiles ; object code as is
LDA _tmp6
CMP #$8F
BNE .dict_tiles ; 8F, RLE code next two bytes are
LDX _PPU_DATA ; counter + object idx to insert
LDA _PPU_DATA
loc_24424:
JSR _scenario_map_put_block ; do rle unpack of next two bytes
DEX
BNE loc_24424
JMP _scenario_map_unpack
.dict_tiles:
LDA _tmp6 ; 80-8E, DICT codes (as inused special tiles)
SEC ; every scenario has a DICT of 2x1 tiles, 15 each
SBC #$80 ; extract DICT entry idx
ASL
PHA ; OPTIMIZED
TAY
LDA (_tmp2),Y
JSR _scenario_map_put_block
; LDA _tmp6 ; REDUNDANT, save in stack instead
; SEC ; -
; SBC #$80 ; -
; ASL ; -
; TAY ; -
PLA ; OPTIMIZED, pop from stack
TAY ; -
INY
LDA (_tmp2),Y
JSR _scenario_map_put_block
JMP _scenario_map_unpack
.raw_tiles:
LDA _tmp6 ; raw tiles 00-7F, 90-FF
JSR _scenario_map_put_block
JMP _scenario_map_unpack
; =============== S U B R O U T I N E =======================================
; NOTE, thatalready buldozzereg ground already in buffer need to be overwritten with
; bulldozered ground in any case, because there is no code for just skip positions
; maybe we would save some space if repack it with such code...
;
_scenario_map_put_block:
STA _tmp6+1
.map_tile_fetch:
LDY #$00
LDA (_tmp4),Y ; put only on buldozered ground
CMP #_MAP_GROUND ; when we build 2x2 or more, the next
BEQ loc_2446F ; tile would be non _MAP_GROUND, so skip it
INCW _tmp4 ; this way we don't need to store actual pos
LDA _tmp4 ; of the buildings in row.
CMP #<[_city_map_end]
BNE .map_tile_fetch
LDA _tmp5
CMP #>[_city_map_end]
BNE .map_tile_fetch ; try again
BEQ .break_unpack ; end of map, break unpack
loc_2446F:
TXA ; OPTIMIZED: we need X here now
PHA
LDA _tmp6+1
BMI loc_244D9 ; all tiles above 80 are single
LDX #$0F ; OPTIMIZED
CMP #_MAP_AIR_PORT ; the reset are a large buildings
BEQ loc_244D6 ; OPTIMIZED
; REDUNDANT
; BNE loc_2449E ; draw airport 4x4 special tiles
; LDY #$03 ; xxxxxx8E (03)
; LDA #$8E ; xxxxxx8D (4F)
; STA (_tmp4),Y ; xxxxxx8C (9B)
; LDY #$4F ; 88898A8B
; LDA #$8D ;(E4E5E6E7)
; STA (_tmp4),Y
; LDY #$9B
; LDA #$8C
; STA (_tmp4),Y
; LDY #$E4
; LDA #$88
; STA (_tmp4),Y
; INY
; LDA #$89
; STA (_tmp4),Y
; INY
; LDA #$8A
; STA (_tmp4),Y
; INY
; LDA #$8B
; STA (_tmp4),Y
loc_2449E:
LDX #$03 ; OPTIMIZED
CMP #_MAP_COAL_POWER ; default draw 2x2 tiles
BCC loc_244D6 ; draw 3x3 buildings tiles
LDX #$08 ; OPTIMIZED
; REDUNDANT
; LDY #$02 ; xxxx87
; LDA #$87 ; xxxx86
; STA (_tmp4),Y ; 838485
; LDY #$4E
; LDA #$86
; STA (_tmp4),Y
; LDY #$98
; LDA #$83
; STA (_tmp4),Y
; INY
; LDA #$84
; STA (_tmp4),Y
; INY
; LDA #$85
; STA (_tmp4),Y
;loc_244BE:
; LDY #$00 ; the rest is 2x2 buildings
; LDA _tmp6+1 ; ID82
; STA (_tmp4),Y ; 8081
; INY
; LDA #$82
; STA (_tmp4),Y
; LDA #$80
; LDY #$4C
; STA (_tmp4),Y
; INY
; LDA #$81
; STA (_tmp4),Y
; BNE loc_244DA
loc_244D6:
LDA _special_tiles_ofs_list-1,X ; OPTIMIZED
TAY ; -
LDA _special_tiles_list-1,X ; -
STA (_tmp4),Y ; -
DEX ; -
BNE loc_244D6 ; -
LDA _tmp6+1
loc_244D9:
LDY $00
STA (_tmp4),Y
PLA ; restore X back
TAX ; -
;loc_244DA:
INCW _tmp4
LDA _tmp4
CMP #<[_city_map_end]
BNE .exit_map_tile_store
LDA _tmp5
CMP #>[_city_map_end]
BNE .exit_map_tile_store
.break_unpack:
PLA
PLA
.exit_map_tile_store:
LDA _tmp6+1
RTS
; building special tiles scheme to copy to map.
;
_special_tiles_list:
.BYTE _MAP_INTERNAL_BUILD0,_MAP_INTERNAL_BUILD1,_MAP_INTERNAL_BUILD2
.BYTE _MAP_INTERNAL_BUILD3,_MAP_INTERNAL_BUILD4,_MAP_INTERNAL_BUILD5,_MAP_INTERNAL_BUILD6,_MAP_INTERNAL_BUILD7
.BYTE _MAP_INTERNAL_BUILD8,_MAP_INTERNAL_BUILD9,_MAP_INTERNAL_BUILDA,_MAP_INTERNAL_BUILDB,_MAP_INTERNAL_BUILDC,_MAP_INTERNAL_BUILDD,_MAP_INTERNAL_BUILDE
; =============== S U B R O U T I N E =======================================
;_unref_19:
; INC _ptr0
; BNE locret_244F7
; INC _ptr0+1
;locret_244F7:
; RTS
; =============== S U B R O U T I N E =======================================
_game_setup00_new_city_gen:
JSR _ppu_queues_reset ; oddly enough, this is the only
JSR _pal_fade_out ; game setup uses the regular ingame
LDA #$24 ; screen resource code
STA _mmc5_nt_mode_shadow
STA _MMC5_NT_MODE
LDA #$07
STA _scr_res_idx
LDA #$00
STA _scr_res_control_flags
FJSRA _scr_res_common,SRAM,PRG9
LDA _title_sub_idx
BEQ loc_249F4
DEC _main_sub_idx
JSR _pal_fade_out
loc_249F4:
INC _game_setup_sub_idx
RTS
; =============== S U B R O U T I N E =======================================
_game_setup01_name_input_init:
; REDUNDANT
; JSR _ppu_queues_reset
; JSR _pal_fade_out
; JSR _render_off
; LDY #$80
; STY _game_wnd_spr_mode_flag
; STY _ppu_ctrl_shadow
; LDY #$01
; STY _scr_mode_idx
; INY
; STY _scr_res_idx
; DEC _mmc5_operation_in_progress_flag
; LDA #$08
; STA _mmc5_nt_mode_shadow
; STA _MMC5_NT_MODE
; JSR _spr_clear
; -
JSR _game_setup_screen_init ; OPTIMIZED
; -
; LDXY _tlm_res_lz_name_init ; REDUNDANT, draw external tilemap for name input screen
; FJSRA _res_ppu_lz_unpack,SRAM,PRGA
; -
JSRXY _res_ppu_lz_unpack,_tlm_res_lz_name_init ; OPTIMIZED, now local
LDA #$00
STA _tmp6DC+2
LDA #$02
STA _MMC5_CHR_MODE ; unpack upper part of the input screen
; JSRXY _rle_nt_res_queue,_rle_tlm_nt_input_name
; JSRXY _rle_extnt_res_queue,_rle_tlm_extnt_input_name
LDX #$04 ; OPTIMIZED
JSR _rle_tlm_queue
; JSR _name_input_char_nt_queue ; REDUNDANT. draw name buffer (now empty)
; JSR _name_input_char_extnt_queue
JSR _name_input_name_buf_queue ; OPTIMIZED, called both at the same time, merge
;loc_24549:
; JSR _ppu_dequeue ; REDUNDANT, merged
; JSR _extnt_dequeue
; JSR _buffers_test_flush
; BNE loc_24549
JSR _buffers_force_flush ; OPTIMIZED, force flush common
LDA #$01
STA _MMC5_CHR_MODE
LDA #$2C
STA _MMC5_CHR_BANKSA+2 ; set CHR banks for sprites here
LDA #$2D
STA _MMC5_CHR_BANKSA+3
LDA #$CD ; init starting cursor position
STA _tmp6CC
LDA #$A6
STA _tmp6CE
LDA #$00
STA _tmp6D0+1
STA _tmp6D0
LDA #$09
STA _screen_pal_cur_bg_idx ; init palettes
LDA #$07
STA _screen_pal_cur_spr_idx
; REDUNDANT
; INC _game_setup_sub_idx
; JSR _render_on
; INC _mmc5_operation_in_progress_flag
; JMP _pal_fade_in ; show screen
JMP _game_setup_screen_start
; =============== S U B R O U T I N E =======================================
_game_setup02_name_input_input:
JSR _name_input_cursor_move_control ; main name input handler
JSR _common_select_cursor_control ; calling all stuff for input handling
JSR _name_input_char_select ; printing and storing input data
JSR _name_input_button_push_draw
JSR _name_input_char_store
; JSR _name_input_char_nt_queue ; REDUNDANT
; JSR _name_input_char_extnt_queue
JSR _name_input_name_buf_queue ; OPTIMIZED, called both at the same time, merge
JSR _spr_finish
BIT _pad0_press
BVC locret_245A9
JMP _name_input_previous_scr ; test for back button B
locret_245A9:
RTS
; =============== S U B R O U T I N E =======================================
_name_input_next_scr:
LDA _tmp6DC+2 ; current input screen type
BNE loc_245C9 ; if 0, then name input, jump next
INC _tmp6DC+2
JSR _ppu_queues_reset
JSR _name_input_clear_header_area ; redraw only upper portion of the screen
; JSRXY _rle_nt_res_queue,_rle_tlm_nt_input_word
; JSRXY _rle_extnt_res_queue,_rle_tlm_extnt_input_word
LDX #$08 ; OPTIMIZED
JSR _rle_tlm_queue
JMP _buffers_test_wait_flush
loc_245C9:
LDA #$0D ; jump to difficult setting
STA _game_setup_sub_idx ; if 1, then we at fav word input,
RTS ; then go to difficult setup
; =============== S U B R O U T I N E =======================================
_name_input_previous_scr:
LDA _tmp6DC+2 ; if we at name input screen
BEQ loc_245EE ; then jump to the city gen screen
DEC _tmp6DC+2
JSR _ppu_queues_reset ; or return from fav word screen back
JSR _name_input_clear_header_area ; redraw upper part with name input again
; JSRXY _rle_nt_res_queue,_rle_tlm_nt_input_name
; JSRXY _rle_extnt_res_queue,_rle_tlm_extnt_input_name
LDX #$04 ; OPTIMIZED
JSR _rle_tlm_queue
JMP _buffers_test_wait_flush
loc_245EE:
LDA #$00
STA _game_setup_sub_idx
RTS
; =============== S U B R O U T I N E =======================================
; clear upper part of the name input screen for new header.
;
_name_input_clear_header_area:
; JSRXY _rle_nt_res_queue,_rle_tlm_nt_clear_area
; JSRXY _rle_extnt_res_queue,_rle_tlm_extnt_clear_area
LDX #$00 ; OPTIMIZED
JSR _rle_tlm_queue
JMP _buffers_test_wait_flush
; =============== S U B R O U T I N E =======================================
_common_select_cursor_control:
LDA _pad0_press ; test for any button press
BEQ loc_24614
LDA #$FF ; if any button pressed
STA _tmp6D0+1 ; stop blinking flag set
loc_24614:
LDA _tmp6D0+1
BMI .force_draw ; if 80 raized draw always
LDA _tmp6D0 ;
BNE .timer_draw ; or draw while timer not zero
LDY #$08 ; reload hide time
LDA _tmp6D0+1 ; toggle draw allow flag low bit
EOR #$01 ; disable the cursor
STA _tmp6D0+1
BEQ .reload_draw ; delay for show -10, for hide -8
LDY #$10
.reload_draw:
STY _tmp6D0 ; reload timer
.timer_draw:
DEC _tmp6D0 ; do
.force_draw:
LDA #$00
STA _spr_insert_args._idx ; reset spr buf
STA _spr_buf_pos
LDA _tmp6D0+1
BEQ loc_2464A ; check if we allow to show cursor
LDA _tmp6CC
STA _spr_insert_args._pos._COL ; draw actually
LDA _tmp6CE
STA _spr_insert_args._pos._ROW
JMP _spr_lib_attr_insert
loc_2464A:
JMP _spr_finish ; or close spr buffer for now
; =============== S U B R O U T I N E =======================================
; BUG: all tlm queue functions here when used frequently overflows the buffer
; (use turbo button for example), to fix it just add some flush wait.
;
_name_input_button_push_draw:
LDA _tmp6DC+3 ; push anim counter
BEQ locret_246DB ; draw if non-zero
DEC _tmp6DC+3 ; decrease
LDY _tmp6DC+6 ; get pressed button type
CPY #$21
BCS .draw_simple_button_press ; all above TAB is simple letters
CPY #$08
BEQ .draw_simple_button_press ; BACK button simple to
CMP #$10
BNE .push_wait ; if anim already started, skip
CPY #$20 ; else anim frame, draw push
BNE loc_24676 ; two special buttons here
; JSRXY _rle_nt_res_queue,_tlm_nt_space_press
; JSRXY _rle_extnt_res_queue,_tlm_extnt_space_press
LDX #$30
JSR _tlm_lib_queue ; OPTIMIZED
JMP _buffers_test_wait_flush ; FIX
loc_24676:
CPY #$0C
BNE locret_246DB
; JSRXY _rle_nt_res_queue,_tlm_nt_back_button_press ; REDUNDANT
; JSRXY _rle_extnt_res_queue,_tlm_extnt_back_button_press
LDX #$2C
JSR _tlm_lib_queue ; OPTIMIZED
JMP _buffers_test_wait_flush ; FIX
.push_wait:
CMP #$01 ; last anim frame, release buttons
BEQ _all_buttons_release_draw ; all at once.
RTS
.draw_simple_button_press:
CMP #$10 ; if you press buttons fast, you may
BNE loc_246AC ; reset the nt buttons animation and it won't release
JSR _all_buttons_release_draw ; so force all nt buttons to clear first
loc_246AC:
LDA #$A0 ; this is a sprite effect
STA _spr_insert_args._idx
LDA _tmp6DC+4
STA _spr_insert_args._pos._COL
LDA _tmp6DC+5
STA _spr_insert_args._pos._ROW
JSR _spr_lib_attr_insert ; draw common button frame sprite
LDX #$FD ; then manually hack its
LDA _tmp6DC+6 ; middle tile to display a corresponding
CMP #$08 ; letter in it