1 |
2 |
idiolatrie |
#!/usr/bin/env python
|
2 |
|
|
#------------------------------------------------------------------------------#
|
3 |
|
|
# BDF character set to VHDL converter #
|
4 |
|
|
#------------------------------------------------------------------------------#
|
5 |
|
|
# Copyright (C) 2011 Mathias Hoertnagl, <mathias.hoertnagl@student.uibk.ac.at> #
|
6 |
|
|
# #
|
7 |
|
|
# This program is free software; you can redistribute it and/or modify it #
|
8 |
|
|
# under the terms of the GNU General Public License as published by the Free #
|
9 |
|
|
# Software Foundation; either version 3 of the License, or (at your option) #
|
10 |
|
|
# any later version. #
|
11 |
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
12 |
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
13 |
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
14 |
|
|
# more details. #
|
15 |
|
|
# You should have received a copy of the GNU General Public License along with #
|
16 |
|
|
# this program; if not, see <http://www.gnu.org/licenses/>. #
|
17 |
|
|
#------------------------------------------------------------------------------#
|
18 |
|
|
import sys
|
19 |
|
|
import string
|
20 |
|
|
|
21 |
|
|
if len(sys.argv) == 2:
|
22 |
|
|
|
23 |
|
|
inp = open(sys.argv[1], 'r')
|
24 |
|
|
outp = open('./rtl/rom.vhd', 'w')
|
25 |
|
|
|
26 |
|
|
i = 0
|
27 |
|
|
b = 0
|
28 |
|
|
|
29 |
|
|
outp.write('library ieee;\n')
|
30 |
|
|
outp.write('use ieee.std_logic_1164.all;\n')
|
31 |
|
|
outp.write('use ieee.numeric_std.all;\n\n')
|
32 |
|
|
|
33 |
|
|
outp.write('entity rom is\n')
|
34 |
|
|
outp.write(' port(\n')
|
35 |
|
|
outp.write(' clk : in std_logic;\n')
|
36 |
|
|
outp.write(' rom_addr : in std_logic_vector(11 downto 0);\n')
|
37 |
|
|
outp.write(' rom_word : out std_logic_vector(7 downto 0)\n')
|
38 |
|
|
outp.write(' );\n')
|
39 |
|
|
outp.write('end rom;\n\n')
|
40 |
|
|
|
41 |
|
|
outp.write('architecture rtl of rom is\n')
|
42 |
|
|
outp.write('begin\n')
|
43 |
|
|
outp.write(' chrs : process(clk)\n')
|
44 |
|
|
outp.write(' begin\n')
|
45 |
|
|
outp.write(' if rising_edge(clk) then\n')
|
46 |
|
|
outp.write(' case to_integer(unsigned(rom_addr)) is\n')
|
47 |
|
|
|
48 |
|
|
for l in inp:
|
49 |
|
|
l2 = string.strip(l)
|
50 |
|
|
if l2 == 'ENDCHAR':
|
51 |
|
|
b = 0
|
52 |
|
|
if b == 1:
|
53 |
|
|
if l2 != '00':
|
54 |
|
|
# Transform hex-string into 8bit zero padded bin-string without
|
55 |
|
|
# preceeding 'b0'.
|
56 |
|
|
s = bin(int(l2, 16))[2:].zfill(8)
|
57 |
|
|
# Reverse binary number. [not x(2 downto 0)]
|
58 |
|
|
s = s[::-1]
|
59 |
|
|
# Rotate binary number 2 digits to the right. [x(2 downto 0) - 2]
|
60 |
|
|
s = s[2:] + s[:2]
|
61 |
|
|
outp.write( ' ' )
|
62 |
|
|
outp.write( 'when %4d => rom_word <= "%8s";\n' % (i, s) )
|
63 |
|
|
i = i+1
|
64 |
|
|
if l2 == 'BITMAP':
|
65 |
|
|
b = 1
|
66 |
|
|
|
67 |
|
|
outp.write(' when others => rom_word <= X"00";\n')
|
68 |
|
|
outp.write(' end case;\n')
|
69 |
|
|
outp.write(' end if;\n')
|
70 |
|
|
outp.write(' end process;\n')
|
71 |
|
|
outp.write('end rtl;')
|
72 |
|
|
|
73 |
|
|
outp.close()
|
74 |
|
|
inp.close()
|
75 |
|
|
|
76 |
|
|
else:
|
77 |
|
|
print "Usage: python", sys.argv[0], "<*.bdf file>"
|