-
Notifications
You must be signed in to change notification settings - Fork 0
/
semiprogressive.asm
217 lines (192 loc) · 4.02 KB
/
semiprogressive.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
; Semiprogressive Swords/Armor
; Str/Def scales off of the number of Swords/Armors Obtained while unique effects are still tied to their respective item.
if not(defined("initialized"))
arch 65816
lorom
check title "SOULBLAZER - 1 USA "
!initialized = 1
endif
namespace SemiProgressive
; There is some space starting in $1FFC90 So lets put our hack there.
StartAddress = $1FFC9D
; At the time of writing, this file uses up to $1FFD67
; This should be enough extra space for any small changes without needing a major version bump.
EndAddress = $1FFD7F
org StartAddress
; New code section.
; Hook Into the drawing Function that draws Swords/Shields (and lots of other stuff too)
; Address to load is in A
DrawHook:
CMP #$0000
BEQ .weapon
CMP #$0001
BEQ .armor
; Not our magic numbers, run original code and return
TAY
LDA $0000,Y
RTL
.weapon
JSL CalcSwords
RTL
.armor
JSL CalcShields
RTL
GiveItemHook:
; Original Code that was replaced
DEY
STA.W $1B1E,Y
; Save register state to prevent softlocks when NPCs give items.
PHA
PHX
; This is a copy of the routine that sets STR/DEF after equiping a sword/armor
LDX $1B5E
JSL CalcStrength
STA $1B70
LDA.L $02E1BD,X
STA $1B74
LDX $1B60
LDA.L $02E1AC,X
CLC
ADC $1B70
STA $1B70
JSL CalcDefense
CLC
ADC $1B74
STA $1B74
PLX
PLA
RTL
; Calculates strength based off of the number of swords obtained
CalcStrength:
PHP
PHX
PHY
REP #$10
SEP #$20
LDA $1B5E ; Check current sword
BEQ .end ; Not Equipped = 0 Strength
LDY #$1B1E ; Address of Swords Inventory
JSL CountSwordArmor
TAX
LDA $02E1C5,X ; User the number of obtained swords as the index into the sword power table
.end:
PLY
PLX
PLP
RTL
; Like CalcStrength, but not a long subroutine and doesnt check equipped item
CalcSwords:
PHP
PHX
PHY
REP #$10
SEP #$20
LDY #$1B1E ; Address of Swords Inventory
JSL CountSwordArmor
TAX
LDA $02E1C5,X ; User the number of obtained swords as the index into the sword power table
PLY
PLX
PLP
RTL
; Calculates defense based off of the number of armors obtained
CalcDefense:
PHP
PHX
PHY
REP #$10
SEP #$20
LDA $1B60 ; Check current armor
BEQ .end ; Not Equipped = 0 Defense
LDY #$1B26 ; Address of Armor Inventory
JSL CountSwordArmor
TAX
LDA $02E1AC,X ; User the number of obtained armors as the index into the armor defense table
.end:
PLY
PLX
PLP
RTL
; Like CalcDefense, but not a long subroutine and doesnt check equipped item
CalcShields:
PHP
PHX
PHY
REP #$10
SEP #$20
LDY #$1B26 ; Address of Armor Inventory
JSL CountSwordArmor
TAX
LDA $02E1AC,X ; User the number of obtained armors as the index into the armor defense table
PLY
PLX
PLP
RTL
CountSwordArmor:
LDX #$0008 ; Loop 8 Times
LDA #$00 ; Number of counted items, in B
XBA
.loop:
LDA $0000,Y
AND #$7F ; Equipped items have the highest bit set
BEQ .skip
XBA
INC
XBA
.skip:
INY
DEX
BNE .loop
LDA #$00
XBA
RTL
; Hooks and original rom data overwrite section
pushpc
org $029EF0
JSL CalcStrength
org $029F0C
JSL CalcDefense
org $02A837
JSL DrawHook
org $02A105
JSL GiveItemHook
; Edit the Weapon Table to modify the strength pointers
org $02D60F
dw $0000
org $02D63C
dw $0000
org $02D67A
dw $0000
org $02D6A8
dw $0000
org $02D6EB
dw $0000
org $02D720
dw $0000
org $02D75D
dw $0000
org $02D79C
dw $0000
; Edit the Armor Table to modify the defense pointers
org $02D7CC
dw $0001
org $02D806
dw $0001
org $02D838
dw $0001
org $02D864
dw $0001
org $02D895
dw $0001
org $02D8CA
dw $0001
org $02D906
dw $0001
org $02D935
dw $0001
; Edit the Level Requirement Table (word, BCD)
org $02E1CE
dw $0001, $0001, $0001, $0001, $0001, $0001, $0001, $0001
pullpc
assert pc() <= EndAddress
namespace off