1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tools/makefont.py Tue May 30 00:07:29 2017 +0200
1.3 @@ -0,0 +1,154 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +Convert GNU Unifont format definitions into data statements for GNU as.
1.8 +
1.9 +Copyright (C) 2017 Paul Boddie <paul@boddie.org.uk>
1.10 +
1.11 +This program is free software; you can redistribute it and/or modify it under
1.12 +the terms of the GNU General Public License as published by the Free Software
1.13 +Foundation; either version 3 of the License, or (at your option) any later
1.14 +version.
1.15 +
1.16 +This program is distributed in the hope that it will be useful, but WITHOUT ANY
1.17 +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
1.18 +PARTICULAR PURPOSE. See the GNU General Public License for more details.
1.19 +
1.20 +You should have received a copy of the GNU General Public License along
1.21 +with this program. If not, see <http://www.gnu.org/licenses/>.
1.22 +"""
1.23 +
1.24 +from os.path import split
1.25 +import sys
1.26 +
1.27 +def convert_font(fin, fout, points, missing=32):
1.28 +
1.29 + """
1.30 + Convert the font obtained via 'fin' to an assembly language representation,
1.31 + writing to 'fout' the characters for the chosen sequence of 'points'.
1.32 +
1.33 + A table of offsets is written to permit each character to be found in the
1.34 + generated data.
1.35 +
1.36 + If 'missing' is specified, the character of the given value will be used
1.37 + for missing character data.
1.38 + """
1.39 +
1.40 + points.sort()
1.41 + base = points[0]
1.42 + limit = points[-1]
1.43 +
1.44 + # Store the offset of each chosen character.
1.45 +
1.46 + table = []
1.47 + offset = 0
1.48 +
1.49 + # Search for each character until no more remain to be found.
1.50 +
1.51 + index = 0
1.52 + end = len(points)
1.53 +
1.54 + print >>fout, """\
1.55 +.globl fontchars
1.56 +.globl fonttable
1.57 +.globl fontbase
1.58 +.globl fontlimit
1.59 +
1.60 +.section .flash, "a"
1.61 +
1.62 +fontchars:"""
1.63 +
1.64 + line = fin.readline()
1.65 +
1.66 + while line and index < end:
1.67 +
1.68 + # Obtain the code point and data.
1.69 +
1.70 + point, data = line.rstrip().split(":")
1.71 + point = int(point, 16)
1.72 +
1.73 + # Add null offsets for missing characters.
1.74 +
1.75 + i = len(table) + base
1.76 + while i < point:
1.77 + table.append(None)
1.78 + i += 1
1.79 +
1.80 + # Add a null offset for unselected characters.
1.81 +
1.82 + if point < points[index]:
1.83 + if point >= base:
1.84 + table.append(None)
1.85 + line = fin.readline()
1.86 + continue
1.87 +
1.88 + # Obtain the byte values from the data.
1.89 +
1.90 + bytes = []
1.91 + i = 0
1.92 + while i < len(data):
1.93 + bytes.append("0x%s" % data[i:i+2])
1.94 + i += 2
1.95 +
1.96 + # Add an offset for the character.
1.97 +
1.98 + table.append(offset)
1.99 + offset += len(bytes)
1.100 +
1.101 + # Write the character details.
1.102 +
1.103 + print >>fout, "/* %s */" % point
1.104 + print >>fout, ".byte", ", ".join(bytes)
1.105 +
1.106 + index += 1
1.107 + line = fin.readline()
1.108 +
1.109 + # Add a final offset to mark the end of the data.
1.110 +
1.111 + table.append(offset)
1.112 +
1.113 + # Write the offset table.
1.114 +
1.115 + print >>fout, """
1.116 +fonttable:"""
1.117 +
1.118 + for offset in table:
1.119 + if offset is None:
1.120 + offset = table[missing - base]
1.121 + print >>fout, ".word %d" % offset
1.122 +
1.123 + print >>fout, """
1.124 +fontbase:
1.125 +.byte %d
1.126 +
1.127 +fontlimit:
1.128 +.byte %d""" % (base, limit)
1.129 +
1.130 +# Main program.
1.131 +
1.132 +if __name__ == "__main__":
1.133 +
1.134 + # Test options.
1.135 +
1.136 + if "--help" in sys.argv or len(sys.argv) < 3:
1.137 + basename = split(sys.argv[0])[1]
1.138 + print >>sys.stderr, """\
1.139 +Usage:
1.140 +
1.141 +%s <input filename> <output filename>
1.142 +""" % basename
1.143 + sys.exit(1)
1.144 +
1.145 + base = 32
1.146 + points = range(32, 127)
1.147 +
1.148 + input_filename, output_filename = sys.argv[1:3]
1.149 + fin = open(input_filename)
1.150 + fout = open(output_filename, "w")
1.151 + try:
1.152 + convert_font(fin, fout, points, base)
1.153 + finally:
1.154 + fin.close()
1.155 + fout.close()
1.156 +
1.157 +# vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/tools/makeimage.py Sun May 28 23:11:05 2017 +0200
2.2 +++ b/tools/makeimage.py Tue May 30 00:07:29 2017 +0200
2.3 @@ -39,6 +39,12 @@
2.4
2.5 f = open(output_filename, "w")
2.6 try:
2.7 + print >>f, """\
2.8 +.globl screendata
2.9 +
2.10 +.section .flash, "a"
2.11 +"""
2.12 +
2.13 word = []
2.14 y = 0
2.15