-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbank9.inc
4277 lines (4111 loc) · 117 KB
/
bank9.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 $F9
; ---------------------------------------------------------------------------
; -----M-A-I-B--S-C-R-E-E-N--R-E-S-O-U-R-C-E-S--C-O-D-E--A-N-D--D-A-T-A------
; ---------------------------------------------------------------------------
SECTION_START C10
; FIX, moved from PRG7 to the local place
; -
; =============== S U B R O U T I N E =======================================
_scr_chr_vars_init:
LDA _ppu_ctrl_shadow ; set scroll high bits to nt 2400
ORA #$01
STA _ppu_ctrl_shadow
STA _PPU_CTRL
LDA #$84 ; switch mmc5 to one-screen mode with
STA _mmc5_nt_mode_shadow ; exnt mapped to nt 2C00
STA _MMC5_NT_MODE
LDA _scr_res_idx ; _scr_res_idx now = _scr_res_idx*2 be careful!
ASL
STA _scr_res_idx
ASL
TAX
LDY #$00
loc_A001C:
LDA _screen_chr_banks_lib,X ; load CHR banks for sprites
BEQ loc_A0024 ; $00 means - no change bank
STA _MMC5_CHR_BANKSA,Y
loc_A0024:
INX
INY
CPY #$04
BNE loc_A001C
LDA #$00 ; reset screen specific vars
STA _mini_map_cur_row
STA _mini_map_cur_col
STA _max_tax_rate+1
STA _game_msg_wnd_active_flag
LDA #$14
STA _max_tax_rate ; hardcoded tax maximum = 20
LDA #$80
STA _game_wnd_spr_mode_flag
STA _game_core_state
STA _scr_res_control_flags
; JMP _screen_pal_spr_init ; REDUNDANT
;
; =============== S U B R O U T I N E =======================================
;_screen_pal_spr_init:
LDA _scr_res_idx
LSR
TAX
LDA _screen_pal_spr_list,X ; load spr pal idx
STA _screen_pal_cur_spr_idx
RTS
_screen_pal_spr_list:
.BYTE $03,$08,$02,$02,$03,$03,$06,$04,$00
_screen_chr_banks_lib:
.BYTE $34,$00,$36,$00
.BYTE $34,$00,$39,$00
.BYTE $34,$5D,$36,$37
.BYTE $34,$00,$00,$00
.BYTE $34,$00,$00,$00
.BYTE $34,$00,$00,$00
.BYTE $34,$00,$00,$37
.BYTE $34,$00,$1A,$37
; REDUNDANT, unreferenced copy of the routine below
;
; =============== S U B R O U T I N E =======================================
;_screen_pal_bg_init_unref:
; LDA _scr_res_idx
; AND #$FE
; BNE loc_A00A7
; LDY _cur_info_maps_button_idx
; LDA _screen_pal_extra_list,Y
; JMP loc_A00AC
;loc_A00A7:
; LSR
; TAY
; LDA _screen_pal_list,Y
;loc_A00AC:
; STA _screen_pal_cur_bg_idx
; RTS
; =============== S U B R O U T I N E =======================================
_scr_pal_bg_load:
LDA #$02
STA _ppu_pal_dequeue_req ; only bg queue flag
LDA _scr_res_idx
AND #$FE
BNE loc_A0080
LDY _cur_info_maps_button_idx ; for infom maps pal differs by info type
LDA _screen_pal_extra_list,Y
JMP loc_A0085
loc_A0080:
LSR ; the rest is always the same
TAY
LDA _screen_pal_list,Y
loc_A0085:
STA _screen_pal_cur_bg_idx
JMP _pal_load_lib ; load pal immediately
_screen_pal_list:
.BYTE $00,$04,$03,$02,$0B,$12,$06,$0A
_screen_pal_extra_list:
.BYTE $05,$05,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01
; =============== S U B R O U T I N E =======================================
_scr_res_wnd_close:
LDX #$FF
STX _full_game_field_redraw_req ; map area redraw request
INX
STX _gui_active_controls_flags ; clear gui flags, request to redraw
; STX _update_rect_left ; REDUNDANT, redraw top-leftmost area of map
; STX _update_rect_top ; which is not correct here
STX _scr_res_control_flags
STX _game_core_stop_flag
STX _scr_res_idx ; FIX BUGS#19
; INX ; REDUNDANT, one more leftover
; LDA #$18 ; REDUNDANT, continue, these paremerers
; STA _update_rect_right ; are set in another routine
; LDA #$14 ; and calculated from cur screen pos
; STA _update_rect_bottom
LDA #$44 ; NOTE: always the same cursor pos
STA _cur_game_cursor_scr_pos._COL ; after exit any screen resourse
LDA #$30
STA _cur_game_cursor_scr_pos._ROW
JSR _buffers_wait_flush ; wait for ppu queues if any
JSR _pal_fade_out ; fade out
LDA _ppu_ctrl_shadow ; restore regular game ppo modes
AND #$FC
STA _ppu_ctrl_shadow
STA _PPU_CTRL
LDA #$00
STA _MMC5_NT_MODE
STA _game_wnd_spr_mode_flag
STA _scr_res_window_opened_flag
RTS
; =============== S U B R O U T I N E =======================================
_scr_res_common:
JSR _thread_lock_flag_set ; enter THREAD1-safe critical section
JSR _render_off
DEC _mmc5_operation_in_progress_flag
JSR _spr_clear
; FJSRA _scr_chr_vars_init,PRG6,PRG9 ; REDUNDANT
JSR _scr_chr_vars_init ; FIX, now local
JSR _wait_for_nmi
; FJSRA _scr_pal_bg_load,PRG6,PRG9
JSR _scr_pal_bg_load ; FIX, now local
JSR _wait_for_nmi
FJSRA _scr_common_draw,PRG6,PRG9 ; static tlm draw
; NOTE
; for some reason attempting to use a regular handler system with no extra checks
; lead to screen garbling... all functions although uses ppu queue buffers,
; flushes them manually to ppu, so all these functions should be called
; when render is off. neither of any code here does its own render off stuff
;
; in order to remove these functions from here and inserting them into main
; sub list you need to remove all force flush code and make the nmi code do its
; work instead
;
JSR _scr_res_hndl2_A_budget_draw
JSR _scr_res_hndl3_A_city_eval_draw
; JSR _far_scr_res_hndl5_A_history_draw ; REDUNDANT
FJSRA _scr_res_hndl5_A_history_draw,PRG7,PRG9 ; OPTIMIZED
; JSR _far_scr_res_hndl6_A_bank_draw ; REDUNDANT
FJSRA _scr_res_hndl6_A_bank_draw,PRG7,PRG9 ; OPTIMIZED
;-
LDA _scr_res_idx ; currently _scr_res_idx = _scr_res_idx*2
LSR
TAY
LDA _scr_res_ctlr_flag_list,Y ; preload control flags
STA _scr_res_control_flags
JSR _ppu_reset
JSR _wait_for_nmi
JSR _render_on
INC _mmc5_operation_in_progress_flag
LDA #$01
STA _scr_res_window_opened_flag
JSR _pal_fade_in ; show the actual screen
.scr_res_loop:
JSR _wait_for_nmi
; FJSRA _wnd_common_cursor_spr_clear,PRG7,PRG9 ; REDUNDANT
JSR _wnd_common_cursor_spr_clear ; OPTIMIZED, now local
JSR _spr_finish
; FJSRA _scr_res_cursor_move,PRG6,PRG9 ; REDUNDANT, common cursor handlers
JSR _scr_res_cursor_move ; OPTIMIZED, now local
; FJSRA _scr_res_cursor_draw,PRG6,PRG9 ; REDUNDANT, common cursor draw
JSR _scr_res_cursor_draw ; OPTIMIZED, now local
JSR _scr_res_hndl_common_exec ; execure screen handler
BIT _scr_res_control_flags
BVC .scr_res_quick_warp_test ; cancel command test
APUA_SE _SE_IDX_CLICK ; exit from screen
; FJSRA _scr_res_wnd_close,PRG6,PRG9 ; REDUNDANT
; RTS
JMP _scr_res_wnd_close ; OPTIMIZED, now local
.scr_res_quick_warp_test:
LDA _scr_res_control_flags ; for warp from one screen to another
CMP #$10 ; used in budget to banks screen jump
BNE .scr_res_loop
JMP _scr_res_common
_scr_res_ctlr_flag_list:
.BYTE $00,$00,$20,$08,$08,$08,$08,$A8
; OPTIMIZED, local now
; =============== S U B R O U T I N E =======================================
_scr_res_cursor_move:
LDA _scr_res_control_flags ; for resources with a free cursor
AND #$20 ; like graphs and info maps
BNE locret_A0323
LDA _pad0_held ; test for D-Pad movements only
AND #$0F
BNE loc_A0324
locret_A0323:
RTS
loc_A0324:
LDX #$00
LDY #$03
LDA _pad0_held ; fetch held buttons, keep in A
loc_A032A:
LSR
BCC loc_A0341 ; shift d-pad bits in order R, L, U, D
PHA ; save d-pad bits for now
LDA _cur_game_cursor_scr_pos,X ; get cur pos
CLC
ADC _scr_res_cursor_speed,Y ; increment position for 4 directions
CMP _scr_res_cursor_min_pos_list,X ; test for limits
BCC loc_A0340
CMP _scr_res_cursor_max_pos_list,X
BCS loc_A0340
STA _cur_game_cursor_scr_pos,X ; if not at the side of the screen, store
loc_A0340:
PLA ; restore d-pad bits
loc_A0341:
CPY #$02 ; Y is dpad pos idx, 0,1 - hor, 2,3 - vert
BNE loc_A0346 ; so test if we should switch X to Y
INX ; switch once at Y 02
loc_A0346:
DEY
BPL loc_A032A ; loop until all 4 dpad tested
LDA #$00
STA _cur_game_cursor_area ; not used the same way as ingame
RTS
; all directions has it's own speed just for convinience to correspond
; to the d-pad index counter
;
_scr_res_cursor_speed:
.BYTE $FE,$02,$FE,$02
_scr_res_cursor_min_pos_list:
.BYTE $08,$18
_scr_res_cursor_max_pos_list:
.BYTE $E9,$D9
; =============== S U B R O U T I N E =======================================
_scr_res_cursor_draw:
LDA _scr_res_control_flags
AND #$08
BNE locret_A0360
LDA _spr_buf_pos ; draw new cursor always from 0
BEQ _scr_res_cursor_spr_insert_ex ; if already 0, jump directly
PHA ; if no, save old position
JSR _scr_res_cursor_spr_insert_ex_0 ; draw and return here
POPB _spr_buf_pos ; then restore
locret_A0360:
RTS
; =============== S U B R O U T I N E =======================================
_scr_res_cursor_spr_insert_ex_0:
LDA #$00
STA _spr_buf_pos ; FIX if already 0, no need to store
; =============== S U B R O U T I N E =======================================
_scr_res_cursor_spr_insert_ex:
STA _spr_insert_args._idx ; in any cases A here is 0
STA _spr_insert_args._attr
LDA _cur_game_cursor_scr_pos._COL
STA _spr_insert_args._pos._COL
LDA _cur_game_cursor_scr_pos._ROW
STA _spr_insert_args._pos._ROW
JMP _spr_lib_attr_insert
; -
; =============== S U B R O U T I N E =======================================
_wnd_common_cursor_spr_clear:
LDX #$0F
LDA #$FA
loc_B97FC:
STA _spr_buf,X
DEX
BPL loc_B97FC
RTS
; =============== S U B R O U T I N E =======================================
; there are two handlers for every event. one is for init/draw, the second is
; for input and interact. some init/draw routines doesn't call from this array
; they call from the main code instead, because they can draw only when render is
; off and flushes its buffers directly to PPU.
; this probably were done in order to draw the screen at once without waiting
; but some other screens don't do that, like overall info screen. unless other
; screens where all the numbers should be drawn before the screen shows, this
; one draw numbers one by one after the screen shown...
;
_scr_res_hndl_common_exec:
LDA _scr_res_idx
JSR _switch
.WORD _scr_res_hndl0_A_info_maps_draw, _scr_res_hndl0_B_info_maps_input
.WORD _far_scr_res_hndl1_A_graphs_draw, _far_scr_res_hndl1_B_graphs_input
.WORD 0, _far_scr_res_hndl2_B_budget_input
.WORD 0, _scr_res_hndl3_B_city_eval_input
.WORD _scr_res_hndl4_A_city_overview_init,_scr_res_hndl4_B_city_overview_input
.WORD 0, _scr_res_hndl5_B_history_input
.WORD 0, _far_scr_res_hndl6_B_bank_input
.WORD _scr_res_hndl7_A_new_city_gen_init, _scr_res_hndl7_B_new_city_gen_input
; =============== S U B R O U T I N E =======================================
_scr_res_hndl7_A_new_city_gen_init:
LDA #$00
STA _mini_map_cur_col ; this special screen called from
STA _mini_map_cur_row ; _game_setup functions, not from game itself
STA _new_city_screen_cur_row_idx
STA _new_city_screen_cur_col_idx
STA _cur_info_maps_button_idx
STA _info_maps_menu_extra_idx
STA _tmp6D0+1
INC _scr_res_idx
LDA #$10
STA _tmp6D0
; JMP _new_city_map_generate ; REDUNDANT
; !FALLTHROUGH!
; =============== S U B R O U T I N E =======================================
_new_city_map_generate:
JSR _new_city_screen_spr_draw ; put regular sprites
JSR _mini_map_clear_draw ; clear map line by line
; FJSRA _new_city_please_wait_spr_draw,PRG7,PRG9 ; REDUNDANT
JSR _new_city_please_wait_spr_draw ; OPTIMIZED, local now
JSR _wait_for_nmi
JSR _sram_write_enable
FJSRA _generate_new_map,SRAM,PRG3 ; do actual generation, lock other activity
LDA #$80
STA _scr_res_control_flags ; done, go to the input part
LDA #$00
STA _new_city_map_regen_req
; JMP _new_city_screen_spr_draw ; REDUNDANT, already drawn above
RTS
; =============== S U B R O U T I N E =======================================
_scr_res_hndl7_B_new_city_gen_input:
LDA #$80
STA _game_core_state
JSR _new_city_screen_cursor_draw
BIT _scr_res_control_flags ; map update request flag test
BPL .no_mimi_map_redraw
JSR _new_city_screen_spr_draw ; draw cur sprite while we busy
loc_EA0EC:
; JSR _wait_for_nmi ; actually there is already such test inside
JSR _mini_map_fill_block ; draw mini-map block by block
BIT _scr_res_control_flags ; while flag is set
BMI loc_EA0EC
LDA #$20
STA _scr_res_control_flags ; exit, when done
RTS
.no_mimi_map_redraw:
BIT _pad0_press ; press B test
BVC .no_b_pressed
LDA #$40 ; exit to title
STA _scr_res_control_flags
LDA #$02
STA _title_sub_idx
RTS
.no_b_pressed:
BMI .button_a_pressed ; test if A pressed instead
BIT _pad0_autorep ; or autorep falling edge
BMI .button_a_pressed
JSR _new_city_screen_cursor_move ; move cursor then, C=1 if moved
BCS .new_city_defalut_darw
LDA _new_city_map_regen_req ; test if any map number controls changed
BEQ .new_city_defalut_darw
DEC _new_city_map_regen_delay ; no regen immediately, wait
BNE .new_city_defalut_darw
JMP _new_city_map_generate ; if no activyty for a long time, do regen
.button_a_pressed:
LDA _new_city_screen_cur_row_idx
BNE loc_EA12C ; test if next map button ressed
JMP _new_city_next_map_push ; draw push button
loc_EA12C:
CMP #$01
BNE loc_EA138 ; test if start game button pressed
LDA #$00 ; this is hacky way to tell _game_setup
STA _title_sub_idx ; routine that we need to play game or back to title
JMP _new_city_start_new_game_push ; draw push button
loc_EA138:
JMP _new_city_map_num_change_push ; draw push map change buttons
.new_city_defalut_darw:
JMP _new_city_screen_spr_draw
; =============== S U B R O U T I N E =======================================
_new_city_screen_cursor_draw: ; draws a cursor at a fixed
LDA _new_city_screen_cur_row_idx ; positions on the screen controls
CMP #$02
BCC .get_spr_pos ; upper buttons, fixed pos
BEQ .get_up_arrow_pos ; idx=A=2 already
CLC ; A>2, then idx = A+2
ADC #$02
.get_up_arrow_pos:
CLC
ADC _new_city_screen_cur_col_idx ; get col idx
.get_spr_pos:
ASL
TAY
LDA _new_city_cur_pos_list,Y ; fixed cursor positions from the list
STA _tmp6CE
LDA _new_city_cur_pos_list+1,Y
STA _tmp6CC
FJSRA _common_select_cursor_control,SRAM,PRG1
RTS
_new_city_cur_pos_list:
.BYTE $48,$E0 ; new city gen pos
.BYTE $68,$E0 ; start game pos
.BYTE $D2,$E2 ; up arrow 0
.BYTE $D2,$DA ; up arrow 1
.BYTE $D2,$D2 ; up arrow 2
.BYTE $DA,$E2 ; down arrow 0
.BYTE $DA,$DA ; down arrow 1
.BYTE $DA,$D2 ; down arrow 2
; =============== S U B R O U T I N E =======================================
_new_city_screen_cursor_move:
LDA _pad0_press
AND #$0F
BEQ .no_cursor_moved ; if any dpad pressed
APUX_SE _SE_IDX_SELECT ; play sound
AND #$03
BNE .hor_movements
LDA _pad0_autorep ; vert movements here
CMP #$08
BNE .up_movements
DEC _new_city_screen_cur_row_idx ; dec twice to not to use jmp instead
DEC _new_city_screen_cur_row_idx ; dummy dec, because we inc immediately
.up_movements:
INC _new_city_screen_cur_row_idx ; inc if needed
LDA _new_city_screen_cur_row_idx ; wrap around
AND #$03
STA _new_city_screen_cur_row_idx
BPL .cursor_moved ; always S=0 here, unconditional jump
.hor_movements:
LDA _new_city_screen_cur_row_idx
CMP #$02
BCC .no_cursor_moved ; no left-right movements for upper buttons
LDA _pad0_autorep
LSR
BCC .left_movements
DEC _new_city_screen_cur_col_idx ; the same for hor idxes
DEC _new_city_screen_cur_col_idx
.left_movements:
INC _new_city_screen_cur_col_idx
LDY _new_city_screen_cur_col_idx ; wrap around 3 using table
BPL loc_EA181 ; if S=1, then wrap to 2
LDY #$02
loc_EA181:
LDA _wrap_3_table,Y
STA _new_city_screen_cur_col_idx
.cursor_moved:
SEC
RTS
.no_cursor_moved:
CLC
RTS
_wrap_3_table:
.BYTE $00,$01,$02,$00
; =============== S U B R O U T I N E =======================================
_new_city_start_new_game_push:
APUA_SE _SE_IDX_SELECT ; play se
LDA _new_city_map_regen_req ; wait for map fully redrawn
BNE locret_EA1F3 ; actually dows not need here
; MOVWO _ptr0,_tlm_nt_new_game_push ; REDUNDANT, merged in lib routine
; MOVWO _tmp2,_tlm_extnt_new_game_push
; LDA #$FF
; JSR _tlm_queue ; queue push button tilemaps
LDX #$14 ; OPTIMIZED
JSR _tlm_lib_queue ; -
JSR _new_city_screen_spr_draw
LDX #$08 ; delay for 8 frames
loc_EA1E8:
JSR _wait_for_nmi
DEX
BNE loc_EA1E8
LDA #$40
STA _scr_res_control_flags ; set exit flag
locret_EA1F3:
RTS
; =============== S U B R O U T I N E =======================================
_new_city_map_num_change_push:
APUA_SE _SE_IDX_SBUILD ; the same sound as for small buildings
LDX #$00
LDA _new_city_screen_cur_row_idx
CMP #$02
BEQ loc_EA203 ; change what, up or...
LDX #$80 ; change down
loc_EA203:
STX _new_city_button_to_change_flags
LDY _new_city_screen_cur_col_idx
LDA _new_city_map_change_idx_list,Y
ORA _new_city_button_to_change_flags; generate mask of button to change
STA _new_city_button_to_change_flags
LDA #$80
STA _new_city_map_regen_delay ; reload delay, map number is changed
STA _new_city_map_regen_req ; set flag to redraw map
; FJSRA _new_city_map_num_button_update,PRG7,PRG9 ; REDUNDANT, draws dummy sprite, no need here
MOVW _ptr0,_new_map_number ; hex to dec
JSR _hex_to_dec9999
LDY _new_city_screen_cur_col_idx ; do map number change decimally
BIT _new_city_button_to_change_flags; by decimal digit, Y=digit idx
BPL loc_EA242 ; _tmp0-_tmp2 contains a decimal number
LDA _ptr0,Y
BNE loc_EA23D
LDA #$0A
loc_EA23D:
SEC
SBC #$01
BPL loc_EA24E
loc_EA242:
LDA _ptr0,Y
CMP #$09
BNE loc_EA24B
LDA #$FF
loc_EA24B:
CLC
ADC #$01
loc_EA24E:
STA _ptr0,Y
LDA _tmp2 ; convert decomal to hex back
ASL
TAY
LDA _num_hundreds,Y
CLC
ADC _ptr0
STA _ptr0
LDA _num_hundreds+1,Y
ADC #$00
STA _tmp3 ; temporary higher hex nubble of map num
LDY _ptr0+1
LDA _num_decals,Y
CLC
ADC _ptr0
STA _ptr0 ; _tmo0-lower hex nubble
STA _new_map_number ; update hex map number
LDA _tmp3 ; in case there are overflow bits,
ADC #$00 ; increment it to hi nibble
STA _ptr0+1 ; now _tmp1 full hight nibble, _ptr0 - 16bit hex
STA _new_map_number+1 ; update hex map number hi nibble
JSR _hex_to_dec9999 ; now CONVERT TO DECIMAL ONE MORE TIME LOL
JSR _new_city_map_num_spr_insert ; because we need to draw decimal but we erase it already
LDA #$F2 ; BUG, see, this is tiles for pressed
BIT _new_city_button_to_change_flags; number selection arrows, but
BPL loc_EA289 ; ...
LDA #$F7 ; here is NO button update code!
loc_EA289:
; FIX. now arrow buttons are animated! they probably haven't enabled it here
; because of previously it was an FJSRA call (see below) which is changes
; content of ram vars _tmp0 to _tmp6 (saves the temporary vars there)
; since we moved this routine here and made it local, there is no more
; var changes, so we can use it now and all working as intended
; -
JSR _new_city_map_num_button_update
; -
JSR _new_city_map_num_roll_anim ; after press we do rolling number anim here
LDA #$F1 ; and restore button back, unpush!
BIT _new_city_button_to_change_flags
BPL loc_EA295
LDA #$F6
loc_EA295:
; FJSRA _new_city_map_num_button_update,PRG7,PRG9 ; here is the proper routine called!
JSR _new_city_map_num_button_update ; FIX, now local, draw unpressed button back
RTS
_new_city_map_change_idx_list:
.BYTE $01,$02,$04
_num_hundreds:
.WORD 0,100,200,300,400,500,600,700,800,900
_num_decals:
.BYTE 0, 10, 20, 30, 40, 50, 60, 70, 80, 90
; =============== S U B R O U T I N E =======================================
; updates one particular button tile with a custom one. seems planned to animate
; pushes of the buttons, but writes always the same values.
; moved from PRG7, now local here
;
_new_city_map_num_button_update:
PHA
LDY #$FF ; valid flags 04 02 01
BIT _new_city_button_to_change_flags; 84 82 81
BPL loc_B96AB
LDY #$02
loc_B96AB:
LDA _new_city_button_to_change_flags
loc_B96AE:
LSR ; calc spr buf pos idx
INY
BCC loc_B96AE
LDA _new_city_ctrl_spr_pos_list,Y
TAX
PLA
STA _spr_buf,X ; set the map num select button tile
RTS
_new_city_ctrl_spr_pos_list:
.BYTE $1D,$21,$25
.BYTE $11,$15,$19
; =============== S U B R O U T I N E =======================================
_new_city_next_map_push:
APUA_SE _SE_IDX_SELECT ; play se
LDA _new_city_map_regen_req ; if we already pending a new map
BNE .next_skip ; skip this part
; MOVWO _ptr0,_tlm_nt_next_map_push
; MOVWO _tmp2,_tlm_extnt_next_map_push
; LDA #$FF
; JSR _tlm_queue ; draw push button
LDX #$18
JSR _tlm_lib_queue
; BUG, here we have a problem, after push we wait for nmi and
; at least for one frame we have no sprites shown here. so
; when you press the button, the bottom controls will blink
; FIX, if we remove this frame, then the buffers will flush on the
; number roll animations below without blinking the sprites itself
;
; JSR _wait_for_nmi ; FIX, removed
INCW _new_map_number ; now increment map number
CMPW _new_map_number,999 ; clamp to 0 after 999
BCC .do_next_map
MOVWI _new_map_number,0
.do_next_map:
MOVW _tmp0,_new_map_number
JSR _hex_to_dec9999 ; also hex to dec it
LDA #$01 ; masks for buttons to roll
LDX _ptr0 ; all positive because increment only
BNE loc_EA342
LDA #$03
LDX _ptr0+1
BNE loc_EA342
LDA #$07
loc_EA342:
STA _new_city_button_to_change_flags
JSR _new_city_map_num_spr_insert
JSR _new_city_map_num_roll_anim ; animate change
JSR _new_city_map_generate
; MOVWO _ptr0,_tlm_nt_next_map_release ; REDUNDANT, merged
; MOVWO _tmp2,_tlm_extnt_netx_map_release
; LDA #$FF
; JMP _tlm_queue
LDX #$1C ; OPTIMIZED
JMP _tlm_lib_queue ; draw release button again
.next_skip:
JMP _new_city_screen_spr_draw
_tlm_nt_next_map_push:
.BYTE $F9,$24,$04,$AF,$AF,$AF,$AF
.BYTE $19,$25,$04,$ED,$DE,$EE,$FD
.BYTE $39,$25,$03,$FE,$AD,$B9
.BYTE $FF
_tlm_extnt_next_map_push:
.BYTE $19,$5D,$04,$0A,$0A,$0A,$0A
.BYTE $39,$5D,$03,$0A,$0A,$0A
.BYTE $FF
_tlm_nt_next_map_release:
.BYTE $F9,$24,$04,$A9,$A9,$A9,$A9
.BYTE $19,$25,$04,$4E,$45,$58,$54
.BYTE $39,$25,$03,$4D,$41,$50
.BYTE $FF
_tlm_extnt_netx_map_release:
.BYTE $19,$5D,$04,$8B,$8B,$8B,$8B
.BYTE $39,$5D,$03,$8B,$8B,$8B
.BYTE $FF
_tlm_nt_new_game_push:
.BYTE $79,$25,$04,$AF,$AF,$AF,$AF
.BYTE $99,$25,$04,$AB,$AC,$AD,$AE
.BYTE $B9,$25,$04,$9E,$AD,$9F,$DE
.BYTE $FF
_tlm_extnt_new_game_push:
.BYTE $99,$5D,$04,$0A,$0A,$0A,$0A
.BYTE $B9,$5D,$04,$0A,$0A,$0A,$0A
.BYTE $FF
; REDUNDANT, merged with similar routine in PRG7, then moved it to the system bank
; and converted all calls to the library calls by its indexes
; now we have much shorter calls and all tlm are in one table in system bank
;
; =============== S U B R O U T I N E =======================================
; args: _ptr0 - nt data
; _tmp2 - extnt data
; A - stop byte for data
;_tlm_queue:
; STA byte_15F ; REDUNDANT, custom stop byte stored here
; PPUQSTART
; LDY #$00
;loc_EA36D:
; LDA (_ptr0),Y ; first queue nt data
; CMP byte_15F ; REDUNDANT, now all data uses the same stop-byte
; CMP #$FF
; BEQ loc_EA37B
; PPUQMOVA
; INY
; BNE loc_EA36D
;loc_EA37B:
; PPUQEND
; EXTQSTART
; LDY #$00
;loc_EA381:
; LDA (_tmp2),Y ; then queue extnt data
; CMP byte_15F
; CMP #$FF
; BEQ loc_EA38F
; EXTQMOVA
; INY
; BNE loc_EA381
;loc_EA38F:
; EXTQEND
; RTS
; REDUNDANT, unused
; .BYTE $01,$00,$0A,$00,$64,$00,$64,$00
; =============== S U B R O U T I N E =======================================
_new_city_screen_spr_draw:
JSR _new_city_map_num_spr_insert ; insert default num frame
MOVW _ptr0,_new_map_number ; insert actual number
JSR _hex_to_dec9999
LDX #$50
LDY #$02
loc_EA419:
LDA #$BE
JSR _new_city_map_num_digit_spr_draw
DEY
BPL loc_EA419
RTS
; =============== S U B R O U T I N E =======================================
_new_city_map_num_spr_insert:
LDX #$10 ; draws map number control
LDY #$3B
loc_EA426:
LDA _spr_new_city_map_def,Y ; default map number frame sprites
STA _spr_buf,X
INX
DEY
BPL loc_EA426
STX _spr_buf_pos
RTS
; NOTE, sprites drawn here in reverse order, from latest to earliest
; here we may use the regular _spr_raw_insert if move it to the
; system bank
;
_spr_new_city_map_def:
.BYTE $D0,$02,$EA,$AE
.BYTE $D8,$02,$EB,$AE
.BYTE $E0,$02,$EC,$AE
.BYTE $D0,$01,$ED,$B6
.BYTE $D8,$01,$ED,$B6
.BYTE $E0,$01,$EE,$B6
.BYTE $D0,$01,$EF,$C6
.BYTE $D8,$01,$EF,$C6
.BYTE $E0,$01,$F0,$C6
.BYTE $D0,$03,$F1,$CE
.BYTE $D8,$03,$F1,$CE
.BYTE $E0,$03,$F1,$CE
.BYTE $D0,$03,$F6,$D6
.BYTE $D8,$03,$F6,$D6
.BYTE $E0,$03,$F6,$D6
; =============== S U B R O U T I N E =======================================
_new_city_map_num_roll_anim:
LDA #$BE
STA _new_city_digit_spr_y_pos ; default Y pos for map num digit sprites
LDY #$02
LDX #$50
.num_draw_loop:
LDA _new_city_button_to_change_flags; check if button need to be drawn
AND _new_city_map_num_bitmasks,Y ; by masking its bit
BNE .num_to_animate
LDA _new_city_digit_spr_y_pos ; if masked, just draw at the same position
JSR _new_city_map_num_digit_spr_draw; draw dummy sprite for not moved digits
LDA _new_city_digit_spr_y_pos ; to have two sprites for every digit all the time
BNE .num_draw_next ; non-zero value, unconditional jump here
.num_to_animate:
LDA _ptr0,Y ; read digit
PHA ; save current value
JSR _new_city_map_old_digit_draw ; calc previous value and draw it as starting digit
PLA
STA _ptr0,Y ; restore new digit value, calc position of new sprite
BIT _new_city_button_to_change_flags; roll direction
BPL loc_EA467
LDA _new_city_digit_spr_y_pos
SEC
SBC #$0C
BNE .num_draw_next
loc_EA467:
LDA _new_city_digit_spr_y_pos
CLC
ADC #$0C
.num_draw_next:
JSR _new_city_map_num_digit_spr_draw; draw new sprite below or above the centered one
DEY
BPL .num_draw_loop
STX _spr_buf_pos ; store _spr_buf_pos
BIT _new_city_button_to_change_flags
BPL .do_scroll_up
.do_scroll_down:
JSR _wait_for_nmi
INC _new_city_digit_spr_y_pos ; animate position for sprites
LDA _new_city_digit_spr_y_pos
CMP #$CB
BEQ .stop_scroll
BNE .do_scrolls
.do_scroll_up:
JSR _wait_for_nmi
DEC _new_city_digit_spr_y_pos
LDA _new_city_digit_spr_y_pos
CMP #$B1
BEQ .stop_scroll
.do_scrolls:
LDA _new_city_button_to_change_flags; extract sprite idx to scroll
LDY #$02
LDX #$10
.roll_digits:
LSR
BCC loc_EA4B3
BIT _new_city_button_to_change_flags; dec/inc direct sprite data
BMI loc_EA4AD
DEC _spr_buf+$50,X
DEC _spr_buf+$54,X
BNE loc_EA4B3
loc_EA4AD:
INC _spr_buf+$50,X
INC _spr_buf+$54,X
loc_EA4B3:
PHA
LDA _num_spr_pos_adjust_list,Y ; switch digit to scroll
TAX
PLA
DEY
BPL .roll_digits
BIT _new_city_button_to_change_flags
BPL .do_scroll_up
BMI .do_scroll_down
.stop_scroll:
LDX #$68
STA _spr_buf_pos ; fixed _spr_buf_pos here
RTS
_num_spr_pos_adjust_list:
.BYTE $00,$00,$08
_new_city_map_num_bitmasks:
.BYTE $01,$02,$04
; =============== S U B R O U T I N E =======================================
_new_city_map_num_digit_spr_draw:
STA _spr_buf,X
INX
LDA _ptr0,Y
CLC
ADC #$E0
STA _spr_buf,X
INX
LDA #$00
STA _spr_buf,X
INX
LDA _new_city_map_num_digit_row_list,Y
STA _spr_buf,X
INX
RTS
_new_city_map_num_digit_row_list:
.BYTE $E0,$D8,$D0
; =============== S U B R O U T I N E =======================================
_new_city_map_old_digit_draw:
BIT _new_city_button_to_change_flags; check the direction of change
BPL .decrement_digit ; push up
LDA _ptr0,Y ; push down
CMP #$09
BNE loc_EA4F8 ; increment or wrap to 0
LDA #$FF
loc_EA4F8:
CLC
ADC #$01
BPL loc_EA507
.decrement_digit:
LDA _ptr0,Y
SEC
SBC #$01
BPL loc_EA507 ; decrement or wrap to 9
LDA #$09
loc_EA507:
STA _ptr0,Y ; store new digit
LDA _new_city_digit_spr_y_pos
JMP _new_city_map_num_digit_spr_draw
; =============== S U B R O U T I N E =======================================
_scr_res_hndl0_A_info_maps_draw:
LDA _cur_map_wnd_pos._ROW ; copy current screen map position
ASL ; to info map selection rect sprite pos
CLC
ADC #$3C
STA _info_maps_rect_pos._ROW
LDA _cur_map_wnd_pos._COL
ASL
CLC
ADC #$45
STA _info_maps_rect_pos._COL
JSR _info_maps_city_name_hud_draw ; force draw hud names, same as in-game, but
JSR _info_maps_date_hud_draw_ex ; without need to recalc ppu offsets
JSR _info_maps_popul_hud_draw
LDA #$00
STA _info_maps_button_pending
INC _scr_res_idx
LDA #$80
STA _scr_res_control_flags
; LDA #$0B ; REDUNDANT
LDA #$FF ; FIX, another special value on entry
STA _prev_info_maps_button_idx ; to prevent button release draw at start
JMP _scr_res_hndl0_AB_info_maps_redraw
; NOTE, for some reasons, original logic for this screen allows the cursor
; movements and even the button pushes while current map is drawn, in this
; case the new button number is pending and will be redrawn after the map draw
; process is complete.
; however, when THREAD1 set flag when map is changes, the info map lock
; all controls until it redraw the map again.
; that's weird somehow.
;
; =============== S U B R O U T I N E =======================================
_scr_res_hndl0_B_info_maps_input:
JSR _info_maps_date_hud_draw ; date update if needed (when requested)
JSR _info_maps_popul_hud_draw ; update popul all the time
; JSR sub_EADC9 ; REDUNDANT
; OPTIMIZED
LDX #$10
STX _spr_buf_pos ; draw mini-map frame
FJSRA _info_maps_spr_rect_draw,PRG7,PRG9
; -
JSR _info_maps_spr_arrows_hide ; hide mini-map arrows
BIT _scr_res_control_flags ; button A pressed and mini-map redraw in progress
BPL .no_mini_map_redraw ; skip if masked
JMP _info_maps_mini_map_update ; pending buttons press test here
.no_mini_map_redraw:
BIT _info_maps_button_pending
BPL .no_buttons_pending
; BVC loc_EA563 ; REDUNDANT, there is no B button exit here
; LDA #$40 ; nor skip exit from _info_maps_mini_map_update
; STA _scr_res_control_flags ; function, so never executed.
; JMP _info_maps_exit
;loc_EA563:
LDA _info_maps_button_pending ; if previously pending, read new button idx
AND #$0F
TAX
LDA _scr_res_ctrl_flag_list,X ; read busy flag for particular screen
STA _scr_res_control_flags ; because some buttons arent allowed to be "pended"
LDA #$00
STA _info_maps_button_pending ; clear request,
LDA _cur_info_maps_button_idx ; store new/prev button idxes
STA _prev_info_maps_button_idx
STX _cur_info_maps_button_idx ; redraw without buttons, they're already drawn
JMP _scr_res_hndl0_AB_info_maps_redraw_ex
.no_buttons_pending:
LDA _budget_scr_draw_req ; city engine still active, so fiscal year over
BEQ loc_EA588 ; may occurs at info screen, do special jump to it
JMP _info_maps_budget_screen_warp
loc_EA588:
LDA _mini_map_need_redraw_flag ; flag from THREAD1 when values are recalculated
BNE loc_EA5BA
BIT _pad0_held ; test for B held
BVC .idle_test
JMP _info_maps_arrows_move ; in this case draw arrows and move them
.idle_test:
LDA #$00 ; idle state for info maps screen
STA _scr_res_control_flags
STA _game_core_state
BIT _pad0_press ; regular button press test performed here
BPL _info_maps_idle
APUA_SE _SE_IDX_BCLICK
LDA #$80
STA _game_core_state
JSR _info_maps_get_hover_button_idx ; check hovered button
BCC _info_maps_exit
LDA _cur_info_maps_button_idx ; button detected