-
Notifications
You must be signed in to change notification settings - Fork 0
/
ed02.asm
1550 lines (1275 loc) · 26.9 KB
/
ed02.asm
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
.inesprg 16 ; UOROM
.ineschr 0 ; 1x 8KB CHR data (bank 4)
.inesmap 2 ; mapper 0 = NROM, no bank swapping; 2 = UNROM
.inesmir 1 ; background mirroring
;; DECLARE SOME VARIABLES HERE
.rsset $0050 ; start variables at ram location 50
.include "inc/variables.asm"
;;;;;;;;;;;;;;;;;
.include "inc/const.asm"
;;;;;;;;;;;;;;; banks
.code
.bank 0 ; 0
.org $8000
chrdata:
.incbin "ed.chr"
.bank 2 ; 1
.org $8000
.include "bg-stage.asm"
.bank 4 ; 2
.org LOAD_ADDRESS_BANK_1
incbin "NSFs/1_2.nsf"
.bank 6 ; 3
.org LOAD_ADDRESS_BANK_2
incbin "NSFs/3.nsf"
.bank 8 ; 4
.org LOAD_ADDRESS_BANK_3
incbin "NSFs/4.nsf"
.bank 10 ; 5
.org LOAD_ADDRESS_BANK_4
incbin "NSFs/5.nsf"
.bank 12 ; 6
.org LOAD_ADDRESS_BANK_5
incbin "NSFs/6_7.nsf"
.bank 14 ; 7
.org LOAD_ADDRESS_BANK_6
incbin "NSFs/8.nsf"
.bank 16 ; 8
.org LOAD_ADDRESS_BANK_7
incbin "NSFs/9.nsf"
.bank 18 ; 9
.org LOAD_ADDRESS_BANK_8
incbin "NSFs/10.nsf"
.bank 20 ; A
.org LOAD_ADDRESS_BANK_9
incbin "NSFs/11.nsf"
.bank 22 ; B
.org LOAD_ADDRESS_BANK_10
incbin "NSFs/12.nsf"
.bank 24 ; C
.org LOAD_ADDRESS_BANK_11
incbin "NSFs/13.nsf"
.bank 27 ; D
.org LOAD_ADDRESS_BANK_12
incbin "NSFs/aids.nsf"
.bank 29 ; E
.org LOAD_ADDRESS_BANK_13
incbin "NSFs/thend.nsf"
.bank 30
.org $C000
.include "inc/samples.asm" ; 55 55 55 95 AA 2A 95 E0
;;;;; reset console params and clear RAM
RESET:
SEI ; disable IRQs
CLD ; disable decimal mode
LDX #$40
STX $4017 ; disable APU frame IRQ
LDX #$FF
TXS ; Set up stack
INX ; now X = 0
STX $2000 ; disable NMI
STX $2001 ; disable rendering
STX $4010 ; disable DMC IRQs
vblankwait1: ; First wait for vblank to make sure PPU is ready
BIT $2002
BPL vblankwait1
clrmem:
LDA #$00
STA $0000, x
STA $0100, x
STA $0300, x
STA $0200, x
STA $0500, x
STA $0600, x
STA $0700, x
LDA #$FE
STA $0400, x
INX
BNE clrmem
vblankwait2: ; Second wait for vblank, PPU is ready after this
BIT $2002
BPL vblankwait2
;;;;;;; PAL/NTSC recognition
;;;;;;; wait for the next NTSC vertical blank (PAL and Dendy would take longer)
LDX #$70
cd1:
LDY #$35
cd2:
DEY
BNE cd2
DEX
BNE cd1
;detect whether the frame rate is 60Hz or 50Hz
LDA $2002
STA frameRateIs60
;;;;;; initialize memory
JSR LoadCHRAM
LDA #$00
STA playingSongNumber
STA samplePointer
STA gameFlags
STA soundFlags
STA xpos
STA hitBeatTimeout
STA playerScore+0
STA playerScore+1 ; reset score
STA highScore+0
STA highScore+1 ; reset score
STA scoreLo
STA scoreHi
JSR LoadSongPalette
JSR LoadSprites
LDA #TRACK_1
STA currentSong
STA ARROW_RAM
LDA #$05
STA frameTimeout
STA animationClock
LDA #%10010000 ; enable NMI, sprites from Pattern 0, background from Pattern 1
STA $2000
JSR LoadMenuBackground
JSR HighScorePositionOnMenu
LDA #PPU_SETUP ; enable sprites, enable background
STA $2001
;;;;;;;;;;;;;;;;;;;;;;;;;;
Forever:
JMP Forever ; jump back to Forever, infinite loop
;;;;;;;;;;;;;;;;;;;;;;;;;;
NMI:
LDA #$00
STA $2003 ; set the low byte (00) of the RAM address
LDA #$04
STA $4014 ; set the high byte (02) of the RAM address, start the transfer
JSR StartClock
JSR ReadController1 ; get the current button data for player 1
GameEngine:
LDA #HERO_HIT
BIT gameFlags
BNE GameEngine_GameOver
LDA #GAME_COMPLETE
BIT gameFlags
BNE GameEngine_Complete
LDA #MUSIC_ONLY
BIT soundFlags
BNE GameEngine_Title
LDA playingSongNumber
CMP #$00
BNE GameEngine_Playing ; need to use JMP here because relative addressing used by BEQ goes out of range
GameEngine_Title:
JMP EngineTitle ; game is displaying title screen
GameEngine_Playing:
JMP EnginePlaying
GameEngine_GameOver:
JMP EngineGameOver
GameEngine_Complete:
JMP EngineGameComplete
GameEngineDone:
RTI
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; audio controls
.include "inc/service_audio.asm"
;;;;; engine title
EngineTitle:
JSR DisplayHighScore
;;;;; react to menu input
LDA buttons1
AND #BTN_START
BNE EngineTitle_TitleStartPressed
LDA buttons1
AND #BTN_UP
BNE EngineTitle_ArrowMoveUp
LDA buttons1
AND #BTN_DOWN
BNE EngineTitle_ArrowMoveDown
LDA buttons1
AND #BTN_A
BNE EngineTitle_PlayMusic
LDA buttons1
AND #BTN_B
BNE EngineTitle_StopMusic
LDA buttons1
AND #%00000000
BNE EngineTitle_DoNothing
LDA #$00
STA buttonlatch
;;;;;;;;;;;;;;;;;;;;;;;; music
LDA playingSongNumber
BEQ EngineTitle_DoNothing
LDA #MUSIC_INITIALIZED
BIT soundFlags
BEQ EngineTitle_GoToInitTrack
JSR PLAY_ADDRESS
EngineTitle_DoNothing:
JMP GameEngineDone
EngineTitle_TitleStartPressed:
JMP TitleStartPressed
EngineTitle_ArrowMoveUp:
JMP ArrowMoveUp
EngineTitle_ArrowMoveDown:
JMP ArrowMoveDown
EngineTitle_PlayMusic:
JMP PlayOnlyMusic
EngineTitle_StopMusic:
JSR AS_StopMusic
JMP GameEngineDone
EngineTitle_GoToInitTrack:
JMP InitTrack
;;;;;;; game over state
EngineGameOver:
LDA playingSongNumber
CMP #$0E
BNE EngineGameOver_NoScroll
JSR AdvanceXPos
LDA #$00
STA $2005 ; first write: no horizontal scrolling
LDA counter
STA $2005 ; second write: advance vertical scroll to ppu_scroll
LDA #PPU_SETUP ; enable sprites, enable background
STA $2001
EngineGameOver_NoScroll:
LDA buttons1
AND #BTN_SELECT
BNE EngineGameOver_Reset
LDA buttons1
AND #BTN_START
BNE EngineGameOver_Reset
LDA playingSongNumber
BEQ EngineGameOver_SkipMusic
LDA #MUSIC_INITIALIZED
BIT soundFlags
BEQ EngineGameOver_GoToInitTrack
JSR PLAY_ADDRESS
EngineGameOver_SkipMusic:
JMP GameEngineDone
EngineGameOver_Reset:
LDA currentSong
CMP #TRACK_10
BEQ EngineGameOver_Closed
JSR ResetHeroHitFlag
JSR ResetHitDetect
JMP PlayingSelectPressed
EngineGameOver_Closed:
JMP GamesClosed
EngineGameOver_GoToInitTrack:
JMP InitTrack
;;;;;;; game complete state
EngineGameComplete:
JSR DisplayHighScore
LDA #MUSIC_INITIALIZED
BIT soundFlags
BEQ EngineGameComplete_GoToInitTrack
JSR PLAY_ADDRESS
JMP GameEngineDone
EngineGameComplete_GoToInitTrack:
JMP InitTrack
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; game playing state
EnginePlaying:
JSR AdvanceXPos ; pills and objects random position
JSR AdvanceAnimationFrame ; for all animations
;;;;;;;; coins and tomatoes animation and hit detection
LDA playingSongNumber
CMP #$09 ; song is Red Pilled, different sprite detection there
BEQ EnginePlaying_HeroCheckObjHitDone
JSR AnimateObjs
JMP HeroCheckObjHit
EnginePlaying_HeroCheckObjHitDone:
;;;;;;; UFO
LDA playingSongNumber
CMP #$07 ; song is not Systematic Chaos - no UFO
BNE EnginePlaying_SkipUFO
JSR AnimateUFO
EnginePlaying_SkipUFO:
;;;;;;; pills and hit detection
LDA playingSongNumber
CMP #$09 ; song is not Red Pilled - no pills
BNE EnginePlaying_HeroCheckRedPillHitDone
JSR AnimatePills
JSR AnimatePills2
JMP HeroCheckBluePillHit
EnginePlaying_HeroCheckBluePillHitDone:
JMP HeroCheckRedPillHit
EnginePlaying_HeroCheckRedPillHitDone:
;;;;;;;; check bonus
JSR CheckPlayerBonusFlag
;;;;;;;; check death
LDA playingSongNumber
CMP #$04 ; no death in High Stakes
BEQ EnginePlaying_SkipHeroHitCheck
LDA #HERO_HIT
BIT gameFlags
BNE EnginePlaying_PlayerHit
EnginePlaying_SkipHeroHitCheck:
JSR ResetHeroHead
;;;;;;;; input reactions
JMP EnginePlaying_ReactToActions
EnginePlaying_ActionsReactDone:
JMP EnginePlaying_ReactToDpad
EnginePlaying_DpadReactDone:
LDA #HIT_ON_BEAT
BIT gameFlags
BNE EnginePlaying_ResetBeatFlag
EnginePlaying_ResetBeatFlagDone:
JSR PlaySampleA
JSR PlaySampleB
;;;;;;;;; routine animations
JSR AnimateGuitars
JSR AnimateCymbals
;;;;;;;;; song and audio
EnginePlaying_SongAndAudio:
LDA playingSongNumber
BEQ EnginePlaying_SkipMusic
LDA #MUSIC_INITIALIZED
BIT soundFlags
BEQ EnginePlaying_GoToInitTrack
JSR PLAY_ADDRESS
LDA IS_PLAYING_RAM
BEQ EnginePlaying_SongFinished
EnginePlaying_SkipMusic:
JMP GameEngineDone
EnginePlaying_GoToInitTrack:
JMP InitTrack
EnginePlaying_SongFinished:
JSR MarkSongAsFinished
JMP CheckIfGameComplete
EnginePlaying_CheckIfGameCompleteDone:
JMP PlayingSelectPressed
EnginePlaying_ResetBeatFlag:
LDA hitBeatTimeout
CMP #$1B
BCS SkipResetBeatFlag
LDA #HIT_ON_BEAT
EOR #%11111111
AND gameFlags
STA gameFlags
SkipResetBeatFlag:
JMP EnginePlaying_ResetBeatFlagDone
EnginePlaying_PlayerHit:
JMP PlayerHit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CheckPlayerBonusFlag:
LDA #BONUS_HIT
BIT gameFlags
BEQ PlayerNoBonus
JSR ResetBonusFlag
JSR ResetHitDetect
JSR IncrementScoreDisplay
JSR IncrementScoreDisplay
PlayerNoBonus:
RTS
HideAllSprites:
LDX #$00
HideSpritesLoop:
LDA #$F0
STA $0400, x
INX
INX
INX
INX
CPX #$E8
BNE HideSpritesLoop
DontHideSprites:
RTS
ShowSongSprites:
ShowElmo:
LDX #LOW(ELMO_RAM)
LDA #SPRITE_ELM_X
JSR ShowMetaSpriteX
LDA #SPRITE_ELM_Y
JSR ShowMetaSpriteY
LDX #LOW(ELMO_RAM)
LDA #$04
JSR ChangeElmoTiles
ShowAldo:
LDX #LOW(ALDO_RAM)
LDA #SPRITE_ALDO_X
JSR ShowMetaSpriteX
LDA #SPRITE_ALDO_Y
JSR ShowMetaSpriteY
ShowGuin:
JSR ShowGuiness
ShowBass:
LDX #LOW(BASS_RAM)
LDA #$3E
JSR ShowGuitX
LDX #LOW(BASS_RAM)
LDA #$2A
JSR ChangeGuitTiles
LDA #%00000011
STA ($0400+2), x
STA ($0400+2+4), x
STA ($0400+2+4*2), x
STA ($0400+2+4*3), x
STA ($0400+2+4*4), x
STA ($0400+2+4*5), x
ShowGuitars:
LDX #LOW(GUITAR_RAM)
LDA #$B3
JSR ShowGuitX
LDX #LOW(GUITAR_RAM)
LDA #$0A
JSR ChangeGuitTiles
ShowCymbals:
LDX #LOW(CYMBALS_RAM)
LDA #SPRITE_CYM_X
STA ($0400+3), x
CLC
ADC #$08
STA ($0400+3+4), x
ADC #$08
STA ($0400+3+4*2), x
ADC #$08
STA ($0400+3+4*3), x
LDA #SPRITE_CYM_Y
STA $0400, x
STA ($0400+4), x
STA ($0400+4*2), x
STA ($0400+4*3), x
ShowLives:
LDA #$0D
STA LIVES_RAM
STA (LIVES_RAM+4)
ShowScore:
STA SCORE_RAM
STA (SCORE_RAM+4)
STA (SCORE_RAM+4*2)
LDA #$E0
STA (SCORE_RAM+3)
LDA #$E8
STA (SCORE_RAM+3+4)
LDA #$F0
STA (SCORE_RAM+3+4*2)
ShowInventory:
LDA #$0D
STA INVENTORY_RAM
LDA #$C0
STA (INVENTORY_RAM+3)
ShowSparx:
LDX #LOW(HERO_RAM)
LDA #SPRITE_SPR_X
JSR ShowSpratzX
LDA #SPRITE_SPR_Y
JSR ShowSpratzY
LDX currentHero
LDA heroDefaultSprites, x
LDX #LOW(HERO_RAM)
JSR ChangeHeroTiles
DontShowSprites:
RTS
ShowGuiness:
LDX #LOW(GUINESS_RAM)
LDA #SPRITE_GUIN_X
JSR ShowMetaSpriteX
LDA #SPRITE_GUIN_Y
JSR ShowMetaSpriteY
RTS
ShowMetaSpriteX:
STA ($0400+3), x
STA ($0400+3+4*2), x
STA ($0400+3+4*4), x
CLC
ADC #$08
STA ($0400+3+4), x
STA ($0400+3+4*3), x
STA ($0400+3+4*5), x
RTS
ShowMetaSpriteY:
STA $0400, x
STA ($0400+4), x
CLC
ADC #$08
STA ($0400+4*2), x
STA ($0400+4*3), x
ADC #$08
STA ($0400+4*4), x
STA ($0400+4*5), x
RTS
ShowSpratzX:
JSR ShowMetaSpriteX
SEC
SBC #$08
STA ($0400+3+4*6), x
CLC
ADC #$08
STA ($0400+3+4*7), x
RTS
ShowSpratzY:
JSR ShowMetaSpriteY
CLC
ADC #$08
STA ($0400+4*6), x
STA ($0400+4*7), x
RTS
ChangeHeroTiles:
STA ($0400+1), x
CLC
ADC #$01
STA ($0400+1+4), x
ADC #$0F
STA ($0400+1+4*2), x
ADC #$01
STA ($0400+1+4*3), x
LDA #$20
STA ($0400+1+4*4), x
ADC #$01
STA ($0400+1+4*5), x
ChangeHeroTilesEnd:
RTS
ChangeElmoTiles:
STA ($0400+1), x
CLC
ADC #$01
STA ($0400+1+4), x
ADC #$0F
STA ($0400+1+4*2), x
ADC #$01
STA ($0400+1+4*3), x
ADC #$0F
STA ($0400+1+4*4), x
ADC #$01
STA ($0400+1+4*5), x
ChangeElmoTilesEnd:
RTS
ChangeGuitTiles:
STA ($0400+1), x
CLC
ADC #$01
STA ($0400+1+4), x
ADC #$01
STA ($0400+1+4*2), x
ADC #$0E
STA ($0400+1+4*3), x
ADC #$01
STA ($0400+1+4*4), x
ADC #$01
STA ($0400+1+4*5), x
RTS
ShowGuitX:
STA ($0400+3), x
STA ($0400+3+4*3), x
CLC
ADC #$08
STA ($0400+3+4), x
STA ($0400+3+4*4), x
ADC #$08
STA ($0400+3+4*2), x
STA ($0400+3+4*5), x
RTS
ReadController1:
LDA #$01
STA $4016
LDA #$00
STA $4016
LDX #$08
ReadController1Loop:
LDA $4016
LSR A ; bit0 -> Carry
ROL buttons1 ; bit0 <- Carry
DEX
BNE ReadController1Loop
RTS
EnginePlaying_ReactToDpad:
LDA buttons1
AND #BTN_LEFT
BNE EnginePlaying_SpratzMoveLeft
LDA buttons1
AND #BTN_RIGHT
BNE EnginePlaying_SpratzMoveRight
LDA buttons1
AND #BTN_UP
BNE EnginePlaying_ChangeSamples
; below will be executed if NOT LEFT/RIGHT/UP
LDA #SAMPLE_CHANGED ; 00000001
EOR #%11111111 ; 11111110
AND soundFlags
STA soundFlags
JMP EnginePlaying_DpadReactDone
;;;;;;;;;;;;;;;;;;;;;;;
EnginePlaying_ReactToActions:
LDA buttons1
AND #BTN_SELECT
BNE EnginePlaying_PlayingSelectPressed
LDA buttons1
AND #BTN_A
BNE EnginePlaying_MoveGuiness
LDA buttons1
AND #BTN_B
BNE EnginePlaying_MoveGuiness
; below will be executed if NOT SELECT/A/B
; reset Guiness
JSR ShowGuiness
LDA buttons1
AND #BTN_DOWN
BNE EnginePlaying_SpritesBop
; below will be executed if NOT SELECT/A/B/DOWN
; reset samples
JSR ResetSamples
JMP EnginePlaying_ActionsReactDone
ResetSamples:
LDA #SAMPLE_PLAYED ; 00000001
EOR #%11111111 ; 11111110
AND soundFlags
STA soundFlags
LDA bufferTimeout
BNE ResetSamplesEnd
JSR ResetBufferA
JSR ResetBufferB
ResetSamplesEnd:
RTS
EnginePlaying_SpratzMoveLeft:
LDA playingSongNumber
CMP #$0B
BEQ FlipLeftToRight
JMP SpratzMoveLeft
FlipLeftToRight:
JMP SpratzMoveRight
EnginePlaying_SpratzMoveRight:
LDA playingSongNumber
CMP #$0B
BEQ FlipRightToLeft
JMP SpratzMoveRight
FlipRightToLeft:
JMP SpratzMoveLeft
EnginePlaying_ChangeSamples:
JMP ChangeSamples
EnginePlaying_SpritesBop:
JMP SpritesBop
EnginePlaying_PlayingSelectPressed:
JMP PlayingSelectPressed
EnginePlaying_MoveGuiness:
LDX #LOW(GUINESS_RAM)
LDA #SPRITE_GUIN_X-2
JSR ShowMetaSpriteX
LDA buttons1
AND #BTN_A
BNE e_PlaySampleA
LDA buttons1
AND #BTN_B
BNE e_PlaySampleB
JMP EnginePlaying_ActionsReactDone
e_PlaySampleA:
JSR BufferA
JMP EnginePlaying_ActionsReactDone
e_PlaySampleB:
JSR BufferB
JMP EnginePlaying_ActionsReactDone
ResetHeroHitFlag:
LDA #HERO_HIT
EOR #%11111111
AND gameFlags
STA gameFlags
RTS
ResetBonusFlag:
LDA #BONUS_HIT
EOR #%11111111
AND gameFlags
STA gameFlags
RTS
ResetHitDetect:
LDA #HIT_DETECT
EOR #%11111111
AND gameFlags
STA gameFlags
RTS
ResetHeroHead:
LDA #SAMPLE_PLAYED
BIT soundFlags
BNE ResetHeroHeadDone
LDA faceTimeout
BNE ResetHeroHeadDone
LDX currentHero
LDA heroDefaultSprites, x
LDX #LOW(HERO_RAM)
JSR ChangeHeroTiles
LDA #$54
STA (GUINESS_RAM+1+4*2)
CLC
ADC #$01
STA (GUINESS_RAM+1+4*3)
ResetHeroHeadDone:
RTS
;;;;;;;;;;
CheckIfGameComplete:
LDA #%11111111
CMP completionFlags
BNE NoCompletion
LDA #%00011111
CMP (completionFlags+1)
BNE NoCompletion
JSR UpdateHighScoreValues
LDA gameFlags
ORA #GAME_COMPLETE
STA gameFlags
JSR ResetPPU
JSR HideAllSprites
JSR AS_StopMusic
CheckHighScore:
LDA (highScore+0)
CMP #$01
BCC YouLose
BEQ ContinueCheckHighScore
BCS YouWin
ContinueCheckHighScore:
LDA (highScore+1)
CMP #$2C
BCC YouLose
JMP YouWin ; high score over 500
YouLose:
LDA #$0E ; loser music
STA playingSongNumber
JSR LoadSongPalette
JSR LoadYouLoseBackground
LDA #PPU_SETUP ; enable sprites, enable background
STA $2001
JSR HighScorePositionOnMenu
JSR AS_StartPlayingCurrentTrack
JMP GameEngineDone
YouWin:
LDA #$0F ; winner music
STA playingSongNumber
JSR LoadSongPalette
JSR LoadYouWinBackground
LDA #PPU_SETUP ; enable sprites, enable background
STA $2001
JSR HighScorePositionOnMenu
JSR AS_StartPlayingCurrentTrack
JMP GameEngineDone
NoCompletion:
JMP EnginePlaying_CheckIfGameCompleteDone
MarkSongAsFinished:
LDX playingSongNumber
LDA completionMap, x
CPX #$09
BCC storeProgressIn1
ORA (completionFlags+1)
STA (completionFlags+1)
JMP MarkSongAsFinishedEnd
storeProgressIn1:
ORA completionFlags
STA completionFlags
MarkSongAsFinishedEnd:
RTS
DisplayLives:
LDA playerLives
CMP #99
BEQ Show99Lives
CMP #0
BEQ Show0Lives
LDA #$C0
STA (LIVES_RAM+1)
LDA #$C1
STA (LIVES_RAM+1+4)
JMP DisplayLivesDone
Show99Lives:
LDA #$C9
STA (LIVES_RAM+1)
STA (LIVES_RAM+1+4)
JMP DisplayLivesDone
Show0Lives:
LDA #$C0
STA (LIVES_RAM+1)
STA (LIVES_RAM+1+4)
DisplayLivesDone:
RTS
PlayingSelectPressed:
JSR ResetPPU
JSR HideAllSprites
JSR ShowIndicatorSprites
LDA #$00
STA pointerLo
STA pointerHi
STA tmp
STA nextFrame
STA nextFrame3
STA frameTimeout
STA faceTimeout
STA hitBeatTimeout
STA bufferTimeout
STA animationClock
JSR UpdateHighScoreValues
JSR HighScorePositionOnMenu
LDA #$C0
STA (SCORE_RAM+1)
STA (SCORE_RAM+1+4)
STA (SCORE_RAM+1+4*2)
LDA currentSong
STA ARROW_RAM
JSR AS_StopMusic
JSR LoadSongPalette ; LoadPalette9
JSR LoadMenuBackground
LDA #PPU_SETUP ; enable sprites, enable background
STA $2001
JMP GameEngineDone
GamesClosed:
JSR ResetPPU
JSR HideAllSprites