Last active
February 19, 2020 03:41
-
-
Save earthmeLon/1aa5a3e2df2f2e72242f7bdd43152acf to your computer and use it in GitHub Desktop.
Determine HEX values for various ASCII characters within Super Mario World.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# @earthmeLon | |
''' | |
Translate ASCII characters to Hex values which map to the same/similar char. | |
Otherwise: | |
$: Coin | |
@: Clock | |
*: Star | |
$ ./smwCharLut.py meLon | |
0x16 0xe 0x15 0x18 0x17 | |
These values can be used directly to adjust the Status Bar in RAM. | |
!smwedit 7E0EF9 0x16 0xe 0x15 0x18 0x17 | |
Within ROM, each character is followed by additional YXPPCCCT byte (ie: 0x28) | |
0x16 0x28 0xe 0x28 0x15 0x28 0x18 0x28 0x17 0x28 | |
Shoutout to SMWCentral.net | |
https://media.smwcentral.net/Diagrams/StatusBarMap.png | |
''' | |
import sys | |
LUT = [ | |
('0', '9', 0x00), | |
('A', 'Z', 0x0A), | |
('a', 'z', 0x0A) | |
] | |
SPECIAL_MAP = { | |
'.': '0x24', | |
',': '0x25', | |
'_': '0x27', | |
'!': '0x28', | |
'$': '0x2e', # Coin | |
' ': '0x72', | |
'@': '0x76', # Clock | |
'=': '0x77', | |
':': '0x78', | |
'\'': '0x85', | |
'"': '0x86', | |
'*': '0x87', # Star | |
} | |
def xlate_char(ichar): | |
for tlow, thigh, toffset in LUT: | |
if ord(ichar) >= ord(tlow) and ord(ichar) <= ord(thigh): | |
return hex((ord(ichar) - ord(tlow)) + toffset) | |
if (schar := SPECIAL_MAP.get(ichar)): | |
return schar | |
return '' | |
def xlate_str(istr): | |
splist = [] | |
for tchar in istr: | |
if (hexv := xlate_char(tchar)): | |
splist.append(hexv) | |
return splist | |
x = xlate_str(' '.join(sys.argv[1:])) | |
print(' '.join(x)) |
Author
earthmeLon
commented
Feb 6, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment