Powerup Selector

A lua script for Super Mario World (for SNES9X) that lets you modify the hexadecimal number for a powerup

--[[
  made by coolkase for SNES9X
  (this is a kinda old file and if it doesn't work send an email to hello@coolkase.dev)

  This work is licensed under a Creative Commons Attribution 4.0 International License.
]]--

local cooldown = 0
local hexcodes = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F}
local hexcodes_stringletters = {0,1,2,3,4,5,6,7,8,9,"A","B","C","D","E","F"}
local powerup_1 = 1
local powerup_2 = 1

print("How to use this: Down + Start edits the first hex letter. | Down + Select edits the second hex letter. | Down + R sets the player to the selected powerup. | Down + L sends the powerup data to the item reserve box. || Mushrooms will give you the powerup automatically.")

function checkJoypad()
    if cooldown <= 1 then
        cooldown = 0
    else
        cooldown = cooldown - 1
    end
    if joypad.getdown().down == true and joypad.getdown().start == true then
        if cooldown <= 0 then
            cooldown = 15
            if powerup_1 == 16 then
                powerup_1 = 1
            else
                powerup_1 = powerup_1 + 1
            end
            emu.message("New powerup is: 0x" .. hexcodes_stringletters[powerup_1] .. hexcodes_stringletters[powerup_2])
        end
    end
    if joypad.getdown().down == true and joypad.getdown().select == true then
        if cooldown <= 0 then
            cooldown = 15
            if powerup_2 == 16 then
                powerup_2 = 1
            else
                powerup_2 = powerup_2 + 1
            end
            emu.message("New powerup is: 0x" .. hexcodes_stringletters[powerup_1] .. hexcodes_stringletters[powerup_2])
        end
    end
    if joypad.getdown().down == true and joypad.getdown().R == true then
        memory.writebyte(0x7E0019, hexcodes[powerup_1] .. hexcodes[powerup_2])
        emu.message("Set player to selected powerup: 0x" .. hexcodes_stringletters[powerup_1] .. hexcodes_stringletters[powerup_2])
    end
    if joypad.getdown().down == true and joypad.getdown().L == true then
        memory.writebyte(0x7E0DC2, hexcodes[powerup_1] .. hexcodes[powerup_2])
        emu.message("Set players item reserve slot to selected powerup: 0x" .. hexcodes_stringletters[powerup_1] .. hexcodes_stringletters[powerup_2])
    end
end

while true do
    emu.frameadvance()
    checkJoypad()
    if memory.readbyte(0x7E0019) == 0x01 then
        memory.writebyte(0x7E0019, hexcodes[powerup_1] .. hexcodes[powerup_2])
    end
end