Created
November 29, 2020 22:03
-
-
Save nurpax/5057e9ef78c3dca215d16fe9a53c11c8 to your computer and use it in GitHub Desktop.
64c from C64 ROM font binary with some chars X'd out
This file contains 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
import numpy as np | |
import sys | |
# C64 ROM font: | |
# https://github.com/nurpax/petmate/raw/master/assets/system-charset.bin | |
unallowed_pattern = np.array([ | |
[1, 0, 0, 0, 0, 0, 1, 0], | |
[1, 1, 0, 0, 0, 1, 1, 0], | |
[0, 1, 1, 0, 1, 1, 0, 0], | |
[0, 0, 1, 1, 1, 0, 0, 0], | |
[0, 0, 1, 1, 1, 0, 0, 0], | |
[0, 1, 1, 0, 1, 1, 0, 0], | |
[1, 1, 0, 0, 0, 1, 1, 0], | |
[1, 0, 0, 0, 0, 0, 1, 0], | |
], dtype=np.uint8) | |
def main(): | |
if len(sys.argv) < 3: | |
print (f'Usage: {sys.argv[0]} <input rom font> <output.64c>') | |
sys.exit(1) | |
rom_font = np.fromfile(sys.argv[1], dtype=np.uint8) | |
rom_font = np.unpackbits(rom_font).reshape([-1,8,8]) | |
num_chars = rom_font.shape[0] | |
print (f'Loaded ROM font: {sys.argv[1]}, (size: {rom_font.shape[0]} chars)') | |
# Mark some characters as unallowed in DirArt -- overwrite | |
# their character bitmaps with an X pattern. | |
unallowed_chars = np.array([0, 1, 2, 10]) | |
rom_font[unallowed_chars] = unallowed_pattern | |
# Write a .64c file out. The format is basically just the character | |
# bits plus two bytes of header that says how many characters the | |
# font contains. | |
out_font = np.packbits(rom_font.reshape(-1)) | |
header = np.array([num_chars >> 8, num_chars & 255], dtype=np.uint8) | |
out_font = np.concatenate([header, out_font]) | |
out_font.tofile(sys.argv[2]) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment