Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/Assets/Lua/PCE/Castlevania_Rondo_of_Blood.lua
2 views
1
--Castlevania: Rondo of Blood
2
3
fill = 0x64FFC8C8
4
line = 0xFFFFC8C8
5
6
function drawObjInfo()
7
8
for i = 0,88 do
9
10
objX = mainmemory.read_u8(0xBC8+i)
11
objY = mainmemory.read_u8(0xCD0+i)
12
objVisibleX = mainmemory.read_u8(0xB70+i)*255
13
objVisibleY = mainmemory.read_u8(0xC78+i)*255
14
objDamage = mainmemory.read_u8(0x1300+i) --how much damage it will do if it collides with you
15
objHealth = mainmemory.read_u8(0x12A8+i-2) --something is wrong, -2 makes it right in some cases but makes others wrong
16
objStatus = mainmemory.read_u8(0x1250+i) --collision status
17
adjustedX = objX - objVisibleX
18
adjustedY = objY - objVisibleY
19
--clipping
20
if(adjustedX > 0 and adjustedY > 0) then
21
gui.text(
22
adjustedX * xmult,
23
adjustedY * ymult,
24
objX
25
.. " " .. objY
26
-- .. " " .. "#" .. i
27
-- .. " D" .. objDamage
28
-- .. " HP" .. objHealth
29
-- .. " S" .. objStatus
30
)
31
end
32
end
33
end
34
35
function drawHitBoxes()
36
37
for i = 0,88 do
38
39
objX = mainmemory.read_u8(0xBC8+i)
40
objY = mainmemory.read_u8(0xCD0+i)
41
objVisibleX = mainmemory.read_u8(0xB70+i)*255
42
objVisibleY = mainmemory.read_u8(0xC78+i)*255
43
adjustedX = objX - objVisibleX
44
adjustedY = objY - objVisibleY
45
objOffsetX = mainmemory.read_u8(0x1930+i)
46
objDirection = mainmemory.read_u8(0xAC0+i)
47
objUnknownY = mainmemory.read_u8(0x19E0+i)
48
hitSizeX = mainmemory.read_u8(0x1988+i)
49
hitSizeY = mainmemory.read_u8(0x1A38+i)
50
51
if(objDirection == 1) then --9484
52
objOffsetX = bit.bxor(0xFF,objOffsetX) --9488
53
objOffsetX = objOffsetX+1 --948A
54
end
55
56
off00 = 0 --942B
57
if (bit.band(0x80, objOffsetX) == 128) then --942F
58
of00=bit.band(0xFF,(off00-1)) --9431
59
end
60
61
hitBoxCornerX = bit.band(0xFF,(objX + objOffsetX)) --9434
62
hitBoxCornerY = bit.band(0xFF,(objY + objUnknownY)) --944F
63
64
objStatus = mainmemory.read_u8(0x1250+i)-- generally: 0 inert, 1 benign, 2 damageable/possibly damaging
65
66
if(objStatus == 0) then
67
fill = 0x600000FF
68
line = 0xC0000000
69
elseif(objStatus == 1) then
70
fill = 0x3C00FF00
71
line = 0x8000FF00
72
elseif(objStatus == 2) then
73
fill = 0x50FF0000
74
line = 0x80FF0000
75
end
76
77
--clipping
78
if(adjustedX > 0 and adjustedY > 0) then
79
gui.drawBox(
80
hitBoxCornerX-hitSizeX,
81
hitBoxCornerY+hitSizeY,
82
hitBoxCornerX+hitSizeX,
83
hitBoxCornerY-hitSizeY,
84
line,
85
fill
86
)
87
end
88
end
89
end
90
91
function dispProperties(num)
92
93
fill = 0x80FFC8C8
94
95
ObjDamageInfo = {
96
0x13b0,--5 means is being damaged
97
0x1a90,--invulnerability countdown
98
0xf90,--if 0, animate. seems to be used as a counter to temporarily freeze objs when damaged
99
0xb18,--flashing if equal to 0x10, white if equal to 0x86
100
0x1ae8,
101
0x1f18,
102
0x11f8,
103
0x12a8--health
104
}
105
106
for i = 1,8 do
107
gui.text((10+(i*20)) * xmult ,100 * ymult, mainmemory.read_u8(ObjDamageInfo[i]+num))
108
end
109
110
hitBoxInfo = {
111
0x1988,
112
0x1A38,
113
0x1930,
114
0xAC0
115
}
116
117
for i = 1,4 do
118
gui.text((10+(i*20)) * xmult,120 * ymult, mainmemory.read_u8(hitBoxInfo[i]+num))
119
end
120
121
ObjPositionInfo = {
122
0xB70, --offscreen or not
123
0xBC8, --x position
124
0xC20,
125
0xC78,
126
0xCD0, --y position
127
0xD28,
128
}
129
130
for i = 1,6 do
131
gui.text((10+(i*20)) * xmult,140 * ymult, mainmemory.read_u8(ObjPositionInfo[i]+num))
132
end
133
134
collisionInfo = {
135
0x710, --compensated x
136
0x720, --compensated y
137
0x730 --compensated "visible"
138
}
139
140
for i = 1,3 do
141
gui.text((10+(i*20)) * xmult,160 * ymult, mainmemory.read_u8(collisionInfo[i]+num))
142
end
143
end
144
145
while true do
146
--Multiplier for text rendering
147
xmult = client.screenwidth() / 256
148
ymult = client.screenheight() / 225
149
line = 0xFFFFC8C8
150
--display info about a given object
151
--dispProperties(0)
152
153
drawHitBoxes()
154
drawObjInfo()
155
emu.frameadvance()
156
--invincibility cheat
157
-- memory.writebyte(0x13B0, 0)
158
159
end
160
161
--[[ Notes
162
163
--Object Damage
164
165
A1ED LDY $33B0,X ;"can damage"
166
A1F0 LDA $A26D,Y
167
A1F3 STA $3A90,X ;invulnerability countdown
168
A1F6 LDA $A27D,X
169
A1F9 STA $2F90,X ;whether to animate the obj or not
170
A1FC LDA $2B18,X ;flashing or not
171
A1FF STA $3AE8,X
172
A202 LDA #$86 ;make the palette white
173
A204 STA $2B18,X
174
A207 LDA $3F18,X
175
A20A ORA #$03
176
A20C STA $31F8,X
177
A20F LDA $32A8,X
178
A212 SEC
179
A213 SBC $00 ;subtract the amount of damage to do
180
A215 STA $32A8,X ;x is the object slot to modify
181
182
--Where the player's health is decremented
183
184
A1F2 LDA $33B0 ;check if the player is vulnerable
185
A1F5 BEQ $A234
186
A1F7 LDA $33B0
187
A1FA bit.band #$07
188
A1FC CMP #$05
189
A1FE BNE $A20B
190
A200 LDA $36D3
191
A203 BNE $A20B
192
A205 STZ $33B0
193
A20B LDA $98 ;player health
194
A20D SEC
195
A20E SBC $32A8 ;subtract amount of damage received
196
A211 STA $98
197
198
--Where the damage received (32A8) is set
199
200
9546 STA $33B0,X
201
9549 LDA $33B0
202
954C BNE $955A
203
954E LDA $3358,X
204
9551 STA $33B0
205
9554 LDA $3300,X ;the amount of damage an object will deal to you
206
9557 STA $32A8
207
208
--Where the hitbox offset is calculated
209
210
9413 LDX #$00
211
9415 LDA $3250,X ;load the hitbox type
212
9418 BEQ $9460 ;we quit if type 0
213
941A LDA $3930,X ;x offset
214
941D STA $01 ;store it in 01
215
941F LDA $2AC0,X ;direction facing, left is 1, right is 0
216
9422 BEQ $942B ;we are facing...
217
9424 LDA $01 ;left, load offset
218
9426 EOR #$FF
219
9428 INC
220
9429 STA $01 ;store the altered offset
221
942B STZ $00
222
942D LDA $01 ;get the either altered or unaltered offset
223
942F BPL $9433
224
9431 DEC $00
225
9433 CLC
226
9434 ADC $2BC8,X ;add x position to either altered or unaltered offset
227
9437 STA $2710,X ;store that as the hitbox corner
228
943A LDA $2B70,X ;is the object visible
229
943D ADC $00 ;correct it depending on the altered x offset
230
943F STA $2730,X
231
9442 STZ $00
232
9444 LDA $39E0,X
233
9447 BPL $944B
234
9449 DEC $00
235
944B LDA $2CD0,X ;y position
236
944E CLC
237
944F ADC $39E0,X
238
9452 STA $2720,X ;store hitbox y corner
239
9455 LDA $2C78,X ;indicator that the object is y visible
240
9458 ADC $00
241
945A ORA $2730,X
242
945D STA $2730,X
243
9460 INX
244
9461 CPX #$10 ;we can only do 16 objects
245
9463 BCC $9415 ;start again if we have objects left
246
9465 RTS
247
9466 STZ $33B0,X ;zero the "can damage" byte
248
9469 LDA $3250,X ;objStatus / collision status
249
946C BNE $9471 ;if the status is 0 we continue
250
946E JMP $9507 ;otherwise we quit
251
252
--X and Y represent our two objects
253
254
9471 LDA $3988,X ;x hitbox size
255
9474 ORA $3A38,X ;y hitbox size
256
9477 BNE $947C
257
9479 JMP $9507
258
947C LDA $3930,X ;x offset
259
947F STA $01
260
9481 LDA $2AC0,X ;objDirection
261
9484 BEQ $948D ;branch if we are facing right
262
9486 LDA $01 ;left
263
9488 EOR #$FF
264
948A INC
265
948B STA $01
266
948D STZ $00 ;right, zero our temp byte
267
948F LDA $01 ;load the possibly manipulated offset
268
9491 BPL $9495
269
9493 DEC $00
270
9495 CLC
271
9496 ADC $2BC8,X ;add object x position to the possibly manipulated offset
272
9499 STA $26FF
273
949C LDA $2B70,X ;objVisibleX
274
949F ADC $00
275
94A1 BNE $9507 ;quit if the result is non-zero
276
94A3 STZ $00
277
94A5 LDA $39E0,X ;y related
278
94A8 BPL $94AC
279
94AA DEC $00
280
94AC CLC
281
94AD ADC $2CD0,X ;obj y position
282
94B0 STA $2700
283
94B3 LDA $2C78,X ;objVisibleY
284
94B6 ADC $00
285
94B8 BNE $9507
286
94BA LDA $3250,X ;objStatus / collision status
287
94BD BPL $94C2
288
94BF CLY
289
94C0 BRA $94C4
290
94C2 LDY #$0F ;16 objects max
291
292
94C4 LDA $3250,Y ;objStatus / collision status
293
94C7 BEQ $9504 ;if objStatus is zero, go to the next object
294
94C9 LDA $2730,Y ;compensated "visible"
295
94CC BNE $9504
296
94CE LDA $3988,X ;x hitbox size of 1st object
297
94D1 CLC
298
94D2 ADC $3988,Y ;x hitbox size of 2nd object
299
94D5 STA $2701
300
94D8 LDA $3A38,X ;y hitbox size of 1st object
301
94DB CLC
302
94DC ADC $3A38,Y ;y hitbox size of 2nd object
303
94DF STA $2702
304
94E2 LDA $26FF
305
94E5 SEC
306
94E6 SBC $2710,Y ;subtract compensated x position for the current object
307
94E9 BCS $94EE
308
94EB EOR #$FF
309
94ED INC
310
94EE CMP $2701
311
94F1 BCS $9504
312
94F3 LDA $2700
313
94F6 SEC
314
94F7 SBC $2720,Y ;subtract compensated y position for the current object
315
94FA BCS $94FF
316
94FC EOR #$FF
317
94FE INC
318
94FF CMP $2702
319
9502 BCC $9508
320
9504 DEY
321
9505 BPL $94C4
322
9507 RTS
323
324
]]
325