Skip to content

Instantly share code, notes, and snippets.

@AreTillery
Last active May 30, 2021 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AreTillery/4e5969b99039ff79f00711606527a733 to your computer and use it in GitHub Desktop.
Save AreTillery/4e5969b99039ff79f00711606527a733 to your computer and use it in GitHub Desktop.
Find the spell costs at each level of Magic in a Zelda 2 ROM.
inputfile = r"path\to\ROM"
# Because ROM hacks might change the actual spells, I left out the names from the list, but here they are, along with vanilla costs:
"""
Vanilla costs:
Shield [32, 24, 24, 16, 16, 16, 16, 16]
Jump [48, 40, 32, 32, 20, 16, 12, 8]
Life [70, 70, 60, 60, 50, 50, 50, 50]
Fairy [80, 80, 60, 60, 40, 40, 40, 40]
Fire [120, 80, 60, 30, 16, 16, 16, 16]
Reflect [120, 120, 80, 48, 40, 32, 24, 16]
Spell [120, 112, 96, 80, 48, 32, 24, 16]
Thunder [120, 120, 120, 120, 120, 120, 100, 64]
"""
spells = list()
with open(inputfile, "rb") as fh:
fh.seek(0x0D8B) # The position of the spell cost table in the ROM
for i in range(8):
spell = list(fh.read(8))
# Mechanically, magic values are 0-255 instead of 0-128; divide internal number by 2 to get player-shown value
spell = [ord(i)/2 for i in spell]
spells.append(spell)
# Spells, in order, are now in the spells list (which is a list of lists, as a result).
for spell in spells:
print spell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment