Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/Assets/Lua/NES/Super Mario Brothers 3 (USA) (Rev A).lua
2 views
1
-- Super Mario Bros. 3 (USA) Rev A collision box viewer V1.0
2
-- For use with Bizhawk
3
-- Author: Pasky (June 22, 2015)
4
-- TODO:
5
-- Find coin and hidden block collisions
6
7
memory.usememorydomain("System Bus")
8
9
local camx
10
local camy
11
12
local TOGGLE_MARIO = "ON"
13
local TOGGLE_OBJECTS = "ON" --Enemies etc...
14
local TOGGLE_PROJECTILES = "ON"
15
local TOGGLE_OTHERATTACKS = "ON" -- Tanooki tail etc...
16
local TOGGLE_UI = "ON"
17
local K1,K2,K3,K4,K5,K6
18
19
20
function axis(x,y,color,size)
21
if size == nil then
22
size = 2
23
end
24
gui.drawLine(x+size,y,x-size,y,color)
25
gui.drawLine(x,y+size,x,y-size,color)
26
gui.drawPixel(x,y,0xFF000000)
27
end
28
29
30
local function camera()
31
camx = memory.read_u8(0xFD) + (memory.read_u8(0x12) * 0xFF)
32
camy = memory.read_u8(0xFC) + (memory.read_u8(0x12) * 0xFF)
33
end
34
35
--Player
36
local function player()
37
if TOGGLE_MARIO == "ON" then
38
if memory.read_u8(0xD87F) == 0x20 and memory.read_u8(0xD880) == 0x7B and memory.read_u8(0xD881) == 0xD9 then -- Bank check (BANK #0)
39
local x = memory.read_u8(0xAB)
40
local y = memory.read_u8(0xB4)
41
local x1 = memory.read_u8(0x02)
42
local y1 = memory.read_u8(0x06)
43
local x2 = x1 + memory.read_u8(0x03)
44
local y2 = y1 + memory.read_u8(0x07)
45
gui.drawBox(x1,y1,x2,y2,0xFF0000FF,0x400000FF)
46
end
47
end
48
end
49
50
--Enemies hit boxes
51
local function objects()
52
if TOGGLE_OBJECTS == "ON" then
53
if memory.read_u8(0xD855) == 0xA5 and memory.read_u8(0xD856) == 0xED and memory.read_u8(0xD857) == 0xF0 and memory.read_u8(0xD858) == 0x09 then -- Bank check (BANK #0)
54
local xreg = emu.getregister("X")
55
local yreg = emu.getregister("Y")
56
local x = memory.read_u8(0xAC + xreg)
57
local y = memory.read_u8(0xB5 + xreg)
58
local x1 = memory.read_u8(0x00)
59
local y1 = memory.read_u8(0x04)
60
local x2 = x1 + memory.read_u8(0x01)
61
local y2 = y1 + memory.read_u8(0x05)
62
gui.drawBox(x1,y1,x2,y2,0xFFFF0000,0x40FF0000)
63
end
64
end
65
end
66
67
--Projectiles
68
local function eprojectiles()
69
if TOGGLE_PROJECTILES == "ON" then
70
if memory.read_u8(0xB7E4) == 0xBD and memory.read_u8(0xB7E5) == 0xBF and memory.read_u8(0xB7E6) == 0x05 then -- Bank check (BANK #3)
71
local xreg = emu.getregister("X")
72
local yreg = emu.getregister("Y")
73
local x = bit.band(memory.read_u8(0x05C9 + xreg) - camx,0xFF) + 6
74
local y = bit.band(memory.read_u8(0x05BF + xreg) - camy,0xFF) + 8
75
axis(x,y,0xFFFFFFFF,4)
76
77
local mx = memory.read_u8(0xAB)
78
local my = memory.read_u8(0xB4)
79
x1 = mx
80
y1 = my + memory.read_u8(0xB6DE + yreg)
81
x2 = x1 + 0x10
82
y2 = y1 + memory.read_u8(0xB6E0 + yreg)
83
gui.drawBox(x1,y1,x2,y2,0xFFFFFF00,0x40FFFF00)
84
end
85
end
86
end
87
88
--Player Projectiles
89
local function projectiles()
90
if TOGGLE_PROJECTILES == "ON" then
91
if memory.read_u8(0xA69A) == 0xDD and memory.read_u8(0xA69B) == 0x6D and memory.read_u8(0xA69C) == 0xA6 then -- Bank check (BANK #3)
92
local xreg = emu.getregister("X")
93
local yreg = emu.getregister("Y")
94
local x = memory.read_u8(0xAC + yreg)
95
local y = memory.read_u8(0xB5 + yreg)
96
axis(memory.read_u8(0x0D),memory.read_u8(0x0C),0xFFFFFFFF,4)
97
local x1 = x
98
local y1 = y
99
local x2 = x1 + memory.read_u8(0xA67D + xreg)
100
local y2 = y1 + memory.read_u8(0xA66D + xreg)
101
gui.drawBox(x1,y1,x2,y2,0xFFFFFF00,0x40FFFF00)
102
end
103
end
104
end
105
106
--Player Other Attacks
107
local function other()
108
if TOGGLE_OTHERATTACKS == "ON" then
109
if memory.read_u8(0xDB4E) == 0x20 and memory.read_u8(0xDB4F) == 0x54 and memory.read_u8(0xDB50) == 0xDD then -- Bank check (BANK #0)
110
--Tail
111
local x = memory.read_u8(0xAB)
112
local y = memory.read_u8(0xB4)
113
local x1 = memory.read_u8(0x02)
114
local y1 = memory.read_u8(0x06)
115
local x2 = x1 + memory.read_u8(0x03)
116
local y2 = y1 + memory.read_u8(0x07)
117
gui.drawBox(x1,y1,x2,y2)
118
119
--Enemy vuln (tail)
120
local xreg = emu.getregister("X")
121
local yreg = bit.band(memory.read_u8(0xC2F4 + memory.read_u8(0x0671 + xreg)),0xF) * 4
122
x = memory.read_u8(0xAC + xreg)
123
y = memory.read_u8(0xB5 + xreg)
124
x1 = x + memory.read_u8(0xC2B4 + yreg)
125
y1 = y + memory.read_u8(0xC2B6 + yreg)
126
x2 = x1 + memory.read_u8(0xC2B5 + yreg)
127
y2 = y1 + memory.read_u8(0xC2B7 + yreg)
128
gui.drawBox(x1,y1,x2,y2,0xFFFFFF00,0x40FFFF00)
129
end
130
end
131
end
132
133
local function toggle(option)
134
if option == "ON" then
135
option = "OFF"
136
else
137
option = "ON"
138
end
139
return option
140
end
141
142
local function PowerCycle()
143
local powerup = memory.read_u8(0xED)
144
if powerup == 0x06 then
145
powerup = 0
146
else
147
powerup = powerup + 1
148
end
149
if powerup == 0x02 then
150
memory.write_u8(0x7D2,0x27)
151
memory.write_u8(0x7D4,0x16)
152
else
153
memory.write_u8(0x7D2,0x16)
154
memory.write_u8(0x7D4,0x0F)
155
end
156
memory.write_u8(0xED,powerup)
157
end
158
159
local function check_inputs()
160
local inputs = input.get()
161
-- Mario boxes
162
if inputs["NumberPad1"] == true then
163
K1 = true
164
end
165
if inputs["NumberPad1"] == nil and K1 == true then -- Key released
166
TOGGLE_MARIO = toggle(TOGGLE_MARIO)
167
K1 = false
168
end
169
-- Enemy boxes
170
if inputs["NumberPad2"] == true then
171
K2 = true
172
end
173
if inputs["NumberPad2"] == nil and K2 == true then
174
TOGGLE_OBJECTS = toggle(TOGGLE_OBJECTS)
175
K2 = false
176
end
177
-- Projectile boxes
178
if inputs["NumberPad3"] == true then
179
K3 = true
180
end
181
if inputs["NumberPad3"] == nil and K3 == true then
182
TOGGLE_PROJECTILES = toggle(TOGGLE_PROJECTILES)
183
K3 = false
184
end
185
-- Other attacks
186
if inputs["NumberPad4"] == true then
187
K4 = true
188
end
189
if inputs["NumberPad4"] == nil and K4 == true then
190
TOGGLE_OTHERATTACKS = toggle(TOGGLE_OTHERATTACKS)
191
K4 = false
192
end
193
194
-- UI
195
if inputs["Home"] == true then
196
K5 = true
197
end
198
if inputs["Home"] == nil and K5 == true then
199
TOGGLE_UI = toggle(TOGGLE_UI)
200
K5 = false
201
end
202
203
--Powerup cycling
204
if inputs["Insert"] == true then
205
K6 = true
206
end
207
if inputs["Insert"] == nil and K6 == true then
208
PowerCycle()
209
K6 = false
210
end
211
end
212
213
local function draw_UI()
214
check_inputs()
215
if TOGGLE_UI == "ON" then
216
gui.drawBox(154,30,255,92,0xFF000000,0xA0000000)
217
gui.drawText(156,28,"MARIO",0xFFFFFFFF,10,"Segoe UI")
218
gui.drawText(190,28,"(NUM1)",0xFFFF0000,10,"Segoe UI")
219
gui.drawText(226,28,"["..TOGGLE_MARIO.."]",0xFFFFFF00,10,"Segoe UI")
220
gui.drawText(156,38,"ENEMY",0xFFFFFFFF,10,"Segoe UI")
221
gui.drawText(226,38,"["..TOGGLE_OBJECTS.."]",0xFFFFFF00,10,"Segoe UI")
222
gui.drawText(190,38,"(NUM2)",0xFFFF0000,10,"Segoe UI")
223
gui.drawText(156,48,"PROJ.",0xFFFFFFFF,10,"Segoe UI")
224
gui.drawText(226,48,"["..TOGGLE_PROJECTILES.."]",0xFFFFFF00,10,"Segoe UI")
225
gui.drawText(190,48,"(NUM3)",0xFFFF0000,10,"Segoe UI")
226
gui.drawText(156,58,"OTHER",0xFFFFFFFF,10,"Segoe UI")
227
gui.drawText(226,58,"["..TOGGLE_OTHERATTACKS.."]",0xFFFFFF00,10,"Segoe UI")
228
gui.drawText(190,58,"(NUM4)",0xFFFF0000,10,"Segoe UI")
229
gui.drawText(156,68,"POWERUP",0xFFFFFFFF,10,"Segoe UI")
230
gui.drawText(214,68,"(INSERT)",0xFFFF0000,10,"Segoe UI")
231
gui.drawText(156,78,"TOGGLE UI",0xFFFFFFFF,10,"Segoe UI")
232
gui.drawText(214,78,"(HOME)",0xFFFF0000,10,"Segoe UI")
233
end
234
end
235
236
event.onmemoryexecute(player,0xD87F)
237
event.onmemoryexecute(objects,0xD855)
238
event.onmemoryexecute(projectiles,0xA69A)
239
event.onmemoryexecute(eprojectiles,0xB7E4)
240
event.onmemoryexecute(other,0xDB4E)
241
242
while true do
243
draw_UI()
244
camera()
245
emu.frameadvance()
246
end
247