Skip to content

Instantly share code, notes, and snippets.

@shirriff
Created April 4, 2018 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shirriff/07fbaf6d852ff9b7485e15a23e38d67a to your computer and use it in GitHub Desktop.
Save shirriff/07fbaf6d852ff9b7485e15a23e38d67a to your computer and use it in GitHub Desktop.
Generate FPGA code to implement a character set
# 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]
print
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