-
Notifications
You must be signed in to change notification settings - Fork 1k
/
vblank.asm
105 lines (85 loc) · 1.54 KB
/
vblank.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
VBlank::
push af
push bc
push de
push hl
ldh a, [hLoadedROMBank]
ld [wVBlankSavedROMBank], a
ldh a, [hSCX]
ldh [rSCX], a
ldh a, [hSCY]
ldh [rSCY], a
ld a, [wDisableVBlankWYUpdate]
and a
jr nz, .ok
ldh a, [hWY]
ldh [rWY], a
.ok
call AutoBgMapTransfer
call VBlankCopyBgMap
call RedrawRowOrColumn
call VBlankCopy
call VBlankCopyDouble
call UpdateMovingBgTiles
call hDMARoutine
ld a, BANK(PrepareOAMData)
ldh [hLoadedROMBank], a
ld [MBC1RomBank], a
call PrepareOAMData
; VBlank-sensitive operations end.
call Random
ldh a, [hVBlankOccurred]
and a
jr z, .skipZeroing
xor a
ldh [hVBlankOccurred], a
.skipZeroing
ldh a, [hFrameCounter]
and a
jr z, .skipDec
dec a
ldh [hFrameCounter], a
.skipDec
call FadeOutAudio
ld a, [wAudioROMBank] ; music ROM bank
ldh [hLoadedROMBank], a
ld [MBC1RomBank], a
cp BANK(Audio1_UpdateMusic)
jr nz, .checkForAudio2
.audio1
call Audio1_UpdateMusic
jr .afterMusic
.checkForAudio2
cp BANK(Audio2_UpdateMusic)
jr nz, .audio3
.audio2
call Music_DoLowHealthAlarm
call Audio2_UpdateMusic
jr .afterMusic
.audio3
call Audio3_UpdateMusic
.afterMusic
farcall TrackPlayTime ; keep track of time played
ldh a, [hDisableJoypadPolling]
and a
call z, ReadJoypad
ld a, [wVBlankSavedROMBank]
ldh [hLoadedROMBank], a
ld [MBC1RomBank], a
pop hl
pop de
pop bc
pop af
reti
DelayFrame::
; Wait for the next vblank interrupt.
; As a bonus, this saves battery.
DEF NOT_VBLANKED EQU 1
ld a, NOT_VBLANKED
ldh [hVBlankOccurred], a
.halt
halt
ldh a, [hVBlankOccurred]
and a
jr nz, .halt
ret