forked from CaitSith2/z3randomizer
-
Notifications
You must be signed in to change notification settings - Fork 4
/
multiworld.asm
301 lines (263 loc) · 6.85 KB
/
multiworld.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
macro Print_Text(hdr, hdr_len, player_id)
PHX : PHY : PHP
REP #$30
LDX #$0000
-
CPX <hdr_len> : !BGE ++
LDA <hdr>, X
STA !MULTIWORLD_HUD_CHARACTER_DATA, X
INX #2
BRA -
++
LDY <hdr_len>
LDA <player_id>
AND #$00FF
DEC
CMP #$00FF : !BGE .textdone
ASL #5
TAX
-
CPY <hdr_len>+$20 : !BGE ++
LDA PlayerNames, X
PHX : TYX : STA !MULTIWORLD_HUD_CHARACTER_DATA, X : PLX
INX #2 : INY #2
BRA -
++
TYX
-
CPX #$0040 : !BGE ++
LDA #$007F
STA !MULTIWORLD_HUD_CHARACTER_DATA, X
INX #2
BRA -
++
SEP #$20
LDA #$01 : STA !NMI_AUX+1 : STA !NMI_AUX
LDA !MULTIWORLD_HUD_DELAY
STA !MULTIWORLD_HUD_TIMER
.textdone
PLP : PLY : PLX
endmacro
WriteText:
{
PHA : PHX : PHP
SEP #$10
LDX $4340 : PHX ; preserve DMA parameters
LDX $4341 : PHX ; preserve DMA parameters
LDX $4342 : PHX ; preserve DMA parameters
LDX $4343 : PHX ; preserve DMA parameters
LDX $4344 : PHX ; preserve DMA parameters
LDX $4345 : PHX ; preserve DMA parameters
LDX $4346 : PHX ; preserve DMA parameters
LDX $2115 : PHX ; preserve DMA parameters
LDX $2116 : PHX ; preserve DMA parameters
LDX $2117 : PHX ; preserve DMA parameters
LDX $2100 : PHX : LDX.b #$80 : STX $2100 ; save screen state & turn screen off
REP #$20
LDX #$80 : STX $2115
LDA #$6000+$0340 : STA $2116
LDA.w #!MULTIWORLD_HUD_CHARACTER_DATA : STA $4342
LDX.b #!MULTIWORLD_HUD_CHARACTER_DATA>>16 : STX $4344
LDA #$0040 : STA $4345
LDA #$1801 : STA $4340
LDX #$10 : STX $420B
PLX : STX $2100 ; put screen back however it was before
PLX : STX $2117 ; restore DMA parameters
PLX : STX $2116 ; restore DMA parameters
PLX : STX $2115 ; restore DMA parameters
PLX : STX $4346 ; restore DMA parameters
PLX : STX $4345 ; restore DMA parameters
PLX : STX $4344 ; restore DMA parameters
PLX : STX $4343 ; restore DMA parameters
PLX : STX $4342 ; restore DMA parameters
PLX : STX $4341 ; restore DMA parameters
PLX : STX $4340 ; restore DMA parameters
PLP : PLX : PLA
RTL
}
GetMultiworldItem:
{
PHP
LDA !MULTIWORLD_ITEM : BNE +
LDA !MULTIWORLD_HUD_TIMER : BNE +
BRL .return
+
LDA $10
CMP #$07 : BEQ +
CMP #$09 : BEQ +
CMP #$0B : BEQ +
BRL .return
+
LDA !MULTIWORLD_HUD_TIMER : BEQ .textend
DEC #$01 : STA !MULTIWORLD_HUD_TIMER
CMP #$00 : BNE .textend
; Clear text
PHP : REP #$30
LDX #$0000
-
CPX #$0040 : !BGE ++
LDA #$007F
STA !MULTIWORLD_HUD_CHARACTER_DATA, X
INX #2
BRA -
++
PLP
LDA #$01 : STA !NMI_AUX+1 : STA !NMI_AUX
.textend
LDA $5D
CMP #$00 : BEQ +
CMP #$04 : BEQ +
CMP #$17 : BEQ +
BRL .return
+
LDA !MULTIWORLD_ITEM : BNE +
BRL .return
+
PHA
LDA #$22
LDY #$04
JSL Ancilla_CheckForAvailableSlot : BPL +
PLA
BRL .return
+
PLA
; Check if we have a key for the dungeon we are currently in
LDX $040C
; Escape
CMP #$A0 : BNE + : CPX #$00 : BEQ ++ : CPX #$02 : BEQ ++ : BRL .keyend : ++ : BRL .thisdungeon : +
; Eastern
CMP #$A2 : BNE + : CPX #$04 : BEQ .thisdungeon : BRA .keyend : +
; Desert
CMP #$A3 : BNE + : CPX #$06 : BEQ .thisdungeon : BRA .keyend : +
; Hera
CMP #$AA : BNE + : CPX #$14 : BEQ .thisdungeon : BRA .keyend : +
; Aga
CMP #$A4 : BNE + : CPX #$08 : BEQ .thisdungeon : BRA .keyend : +
; PoD
CMP #$A6 : BNE + : CPX #$0C : BEQ .thisdungeon : BRA .keyend : +
; Swamp
CMP #$A5 : BNE + : CPX #$0A : BEQ .thisdungeon : BRA .keyend : +
; SW
CMP #$A8 : BNE + : CPX #$10 : BEQ .thisdungeon : BRA .keyend : +
; TT
CMP #$AB : BNE + : CPX #$16 : BEQ .thisdungeon : BRA .keyend : +
; Ice
CMP #$A9 : BNE + : CPX #$12 : BEQ .thisdungeon : BRA .keyend : +
; Mire
CMP #$A7 : BNE + : CPX #$0E : BEQ .thisdungeon : BRA .keyend : +
; TR
CMP #$AC : BNE + : CPX #$18 : BEQ .thisdungeon : BRA .keyend : +
; GT
CMP #$AD : BNE + : CPX #$1A : BEQ .thisdungeon : BRA .keyend : +
; GT BK
CMP #$92 : BNE .keyend : CPX #$1A : BNE .keyend : LDA #$32 : BRA .keyend
.thisdungeon
LDA #$24
.keyend
STA $02D8 ;Set Item to receive
TAY
LDA #$01 : STA !MULTIWORLD_RECEIVING_ITEM
LDA #$00 : STA !MULTIWORLD_ITEM_PLAYER_ID
STZ $02E9
JSL.l $0791B3 ; Player_HaltDashAttackLong
JSL Link_ReceiveItem
LDA #$00 : STA !MULTIWORLD_ITEM : STA !MULTIWORLD_RECEIVING_ITEM
%Print_Text(HUD_ReceivedFrom, #$001C, !MULTIWORLD_ITEM_FROM)
.return
PLP
LDA $5D : ASL A : TAX
RTL
}
Multiworld_OpenKeyedObject:
{
PHP
SEP #$20
LDA ChestData_Player+2, X : STA !MULTIWORLD_ITEM_PLAYER_ID
PLP
LDA !Dungeon_ChestData+2, X ; thing we wrote over
RTL
}
Multiworld_BottleVendor_GiveBottle:
{
PHA : PHP
SEP #$20
%GetPossiblyEncryptedItem(BottleMerchant, SpriteItemValues)
TAY
%GetPossiblyEncryptedPlayerID(BottleMerchant_Player)
STA !MULTIWORLD_ITEM_PLAYER_ID
PLP : PLA
JSL Link_ReceiveItem ; thing we wrote over
RTL
}
Multiworld_MiddleAgedMan_ReactToSecretKeepingResponse:
{
PHA : PHP
SEP #$20
%GetPossiblyEncryptedItem(PurpleChest_Item, SpriteItemValues)
TAY
%GetPossiblyEncryptedPlayerID(PurpleChest_Item_Player)
STA !MULTIWORLD_ITEM_PLAYER_ID
PLP : PLA
JSL Link_ReceiveItem ; thing we wrote over
RTL
}
Multiworld_Hobo_GrantBottle:
{
PHA : PHP
SEP #$20
%GetPossiblyEncryptedItem(HoboItem, SpriteItemValues)
TAY
%GetPossiblyEncryptedPlayerID(HoboItem_Player)
STA !MULTIWORLD_ITEM_PLAYER_ID
PLP : PLA
JSL Link_ReceiveItem ; thing we wrote over
RTL
}
Multiworld_MasterSword_GrantToPlayer:
{
PHA : PHP
SEP #$20
%GetPossiblyEncryptedItem(PedestalSword, SpriteItemValues)
TAY
%GetPossiblyEncryptedPlayerID(PedestalSword_Player)
STA !MULTIWORLD_ITEM_PLAYER_ID : CMP #$00 : BNE + ; If the triforce is for another player, pedestal can stay pulled.
LDA $0589B0 : CMP #$6A : BNE + ; If the item is not triforce, the pedestal can stay pulled.
LDA InvincibleGanon : CMP #$06 : BNE + ; If the goal is pedestal ganon, then pedestal remains pulled, even though this pull caused a win.
LDA $7EF300 : AND #$BF : STA $7EF300 ; Otherwise, reset the pedestal so that it can be pulled again after the full credit roll.
+
PLP : PLA
JSL Link_ReceiveItem ; thing we wrote over
RTL
}
Multiworld_AddReceivedItem_notCrystal:
{
TYA : STA $02E4 : PHX ; things we wrote over
LDA !MULTIWORLD_ITEM_PLAYER_ID : BEQ +
PHY : LDY $02D8 : JSL AddInventory : PLY
%Print_Text(HUD_SentTo, #$0010, !MULTIWORLD_ITEM_PLAYER_ID)
LDA #$33 : STA $012F
JML.l AddReceivedItem_gfxHandling
+
JML.l AddReceivedItem_notCrystal+5
}
Multiworld_Ancilla_ReceiveItem_stillInMotion:
{
CMP.b #$28 : BNE + ; thing we wrote over
LDA !MULTIWORLD_ITEM_PLAYER_ID : BNE +
JML.l Ancilla_ReceiveItem_stillInMotion_moveon
+
JML.l Ancilla_ReceiveItem_dontGiveRupees
}
Multiworld_ConsumingFire_TransmuteToSkullWoodsFire:
{
LDA $8A : AND.b #$40 : BEQ .failed ; things we wrote over
LDA $0C4A : CMP #$22 : BEQ .failed
LDA $0C4B : CMP #$22 : BEQ .failed
LDA $0C4C : CMP #$22 : BEQ .failed
LDA $0C4D : CMP #$22 : BEQ .failed
LDA $0C4E : CMP #$22 : BEQ .failed
LDA $0C4F : CMP #$22 : BEQ .failed
JML.l ConsumingFire_TransmuteToSkullWoodsFire_continue
.failed
JML.l AddDoorDebris_spawn_failed
}