1- !bank_85_free_space_start = $ 85A050
2- !bank_85_free_space_end = $ 85A100
1+ !bank_85_free_space_start = $85AE20
2+ !bank_85_free_space_end = $85B000
33
4- ; Hook code that run when equipment screen tanks mode (Auto/Manual) is selected:
5- org $ 82AE8E
6- jsl hook_reserve_refill
4+ !bank_82_free_space_start = $82F9E0
5+ !bank_82_free_space_end = $82FA00
6+
7+ !arrow_mode = $7EF59A
8+
9+ ; Hook runs when the dpad is pressed in the SUPPLY section
10+ ; (Note: disableable_etanks also hooks at a later point in this routine, at ACEF (BRANCH_UP).)
11+ org $82AC8E
12+ jml hook_tanks_dpad_response
13+ nop
14+
15+ ; Load equipment menu
16+ org $8291B8
17+ jsl hook_init_arrow_mode
18+ nop
719 nop
820
9- ; update reserve refill code to set the counter value to maximum (#$FFFF) rather than
10- ; to the current amount in reserves. This prevents the refill from abruptly stopping
11- ; if switching back and forth between forward and reverse fill.
21+ org $82AD08
22+ ; There's a PLP / RTS here for when we need to escape hooked $82 routines that had to JML out to $85
23+ fake_rtl:
24+
25+ ; Hook code that prepares the reserve tank delay sound counter
1226org $82AF5E
13- lda # $ FFFF
14- sta $ 0757
15- bra process_reserve_counter
27+ jml hook_reserve_delay_counter_init
28+
29+ ; Hook code that performs the reserve tank refill
30+ org $82AF81
31+ jml hook_reserve_tank_refilling
32+
33+ ; Jump table for the equipment tanks category (A button handler)
34+ org $82AC7C
35+ jsr (hook_tanks_items, x)
36+
37+ org $82AC87
38+ ; Having hijacked the jump table that's normally here, we can repurpose it for a little bit of code...
39+ hook_tanks_arrow_trampoline:
40+ jml hook_tanks_arrow
41+
42+ org $82AD1B
43+ jsr (hook_tanks_glowing_arrow_jumptable, x)
44+
45+ org $82AD25
46+ hook_tanks_glowing_arrow_selected_trampoline:
47+ jml hook_tanks_glowing_arrow_selected
48+
49+ org $82ACD6
50+ jsl hook_tanks_dpad_move_to_reserve
51+ nop
52+ nop
53+ assert pc () == $82ACDC
54+
55+ org $82B292
56+ beq escape
57+ tax
58+ dex
59+ lda $0002 ,y
60+ assert pc () == $82B299
1661
17- warnpc $ 82AF6B
18- org $ 82AF6B
19- process_reserve_counter:
62+ org $82B2A0
63+ escape:
64+
65+ org $82C18E
66+ dw coord_table
67+
68+ org !bank_82_free_space_start
69+
70+ hook_tanks_items:
71+ dw $AE8B , $AF4F , hook_tanks_arrow_trampoline
72+
73+ hook_tanks_glowing_arrow_jumptable:
74+ dw $AD29 , $ADDD , hook_tanks_glowing_arrow_selected_trampoline
75+
76+ coord_table:
77+ dw $001B , $0054 ; Tanks - mode
78+ dw $001B , $005C ; Tanks - reserve tank
79+ dw $0000 , $0000 ; Far off-screen
80+
81+ extern_arrow_glow_off:
82+ jsr $ADEF
83+ rtl
84+
85+ warnpc !bank_82_free_space_end
2086
2187org !bank_85_free_space_start
22- hook_reserve_refill:
23- lda $ 09C0
24- cmp # $ 0002 ; reserves on manual?
25- bne .done
2688
27- lda $ 8B
28- and # $ 8800
29- cmp # $ 8800 ; holding up + B?
30- bne .done
89+ !ram_bg1_tilemap_arrow_top = $7E3902
90+ !ram_bg1_tilemap_arrow_end = $7E3B04
91+ !arrow_top_normal_tile = $3D4C ; Vanilla tile (upward arrowhead)
92+ !arrow_end_normal_tile = $3D6F ; Vanilla tile (short horizontal end)
93+ !arrow_top_reversed_tile = $3D4A ; Custom tile (short vertical end)
94+ !arrow_end_reversed_tile = $3D4B ; Custom tile (rightward arrowhead)
95+
96+ hook_init_arrow_mode:
97+ jsr reset_arrow
98+ lda #$0001 ;Hijacked
99+ sta $0763
100+ rtl
101+
102+ hook_tanks_glowing_arrow_selected:
103+ lda $074F ; X = Pause palette animation frame * 2
104+ asl
105+ tax
106+
107+ lda.l sequence_arrow_shadow_color,x
108+ sta $7EC0CC ; Palette 6 slot 6 (arrow hilight))
109+
110+ lda.l sequence_arrow_fill_color,x
111+ sta $7EC0D6 ; Palette 6 slot B (arrow fill)
112+ jml $82AE01 ; Enable energy glow
113+
114+ sequence_arrow_fill_color:
115+ dw $318C , $35AD , $3DEF , $4A52 , $56B5 , $6739 , $739C , $7FFF , $739C , $6739 , $56B5 , $4A52 , $3DEF , $35AD , $318C
116+
117+ sequence_arrow_shadow_color:
118+ dw $2108 , $2529 , $2D6B , $39CE , $4631 , $56B5 , $6318 , $6F7B , $6318 , $56B5 , $4631 , $39CE , $2D6B , $2108 , $2529
31119
32- ; skip if samus energy <= 1
120+ hook_tanks_dpad_move_to_reserve:
121+ sta $0755 ; Part of the hijacked
122+ ; Z = Don't move to the reserve tank, NZ = Do
123+ lda !arrow_mode
124+ beq .vanilla
33125 lda $09C2
34- cmp # $ 0002
35- bmi .done
36-
37- ; play sound every 8 frames:
38- LDA $ 0757
39- DEC A
40- STA $ 0757
41- AND # $ 0007
42- BNE .refill
43- LDA # $ 002D
44- JSL $ 80914D ;} Queue sound 2Dh, sound library 3, max queued sounds allowed = 6 (gaining/losing incremental health)
45-
46- .refill:
47- ; do reverse refill, where energy transfers into reserves:
126+ dec a
127+ rtl
128+ .vanilla
129+ lda $09D6
130+ rtl
131+
132+ reset_arrow:
133+ lda #$0000
134+ sta !arrow_mode
135+ lda.l arrow_top_tile
136+ sta !ram_bg1_tilemap_arrow_top
137+ lda.l arrow_end_tile
138+ sta !ram_bg1_tilemap_arrow_end
139+ jsl extern_arrow_glow_off
140+ ; If this reset because you went to the map need to also reset the reserve timer
141+ lda $0757
142+ beq .no
143+ lda $09D6
144+ clc
145+ adc #$0007
146+ and #$fff8
147+ sta $0757
148+ .no
149+ rts
150+
151+ hook_tanks_arrow:
152+ php
153+ lda $8F
154+ bit #$0080
155+ beq .no
156+ lda !arrow_mode
157+ eor #$0001
158+ sta !arrow_mode
159+ asl
160+ tax
161+ lda.l arrow_top_tile, x
162+ sta !ram_bg1_tilemap_arrow_top
163+ lda.l arrow_end_tile, x
164+ sta !ram_bg1_tilemap_arrow_end
165+ lda #$0037
166+ jsl $809049 ; Play sound: moved cursor
167+ ; Reset the reserve fill sound timer
168+ lda $0757
169+ beq .no
170+ txa
171+ beq .resume_normal
48172 lda $09C2
49- dec
50- sta $ 09C2
173+ dec a
174+ bra .resume
175+ .resume_normal
176+ lda $09D6
177+ .resume
178+ clc
179+ adc #$0007
180+ and #$FFF8
181+ sta $0757
182+ .no
183+ jml fake_rtl
184+
185+ arrow_top_tile:
186+ dw !arrow_top_normal_tile, !arrow_top_reversed_tile
187+
188+ arrow_end_tile:
189+ dw !arrow_end_normal_tile, !arrow_end_reversed_tile
190+
191+ hook_tanks_dpad_response:
192+ ; Arrived here by JML from an $82 JSR - MUST JML back to an $82 PLP/RTS!
193+ ;Hijacked instructions
194+ lda $0755
195+ sta $12
196+
197+ lda $8F
198+ bit #$0200 ; P1 D-Pad Left
199+ beq .not_left
200+
201+ ; Move to the arrow
202+ lda $09C0 ; Reserve = [AUTO] -> don't
203+ cmp #$0001
204+ beq .not_left
205+
206+ lda $0755
207+ and #$00FF
208+ ora #$0200
209+ sta $0755
210+ bra .moved
211+
212+ .not_left
51213
214+ lda $12
215+ xba
216+ and #$00FF
217+ cmp #$0002 ; Arrow selected
218+ bne .not_arrow
219+
220+ lda $8F
221+ bit #$0100 ; P1 D-Pad Right
222+ beq .not_right
223+
224+ ; Move back to the Mode select
225+ stz $0755
226+ .moved
227+ lda #$0037
228+ jsl $809049 ; Play sound: moved cursor
229+
230+ .not_right
231+ jml fake_rtl ; Skip the rest of the vanilla routine
232+
233+ .not_arrow
234+ jml $82AC93 ; Return to vanilla code
235+
236+ hook_reserve_delay_counter_init:
237+ lda !arrow_mode
238+ beq .vanilla
239+ lda $09c2 ; Reserve tank delay sound counter = [Samus health] - 1, rounded up to nearest 8
240+ dec a
241+ clc
242+ adc #$0007
243+ and #$fff8
244+ sta $0757
245+ jml $82AF6B ; Return to vanilla code at handling the reserve tank delay sound counter
246+ .vanilla
247+ lda $09d6 ; Hijacked code
248+ clc
249+ jml $82AF62 ; Return to vanilla code
250+
251+ hook_reserve_tank_refilling:
252+ lda !arrow_mode
253+ beq .vanilla
254+
255+ ; Samus health -= 1, unless this would be 0
256+ lda $09C2
257+ dec a
258+ beq .stop_etanks_empty
259+ sta $09C2
52260 lda $09D6
261+ inc a
53262 cmp $09D4
54- bpl .overfull
55- inc
263+ bpl .stop_dump_etanks
56264 sta $09D6
265+ lda $09C2
266+ dec a
267+ beq .stop_etanks_empty
57268 bra .done
58-
59- .overfull:
60- ; reserves are being overfilled, so set regular energy to 1
61- ; (mirroring vanilla quirky behavior that sets reserve energy to 0 when overfilling regular energy)
269+
270+ .stop_dump_etanks
271+ ; Reserves hit full, vent regular energy
272+ lda $09D4
273+ sta $09D6
62274 lda #$0001
63275 sta $09C2
276+ ;jsl extern_disable_arrow_glow
64277
65- .done:
66- ; run hi-jacked code
67- lda $ 8f
68- bit # $ 0080
69- rtl
278+ .stop_etanks_empty
279+ stz $0755
280+ stz $0757
281+
282+ .done
283+ jml fake_rtl
284+
285+ .vanilla
286+ lda $09C2 ; Hijacked code
287+ clc
288+ jml $82AF85 ; Return to vanilla function
289+
290+ warnpc !bank_85_free_space_end
291+
292+ ; There's a free spot right here in the vanilla pause BG1 tiles
293+ org $B6A940
294+ db $00 , $00 , $00 , $00 , $00 , $00 , $10 , $18 , $10 , $18 , $10 , $18 , $10 , $18 , $10 , $18
295+ db $00 , $00 , $00 , $00 , $3C , $00 , $2C , $10 , $2C , $10 , $2C , $10 , $2C , $10 , $2C , $10
70296
71- warnpc !bank_85_free_space_end
297+ db $00 , $80 , $80 , $C0 , $C0 , $E0 , $E0 , $F0 , $F0 , $F0 , $E0 , $E0 , $C0 , $C0 , $80 , $80
298+ db $C0 , $00 , $60 , $80 , $30 , $C0 , $18 , $E0 , $08 , $F0 , $10 , $E0 , $20 , $C0 , $40 , $80
0 commit comments