forked from DevEd2/CryEd
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMain.asm
2534 lines (2417 loc) · 59.4 KB
/
Main.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
; ======================================
; CryEd - cry editor for Pokémon Crystal
; ======================================
INCLUDE "macros.asm"
INCLUDE "constants.asm"
INCLUDE "wram.asm"
; =============
; Reset vectors
; =============
section "Reset $00",rom0[$00]
CallHL: jp hl
section "Reset $08",rom0[$08]
FillRAM:: jp _FillRAM
section "Reset $10",rom0[$10]
WaitVBlank:: jp _WaitVBlank
section "Reset $18",rom0[$18]
WaitTimer:: jp _WaitTimer
section "Reset $20",rom0[$20]
WaitLCDC:: jp _WaitLCDC
section "Reset $30",rom0[$30]
Panic:: jp _Panic
section "Reset $38",rom0[$38]
GenericTrap::
xor a
jp _Panic
; ==================
; Interrupt handlers
; ==================
section "VBlank IRQ",rom0[$40]
IRQ_VBlank:: jp DoVBlank
section "STAT IRQ",rom0[$48]
IRQ_Stat:: jp DoStat
section "Timer IRQ",rom0[$50]
IRQ_Timer:: jp DoTimer
section "Serial IRQ",rom0[$58]
IRQ_Serial:: reti ; not used
;section "Joypad IRQ",rom0[$60]
IRQ_Joypad:: reti ; not used
; ===============
; System routines
; ===============
include "SystemRoutines.asm"
; ==========
; ROM header
; ==========
section "ROM header",rom0[$100]
EntryPoint::
nop
jp ProgramStart
NintendoLogo: ; DO NOT MODIFY OR ROM WILL NOT BOOT!!!
db $ce,$ed,$66,$66,$cc,$0d,$00,$0b,$03,$73,$00,$83,$00,$0c,$00,$0d
db $00,$08,$11,$1f,$88,$89,$00,$0e,$dc,$cc,$6e,$e6,$dd,$dd,$d9,$99
db $bb,$bb,$67,$63,$6e,$0e,$ec,$cc,$dd,$dc,$99,$9f,$bb,$b9,$33,$3e
ROMTitle: romTitle "CRYED" ; ROM title (15 bytes)
GBCSupport: db $00 ; GBC support (0 = DMG only, $80 = DMG/GBC, $C0 = GBC only)
NewLicenseCode: db "DS" ; new license code (2 bytes)
SGBSupport: db 0 ; SGB support
CartType: db $1b ; Cart type, see hardware.inc for a list of values
ROMSize: ds 1 ; ROM size (handled by post-linking tool)
RAMSize: db 2 ; RAM size
DestCode: db 1 ; Destination code (0 = Japan, 1 = All others)
OldLicenseCode: db $33 ; Old license code (if $33, check new license code)
ROMVersion: db 0 ; ROM version
HeaderChecksum: ds 1 ; Header checksum (handled by post-linking tool)
ROMChecksum: ds 2 ; ROM checksum (2 bytes) (handled by post-linking tool)
; =====================
; Start of program code
; =====================
ProgramStart::
di
ld sp,$e000
push bc
push af
; disable LCD
.wait
ldh a,[rLY]
cp $90
jr nz,.wait
xor a
ldh [rLCDC],a
; init memory
ld hl,$c000 ; start of WRAM
ld bc,$1ffa ; don't clear stack
xor a
rst $08
ld hl,$8000 ; start of VRAM
ld bc,$2000
xor a
rst $08
; clear HRAM
ld bc,$7f80
xor a
.loop
ld [c],a
inc c
dec b
jr nz,.loop
call CopyDMARoutine
call $ff80 ; clear OAM
call LoadSaveScreen_SRAMCheck
jr nc,.noinitsram
ld a,$a
ld [rRAMG],a
xor a
ld hl,$a000
ld bc,$2000
rst $08
ld hl,.savestr
ld de,$a600
ld b,5
.strloop
ld a,[hl+]
ld [de],a
inc de
dec b
jr nz,.strloop
xor a
ld [$0000],a
jr .noinitsram
.savestr
db "SAVE!"
.noinitsram
; check GB type
; sets sys_GBType to 0 if DMG/SGB/GBP/GBL/SGB2, 1 if GBC, 2 if GBA/GBA SP/GB Player
; TODO: Improve checks to allow for GBP/SGB/SGB2 to be detected separately
pop af
pop bc
cp $11
jr nz,.dmg
.gbc
and 1 ; a = 1
add b ; b = 1 if on GBA
ld [sys_GBType],a
jr .continue
.dmg
xor a
ld [sys_GBType],a
.continue
InitCryEditor::
rst $10
xor a
ldh [rLCDC],a
ld a,9
ld [sys_MenuMax],a
xor a
ld [sys_MenuPos],a
call InitSound
; load font + graphics
CopyTileset1BPP Font,0,98
ld hl,CryEditorTilemap
call LoadMapText
; init rendering variables
SetDMGPal rBGP, 0,1,2,3
SetDMGPal rOBP0,0,0,2,3
SetDMGPal rOBP1,0,1,2,3
xor a
ldh [rSCX],a
ldh [rSCY],a
ldh [rWX],a
ldh [rWY],a
ld a,%10010001
ldh [rLCDC],a
ld a,IEF_VBLANK
ldh [rIE],a
ei
halt
CryEditorLoop::
ld a,[sys_btnPress]
bit A_BUTTON_F,a
jr nz,.playCry
bit START_F,a
jr nz,.playCry
bit B_BUTTON_F,a
jr nz,.resetCry
bit SELECT_F,a
jp nz,InitOptionsMenu
ld hl,sys_MenuPos
bit D_UP_F,a
jr nz,.editUp
bit D_DOWN_F,a
jr nz,.editDown
bit D_RIGHT_F,a
jr nz,.cursorNext
bit D_LEFT_F,a
jr nz,.cursorPrev
jr .continue
.resetCry
xor a
ld hl,CryEdit_CryBase
ld [hl+],a
ld [hl+],a
ld [hl+],a
ld [hl+],a
ld [hl+],a
jr .continue
.playCry
ld hl,CryEdit_CryBase
ld d,0
ld e,[hl]
inc hl
ld a,[hl+]
ld [wCryPitch],a
ld a,[hl+]
ld [wCryPitch+1],a
ld a,[hl+]
ld [wCryLength],a
ld a,[hl+]
ld [wCryLength+1],a
call CryEd_PreviewCry
jr .continue
.editUp
ld e,1
call CryEdit_EditNybble
jr .continue
.editDown
ld e,0
call CryEdit_EditNybble
jr .continue
.setItem
ld [hl],b
jr .continue
.cursorNext
ld b," "-32
call CryEditor_DrawCursor
inc [hl]
ld b,[hl]
ld a,[sys_MenuMax]
inc a
cp b
jr nz,.setItem
ld [hl],0
jr .continue
.cursorPrev
ld b," "-32
call CryEditor_DrawCursor
dec [hl]
ld a,[hl]
cp $ff
ld b,a
jr nz,.setItem
ld a,[sys_MenuMax]
ld [hl],a
; fall through to .continue
.continue
ld b,"^"-32
call CryEditor_DrawCursor
ld a,[CryEdit_CryBase]
ld hl,$9831
call DrawHex
ld a,[CryEdit_CryPitch+1]
ld hl,$986f
call DrawHex
ld a,[CryEdit_CryPitch]
call DrawHex
ld a,[CryEdit_CryLength+1]
ld hl,$98af
call DrawHex
ld a,[CryEdit_CryLength]
call DrawHex
halt
call UpdateSound
jp CryEditorLoop
; INPUT: b = char to use for cursor
; Destroys A.
CryEditor_DrawCursor::
push hl
ld a,[sys_MenuPos]
ld hl,CryEdit_CursorLocations
add a
add l
ld l,a
jr nc,.nocarry
inc h
.nocarry
ld a,[hl+]
ld h,[hl]
ld l,a
; write char
WaitForVRAM
ld [hl],b
pop hl
ret
CryEdit_EditNybble:
ld a,[sys_MenuPos]
ld b,a
add a
add b
ld hl,CryEdit_NybbleLocations
add l
ld l,a
jr nc,.nocarry
inc h
.nocarry
ld a,[hl+]
ld d,a
ld a,[hl+]
ld h,[hl]
ld l,a
ld a,d
and a
jr nz,.uppernybble
.lowernybble
ld a,e
and a
jr z,.sub1
jr .add1
.uppernybble
ld a,e
and a
jr z,.sub10
jr .add10
.add1
inc [hl]
ld a,[hl]
and $f
cp 0
ret nz
ld a,[hl]
sub $10
ld [hl],a
ret
.sub1
dec [hl]
ld a,[hl]
and $f
cp $f
ret nz
ld a,[hl]
add $10
ld [hl],a
ret
.add10
ld a,[hl]
add $10
ld [hl],a
ret
.sub10
ld a,[hl]
sub $10
ld [hl],a
ret
CryEdit_CursorLocations:
dw $9851,$9852 ; base
dw $988f,$9890,$9891,$9892 ; pitch
dw $98cf,$98d0,$98d1,$98d2 ; length
CryEdit_NybbleLocations:
dbw 1,CryEdit_CryBase
dbw 0,CryEdit_CryBase
dbw 1,CryEdit_CryPitch+1
dbw 0,CryEdit_CryPitch+1
dbw 1,CryEdit_CryPitch
dbw 0,CryEdit_CryPitch
dbw 1,CryEdit_CryLength+1
dbw 0,CryEdit_CryLength+1
dbw 1,CryEdit_CryLength
dbw 0,CryEdit_CryLength
Menu_DrawCursor::
push af
ld h,0
ld a,[sys_MenuPos]
ld l,a
add hl,hl ; x2
add hl,hl ; x4
add hl,hl ; x8
add hl,hl ; x16
add hl,hl ; x32
ld b,h
ld c,l
ld hl,$9861
add hl,bc
WaitForVRAM
pop af
ld [hl],a
ret
CryEditorTilemap::
; ####################
db " "
db " Base: $?? "
db " "
db " Pitch: $???? "
db " "
db " Length: $???? "
db " "
db " - CONTROLS - "
db "Left/Right Cursor"
db "Up/Down Edit value"
db "A/Start Test"
db "B Reset"
db "Select Menu"
db " "
db "Build date: "
.datestart
db __DATE__
.dateend
rept 20-(.dateend-.datestart)
db 20
endr
.timestart
db __TIME__
.timeend
rept 20-(.timeend-.timestart)
db 20
endr
db " "
; ####################
; ================================
InitOptionsMenu::
rst $10
xor a
ldh [rLCDC],a
ld a,2
ld [sys_MenuMax],a
xor a
ld [sys_MenuPos],a
call InitSound
; load font + graphics
CopyTileset1BPP Font,0,98
ld hl,OptionsMenuTilemap
call LoadMapText
xor a
call Options_PrintDescription
; init rendering variables
SetDMGPal rBGP, 0,1,2,3
SetDMGPal rOBP0,0,0,2,3
SetDMGPal rOBP1,0,1,2,3
xor a
ldh [rSCX],a
ldh [rSCY],a
ldh [rWX],a
ldh [rWY],a
ld a,%10010001
ldh [rLCDC],a
ld a,IEF_VBLANK
ldh [rIE],a
ei
ld de,6 ; SFX_MENU
call PlaySFX
halt
OptionsMenuLoop::
ld a,[sys_btnPress]
bit A_BUTTON_F,a
jr nz,.selectItem
bit B_BUTTON_F,a
jp nz,InitCryEditor
bit START_F,a
jr nz,.selectItem
bit SELECT_F,a
jr nz,.nextItem
bit D_UP_F,a
jr nz,.prevItem
bit D_DOWN_F,a
jr z,.continue
.nextItem
ld a," "-$20
call Menu_DrawCursor
ld a,[sys_MenuPos]
inc a
ld b,a
ld a,[sys_MenuMax]
inc a
cp b
ld a,b
jr nz,.setItem
xor a
.setItem
ld [sys_MenuPos],a
call Options_PrintDescription
jr .continue
.prevItem
ld a," "-$20
call Menu_DrawCursor
ld a,[sys_MenuPos]
dec a
cp $ff
jr nz,.setItem
ld a,[sys_MenuMax]
jr .setItem
.selectItem
ld hl,MenuItemPtrs_OptionsMenu
ld a,[sys_MenuPos]
add a
add l
ld l,a
jr nc,.nocarry
inc h
.nocarry
ld de,7 ; SFX_READ_TEXT
call PlaySFX
push af
; wait for SFX to finish playing
.waitSFX
call UpdateSound
halt
call IsSFXPlaying
jr nc,.waitSFX
call PtrToHL
rst $00
.continue
ld a,">"-$20
call Menu_DrawCursor
call UpdateSound
halt
jr OptionsMenuLoop
MenuItemPtrs_OptionsMenu::
dw .importCry
dw .loadSaveCry
dw .exit
.importCry
pop hl ; stack overflow prevention
jp InitCryImporter
.loadSaveCry
pop hl ; stack overflow prevention
xor a
jp InitLoadSaveScreen
.exit
pop hl ; stack overflow prevention
jp InitCryEditor
OptionsMenuTilemap::
; ####################
db " "
db " - OPTIONS - "
db " "
db " Import cry "
db " Load/save cry "
db " Exit "
db " "
db " "
db " "
db " "
db " "
db " "
db " "
db " "
db "DESCRIPTION LINE 1 "
db "DESCRIPTION LINE 2 "
db "DESCRIPTION LINE 3 "
db "DESCRIPTION LINE 4 "
OptionsMenu_DescriptionPointers:
dw .importCry
dw .loadSaveCry
dw .exit
.importCry
db "Import an existing "
db "cry. "
db " "
db " "
.loadSaveCry
db "Load or save a cry. "
db " "
db " "
db " "
.exit
db "Return to the cry "
db "editor. "
db " "
db " "
Options_PrintDescription:
ld bc,OptionsMenu_DescriptionPointers
ld h,0
ld l,a
add hl,hl
add hl,bc
ld a,[hl+]
ld h,[hl]
ld l,a
ld de,$99c0
ld bc,$414
.loop
ld a,[hl+]
sub 32
push af
WaitForVRAM
pop af
ld [de],a
inc de
dec c
jr nz,.loop
ld c,$14
ld a,e
add $c
jr nc,.continue
inc d
.continue
ld e,a
dec b
jr nz,.loop
ret
; ================
; Load/save screen
; ================
InitLoadSaveScreen:
rst $10
xor a
ldh [rLCDC],a
ld [sys_MenuPos],a
ld a,[SelectedSaveSlot]
ld [sys_MenuMax],a ; sys_MenuMax is repurposed as currently selected save slot
call InitSound
; load font + graphics
CopyTileset1BPP Font,0,98
CopyTileset1BPPInvert Font,$800,98
ld hl,LoadSaveScreenTilemap
call LoadMapText
xor a
ld hl,msg_dummy
call LoadSaveScreen_PrintLine
inc a
ld hl,msg_dummy
call LoadSaveScreen_PrintLine
; init rendering variables
SetDMGPal rBGP, 0,1,2,3
SetDMGPal rOBP0,0,0,2,3
SetDMGPal rOBP1,0,1,2,3
xor a
ldh [rSCX],a
ldh [rSCY],a
ldh [rWX],a
ldh [rWY],a
ld a,%10010001
ldh [rLCDC],a
ld a,IEF_VBLANK
ldh [rIE],a
ei
halt
LoadSaveScreenLoop:
call UpdateSound
ld hl,sys_MenuMax
ld a,[sys_btnPress]
bit A_BUTTON_F,a
jp nz,.selectSlot
bit B_BUTTON_F,a
jr nz,.exit
bit SELECT_F,a
jr nz,.previewCry
bit D_UP_F,a
jr nz,.add16
bit D_DOWN_F,a
jr nz,.sub16
bit D_RIGHT_F,a
jr nz,.add1
bit D_LEFT_F,a
jr nz,.sub1
.continue
ld a,[sys_MenuMax]
ld [SelectedSaveSlot],a
ld hl,$9871
call DrawHex
halt
jr LoadSaveScreenLoop
.previewCry
call LoadSaveScreen_SRAMCheck
jr c,.previewfail
ld a,[sys_MenuMax]
call LoadSaveScreen_GetPtr
ld a,$a
ld [rRAMG],a
push hl
call LoadSave_CheckIfCryExists
jp nc,.crydoesntexist
pop hl
ld a,[hl+]
ld d,0
ld e,a
inc hl
ld a,[hl+]
ld [wCryPitch],a
ld a,[hl+]
ld [wCryPitch+1],a
ld a,[hl+]
ld [wCryLength],a
ld a,[hl+]
ld [wCryLength+1],a
call CryEd_PreviewCry
jr .continue
.previewfail
call InitSound
ld de,$19 ; SFX_WRONG
call PlaySFX
ld hl,msg_previewfail
jp .doprintmessage
.sub1
dec [hl]
jr .continue
.add1
inc [hl]
jr .continue
.sub16
ld a,[hl]
sub 16
ld [hl],a
jr .continue
.add16
ld a,[hl]
add 16
ld [hl],a
jr .continue
.exit
call InitSound
ld de,$e
call PlaySFX
.waitSFX
call UpdateSound
halt
call IsSFXPlaying
jr nc,.waitSFX
jp InitCryEditor
.selectSlot
call InitSound
ld de,$7
call PlaySFX
.loop1
xor a
ld hl,msg_loadsave
call LoadSaveScreen_PrintLine
inc a
ld hl,prompt_loadsave
call LoadSaveScreen_PrintLine
call LoadSaveScreen_WaitForPrompt
cp $ff
jp z,.cancel
and a
jp nz,.doSave
dec a
jr nz,.doLoad
jp .continue
.doLoad
call LoadSaveScreen_SRAMCheck
jr c,.loadfail
call LoadSaveScreen_GetPtr
ld a,$a
ld [rRAMG],a
push hl
call LoadSave_CheckIfCryExists
jr nc,.crydoesntexist
pop hl
ld a,[hl+]
ld [CryEdit_CryBase],a
inc hl
ld a,[hl+]
ld [CryEdit_CryPitch],a
ld a,[hl+]
ld [CryEdit_CryPitch+1],a
ld a,[hl+]
ld [CryEdit_CryLength],a
ld a,[hl]
ld [CryEdit_CryLength+1],a
xor a
ld [rRAMG],a
call InitSound
ld de,$22
call PlaySFX
ld hl,msg_loaded
jr .doprintmessage
.crydoesntexist
xor a
ld [rRAMG],a
call InitSound
ld de,$19 ; SFX_WRONG
call PlaySFX
ld hl,msg_slotempty
jr .doprintmessage
.loadfail
call InitSound
ld de,$19 ; SFX_WRONG
call PlaySFX
ld hl,msg_loadfail
jr .doprintmessage
.savefail
xor a
ld [rRAMG],a
call InitSound
ld de,$19 ; SFX_WRONG
call PlaySFX
ld hl,msg_savefail
.doprintmessage
xor a
call LoadSaveScreen_PrintLine
inc a
ld hl,msg_dummy
call LoadSaveScreen_PrintLine
call LoadSaveScreen_WaitForButton
ld b,60
.loop
push bc
call UpdateSound
halt
pop bc
dec b
jr nz,.loop
; fall through to .cancel
.cancel
xor a
ld [rRAMG],a
ld hl,msg_dummy
call LoadSaveScreen_PrintLine
inc a
ld hl,msg_dummy
call LoadSaveScreen_PrintLine
jp .continue
.doSave
; save check
ld a,$a
ld [rRAMG],a
ld hl,$a606
ld a,$ed
ld [hl],a
ld b,a
ld a,[hl]
cp b
jr nz,.savefail
ld a,[sys_MenuMax]
call LoadSaveScreen_GetPtr
push hl
; check if cry exists
call LoadSave_CheckIfCryExists
jr nc,.crydoesntexist2
xor a
ld hl,msg_overwrite
call LoadSaveScreen_PrintLine
inc a
ld hl,prompt_yesno
call LoadSaveScreen_PrintLine
call InitSound
ld de,$7
call PlaySFX
call LoadSaveScreen_WaitForPrompt
cp $ff
jr z,.cancel
and a
jr nz,.crydoesntexist2
jr .cancel
.crydoesntexist2
pop de
ld hl,CryEdit_CryBase
ld a,[hl+]
ld [de],a
inc de
inc de
ld b,4
.saveloop
ld a,[hl+]
ld [de],a
inc de
dec b
jr nz,.saveloop
xor a
ld [rRAMG],a
call InitSound
ld de,$22
call PlaySFX
ld hl,msg_saved
jp .doprintmessage
; carry = 1 if cry exists
LoadSave_CheckIfCryExists:
ld b,3
.loop
ld c,0
ld a,[hl+]
add c
ld c,a
ld a,[hl+]
add c
ld c,a
cp 0
jr nz,.exists
dec b
jr nz,.loop
and a ; clear carry
ret
.exists
scf
ret
LoadSaveScreen_GetPtr:
ld a,[sys_MenuMax]
ld e,a
ld d,0
ld hl,$a000
add hl,de
add hl,de
add hl,de
add hl,de
add hl,de
add hl,de
ret
LoadSaveScreen_SRAMCheck:
ld a,$a
ld [rRAMG],a ; enable SRAM
ld hl,$a600
ld b,5
ld c,0
.loop
ld a,[hl+]
add c
ld c,a
dec b
jr nz,.loop
xor a
ld [rRAMG],a
ld a,c
cp $50
scf
ret nz ; return carry = 1 if check failed
ccf ; return carry = 0 if check passed
ret
LoadSaveScreen_WaitForButton:
call UpdateSound
halt
ld a,[sys_btnPress]
and a
jr nz,LoadSaveScreen_WaitForButton
ret
; OUTPUT: 0 if item 1 selected, 1 if item 2 selected, $ff if user cancelled
LoadSaveScreen_WaitForPrompt:
xor a
ld [sys_MenuPos],a
halt
.loop
ld a,[sys_btnPress]
bit D_LEFT_F,a
jr nz,.toggle
bit D_RIGHT_F,a
jr nz,.toggle
bit A_BUTTON_F,a
jr nz,.select
bit B_BUTTON_F,a
jr nz,.cancel
.continue
ld a,[sys_MenuPos]
and a