forked from KatDevsGames/z3randomizer
-
Notifications
You must be signed in to change notification settings - Fork 6
/
newhud.asm
268 lines (241 loc) · 8.76 KB
/
newhud.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
NewDrawHud:
SEP #$30
;================================================================================
; Draw bomb count
!BOMBCOUNT_DRAW_ADDRESS = "$7EC75A"
!INFINITE_BOMBS = "$7F50C9"
;================================================================================
LDA !INFINITE_BOMBS : BNE .infinite_bombs
.finite_bombs
LDA.l $7EF343 ; bombs
JSR HudHexToDec2Digit ;requires 8 bit registers!
REP #$20
LDX.b $06 : TXA : ORA.w #$2400 : STA !BOMBCOUNT_DRAW_ADDRESS ; Draw bombs 10 digit
LDX.b $07 : TXA : ORA.w #$2400 : STA !BOMBCOUNT_DRAW_ADDRESS+2 ; Draw bombs 1 digit
BRA +
.infinite_bombs
REP #$20
LDA.w #$2431 : STA !BOMBCOUNT_DRAW_ADDRESS ; infinity (left half)
INC A : STA !BOMBCOUNT_DRAW_ADDRESS+2 ; infinity (right half)
+
;================================================================================
; Draw rupee counter
!RUPEE_DRAW_ADDRESS = "$7EC750"
;================================================================================
LDA.l $7EF362 ; Drawing bombs (above) always ends with 16-bit A, so, no need to REP here
JSR HudHexToDec4Digit
LDX.b $04 : TXA : ORA.w #$2400 : STA !RUPEE_DRAW_ADDRESS ; 1000s
LDX.b $05 : TXA : ORA.w #$2400 : STA !RUPEE_DRAW_ADDRESS+2 ; 100s
LDX.b $06 : TXA : ORA.w #$2400 : STA !RUPEE_DRAW_ADDRESS+4 ; 10s
LDX.b $07 : TXA : ORA.w #$2400 : STA !RUPEE_DRAW_ADDRESS+6 ; 1s
;================================================================================
; Draw arrow count
!ARROWCOUNT_DRAW_ADDRESS = "$7EC760"
!INFINITE_ARROWS = "$7F50C8"
;================================================================================
SEP #$20
LDA.l ArrowMode : BNE +
LDA !INFINITE_ARROWS : BNE .infinite_arrows
.finite_arrows
LDA.l $7EF377 ; arrows
JSR HudHexToDec2Digit
REP #$20
LDX.b $06 : TXA : ORA.w #$2400 : STA !ARROWCOUNT_DRAW_ADDRESS ; Draw arrows 10 digit
LDX.b $07 : TXA : ORA.w #$2400 : STA !ARROWCOUNT_DRAW_ADDRESS+2 ; Draw arrows 1 digit
BRA +
.infinite_arrows
REP #$20
LDA.w #$2431 : STA !ARROWCOUNT_DRAW_ADDRESS ; infinity (left half)
INC A : STA !ARROWCOUNT_DRAW_ADDRESS+2 ; infinity (right half)
+
;================================================================================
; Draw Goal Item Indicator
!GOAL_ELDER = "$7EF41A"
!GOAL_COUNTER = "$7EF418"
!GOAL_DRAW_ADDRESS = "$7EC72A"
;================================================================================
REP #$20
LDA.l !GOAL_ELDER : AND.w #$FF : BNE +
LDA.l GoalItemFlags : AND.w #$0001 : BEQ + ; check flag for hide until get triforce piece
LDA.l !GOAL_COUNTER : BNE + : BRL .done : + ; if zero, skip hud writing
LDA.l GoalItemRequirement : BNE + : BRL .done : + ; Star Meter
LDA.l !GOAL_COUNTER
JSR HudHexToDec4Digit
LDA.l GoalItemIcon : STA !GOAL_DRAW_ADDRESS ; draw star icon
LDX.b $05 : TXA : ORA.w #$2400 : STA !GOAL_DRAW_ADDRESS+2 ; draw 100's digit
LDX.b $06 : TXA : ORA.w #$2400 : STA !GOAL_DRAW_ADDRESS+4 ; draw 10's digit
LDX.b $07 : TXA : ORA.w #$2400 : STA !GOAL_DRAW_ADDRESS+6 ; draw 1's digit
LDA.l !GOAL_ELDER : AND.w #$FF : BNE .show_total
LDA.l GoalItemFlags : AND.w #$0002 : BNE .skip
.show_total
LDA.l GoalItemRequirement : CMP #$FFFF : BEQ .skip
LDA.l GoalItemRequirement
JSR HudHexToDec4Digit
LDA.w #$2830 : STA !GOAL_DRAW_ADDRESS+8 ; draw slash
LDX.b $05 : TXA : ORA.w #$2400 : STA !GOAL_DRAW_ADDRESS+10 ; draw 100's digit
LDX.b $06 : TXA : ORA.w #$2400 : STA !GOAL_DRAW_ADDRESS+12 ; draw 10's digit
LDX.b $07 : TXA : ORA.w #$2400 : STA !GOAL_DRAW_ADDRESS+14 ; draw 1's digit
BRA .done
.skip
LDA.w #$207F ; transparent tile
STA !GOAL_DRAW_ADDRESS+8
STA !GOAL_DRAW_ADDRESS+10
STA !GOAL_DRAW_ADDRESS+12
STA !GOAL_DRAW_ADDRESS+14
.done
SEP #$20
;================================================================================
; Draw Dungeon Compass Counts
;================================================================================
REP #$20
LDA.l CompassMode : AND #$00FF : BEQ + ; skip if CompassMode is 0.
JSL.l DrawDungeonCompassCounts ; compasses.asm
+
;================================================================================
; Draw key count
!KEYS = "$7EF36F"
!KEY_DIGITS_ADDRESS = "$7EC764"
!KEY_ICON_ADDRESS = "$7EC726"
;================================================================================
SEP #$20
LDA.l !KEYS : CMP.b #$FF : BEQ .not_in_dungeon
.in_dungeon
JSR HudHexToDec2Digit : REP #$20
; if 10s digit is 0, draw transparent tile instead of 0
LDX.b $06 : TXA : CPX.b #$90 : BNE +
LDA.w #$007F
+
ORA.w #$2400 : STA !KEY_DIGITS_ADDRESS
; 1s digit
LDX.b $07 : TXA : ORA.w #$2400 : STA !KEY_DIGITS_ADDRESS+2
BRA .done_keys
.not_in_dungeon
REP #$20
;in the overworld, draw transparent tiles instead of key count
LDA.w #$247F : STA !KEY_DIGITS_ADDRESS : STA !KEY_DIGITS_ADDRESS+2
STA !KEY_ICON_ADDRESS
.done_keys
;--------------------------------------------------------------------------------
; Draw Magic Meter
!INFINITE_MAGIC = "$7F50CA"
!DrawMagicMeter_mp_tilemap = "$0DFE0F"
;--------------------------------------------------------------------------------
LDA $7EF36E : AND #$00FF ; crap we wrote over when placing the hook for OnDrawHud
!ADD #$0007
AND #$FFF8
TAX ; end of crap
LDA !INFINITE_MAGIC : AND.w #$00FF : BNE + : BRL .green : +
SEP #$20 : LDA.b #$80 : STA $7EF36E : REP #$30 ; set magic to max
LDX.w #$0080 ; load full magic meter graphics
LDA $1A : AND.w #$000C : LSR #2
BEQ .red
CMP.w #0001 : BEQ .yellow
CMP.w #0002 : BNE + : BRL .green : +
.blue
LDA !DrawMagicMeter_mp_tilemap+0, X : AND.w #$EFFF : STA $7EC746
LDA !DrawMagicMeter_mp_tilemap+2, X : AND.w #$EFFF : STA $7EC786
LDA !DrawMagicMeter_mp_tilemap+4, X : AND.w #$EFFF : STA $7EC7C6
LDA !DrawMagicMeter_mp_tilemap+6, X : AND.w #$EFFF : STA $7EC806
RTL
.red
LDA !DrawMagicMeter_mp_tilemap+0, X : AND.w #$E7FF : STA $7EC746
LDA !DrawMagicMeter_mp_tilemap+2, X : AND.w #$E7FF : STA $7EC786
LDA !DrawMagicMeter_mp_tilemap+4, X : AND.w #$E7FF : STA $7EC7C6
LDA !DrawMagicMeter_mp_tilemap+6, X : AND.w #$E7FF : STA $7EC806
RTL
.yellow
LDA !DrawMagicMeter_mp_tilemap+0, X : AND.w #$EBFF : STA $7EC746
LDA !DrawMagicMeter_mp_tilemap+2, X : AND.w #$EBFF : STA $7EC786
LDA !DrawMagicMeter_mp_tilemap+4, X : AND.w #$EBFF : STA $7EC7C6
LDA !DrawMagicMeter_mp_tilemap+6, X : AND.w #$EBFF : STA $7EC806
RTL
.orange
LDA !DrawMagicMeter_mp_tilemap+0, X : AND.w #$E3FF : STA $7EC746
LDA !DrawMagicMeter_mp_tilemap+2, X : AND.w #$E3FF : STA $7EC786
LDA !DrawMagicMeter_mp_tilemap+4, X : AND.w #$E3FF : STA $7EC7C6
LDA !DrawMagicMeter_mp_tilemap+6, X : AND.w #$E3FF : STA $7EC806
RTL
.green
LDA !DrawMagicMeter_mp_tilemap+0, X : STA $7EC746
LDA !DrawMagicMeter_mp_tilemap+2, X : STA $7EC786
LDA !DrawMagicMeter_mp_tilemap+4, X : STA $7EC7C6
LDA !DrawMagicMeter_mp_tilemap+6, X : STA $7EC806
RTL
;================================================================================
; 16-bit A, 8-bit X
; in: A(b) - Byte to Convert
; out: $04 - $07 (high - low)
;================================================================================
HudHexToDec4Digit:
LDY.b #$90
-
CMP.w #1000 : !BLT +
INY
SBC.w #1000 : BRA -
+
STY $04 : LDY #$90 ; Store 1000s digit & reset Y
-
CMP.w #100 : !BLT +
INY
SBC.w #100 : BRA -
+
STY $05 : LDY #$90 ; Store 100s digit & reset Y
-
CMP.w #10 : !BLT +
INY
SBC.w #10 : BRA -
+
STY $06 : LDY #$90 ; Store 10s digit & reset Y
CMP.w #1 : !BLT +
-
INY
DEC : BNE -
+
STY $07 ; Store 1s digit
RTS
;================================================================================
; 8-bit registers
; in: A(b) - Byte to Convert
; out: $05 - $07 (high - low)
;================================================================================
HudHexToDec3Digit: ; this may be overkill, could have used the 4 digit one...
LDY.b #$90
-
CMP.b #100 : !BLT +
INY
SBC.b #100 : BRA -
+
STY $05 : LDY.b #$90 ; Store 100s digit and reset Y
-
CMP.b #10 : !BLT +
INY
SBC.b #10 : BRA -
+
STY $06 : LDY #$90 ; Store 10s digit and reset Y
CMP.b #1 : !BLT +
-
INY
DEC : BNE -
+
STY $07 ; Store 1s digit
RTS
;================================================================================
; 8-bit registers
; in: A(b) - Byte to Convert
; out: $06 - $07 (high - low)
;================================================================================
HudHexToDec2Digit:
LDY.b #$90
-
CMP.b #10 : !BLT +
INY
SBC.b #10 : BRA -
+
STY $06 : LDY #$90 ; Store 10s digit and reset Y
CMP.b #1 : !BLT +
-
INY
DEC : BNE -
+
STY $07 ; Store 1s digit
RTS