-
Notifications
You must be signed in to change notification settings - Fork 10
/
script00.s
1113 lines (1001 loc) · 35.3 KB
/
script00.s
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
include macros.s
include mainsym.s
; Script 0, title screen, game start/load/save
LOGOSTARTROW = 2
TEXTSTARTROW = 12
NUMTEXTROWS = 8
NUMTITLEPAGES = 5
TEXTSPLIT_LINE = 142
LOAD_GAME = 0
SAVE_GAME = 1
TITLE_MOVEDELAY = 8
TITLE_PAGEDELAY = 564
CHEATSTRING_LENGTH = 4
logoStart = chars
logoScreen = chars+608
logoColors = chars+608+168
titleTexts = chars+608+168*2
txtCancel = screen2-$118
txtEndWithoutSaving = screen2-$110
levelNames = screen2-$100
levelNamesTbl = screen2
START_LEVEL = $00 ;Warehouse container (proper start location)
START_X = $6900
START_Y = $1b00
;START_LEVEL = $00 ;Warehouse
;START_X = $6680
;START_Y = $1700
;START_LEVEL = $01 ;Courtyard
;START_X = $0280
;START_Y = $1700
;START_LEVEL = $03 ;Entrance, next to car park
;START_X = $2980
;START_Y = $1b00
;START_LEVEL = $01 ;Car park bottom level
;START_X = $4a80
;START_Y = $2800
;START_LEVEL = $04 ;Service tunnels
;START_X = $5180
;START_Y = $1b00
;START_LEVEL = $04 ;Service tunnels bridge
;START_X = $5480
;START_Y = $3000
;START_LEVEL = $04 ;Service tunnels hideout door
;START_X = $2480
;START_Y = $3000
;START_LEVEL = $05 ;Security center
;START_X = $0b80
;START_Y = $0f00
;START_LEVEL = $05 ;First upgrade lab
;START_X = $0d80
;START_Y = $0600
;START_LEVEL = $06 ;Upper labs
;START_X = $0180
;START_Y = $1700
;START_LEVEL = $06 ;Upper labs, next to recharger
;START_X = $4b80
;START_Y = $1300
;START_LEVEL = $06 ;Upper labs, next to recycler
;START_X = $3780
;START_Y = $1300
;START_LEVEL = $07 ;First cave
;START_X = $1f80
;START_Y = $1c00
;START_LEVEL = $07 ;Large spider's lair
;START_X = $4f80
;START_Y = $3b00
;START_LEVEL = $08 ;Lower labs beginning
;START_X = $4f80
;START_Y = $3900
;START_LEVEL = $08 ;Lower labs corridor
;START_X = $3780
;START_Y = $4100
;START_LEVEL = $08 ;Lower labs server room
;START_X = $1f80
;START_Y = $5300
;START_LEVEL = $09 ;Lower labs security center
;START_X = $2680
;START_Y = $5000
;START_LEVEL = $09 ;Lower labs security center cell
;START_X = $0480
;START_Y = $4800
;START_LEVEL = $08 ;Lower labs, old tunnels entrance
;START_X = $6780
;START_Y = $4a00
;START_LEVEL = $08 ;Next to lower labs operating room
;START_X = $5180
;START_Y = $5600
;START_LEVEL = $0a ;Nether tunnel
;START_X = $0080
;START_Y = $5600
;START_LEVEL = $0a ;Nether tunnel, next to the tunnel machine
;START_X = $a580
;START_Y = $7400
;START_LEVEL = $0a ;Jormungandr
;START_X = $ed80
;START_Y = $7600
;START_LEVEL = $0b ;Next to Bio-Dome
;START_X = $4780
;START_Y = $1700
;START_LEVEL = $0b ;Bio-Dome
;START_X = $5080
;START_Y = $1700
;START_LEVEL = $0d ;Server vault
;START_X = $0180
;START_Y = $2300
;START_LEVEL = $0d ;Next to final server room
;START_X = $3a80
;START_Y = $3500
;START_LEVEL = $0e ;Second cave
;START_X = $1d80
;START_Y = $1d00
;START_LEVEL = $0e ;Second cave fiber cable
;START_X = $bf80
;START_Y = $4900
;START_LEVEL = $0c ;Security chief
;START_X = $1980
;START_Y = $1300
;START_LEVEL = $0f ;Old tunnels
;START_X = $0180
;START_Y = $4a00
;START_LEVEL = $0f ;Old tunnels lab
;START_X = $6f80
;START_Y = $4c00
org scriptCodeStart
dc.w TitleScreen
; Title screen code
TitleScreen: jsr StopScript
jsr SetMenuMode ;Reset in-game menu mode (X=0 on return)
; Setup split mode, load logo chars & title texts
jsr SetupTextScreen
jsr ClearPanelText
lda #REDRAW_ITEM+REDRAW_AMMO+REDRAW_SCORE ;Redraw all
sta panelUpdateFlags
lda #$00
sta armorMsgTime ;Reset armor message if any
sta shakeScreen ;Clear screen shake from any scripts
tax
ClearColorsLoop:sta colors,x ;Set colors for the picture area to all black
sta colors+$100,x
sta colors+$200,x
sta colors+SCROLLROWS*40-$100,x
inx
bne ClearColorsLoop
lda #<textSplitData
sta Irq5_Get+1
lda #>textSplitData
sta Irq5_Get+2
dex
stx ECS_LoadedCharSet+1 ;Mark game charset destroyed (X=$ff)
stx Irq6_SplitMode+1 ;Enable split IRQ mode
lda #F_LOGO
jsr MakeFileName_Direct
lda #<logoStart
ldx #>logoStart
jsr LoadFileRetry
; Print logo to screen
lda #<(screen1+8+LOGOSTARTROW*40)
ldx #>(screen1+8+LOGOSTARTROW*40)
sta zpDestLo
stx zpDestHi
lda #24
ldx #7
sta temp1 ;Chars per row
stx temp2 ;Row counter
ldx #$00
DC_RowLoop: ldy #$00
DC_Loop: lda logoScreen,x
sta (zpDestLo),y
inx
iny
cpy temp1
bcc DC_Loop
stx temp3
lda #40
ldx #zpDestLo
jsr Add8
ldx temp3
dec temp2
bne DC_RowLoop
lda #MUSIC_TITLE
jsr PlaySong
; Go to either the title screen or save screen
lda ES_ParamY+1 ;Script execution parameter
beq TitleTexts
; Save game
SaveGame: lda #SAVE_GAME
jmp LoadOrSaveGame
SaveGameExec: jsr FadeOutText
lda #<(saveStateEnd-saveStateStart) ;Save the savegame first
sta zpBitsLo
lda #>(saveStateEnd-saveStateStart)
sta zpBitsHi
lda #<saveStateStart
ldx #>saveStateStart
jsr SaveFile
ldy #$00
SaveGetLevelName:
lda levelNamesTbl,y ;Levelnum
bmi SGLN_NoCoords
cmp saveStateZP
bne SGLN_Next
lda saveXH ;If there are coord limits, they must be listed
cmp levelNamesTbl+1,y ;in right->left and bottom->top order to work properly
bcc SGLN_Next
lda saveYH
cmp levelNamesTbl+2,y
bcs SGLN_Found
SGLN_Next: iny
iny
SGLN_Next2: iny
iny
bne SaveGetLevelName ;Note: will loop endlessly if name not found
SGLN_NoCoords: and #$7f
cmp saveStateZP
bne SGLN_Next2
dey
dey
SGLN_Found: ldx levelNamesTbl+3,y
lda saveSlotChoice
jsr GetSaveListPos
adc #$10
sta temp1
CopyLevelName: lda levelNames,x ;Copy level name until endzero
sta saveList,y
beq CLN_Done
iny
inx
bne CopyLevelName
CLN_Done: ldx #$00
ldy temp1
CopySaveTime: lda saveStateStart,x ;Copy time
sta saveList,y
iny
inx
cpx #$04
bcc CopySaveTime
lda #F_SAVELIST
jsr MakeFileName_Direct
lda #<MAX_SAVES*SAVEDESCSIZE
sta zpBitsLo
lda #>MAX_SAVES*SAVEDESCSIZE
sta zpBitsHi
lda #<saveList
ldx #>saveList
jsr SaveFile ;Then save the savegamelist also
; Title text display
TitleTexts: lda #0
TitleNextPage: sta titlePage
jsr FadeOutText
jsr ClearText
lda titlePage
asl
tay
lda titleTexts,y
ldx titleTexts+1,y
jsr PrintPage
TitleTextsLoop: jsr UpdateCheckCheat
jsr GetFireClick
bcs EnterMainMenu
jsr TitlePageDelay
bcc TitleTextsLoop
lda titlePage
adc #$00
cmp #NUMTITLEPAGES
bcc TitleNextPage
bcs TitleTexts
EnterMainMenu: jsr PlaySelectSfx
; Main menu
MainMenu: jsr FadeOutText
jsr ClearText
lda titleTexts+NUMTITLEPAGES*2
ldx titleTexts+NUMTITLEPAGES*2+1
jsr PrintPage
MainMenuLoop: lda #11
sta temp1
lda mainMenuChoice
asl
ldx #5
ldy #TEXTSTARTROW+1
jsr DrawChoiceArrow
jsr UpdateCheckCheat
lda mainMenuChoice
ldx #2
jsr TitleMenuControl
sta mainMenuChoice
jsr GetFireClick
bcs MainMenuSelect
jsr TitlePageDelayInteractive
bcc MainMenuLoop
jmp TitleTexts ;Page delay expired, return to title
MainMenuSelect: jsr PlaySelectSfx
ldx mainMenuChoice
lda mainMenuJumpTblLo,x
sta MainMenuJump+1
lda mainMenuJumpTblHi,x
sta MainMenuJump+2
MainMenuJump: jmp $0000
; Options menu
Options: lda #0
sta optionsMenuChoice
jsr FadeOutText
jsr ClearText
lda titleTexts+NUMTITLEPAGES*2+2
ldx titleTexts+NUMTITLEPAGES*2+3
jsr PrintPage
RefreshOptions: lda #22
sta temp1
ldy difficulty
lda difficultyTxtLo,y
ldx difficultyTxtHi,y
ldy #TEXTSTARTROW
jsr PrintOnOffCommon
lda musicMode
ldy #TEXTSTARTROW+2
jsr PrintOnOff
lda soundMode
ldy #TEXTSTARTROW+4
jsr PrintOnOff
OptionsLoop: lda #10
sta temp1
lda optionsMenuChoice
asl
ldx #7
ldy #TEXTSTARTROW
jsr DrawChoiceArrow
jsr UpdateCheckCheat
lda optionsMenuChoice
ldx #3
jsr TitleMenuControl
sta optionsMenuChoice
jsr GetFireClick
bcs OptionsSelect
jsr TitlePageDelayInteractive
bcc OptionsLoop
jmp TitleTexts ;Page delay expired, return to title
OptionsSelect: ldx optionsMenuChoice
cpx #3
bcs OptionsGoBack
lda difficulty,x
adc #$01 ;C=0
sta optionsModified
cmp optionMaxValue,x
bcc OptionsNotOver
lda #$00
OptionsNotOver: sta difficulty,x
jsr PlaySelectSfx
jmp RefreshOptions
OptionsGoBack: jsr PlaySelectSfx
jmp MainMenu
; Load/save game
LoadGame: lda #LOAD_GAME
LoadOrSaveGame: sta LoadOrSaveGameMode+1
jsr FadeOutText
jsr ClearText
lda #TEXTSTARTROW
sta temp2
lda #<txtLoadSlot
ldx #>txtLoadSlot
ldy LoadOrSaveGameMode+1
beq LoadTextOK
lda #<txtSaveSlot
ldx #>txtSaveSlot
LoadTextOK: jsr PrintTextCenter
lda #TEXTSTARTROW+2
sta temp2
jsr ScanSaves
jsr ResetPage
LoadGameLoop: lda #6
sta temp1
lda saveSlotChoice
ldx #MAX_SAVES+1
ldy #TEXTSTARTROW+2
jsr DrawChoiceArrow
jsr UpdateCheckCheat
lda saveSlotChoice
ldx #MAX_SAVES
jsr TitleMenuControl
sta saveSlotChoice
jsr GetFireClick
bcc LoadGameLoop
jsr PlaySelectSfx
lda saveSlotChoice
cmp #MAX_SAVES
bcs LoadGameCancel ;Cancel load/save (TODO: save needs confirm step as data will be lost)
ldx #F_SAVE
jsr MakeFileName
LoadOrSaveGameMode:
lda #$00
beq LoadGameExec
jmp SaveGameExec
LoadGameExec: lda saveSlotChoice
jsr GetSaveListPos
;lda saveList,y ;No save at slot yet?
;beq LoadGameLoop
jsr OpenFile ;Load the savegame file (unpacked)
lda #<saveStateStart
sta zpDestLo
lda #>saveStateStart
sta zpDestHi
ldy #$00
sty saveT
RSF_Loop: jsr GetByte
bcs RSF_End
sta (zpDestLo),y
iny
bne RSF_Loop
inc zpDestHi
bne RSF_Loop
RSF_End: lda saveT ;Check if save is valid (has player actor)
beq LoadGameLoop
jsr FadeOutAll
jsr SaveModifiedOptions
lda #RCP_RESETTIME
jmp RestartCheckpoint ;Start loaded game
LoadGameCancel: jmp MainMenu
; Start new game
StartNewGame: jsr FadeOutAll
jsr SaveModifiedOptions
InitPlayer: lda #$00 ;Init player state (level number, inventory selected item,
ldx #playerStateZPEnd-playerStateZPStart-1 ;inventory items, plotbits, triggers)
IP_InitZPState: sta playerStateZPStart,x
dex
bpl IP_InitZPState
ldx #playerStateZeroEnd-playerStateStart
IP_InitState: sta playerStateStart-1,x
dex
bne IP_InitState
ldx #MAX_LVLACT-1 ;No stored levelactors
IP_InitLevelActors:
sta lvlActT,x
dex
bpl IP_InitLevelActors
ldx #LVLOBJTOTALSIZE
IP_InitLevelObjects:
sta lvlStateBits+LVLDATAACTTOTALSIZE-1,x ;Assume all persistent levelobjects are inactive
dex ;at start
bne IP_InitLevelObjects
ldx #LVLDATAACTTOTALSIZE
lda #$ff
IP_InitLevelData:
sta lvlStateBits-1,x ;Assume all leveldata-actors exist at start
dex
bne IP_InitLevelData
ldx #ITEM_LAST-ITEM_FIRST+1 ;$ff=item not carried
IP_InitInventory:
sta invCount-1,x
dex
bne IP_InitInventory
if SKIP_PLOT2 = 0
ldy lvlDataActBitsStart+$04 ;Disable enemies from level4, ids 16,17,18,19 (must not change.) Will be enabled later
lda #$ff-$40-$80
sta lvlStateBits+2,y
lda #$ff-$01-$02
sta lvlStateBits+3,y
endif
lda #ITEM_FISTS
sta itemIndex
sta lastItemIndex
ldx #1
jsr AddItem
if STARTITEM_CHEAT > 0
lda #ITEM_MINIGUN
ldx #100
jsr AddItem
endif
lda #START_LEVEL
sta levelNum
lda #$00
sta reload
sta battery
sta saveD
#if FILTER_UPGRADE_CHEAT > 0
lda #$80
#endif
#if UPGRADE_CHEAT > 0
lda #$ff
#endif
sta upgrade ;Reset upgrade status
lda #<START_X ;Set startposition
sta saveXL
lda #>START_X
sta saveXH
lda #<START_Y
sta saveYL
lda #>START_Y
sta saveYH
lda #ACT_PLAYER
sta saveT
lda #HP_PLAYER
sta saveHP
lda #MAX_DIFFICULTY ;Reset save difficulty to maximum,
sta saveDifficulty ;will be corrected by SaveCheckpoint
lda #MAX_BATTERY
sta battery+1
lda #MAX_OXYGEN
sta oxygen
sec ;Load first level's actors from disk
jsr CreatePlayerActor
if ALLQUESTITEMS_CHEAT > 0
lda #ITEM_FIRST_IMPORTANT
IP_GiveAllLoop: pha
ldx #1
jsr AddItem
pla
adc #$00
cmp #ITEM_LAST+1
bcc IP_GiveAllLoop
endif
ldx #$02 ;3 persistent NPCs to initialize
IP_NPCLoop: jsr GetLevelActorIndex
lda npcX,x
sta lvlActX,y
lda npcY,x
sta lvlActY,y
lda npcF,x
sta lvlActF,y
lda npcT,x
sta lvlActT,y
lda npcWpn,x
sta lvlActWpn,y
lda npcOrg,x
sta lvlActOrg,y
dex
bpl IP_NPCLoop
lda #<EP_SCIENTIST2 ;Initial NPC scripts to drive the plot forward
ldx #>EP_SCIENTIST2
sta actScriptEP
stx actScriptF
if SKIP_PLOT > 0
if SKIP_PLOT2 > 0
lda #PLOT_HIDEOUTAMBUSH
jsr SetPlotBit
lda #<EP_HACKERAMBUSH
ldx #>EP_HACKERAMBUSH
else
lda #<EP_HACKER3
ldx #>EP_HACKER3
endif
else
lda #<EP_HACKER
ldx #>EP_HACKER
endif
sta actScriptEP+2
stx actScriptF+2
ldx #(MAX_CODES)*3-1
IP_CodeLoop: if CODE_CHEAT > 0
lda #$00
else
jsr Random
and #$0f
cmp #$0a
bcs IP_CodeLoop
endif
sta codes,x
dex
bpl IP_CodeLoop
lda codes+MAX_CODES*3-1 ;Make the last (nether tunnels) code initially
ora #$80 ;impossible to enter, even by guessing
sta codes+MAX_CODES*3-1
jsr SaveCheckpoint ;Save first in-memory checkpoint immediately
jsr FindPlayerZone
if ENDING_TEST > 0
lda #<EP_ENDSEQUENCE
ldx #>EP_ENDSEQUENCE
ldy #ENDING_TEST-1
jmp ExecScriptParam
else
if START_LEVEL = $00 && START_Y = $1b00
lda #<EP_INTROCUTSCENE ;Intro works right only in the official start location
ldx #>EP_INTROCUTSCENE
jmp ExecScript
else
jmp CenterPlayer
endif
endif
; Save options if modified
SaveModifiedOptions:
lda difficulty ;Set player's difficulty damage scaling now
asl ;Easy = 4 (half), Normal = 8 (unmodified) etc.
asl
adc #$04
sta DA_DmgDifficultyMod+1
lda optionsModified
beq SMC_NoChange
lda #F_OPTIONS
jsr MakeFileName_Direct
lda #<3
sta zpBitsLo
lda #>3
sta zpBitsHi
lda #<difficulty
ldx #>difficulty
jsr SaveFile
lda #$00
sta optionsModified
SMC_NoChange: rts
; Check for cheat string, then fall through to update
UpdateCheckCheat:
lda keyType
bmi CC_NoCheat
ldx cheatIndex
cmp cheatString,x
bne CC_CheatWrong
inc cheatIndex
cpx #CHEATSTRING_LENGTH-1
bcc CC_NoCheat
CC_ActivateCheat:
lda DA_ResetRecharge
eor #$86^$a9
sta DA_ResetRecharge
lda DA_ResetRecharge+1 ;Disable player damage & battery drain
eor #healTimer^$80
sta DA_ResetRecharge+1
lda DrainBatteryRound
eor #$69^$a9
sta DrainBatteryRound
lda #$01
sta bgCol2+1 ;Flash logo, then restore colors via the normal fadeout code
sta bgCol3+1
sta logoFadeDir
dec logoFade
jsr WaitBottom
CC_CheatWrong: lda #$00
sta cheatIndex
CC_NoCheat:
; Update controls, text & logo fade
Update: jsr Random ;Make game different according to delay
jsr FinishFrame
jsr GetControls
jsr WaitBottom
lda textFadeDir
beq UC_TextDone
clc
adc textFade
sta textFade
bpl UC_TextNotOverLow
inc textFade
beq UC_StopTextFade
UC_TextNotOverLow:
cmp #12
bcc UC_TextNotOverHigh
UC_StopTextFade:lda #0
sta textFadeDir
UC_TextNotOverHigh:
lda textFade
lsr
lsr
tay
lda textFadeTbl,y
ldx #160
UC_UpdateTextLoop:
sta colors+TEXTSTARTROW*40-1,x
sta colors+TEXTSTARTROW*40+159,x
dex
bne UC_UpdateTextLoop
UC_TextDone: lda logoFadeDir
bne UC_HasLogoFade
rts
UC_HasLogoFade: clc
adc logoFade
sta logoFade
bpl UC_LogoNotOverLow
inc logoFade
beq UC_StopLogoFade
UC_LogoNotOverLow:
cmp #12
bcc UC_LogoNotOverHigh
UC_StopLogoFade:lda #0
sta logoFadeDir
UC_LogoNotOverHigh:
lda logoFade
lsr
lsr
tax
lda logoFadeBg2Tbl,x
sta bgCol2+1
lda logoFadeBg3Tbl,x
sta bgCol3+1
lda logoFade
asl
and #$f8
sta temp1
ldx #23
UC_UpdateLogoLoop:
M set 0
repeat 7
lda logoColors+M*24,x
adc temp1
tay
lda logoFadeCharTbl-8,y
sta colors+M*40+8+LOGOSTARTROW*40,x
M set M+1
repend
dex
bpl UC_UpdateLogoLoop
UC_LogoDone: rts
; Load savegamelist and print savegame descriptions
ScanSaves: lda #F_SAVELIST ;Load the savegamelist which contains levelnames & player state
jsr MakeFileName_Direct ;from all savegames
jsr OpenFile
lda #0
sta actIndex
ldx #1 ;Always select "continue" in main menu after load/save
stx mainMenuChoice
ldx saveSlotChoice ;If "cancel" selected last time, select first slot instead
cpx #MAX_SAVES
bne SaveSlotOK
sta saveSlotChoice
SaveSlotOK: tay
ReadSaveList: jsr GetByte
bcs ScanSaveLoop
sta saveList,y
iny
bcc ReadSaveList
ScanSaveLoop: lda #8
sta temp1
lda actIndex
jsr GetSaveListPos
sty temp8
lda saveList,y
bne GetSaveDescription
lda #<txtEmpty
ldx #>txtEmpty
jsr PrintText
SaveDone: inc temp2
inc actIndex
lda actIndex
cmp #MAX_SAVES
bcc ScanSaveLoop
lda #8
sta temp1
lda #<txtCancel
ldx #>txtCancel
ldy LoadOrSaveGameMode+1
beq ScanLoad
lda #<txtEndWithoutSaving
ldx #>txtEndWithoutSaving
ScanLoad: jmp PrintText
GetSaveDescription:
lda #<saveList
adc temp8 ;Level name
sta zpSrcLo
lda #>saveList
adc #$00
sta zpSrcHi
ldy #16 ;Time hours
lda (zpSrcLo),y
jsr ConvertToBCD8
ldx #0
jsr PrintTimeBCD1
ldy #17 ;Time minutes
lda (zpSrcLo),y
jsr ConvertToBCD8
ldx #2
jsr PrintTimeBCD2
ldy #18 ;Time seconds
lda (zpSrcLo),y
jsr ConvertToBCD8
ldx #5
jsr PrintTimeBCD2
jsr PT_Continue
lda #<txtTime
sta zpSrcLo
lda #>txtTime
sta zpSrcHi
lda #25
sta temp1
jsr PT_Continue
jmp SaveDone
; Pick choice by joystick up/down
TitleMenuControl:
tay
stx temp6
ldx menuCounter
beq TMC_NoDelay
dec menuCounter
rts
TMC_NoDelay: lda joystick
lsr
bcc TMC_NotUp
dey
bpl TMC_HasMove
ldy temp6
TMC_HasMove: jsr PlaySelectSfx
ldx #TITLE_MOVEDELAY
lda joystick
cmp prevJoy
bne TMC_NormalDelay
dex
dex
dex
TMC_NormalDelay:stx menuCounter
TMC_NoMove: tya
rts
TMC_NotUp: lsr
bcc TMC_NoMove
iny
cpy temp6
bcc TMC_HasMove
beq TMC_HasMove
ldy #$00
beq TMC_HasMove
; Title delay counting
TitlePageDelayInteractive:
lda joystick ;Reset delay if joystick moved
bne ResetTitlePageDelay
TitlePageDelay: inc titlePageDelayLo
bne TPD_NotOver
inc titlePageDelayHi
TPD_NotOver: lda titlePageDelayHi
cmp #>TITLE_PAGEDELAY
bne TPD_Done
lda titlePageDelayLo
cmp #<TITLE_PAGEDELAY
TPD_Done: rts
; Print page
PrintPage: ldy #TEXTSTARTROW
sty temp2
sta zpSrcLo
stx zpSrcHi
TitleRowLoop: jsr PrintTextCenterContinue
inc temp2
lda temp2
cmp #TEXTSTARTROW+7
bcc TitleRowLoop
; Reset title delay, set text to fade in
ResetPage: ldx #0
stx textFade
inx
stx textFadeDir
ResetTitlePageDelay:
lda #0
sta titlePageDelayLo
sta titlePageDelayHi
rts
; Fade logo & text
FadeOutAll: lda fastLoadMode ;No fade if using fallback loader
beq FOA_Done
lda #-1
sta logoFadeDir
jsr FadeOutText
FOA_Done: jsr BlankScreen
stx Irq6_SplitMode+1 ;End split mode (X=$00 on return)
sei
lda #<Irq1 ;Make sure irq1 is the next to display to prevent
sta $fffe ;garbage with Kernal mode loader
lda #>Irq1
sta $ffff
cli
FOT_Done: rts
; Fade text only
FadeOutText: lda #-1
sta textFadeDir
FOT_Wait: lda textFade
beq FOT_Done
jsr Update
jmp FOT_Wait
; Clear text rows
ClearText: lda #$20
ldx #160
ClearTextLoop: sta screen1+TEXTSTARTROW*40-1,x
sta screen1+TEXTSTARTROW*40+159,x
dex
bne ClearTextLoop
rts
; Print on/off texts for the options
PrintOnOff: cmp #$01
lda #<txtOff
ldx #>txtOff
bcc PrintOnOffCommon
lda #<txtOn
ldx #>txtOn
PrintOnOffCommon:
sty temp2
jmp PrintText
; Print centered text
PrintTextCenter:sta zpSrcLo
stx zpSrcHi
PrintTextCenterContinue:
lda #20
sta temp1
ldy #$00
PTC_Loop: lda (zpSrcLo),y
bmi PTC_SetAbsolute
beq PTC_Continue
iny
lda (zpSrcLo),y
beq PTC_Continue
iny
dec temp1
bpl PTC_Loop
PTC_SetAbsolute:and #$7f
sta temp1
jsr PT_Done ;Skip the negative byte, then print normally
PTC_Continue: jmp PT_Continue
; Print choice arrow
DrawChoiceArrow:sta zpSrcLo
stx zpSrcHi
jsr GetRowAddress
ldx #0
ldy temp1
DCA_Loop: lda #$20
cpx zpSrcLo
bne DCA_NoArrow
lda #62
DCA_NoArrow: sta (zpDestLo),y
lda zpDestLo
clc