OpenCores
URL https://opencores.org/ocsvn/z80soc/z80soc/trunk

Subversion Repositories z80soc

[/] [z80soc/] [trunk/] [V0.7.3/] [Software/] [C/] [bin/] [hex2romvhdl.sh] - Blame information for rev 46

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 46 rrred
#!/bin/sh
2
# hex2romvhdl.sh
3
# By: Ronivon Candido Costa - ronivon.costa@gmail.com
4
# 2010 - 11 - 01
5
# -----------------------------------------------------------------------------------------------
6
# This tool runs on Cygwin, Linux/Unix and Mac OS X
7
#
8
# hex2romvhdl.sh will take a file with hexa bytes as input and convert to a rom format in vhdl
9
# Input file should be a file named rom.hex, and the format can be:
10
# - Motorola HEX format
11
# - Z80ASM format (after assembled, use the option View in Hex format, and copy the contents
12
#   to rom.hex
13
#
14
# To use:
15
# 1. Generate the file with the hex codes using z80asm or...
16
# 2. Compile you C program using SDCC
17
# 3. Rename the hex file to "rom.hex"
18
# 4. Run "hex2romvhdl.sh > rom.vhd" to create the VHDL file "rom.vhd"
19
# ----------------------------------------------------------------------------------------------
20
 
21
sortHexFile() {
22
 in=$1
23
 >$in.tmp
24
 while read line
25
 do
26
    if [[ "$line" != ":00000001FF" ]];then
27
       len=`echo ${line:1:2} | bc`*2
28
       addr=${line:3:4}
29
       echo "$addr:${line:9:$len}" >>$in.tmp
30
    fi
31
 done<$in
32
 cat $in.tmp | sort >$in
33
 echo ":END" >>$in
34
 rm $in.tmp
35
}
36
 
37
 
38
HexAciiFormat() {
39
file=$1
40
echo "-- File generated by hex2romvhdl.sh"
41
echo "-- by Ronivon C. Costa - ronivon.costa@gmail.com"
42
echo "-- `date`"
43
echo "--"
44
echo "library IEEE;
45
use IEEE.std_logic_1164.all;
46
use ieee.numeric_std.all;
47
--Library XilinxCoreLib;
48
 
49
entity rom is
50
        port(
51
                clka        : in std_logic;
52
                addra       : in std_logic_vector($ROMWIDTH downto 0);
53
                douta       : out std_logic_vector(7 downto 0)
54
        );
55
end rom;
56
 
57
architecture behaviour of rom is
58
 
59
signal A_sig : std_logic_vector($ROMWIDTH downto 0);
60
 
61
begin
62
 
63
process (clka)
64
begin
65
 if clka'event and clka = '1' then
66
    A_sig <= addra;
67
 end if;
68
end process;
69
 
70
process (A_sig)
71
begin
72
    case to_integer(unsigned(A_sig)) is"
73
 
74
 
75
ADDR=0
76
for i in `cat $file | tr ',' ' '`
77
do
78
  BL1="when "
79
  BL3=" => douta <= x\"$i\";"
80
  hexaddr="0000"`echo "obase=10;ibase=10;$ADDR" | bc`
81
  fixhexaddr=${hexaddr:(-5)}
82
  echo "             "$BL1$fixhexaddr$BL3
83
  let ADDR=ADDR+1
84
done
85
echo "             when others  => D <= \"ZZZZZZZZ\";
86
        end case;
87
end process;
88
end;"
89
 
90
}
91
 
92
MotorolaHEXFormat()  {
93
echo "-- File generated by hex2romvhdl.sh"
94
echo "-- by Ronivon C. Costa - ronivon.costa@gmail.com"
95
echo "-- `date`"
96
echo "--"
97
echo "library IEEE;
98
use IEEE.std_logic_1164.all;
99
use ieee.numeric_std.all;
100
--Library XilinxCoreLib;
101
 
102
entity rom is
103
        port(
104
            clka        : in std_logic;
105
            addra       : in std_logic_vector($ROMWIDTH downto 0);
106
            douta       : out std_logic_vector(7 downto 0)
107
        );
108
end rom;
109
 
110
architecture behaviour of rom is
111
 
112
signal A_sig : std_logic_vector($ROMWIDTH downto 0);
113
 
114
begin
115
 
116
process (clka)
117
begin
118
 if clka and clka = '1' then
119
    A_sig <= addra;
120
 end if;
121
end process;
122
 
123
process (A_sig)
124
begin
125
    case to_integer(unsigned(A_sig)) is"
126
 
127
## Generate address mapping
128
##
129
 
130
file=$1
131
 
132
  while read line
133
  do
134
    if [[ "$line" != ":END" ]];then
135
 
136
       address=`echo "obase=10;ibase=16;${line:0:4}" | bc`
137
 
138
       let len=${#line}-5
139
       let bytepos=5
140
       while [[ $len -gt 0 ]]
141
       do
142
          BYTE=${line:$bytepos:2}
143
          BL1="when "
144
          BL3=" => douta <= x\"$BYTE\";"
145
          hexaddr="0000"`echo "obase=10;ibase=10;$address" | bc`
146
          fixhexaddr=${hexaddr:(-5)}
147
          echo "             "$BL1$fixhexaddr$BL3
148
          let bytepos=bytepos+2
149
          let len=len-2
150
          let address=address+1
151
       done
152
    fi
153
  done<$file
154
 
155
echo "             when others  => D <= \"ZZZZZZZZ\";
156
        end case;
157
end process;
158
end;"
159
 
160
}
161
 
162
infile=$1
163
ROMWIDTH=$2
164
 
165
let ROMWIDTH=$ROMWIDTH-1
166
file=$infile.1
167
cp $infile $file
168
read line <$file
169
 
170
if [[ ${line:0:1} = ":" ]];then
171
    sortHexFile $file
172
    MotorolaHEXFormat $file
173
else if [[ ${line:4:1} = ":" ]];then
174
          MotorolaHEXFormat $file
175
     else HexAciiFormat $file
176
     fi
177
fi
178
rm $file
179
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.