Path: blob/master/Assets/Lua/NES/Super Mario Brothers 3 (USA) (Rev A).lua
2 views
-- Super Mario Bros. 3 (USA) Rev A collision box viewer V1.01-- For use with Bizhawk2-- Author: Pasky (June 22, 2015)3-- TODO:4-- Find coin and hidden block collisions56memory.usememorydomain("System Bus")78local camx9local camy1011local TOGGLE_MARIO = "ON"12local TOGGLE_OBJECTS = "ON" --Enemies etc...13local TOGGLE_PROJECTILES = "ON"14local TOGGLE_OTHERATTACKS = "ON" -- Tanooki tail etc...15local TOGGLE_UI = "ON"16local K1,K2,K3,K4,K5,K6171819function axis(x,y,color,size)20if size == nil then21size = 222end23gui.drawLine(x+size,y,x-size,y,color)24gui.drawLine(x,y+size,x,y-size,color)25gui.drawPixel(x,y,0xFF000000)26end272829local function camera()30camx = memory.read_u8(0xFD) + (memory.read_u8(0x12) * 0xFF)31camy = memory.read_u8(0xFC) + (memory.read_u8(0x12) * 0xFF)32end3334--Player35local function player()36if TOGGLE_MARIO == "ON" then37if memory.read_u8(0xD87F) == 0x20 and memory.read_u8(0xD880) == 0x7B and memory.read_u8(0xD881) == 0xD9 then -- Bank check (BANK #0)38local x = memory.read_u8(0xAB)39local y = memory.read_u8(0xB4)40local x1 = memory.read_u8(0x02)41local y1 = memory.read_u8(0x06)42local x2 = x1 + memory.read_u8(0x03)43local y2 = y1 + memory.read_u8(0x07)44gui.drawBox(x1,y1,x2,y2,0xFF0000FF,0x400000FF)45end46end47end4849--Enemies hit boxes50local function objects()51if TOGGLE_OBJECTS == "ON" then52if 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)53local xreg = emu.getregister("X")54local yreg = emu.getregister("Y")55local x = memory.read_u8(0xAC + xreg)56local y = memory.read_u8(0xB5 + xreg)57local x1 = memory.read_u8(0x00)58local y1 = memory.read_u8(0x04)59local x2 = x1 + memory.read_u8(0x01)60local y2 = y1 + memory.read_u8(0x05)61gui.drawBox(x1,y1,x2,y2,0xFFFF0000,0x40FF0000)62end63end64end6566--Projectiles67local function eprojectiles()68if TOGGLE_PROJECTILES == "ON" then69if memory.read_u8(0xB7E4) == 0xBD and memory.read_u8(0xB7E5) == 0xBF and memory.read_u8(0xB7E6) == 0x05 then -- Bank check (BANK #3)70local xreg = emu.getregister("X")71local yreg = emu.getregister("Y")72local x = bit.band(memory.read_u8(0x05C9 + xreg) - camx,0xFF) + 673local y = bit.band(memory.read_u8(0x05BF + xreg) - camy,0xFF) + 874axis(x,y,0xFFFFFFFF,4)7576local mx = memory.read_u8(0xAB)77local my = memory.read_u8(0xB4)78x1 = mx79y1 = my + memory.read_u8(0xB6DE + yreg)80x2 = x1 + 0x1081y2 = y1 + memory.read_u8(0xB6E0 + yreg)82gui.drawBox(x1,y1,x2,y2,0xFFFFFF00,0x40FFFF00)83end84end85end8687--Player Projectiles88local function projectiles()89if TOGGLE_PROJECTILES == "ON" then90if memory.read_u8(0xA69A) == 0xDD and memory.read_u8(0xA69B) == 0x6D and memory.read_u8(0xA69C) == 0xA6 then -- Bank check (BANK #3)91local xreg = emu.getregister("X")92local yreg = emu.getregister("Y")93local x = memory.read_u8(0xAC + yreg)94local y = memory.read_u8(0xB5 + yreg)95axis(memory.read_u8(0x0D),memory.read_u8(0x0C),0xFFFFFFFF,4)96local x1 = x97local y1 = y98local x2 = x1 + memory.read_u8(0xA67D + xreg)99local y2 = y1 + memory.read_u8(0xA66D + xreg)100gui.drawBox(x1,y1,x2,y2,0xFFFFFF00,0x40FFFF00)101end102end103end104105--Player Other Attacks106local function other()107if TOGGLE_OTHERATTACKS == "ON" then108if memory.read_u8(0xDB4E) == 0x20 and memory.read_u8(0xDB4F) == 0x54 and memory.read_u8(0xDB50) == 0xDD then -- Bank check (BANK #0)109--Tail110local x = memory.read_u8(0xAB)111local y = memory.read_u8(0xB4)112local x1 = memory.read_u8(0x02)113local y1 = memory.read_u8(0x06)114local x2 = x1 + memory.read_u8(0x03)115local y2 = y1 + memory.read_u8(0x07)116gui.drawBox(x1,y1,x2,y2)117118--Enemy vuln (tail)119local xreg = emu.getregister("X")120local yreg = bit.band(memory.read_u8(0xC2F4 + memory.read_u8(0x0671 + xreg)),0xF) * 4121x = memory.read_u8(0xAC + xreg)122y = memory.read_u8(0xB5 + xreg)123x1 = x + memory.read_u8(0xC2B4 + yreg)124y1 = y + memory.read_u8(0xC2B6 + yreg)125x2 = x1 + memory.read_u8(0xC2B5 + yreg)126y2 = y1 + memory.read_u8(0xC2B7 + yreg)127gui.drawBox(x1,y1,x2,y2,0xFFFFFF00,0x40FFFF00)128end129end130end131132local function toggle(option)133if option == "ON" then134option = "OFF"135else136option = "ON"137end138return option139end140141local function PowerCycle()142local powerup = memory.read_u8(0xED)143if powerup == 0x06 then144powerup = 0145else146powerup = powerup + 1147end148if powerup == 0x02 then149memory.write_u8(0x7D2,0x27)150memory.write_u8(0x7D4,0x16)151else152memory.write_u8(0x7D2,0x16)153memory.write_u8(0x7D4,0x0F)154end155memory.write_u8(0xED,powerup)156end157158local function check_inputs()159local inputs = input.get()160-- Mario boxes161if inputs["NumberPad1"] == true then162K1 = true163end164if inputs["NumberPad1"] == nil and K1 == true then -- Key released165TOGGLE_MARIO = toggle(TOGGLE_MARIO)166K1 = false167end168-- Enemy boxes169if inputs["NumberPad2"] == true then170K2 = true171end172if inputs["NumberPad2"] == nil and K2 == true then173TOGGLE_OBJECTS = toggle(TOGGLE_OBJECTS)174K2 = false175end176-- Projectile boxes177if inputs["NumberPad3"] == true then178K3 = true179end180if inputs["NumberPad3"] == nil and K3 == true then181TOGGLE_PROJECTILES = toggle(TOGGLE_PROJECTILES)182K3 = false183end184-- Other attacks185if inputs["NumberPad4"] == true then186K4 = true187end188if inputs["NumberPad4"] == nil and K4 == true then189TOGGLE_OTHERATTACKS = toggle(TOGGLE_OTHERATTACKS)190K4 = false191end192193-- UI194if inputs["Home"] == true then195K5 = true196end197if inputs["Home"] == nil and K5 == true then198TOGGLE_UI = toggle(TOGGLE_UI)199K5 = false200end201202--Powerup cycling203if inputs["Insert"] == true then204K6 = true205end206if inputs["Insert"] == nil and K6 == true then207PowerCycle()208K6 = false209end210end211212local function draw_UI()213check_inputs()214if TOGGLE_UI == "ON" then215gui.drawBox(154,30,255,92,0xFF000000,0xA0000000)216gui.drawText(156,28,"MARIO",0xFFFFFFFF,10,"Segoe UI")217gui.drawText(190,28,"(NUM1)",0xFFFF0000,10,"Segoe UI")218gui.drawText(226,28,"["..TOGGLE_MARIO.."]",0xFFFFFF00,10,"Segoe UI")219gui.drawText(156,38,"ENEMY",0xFFFFFFFF,10,"Segoe UI")220gui.drawText(226,38,"["..TOGGLE_OBJECTS.."]",0xFFFFFF00,10,"Segoe UI")221gui.drawText(190,38,"(NUM2)",0xFFFF0000,10,"Segoe UI")222gui.drawText(156,48,"PROJ.",0xFFFFFFFF,10,"Segoe UI")223gui.drawText(226,48,"["..TOGGLE_PROJECTILES.."]",0xFFFFFF00,10,"Segoe UI")224gui.drawText(190,48,"(NUM3)",0xFFFF0000,10,"Segoe UI")225gui.drawText(156,58,"OTHER",0xFFFFFFFF,10,"Segoe UI")226gui.drawText(226,58,"["..TOGGLE_OTHERATTACKS.."]",0xFFFFFF00,10,"Segoe UI")227gui.drawText(190,58,"(NUM4)",0xFFFF0000,10,"Segoe UI")228gui.drawText(156,68,"POWERUP",0xFFFFFFFF,10,"Segoe UI")229gui.drawText(214,68,"(INSERT)",0xFFFF0000,10,"Segoe UI")230gui.drawText(156,78,"TOGGLE UI",0xFFFFFFFF,10,"Segoe UI")231gui.drawText(214,78,"(HOME)",0xFFFF0000,10,"Segoe UI")232end233end234235event.onmemoryexecute(player,0xD87F)236event.onmemoryexecute(objects,0xD855)237event.onmemoryexecute(projectiles,0xA69A)238event.onmemoryexecute(eprojectiles,0xB7E4)239event.onmemoryexecute(other,0xDB4E)240241while true do242draw_UI()243camera()244emu.frameadvance()245end246247