This repository has been archived by the owner on Sep 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.asm
2159 lines (1926 loc) · 36.8 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
; ================================================================
; Scoot the Burbs
; ================================================================
; Debug flag
; If set to 1, enable debugging features.
DebugFlag set 1
; ================================================================
; Project includes
; ================================================================
include "Variables.asm"
include "Constants.asm"
include "Macros.asm"
include "hardware.inc"
; ================================================================
; Reset vectors (actual ROM starts here)
; ================================================================
SECTION "Reset $00",ROM0[$00]
Reset00:
halt
ldh a,[sys_VBlankIRQ]
and a
jr z,Reset00
xor a
ldh [sys_VBlankIRQ],a
ret
SECTION "Reset $10",ROM0[$10]
Reset10:
halt
ldh a,[sys_StatIRQ]
and a
jr z,Reset10
xor a
ldh [sys_StatIRQ],a
ret
SECTION "Reset $20",ROM0[$20]
Reset20:
halt
ldh a,[sys_TimerIRQ]
and a
jr z,Reset20
xor a
ldh [sys_TimerIRQ],a
ret
SECTION "Reset $30",ROM0[$30]
Reset30: jp ShowError
SECTION "Reset $38",ROM0[$38]
Reset38: jp ErrorHandler
; ================================================================
; Interrupt vectors
; ================================================================
SECTION "VBlank interrupt",ROM0[$40]
IRQ_VBlank: jp DoVBlank
SECTION "LCD STAT interrupt",ROM0[$48]
IRQ_STAT: jp DoStat
SECTION "Timer interrupt",ROM0[$50]
IRQ_Timer: jp DoSample
SECTION "Serial interrupt",ROM0[$58]
IRQ_Serial: reti
SECTION "Joypad interrupt",ROM0[$60]
IRQ_Joypad: reti
; ================================================================
; 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: db "SCOOT THE BURBS" ; ROM title (15 bytes)
GBCSupport: db $c0 ; 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 $19 ; Cart type, see hardware.inc for a list of values
ROMSize: ds 1 ; ROM size (handled by post-linking tool)
RAMSize: db 0 ; 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,$dffe
push bc
push af
.wait ; wait for VBlank before disabling the LCD
ldh a,[rLY]
cp $90
jr nz,.wait
xor a
ldh [rLCDC],a ; disable LCD
call ClearWRAM
call ClearVRAM
; clear HRAM
ld bc,$8080
.hramClearLoop
ld [c],a
inc c
djnz .hramClearLoop
xor a
ldh [rSCY],a
ldh [rSCX],a
ldh [rWY],a
ldh [rWX],a
call CopyDMARoutine
pop af
cp $11 ; are we on GBC?
ld [GBCFlag],a
jp z,DoInit ; if we are, jump to main init routine
CopyTileset1BPP DebugFont,0,97
xor a
ldh [rSCX],a
ldh [rSCY],a
ld hl,.dmgTilemap
call LoadMapText
ld a,IEF_VBLANK
ldh [rIE],a
ld a,%10010001
ldh [rLCDC],a
ld a,%11100100
ldh [rBGP],a
ei
.dmgwaitloop
halt
jr .dmgwaitloop
.dmgTilemap
; ####################
db " "
db " "
db " "
db " "
db "- SCOOT THE BURBS - "
db " "
db "This game will not "
db "work on this system."
db " "
db "Please use a Game "
db "Boy Color or Game "
db "Boy Advance to play "
db "this game. "
db " "
db " "
db " "
db " "
db " "
; ####################
DoInit:
; check if we are running in a bad emulator
ld a,$ed ; this value isn't important
ld [EmuCheck],a
ld b,a
ld a,[EmuCheck+$2000] ; read back value from echo RAM (which VBA doesn't support)
cp b
jp z,NoEmu
CopyTileset1BPP DebugFont,0,97
ld hl,.emuTilemap
call LoadMapText
ld hl,Pal_Grayscale
xor a
call LoadBGPalLine ; GBC default palette
ld a,IEF_VBLANK
ldh [rIE],a
ld a,%10010001
ldh [rLCDC],a ; enable LCD
ei
.loop
halt
jr .loop
.emuTilemap
; ####################
db "- SCOOT THE BURBS - "
db " "
db "Isn't it time you "
db "ditched VBA already?"
db " "
db "Unfortunately, VBA "
db "has a large number "
db "accuracy issues, so "
db "we can't let you "
db "play the game until "
db "you get a better "
db "emulator. We would "
db "recommend either BGB"
db "or Gambatte for the "
db "best experience if "
db "you can't run this "
db "ROM on a real Game "
db "Boy. "
; ####################
NoEmu:
pop bc
ld a,b
ld [GBAFlag],a
; ld a,1
; ldh [sys_GameMode],a
ld a,IEF_TIMER+IEF_VBLANK
ldh [rIE],a ; set interrupt flags
xor a
ldh [rTIMA],a
ldh [rTMA],a
or %00000110
ldh [rTAC],a ; initialize timer (for sample playback)
; initialize sample pointer and bank
ld a,$40
ldh [SamplePtr+1],a
ld a,1
ldh [SampleBank],a
; init sound output
ld c,rNR51-$ff00
ld a,$ff
ld [c],a
dec c
xor %10001000
ld [c],a
ld a,$20
ldh [rNR32],a
ld hl,Pal_White
call LoadBGPal
ld hl,Pal_White
call LoadObjPal
call CPUToggleSpeed
; call comm_not_ready
ei
ShowDevsoftSplash:
CopyCompressedTileset DevSoftTiles,0
CopyTileset BlankTiles,$600,(BlankTiles_End-BlankTiles)/16
ld hl,DevSoftMap
call LoadMap
; ld a,$62
; ld hl,$9a40
; push hl
; call LoadRow
; ld a,1
; ldh [rVBK],a
; pop hl
; call LoadRow
; xor a
; ldh [rVBK],a
ld a,$62 ; black tile
call .loadloop ; load BG map
ld a,1
ldh [rVBK],a ; set VRAM bank 1
call .loadloop ; load attributes
jr .continue ; jump ahead
.loadloop
ld d,a ; save tile/attribute ID
ld hl,$9c00 ; window map address
ld bc,$800 ; size of tilemap
.copyloop
ld [hl+],a ; copy byte
dec bc
ld a,b
or c
ld a,d ; restore tile/attribute ID
jr nz,.copyloop ; loop until all bytes are copied
ret
.continue
xor a
ldh [rVBK],a ; set VRAM bank 0
ld a,%10010001 ; LCD on + BG on + BG $8000
ldh [rLCDC],a ; enable LCD
Pal_FadeToPal Pal_Grayscale,1,8
ld a,1
ld hl,Pal_Vinesauce
call LoadBGPalLine
call ShowSplash
ld a,%11110001
ldh [rLCDC],a ; enable window
ld a,176
ld [WindowBasePos],a
di
ld a,IEF_VBLANK+IEF_LCDC
ldh [rIE],a
ld a,%01000000
ldh [rSTAT],a
xor a
ldh [rLYC],a
ld a,1
ld [StatID],a
ei
.scrollLoop
WaitForVBlank
ld a,[WindowBasePos]
dec a
ld [WindowBasePos],a
ld a,[WindowTransitionOffset]
inc a
ld [WindowTransitionOffset],a
ld [WindowTransitionPos1],a
ld [WindowTransitionPos2],a
ld a,[WindowBasePos]
cp $e0
jr nz,.scrollLoop
di
ld a,IEF_VBLANK
ldh [rIE],a
xor a
ld [SpritesDisabled],a
ei
WaitForVBlank
; WaitForVBlank
; xor a
; ldh [rLCDC],a
ShowVinesauceSplash:
CopyTilesetSafe VinesauceTextTiles,$1000,29
CopyTilesetSafe VineshroomTiles,0,2
ld hl,VinesauceTextMap
call LoadMapSafe
di
ld a,IEF_VBLANK
ldh [rIE],a
ei
ld a,80
ldh [rSCY],a
ld a,%10000111
ldh [rLCDC],a
xor a
ld hl,Pal_Vinesauce
call LoadBGPalLine
xor a
ld hl,Pal_Vineshroom
call LoadObjPalLine
xor a
ld [ScrollTablePos],a
ld a,Bank(FXHammer)
ld [rROMB0],a
.loop1
call FXHammer_Update
halt
; make logo fall
ld hl,VinesauceScrollTableY
ld a,[ScrollTablePos]
add l
ld l,a
jr nc,.nocarry
inc h
.nocarry
ld a,[hl]
cp $80
jr z,.endScrollIn
ldh [rSCY],a
ld a,[ScrollTablePos]
cp $16
jr nz,.noplay
push af
ld a,SFX_BigThud
call FXHammer_Trig
pop af
.noplay
inc a
ld [ScrollTablePos],a
jr .loop1
.endScrollIn
; wait a bit before moving logo
ld a,45
ld [ScreenTimer],a
.loop2
call FXHammer_Update
halt
ld a,[ScreenTimer]
dec a
ld [ScreenTimer],a
and a
jr nz,.loop2
; move logo right to make room for vineshroom
ld a,8
ld [ScreenTimer],a
.loop3
call FXHammer_Update
halt
ldh a,[rSCX]
dec a
ldh [rSCX],a
ld a,[ScreenTimer]
dec a
ld [ScreenTimer],a
and a
jr nz,.loop3
LoadSprite Sprite_Vineshroom,OAMBuffer,Sprite_Vineshroom_End-Sprite_Vineshroom
ld a,15
ld [ScreenTimer],a
.loop4
call FXHammer_Update
halt
ld a,[ScreenTimer]
dec a
ld [ScreenTimer],a
and a
jr nz,.loop4
xor a
ld [ScrollTablePos],a
.loop5
call FXHammer_Update
halt
ld hl,VineshroomScrollTable
ld a,[ScrollTablePos]
add l
ld l,a
jr nc,.nocarry2
inc h
.nocarry2
ld a,[hl]
cp $80
jr z,.endScrollIn2
cp 80
jr nz,.noSFX
push af
ld a,SFX_Bounce
call FXHammer_Trig
pop af
.noSFX
ld [VineshroomPosY1],a
ld [VineshroomPosY2],a
ld a,[ScrollTablePos]
inc a
ld [ScrollTablePos],a
jr .loop5
.endScrollIn2
ld a,120
ld [ScreenTimer],a
.loop6
call FXHammer_Update
halt
ld a,[ScreenTimer]
dec a
ld [ScreenTimer],a
and a
jr nz,.loop6
ld a,1
ld [RGBG_fade_to_color],a
call RGBG_SimpleFadeOut
ShowTitleScreen:
WaitForVBlank
xor a
ldh [rLCDC],a
CopyTileset1BPP DebugFont,0,97
ld hl,TitleMap
call LoadMapTitle
ld a,1
ld [rROMB0],a
xor a
ld [FadeType],a
call DS_Init
xor a
ldh [rSCX],a
ldh [rSCY],a
; Pal_FadeToPal Pal_Grayscale,1,8
ld a,0
ld hl,Pal_Grayscale
call LoadBGPalLine
ld a,1
ld hl,Pal_Grayscale
call LoadBGPalLine
ld a,%11110111
ldh [rLCDC],a
di
ld a,IEF_VBLANK;+IEF_LCDC
ldh [rIE],a
; ld a,%01000000
; ldh [rSTAT],a
; ld a,48
; ldh [rLYC],a
; ld a,2
; ld [StatID],a
ei
jr TitleLoop
VinesauceScrollTableY:
db 80,80,80,80,80,80,80,80
db 74,68,62,56,50,44,38,32,26,20,14,8,2,0
db 4,-4,4,-4
db 3,-3,3,-3
db 2,-2,2,-2
db 1,-1,1,-1
db 0,$80 ; $80 = end
VineshroomScrollTable:
db 0,6,12,18,24,30,36,42,48,54,60,66,72,78,80
db 78,76,74,73,72,72,71,71,71,72,72,73,74,76,78
db 80,$80 ; $80 = end
Sprite_Vineshroom:
db 0,22,0,%00000000
db 0,30,0,%00100000
Sprite_Vineshroom_End
; ================================================================
TitleLoop::
WaitForVBlank
call DS_Play
call CheckInput
ld a,[sys_btnPress]
bit btnStart,a
jr nz,.exitTitle
bit btnSelect,a
jp nz,InitSoundTest
jr TitleLoop
.exitTitle
call DS_Stop
ld a,Bank(FXHammer)
ld [rROMB0],a
ld a,SFX_MenuSelect
call FXHammer_Trig
ld b,30
.loop1
push bc
call FXHammer_Update
WaitForVBlank
pop bc
dec b
jr nz,.loop1
ld a,1
ld [RGBG_fade_to_color],a
call RGBG_SimpleFadeOut
WaitForVBlank
xor a
ldh [rLCDC],a
ShowCharSelect:
di
CopyTileset CharSelectTiles,0,(CharSelectTiles_End-CharSelectTiles)/16
ld hl,CharSelectMap
call LoadMapFull
ld a,1
ld [SpritesDisabled],a
ldh [rVBK],a
; TODO: Fix pics not fading in properly
ld hl,Pic_Dummy
call LoadPic
ld a,%10010001
ldh [rLCDC],a
Pal_FadeToPal Pal_CharSelectMain,1,8
ld a,3
ld [StatID],a
ld a,STATF_LYC
ldh [rSTAT],a
ld a,IEF_VBLANK+IEF_LCDC
ldh [rIE],a
ld a,1
ld [rROMB0],a
call DS_Init
ei
.loop
rst $00
xor a
ldh [rLYC],a
jr .loop
ProcessCharSelect:
ld hl,rROMB0
ld [hl],1
call DS_Play
ld [hl],2
call FXHammer_Update
call CheckInput
ld a,[sys_btnPress]
bit btnA,a
jr nz,.select
bit btnB,a
jr nz,.back
bit btnStart,a
jr nz,.select
bit btnLeft,a
jr nz,.prev
bit btnRight,a
jr z,.continue
.next
ld a,SFX_MenuCursor
call FXHammer_Trig
ld hl,CharSel_CharID
inc [hl]
jr .continue
.prev
ld a,SFX_MenuCursor
call FXHammer_Trig
ld hl,CharSel_CharID
dec [hl]
jr .continue
.select
ld [hl],1 ; hl should still be ROM bank select
call DS_Stop ; stop music
; mute all channels to prevent notes from sustaining (why does it do this?)
xor a
ldh [rNR12],a
ldh [rNR22],a
ldh [rNR30],a
ldh [rNR42],a
or $80
ldh [rNR14],a
ldh [rNR24],a
ldh [rNR44],a
ld [hl],2
ld a,SFX_MenuSelect
call FXHammer_Trig
ld a,1
ld [DoExitCharSelect],a
di
ld a,IEF_VBLANK
ldh [rIE],a
xor a
ldh [rSCX],a
ei
ld b,45
.loop
push bc
call FXHammer_Update
pop bc
WaitForVBlank
dec b
jr nz,.loop
di
ld a,IEF_TIMER+IEF_VBLANK+IEF_LCDC
ldh [rIE],a
ei
; init CH3 to prevent samples from being too quiet (isn't DS_Stop supposed to take care of this???)
ld a,$80
ldh [rNR30],a
ld a,%00100000
ldh [rNR32],a
ld a,[CharSel_CharID]
and $3
call PlaySample
jr .sampleLoop
.back
ld a,SFX_MenuBack
call FXHammer_Trig
.continue
ret
.sampleLoop
WaitForVBlank
ld a,[SamplePlaying]
and a
jr nz,.sampleLoop
.samplebreak
di
ld a,IEF_VBLANK
ldh [rIE],a
ei
ld a,1
ld [RGBG_fade_to_color],a
call RGBG_SimpleFadeOut
jr InitGame
CharacterNames:
dw .vinny
dw .joel
dw .thicc
dw .sonic
.vinny str "VINNY"
.joel str "JOEL"
.thicc str "HE THICC"
.sonic str "SONIC"
InitGame:
WaitForVBlank
xor a
ldh [rLCDC],a
.loop
halt
jr .loop
; ================================================================
; Graphics routines
; ================================================================
_CopyTileset: ; WARNING: Do not use while LCD is on!
ld a,[hl+] ; get byte
ld [de],a ; write byte
inc de
dec bc
ld a,b ; check if bc = 0
or c
jr nz,_CopyTileset ; if bc != 0, loop
ret
_CopyTilesetSafe: ; same as _CopyTileset, but waits for VRAM accessibility before writing data
ldh a,[rSTAT]
and 2 ; check if VRAM is accessible
jr nz,_CopyTilesetSafe ; if it isn't, loop until it is
ld a,[hl+] ; get byte
ld [de],a ; write byte
inc de
dec bc
ld a,b ; check if bc = 0
or c
jr nz,_CopyTilesetSafe ; if bc != 0, loop
ret
_CopyTileset1BPP:
ld a,[hl+] ; get byte
ld [de],a ; write byte
inc de ; increment destination address
ld [de],a ; write byte again
inc de ; increment destination address again
dec bc
dec bc ; since we're copying two bytes, we need to dec bc twice
ld a,b ; check if bc = 0
or c
jr nz,_CopyTileset1BPP ; if bc != 0, loop
ret
_CopyTileset1BPPInvert:
ld a,[hl+] ; get byte
cpl ; flip all bits
ld [de],a ; write byte
inc de ; increment destination address
ld [de],a ; write byte again
inc de ; increment destination address again
dec bc
dec bc ; since we're copying two bytes, we need to dec bc twice
ld a,b ; check if bc = 0
or c
jr nz,_CopyTileset1BPPInvert ; if bc != 0, loop
ret
include "FadeRoutines.asm"
; Pic format:
; $000 - Tileset pointer (two bytes)
; $002 - Size of tileset (two bytes)
; $004 - Palette pointer (two bytes)
; $006 - Map data (280 bytes)
; $11e - Attribute data (280 bytes)
LoadPic:
push hl
push hl
inc hl
inc hl
ld a,[hl+]
ld b,[hl]
ld c,a
ld de,$8000
pop hl
ld a,[hl+]
ld h,[hl]
ld l,a
call _CopyTilesetSafe
pop hl
ld a,l
add 4
ld l,a
jr nc,.nocarry
inc h
.nocarry
push hl
ld a,[hl+]
ld h,[hl]
ld l,a
call LoadPalPic
pop hl
ld a,l
inc hl
inc hl
xor a
ldh [rVBK],a
call LoadMapPic
ld a,1
ldh [rVBK],a
call LoadMapPic
xor a
ldh [rVBK],a
ret
LoadMapPic:
ld de,$9840
ld bc,$0e14
.loop
ldh a,[rSTAT]
and 2
jr nz,.loop
ld a,[hl+] ; get tile ID
ld [de],a ; copy to BG map
inc de ; go to next tile
dec c
jr nz,.loop ; loop until current row has been completely copied
ld c,$14 ; reset C
ld a,e
add $c ; go to next row
jr nc,.continue ; if carry isn't set, continue
inc d
.continue
ld e,a
dec b
jr nz,.loop ; loop until all rows have been copied
ret
; temp routine
LoadMapTitle:
ld de,_SCRN1
ld bc,$614
jp LoadMapText_loop
LoadMap:
ld de,_SCRN0 ; BG map address in VRAM
ld bc,$1214 ; size of map (YX)
LoadMap_loop:
ld a,[hl+] ; get tile ID
ld [de],a ; copy to BG map
inc de ; go to next tile
dec c
jr nz,LoadMap_loop ; loop until current row has been completely copied
ld c,$14 ; reset C
ld a,e
add $c ; go to next row
jr nc,.continue ; if carry isn't set, continue
inc d
.continue
ld e,a
dec b
jr nz,LoadMap_loop ; loop until all rows have been copied
ret
LoadMapFull:
ld de,_SCRN0
ld bc,$400
.loop
ld a,[hl+]
ld [de],a
inc de
dec bc
ld a,b
or c
jr nz,.loop
ret
LoadRow:
ld e,a
ld b,$20
.loop
ld a,e
ld [hl+],a
dec b
jr nz,.loop
ret
LoadMapSafe:
ld de,_SCRN0 ; BG map address in VRAM
ld bc,$1214 ; size of map (YX)
LoadMapSafe_loop:
ldh a,[rSTAT]
and 2
jr nz,LoadMapSafe_loop
ld a,[hl+] ; get tile ID
ld [de],a ; copy to BG map
inc de ; go to next tile
dec c
jr nz,LoadMapSafe_loop ; loop until current row has been completely copied
ld c,$14 ; reset C
ld a,e
add $c ; go to next row
jr nc,.continue ; if carry isn't set, continue
inc d
.continue
ld e,a
dec b
jr nz,LoadMapSafe_loop ; loop until all rows have been copied
ret
WaitStat: ; wait for LCD status to change (prevents tearing when using STAT interrupts)
push af
.wait
ldh a,[rSTAT]
and 2
jr z,.wait
.wait2
ldh a,[rSTAT]
and 2
jr nz,.wait2
pop af
ret
; Input: hl = palette data
LoadBGPal:
ld a,0
call LoadBGPalLine
LoadPalPic:
ld a,1
call LoadBGPalLine
ld a,2
call LoadBGPalLine
ld a,3
call LoadBGPalLine
ld a,4
call LoadBGPalLine
ld a,5
call LoadBGPalLine
ld a,6
call LoadBGPalLine
ld a,7
call LoadBGPalLine
ret
; Input: hl = palette data
LoadObjPal:
ld a,0
call LoadObjPalLine