-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfx6.asm
More file actions
187 lines (164 loc) · 3.88 KB
/
fx6.asm
File metadata and controls
187 lines (164 loc) · 3.88 KB
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
section "fx6", ROM0
include "registers.asm"
include "memory.asm"
include "common.asm"
include "assets/underwater.inc"
TABLE_SIZE equ $3F
fx6::
mResetFadeVariables
mResetLoader
mResetVars
mSetStates STATE_FADE_IN, STATE_RUN_FX
mEnableLoading
ld a, [LCDC]
res 1, a
res 3, a
res 5, a
ld [LCDC], a
; set duration
ld a,$FF
ld [duration],a
ld a,$02
ld [duration+1],a
; set water_y
xor a
ld [water_y],a
ld [water_x],a
ld a,150
ld [control_y],a
ld a,1
ld [update_duration], a
; load wave data
ld de, wave_data
ld hl, wave
ld bc, TABLE_SIZE + 1
call unsafe_memcpy
mLoadIn8SongUpdatesBANK underwater_data, $8000, underwater_data_size, 3
mLoadIn4SongUpdatesBANK underwater_map, $9800, underwater_map_size, 3
call fx6_loop
ret
fx6_loop:
mUpdateMusic
mDefineFadeLogic
mUpdateBackground
ld a, [should_quit]
cp $01
jr z, .call_vb
call run_fx
jr .go_to_bottom
.call_vb:
mWaitVBlank
.go_to_bottom:
mJumpCheckEnding fx6_loop
run_fx:
; mWaitVBlank
ld a, [update_duration]
cp $00
jr z, .move_water_down
; Check duration
ld a,[duration]
ld l,a
ld a,[duration+1]
ld h,a
dec hl
ld a,l
ld [duration],a
ld a,h
ld [duration+1],a
cp $00
jr nz,.duration_not_complete
ld a,l
cp $00
jr nz,.duration_not_complete
xor a
ld [update_duration], a
.move_water_down:
ld a, [control_y]
inc a
cp 150
jr nz, .save_control_y
ld a, 1
ld [should_quit], a
ld a,%11100100
ld [BGP], a
mSetStates STATE_FADE_OUT, STATE_END_FX
ret
.save_control_y:
ld [control_y], a
jr .dont_increment_water
.duration_not_complete:
ld a,[control_y]
cp 50
jr c, .dont_increment_water
dec a
ld [control_y],a
.dont_increment_water:
ld a,%11100100
ld [BGP],a ; Set the background palette to default gradient
xor a
ld [SCX],a
ld [SCY],a ; Reset LCD's scroll X and Y registers.
ld a,[water_y] ; Load water Y offset which handles the top wave
inc a
and TABLE_SIZE ; Increment and mask it so it doesn't overflow
ld [water_y],a ; Store it in memory
ld hl,wave
add a,l
ld l,a
ld a,[hl] ; Use this offset to retrieve a wave value
ld c,a ; Move it to C so it can be added to the
ld a,[control_y] ; water Y position. (control_y)
add a,c
ld b,a ; Add it and save it in B for scanline check
.waity0:
ld a,[LY]
cp b
jr nz,.waity0 ; Wait for scanline to be equal to B
ld a,%10010000 ; Once we've reached the scanline == B
ld [BGP],a ; We set the background palette to a light color
; Horizontal wave movement
.repeat_hwave:
ld a,[LY]
inc a
ld b,a
cp $90
jr nc,.end_horizontal_wave
.waity1:
ld a,[LY]
cp b
jr nz,.waity1
; apply effect
ld l,a
ld a,[water_x]
add a,l
and TABLE_SIZE
ld l,a
ld a,[hl]
ld [SCX],a
sub a, 10
ld [SCY],a
jr .repeat_hwave
.end_horizontal_wave:
ld a,[water_x]
inc a
ld [water_x],a
ret
section "WaveDatafx6", ROM0, ALIGN[8]
wave_data:
db $00,$00,$00,$01,$01,$01,$02,$02,$02,$03,$03,$03,$03,$03,$03,$03
db $03,$03,$03,$03,$03,$03,$03,$02,$02,$02,$02,$01,$01,$00,$00,$00
db $00,$00,$00,$FF,$FF,$FE,$FE,$FE,$FE,$FD,$FD,$FD,$FD,$FD,$FD,$FD
db $FD,$FD,$FD,$FD,$FD,$FD,$FD,$FE,$FE,$FE,$FF,$FF,$FF,$00,$00,$00
section "UNDERWATER_VARS", WRAM0, ALIGN[8]
wave: ds TABLE_SIZE + 5
water_y: ds $01
water_x: ds $01
control_y: ds $01
duration: ds $02
fade_step: ds $01
fade_time: ds $01
update_duration: ds $01
should_quit: ds $01
section "Under", ROMX, BANK[3]
underwater_data: incbin "assets/underwater.td"
underwater_map: incbin "assets/underwater.tm"