Skip to content

Commit

Permalink
Replace the console font with Terminus
Browse files Browse the repository at this point in the history
  • Loading branch information
9ary committed Dec 5, 2023
1 parent 8399f8e commit 05b327c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions buildtools/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
python = find_program('python3')
dol2ipl = [python, files('dol2ipl.py')]
psf2c = [python, files('psf2c.py')]

dol2gci = executable(
'dol2gci',
Expand Down
42 changes: 42 additions & 0 deletions buildtools/psf2c.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3

import sys

infile = sys.argv[1]
outfile = sys.argv[2]
symbol = sys.argv[3]

with open(infile, "rb") as f:
data = f.read()

# Magic word: PSF v1
assert data[:2] == b"\x36\x04"

flags = data[2]
height = data[3]

PSF1_MODE512 = 1 << 0
PSF1_MODEHASTAB = 1 << 1
PSF1_MODESEQ = 1 << 2
chars = 512 if flags & PSF1_MODE512 else 256
has_table = bool(flags & (PSF1_MODEHASTAB | PSF1_MODESEQ))

# Constrain the font a little
assert chars == 256
assert height == 16

data = data[4:]
glyphs = data[:chars * height]
directory = data[chars * height:]

with open(outfile, "w") as f:
f.write(f"unsigned char {symbol}[] = {{\n")
while glyphs:
glyph = glyphs[:height]
glyphs = glyphs[height:]
f.write(
" "
+ " ".join(f"{b:#04x}," for b in glyph)
+ "\n"
)
f.write("};\n")
8 changes: 8 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ version_file = vcs_tag(
output: 'version.c',
)

font = custom_target(
'font',
input: terminus,
output: 'font.c',
command: [psf2c, '@INPUT@', '@OUTPUT@', 'console_font_8x16'],
)

iplboot = executable(
'iplboot',
'source/main.c',
Expand All @@ -50,6 +57,7 @@ iplboot = executable(
'source/fatfs/ffunicode.c',
'source/ffshim.c',
version_file,
font,
dependencies: [
libogc_deps['ogc'],
stub_dep,
Expand Down
2 changes: 2 additions & 0 deletions res/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ summary(
)

qoob_sx_updater = files('qoob_sx_13c_upgrade.elf')

terminus = files('terminus-0.49.1-116b-ll2-td1.psf')
Binary file added res/terminus-0.49.1-116b-ll2-td1.psf
Binary file not shown.

0 comments on commit 05b327c

Please sign in to comment.