Skip to content

Instantly share code, notes, and snippets.

@charasyn
Created December 15, 2024 18:21
Show Gist options
  • Save charasyn/a42c9a7a51aca7ed457862090e7290bf to your computer and use it in GitHub Desktop.
Save charasyn/a42c9a7a51aca7ed457862090e7290bf to your computer and use it in GitHub Desktop.
MOTHER2 flyover (12x12px) font extraction script
#!/usr/bin/env python3
# font experiment
NUM_GLYPHS = 313
GLYPH_SIZE_BYTE = 18
GLYPH_HEIGHT = 12
GLYPH_WIDTH = 12
PIXEL0 = '⬜'
PIXEL1 = '⬛'
with open(r"../Mother 2 - Gyiyg no Gyakushuu (Japan).sfc", 'rb') as f:
f.seek(0x210000)
fontdata = f.read(NUM_GLYPHS * GLYPH_SIZE_BYTE)
def getGlyphData(i: int) -> bytes:
return fontdata[i * GLYPH_SIZE_BYTE : (i+1) * GLYPH_SIZE_BYTE]
def outputBits(gfxData12Bits: int):
for _ in range(GLYPH_WIDTH):
char = PIXEL1 if gfxData12Bits & 0x800 else PIXEL0
print(char, end='')
gfxData12Bits <<= 1
print()
def renderGlyph(data: bytes):
for j in range(GLYPH_HEIGHT // 2):
# Every 3 bytes (8 * 3 = 24 bits) stores 2 rows of graphics data (12 * 2 = 24 bits)
# If we use ABCDEFGHIJKL for the top row, and a-l for the bottom row, the format is:
# Byte 0: ABCDEFGH
# Byte 1: IJKLabcd
# Byte 2: efghijkl
rowsData = data[j * 3 : (j + 1) * 3]
rowsInt = int.from_bytes(rowsData, 'big')
outputBits(rowsInt >> 12)
outputBits(rowsInt)
for i in range(NUM_GLYPHS):
renderGlyph(getGlyphData(i))
print('==' * GLYPH_WIDTH)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment