Created
April 4, 2018 03:36
-
-
Save shirriff/a8adf62019cc9b90bc6ccfe35ad3c51c to your computer and use it in GitHub Desktop.
Generate FPGA code to implement a character set
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
# Process font file to generate FPGA code | |
# Font from https://github.com/dhepper/font8x8/blob/master/font8x8_basic.h | |
import re | |
chars = [] | |
for line in open('font8x8_basic.h').readlines(): | |
m = re.search('{([\s0-9A-Fa-fx,]*)}', line) | |
if m: | |
chars.append([int(x, 16) for x in m.group(1).split(',')]) | |
# The characters to output | |
cset = "0123456789BFiuz" | |
for cnum in range(0, len(cset)): | |
ch = cset[cnum] | |
for row in range(0, 8): | |
bits = ('{:08b}'.format(chars[ord(ch)][row]))[::-1] | |
case = '{:04b}{:03b}'.format(cnum, row) | |
print ' 7\'b%s: pixels = 8\'b%s; // %s' % (case, bits, bits.replace('1', 'X').replace('0', ' ')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment