forked from KatDevsGames/z3randomizer
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgoalitem.asm
217 lines (172 loc) · 5.05 KB
/
goalitem.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
;--------------------------------------------------------------------------------
; $7F5010 - Scratch Space (Callee Preserved)
;--------------------------------------------------------------------------------
!GOAL_DRAW_ADDRESS = "$7EC72A"
;--------------------------------------------------------------------------------
; DrawGoalIndicator moved to newhud.asm
;--------------------------------------------------------------------------------
GoalItemGanonCheck:
LDA $0E20, X : CMP.b #$D6 : BNE .success ; skip if not ganon
JSL.l CheckGanonVulnerability
BCS .success
.fail
LDA $0D80, X : CMP.b #17 : !BLT .success ; decmial 17 because Acmlm's chart is decimal
LDA.b #$00
RTL
.success
LDA $44 : CMP.b #$80 ; thing we wrote over
RTL
;--------------------------------------------------------------------------------
;Carry clear = ganon invincible
;Carry set = ganon vulnerable
CheckGanonVulnerability:
PHX
LDA.l InvincibleGanon
ASL
TAX
; Carry
; 0 - invulnerable
; 1 - vulnerable
JSR (.goals, X)
PLX
RTL
.goals
dw .vulnerable
dw .invulnerable
dw .all_dungeons
dw .crystals_and_aga
dw .crystals
dw .goal_item
dw .light_speed
dw .crystals_and_bosses
dw .bosses_only
dw .all_dungeons_no_agahnim
; 00 = always vulnerable
.vulnerable
.success
SEC
RTS
; 01 = always invulnerable
.invulnerable
.fail
CLC
RTS
; 02 = All dungeons
.all_dungeons
LDA.l ProgressIndicator : CMP.b #$03 : BCC .fail ; require post-aga world state
; 09 = All dungeons except agahnim
.all_dungeons_no_agahnim
LDA.l PendantsField : AND.b #$07 : CMP.b #$07 : BNE .fail ; require all pendants
LDA.l CrystalsField : AND.b #$7F : CMP.b #$7F : BNE .fail ; require all crystals
LDA.l OverworldEventDataWRAM+$5B : AND.b #$20 : BEQ .fail ; require aga2 defeated (pyramid hole open)
BRA .success
; 03 = crystals and aga 2
.crystals_and_aga
LDA.l OverworldEventDataWRAM+$5B : AND.b #$20 : BEQ .fail ; check aga2 first then bleed in
; 04 = crystals only
.crystals
JSL CheckEnoughCrystalsForGanon
RTS
; 05 = require goal item
.goal_item
REP #$20
LDA.l GoalCounter : CMP.l GoalItemRequirement
SEP #$20
RTS
; 06 = light speed
.light_speed
BRA .fail
; 07 = Crystals and bosses
.crystals_and_bosses
JSL CheckEnoughCrystalsForGanon ; check crystals first then bleed in to next
BCC .fail
; 08 = Crystal bosses but no crystals
.bosses_only
JMP CheckForCrystalBossesDefeated
;--------------------------------------------------------------------------------
GetRequiredCrystalsForTower:
BEQ + : JSL.l BreakTowerSeal_ExecuteSparkles : + ; thing we wrote over
LDA.l NumberOfCrystalsRequiredForTower : CMP.b #$00 : BNE + : JML.l Ancilla_BreakTowerSeal_stop_spawning_sparkles : +
LDA.l NumberOfCrystalsRequiredForTower : CMP.b #$01 : BNE + : JML.l Ancilla_BreakTowerSeal_draw_single_crystal : +
LDA.l NumberOfCrystalsRequiredForTower : DEC #2 : TAX
JML.l GetRequiredCrystalsForTower_continue
;--------------------------------------------------------------------------------
GetRequiredCrystalsInX:
LDA.l NumberOfCrystalsRequiredForTower : CMP.b #$00 : BNE +
TAX
RTL
+
TXA
- CMP.l NumberOfCrystalsRequiredForTower : BCC +
SBC.l NumberOfCrystalsRequiredForTower ; carry guaranteed set
BRA -
+ INC : CMP.l NumberOfCrystalsRequiredForTower : BNE +
LDA.b #$08
+ : DEC : TAX
RTL
;--------------------------------------------------------------------------------
CheckEnoughCrystalsForGanon:
LDA CrystalCounter
CMP.l NumberOfCrystalsRequiredForGanon
RTL
;--------------------------------------------------------------------------------
CheckEnoughCrystalsForTower:
LDA CrystalCounter
CMP.l NumberOfCrystalsRequiredForTower
RTL
;---------------------------------------------------------------------------------------------------
CheckAgaForPed:
LDA.l InvincibleGanon
CMP.b #$06 : BNE .vanilla
.light_speed
LDA.l OverworldEventDataWRAM+$80 ; check ped flag
AND.b #$40
BEQ .force_blue_ball
.vanilla ; run vanilla check for phase
LDA.w $0E30, X
CMP.b #$02
RTL
.force_blue_ball
LDA.b #$01 : STA.w $0DA0, Y
LDA.b #$20 : STA.w $0DF0, Y
CLC ; skip the RNG check
RTL
;---------------------------------------------------------------------------------------------------
KillGanon:
STA.l ProgressIndicator ; vanilla game state stuff we overwrote
LDA.l InvincibleGanon
CMP.b #$06 : BNE .exit
.light_speed
LDA.l OverworldEventDataWRAM+$5B : ORA.b #$20 : STA.l OverworldEventDataWRAM+$5B ; pyramid hole
LDA.b #$08 : STA.l RoomDataWRAM[$00].high ; kill ganon
LDA.b #$02 : STA.l MoonPearlEquipment ; pearl but invisible in menu
.exit
RTL
;---------------------------------------------------------------------------------------------------
CheckForCrystalBossesDefeated:
PHB : PHX : PHY
LDA.b #CrystalPendantFlags_2>>16
PHA : PLB
REP #$30
; count of number of bosses killed
STZ.b $00
LDY.w #10
.next_check
LDA.w CrystalPendantFlags_2-2,Y
BIT.w #$0040
BEQ ++
TYA
ASL
TAX
LDA.l DrawHUDDungeonItems_boss_room_ids-4,X
TAX
LDA.l RoomDataWRAM.l,X
AND.w #$0800
BEQ ++
INC.b $00
++ DEY
BPL .next_check
SEP #$30
PLY : PLX : PLB
LDA.b $00 : CMP.l NumberOfCrystalsRequiredForGanon
RTS