#!/bin/sh
|
#!/bin/sh
|
# hex2romvhdl.sh
|
# hex2romvhdl.sh
|
# By: Ronivon Candido Costa
|
# By: Ronivon Candido Costa
|
# ronivon.costa@gmail.com
|
# ronivon.costa@gmail.com
|
#
|
#
|
# This tool runs on Cygwin, Linux and Mac OS X
|
# This tool runs on Cygwin, Linux and Mac OS X
|
#
|
#
|
# hex2romvhdl.sh will take a file with hexa bytes as input and convert to a rom format in vhdl
|
# hex2romvhdl.sh will take a file with hexa bytes as input and convert to a rom format in vhdl
|
# Input file should be a file named rom.hex, and the format can be:
|
# Input file should be a file named rom.hex, and the format can be:
|
# - Motorola HEX format
|
# - Motorola HEX format
|
# - Z80ASM format (after assembled, use the View in Hex format, and copy the contents to rom.hex
|
# - Z80ASM format (after assembled, use the View in Hex format, and copy the contents to rom.hex
|
#
|
#
|
# ----------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------
|
convMotorolaHexToAscIIHex() {
|
convMotorolaHexToAscIIHex() {
|
in=rom.hex
|
in=rom.hex
|
outtmp=romC.hex
|
outtmp=romC.hex
|
|
|
>$outtmp
|
>$outtmp
|
|
|
while read line
|
while read line
|
do
|
do
|
if [[ "$line" != ":00000001FF" ]];then
|
if [[ "$line" != ":00000001FF" ]];then
|
lenbytes=${line:1:2}
|
lenbytes=${line:1:2}
|
len=`echo $lenbytes | bc`
|
len=`echo $lenbytes | bc`
|
let bytepos=9
|
let bytepos=9
|
while [[ $len -gt 0 ]]
|
while [[ $len -gt 0 ]]
|
do
|
do
|
echo ${line:$bytepos:2} >> $outtmp
|
echo ${line:$bytepos:2} >> $outtmp
|
let bytepos=bytepos+2
|
let bytepos=bytepos+2
|
let len=len-1
|
let len=len-1
|
done
|
done
|
fi
|
fi
|
done<$in
|
done<$in
|
cp rom.hex rom.hex.bak
|
cp rom.hex rom.hex.bak
|
mv romC.hex rom.hex
|
mv romC.hex rom.hex
|
}
|
}
|
|
|
|
|
file=rom.hex
|
file=rom.hex
|
|
|
# Vefify if file is in Motorola Hex format, and converto to HEX Ascii codes
|
# Vefify if file is in Motorola Hex format, and converto to HEX Ascii codes
|
|
|
read line < $file
|
read line < $file
|
|
|
if [[ ${line:0:1} = ":" ]];then
|
if [[ ${line:0:1} = ":" ]];then
|
convMotorolaHexToAscIIHex
|
convMotorolaHexToAscIIHex
|
fi
|
fi
|
|
|
echo "library IEEE;
|
echo "library IEEE;
|
use IEEE.std_logic_1164.all;
|
use IEEE.std_logic_1164.all;
|
use ieee.numeric_std.all;
|
use ieee.numeric_std.all;
|
|
|
entity rom is
|
entity rom is
|
port(
|
port(
|
Clk : in std_logic;
|
Clk : in std_logic;
|
A : in std_logic_vector(11 downto 0);
|
A : in std_logic_vector(11 downto 0);
|
D : out std_logic_vector(7 downto 0)
|
D : out std_logic_vector(7 downto 0)
|
);
|
);
|
end rom;
|
end rom;
|
|
|
architecture rtl of rom is
|
architecture rtl of rom is
|
begin
|
begin
|
|
|
process (Clk)
|
process (Clk)
|
begin
|
begin
|
if Clk'event and Clk = '1' then
|
if Clk'event and Clk = '1' then
|
case A is"
|
case A is"
|
|
|
|
|
ADDR=0
|
ADDR=0
|
for i in `cat $file | tr ',' ' '`
|
for i in `cat $file | tr ',' ' '`
|
do
|
do
|
BL1="when x\""
|
BL1="when x\""
|
BL3="\" => D <= x\"$i\";"
|
BL3="\" => D <= x\"$i\";"
|
hexaddr="00"`echo "obase=16;ibase=10;$ADDR" | bc`
|
hexaddr="00"`echo "obase=16;ibase=10;$ADDR" | bc`
|
fixhexaddr=${hexaddr:(-3)}
|
fixhexaddr=${hexaddr:(-3)}
|
echo " "$BL1$fixhexaddr$BL3
|
echo " "$BL1$fixhexaddr$BL3
|
let ADDR=ADDR+1
|
let ADDR=ADDR+1
|
done
|
done
|
echo " when others => D <=\"ZZZZZZZZ\";
|
echo " when others => D <=\"ZZZZZZZZ\";
|
end case;
|
end case;
|
end if;
|
end if;
|
end process;
|
end process;
|
end;"
|
end;"
|
|
|
|
|