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

Subversion Repositories z80soc

[/] [z80soc/] [trunk/] [V0.7.1a/] [rom/] [hex2rom.sh] - Blame information for rev 45

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 41 rrred
#!/bin/sh
2
# hex2romvhdl.sh
3
# By: Ronivon Candido Costa
4
# ronivon.costa@gmail.com
5
#
6
# This tool runs on Cygwin, Linux 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 View in Hex format, and copy the contents to rom.hex
12
#
13
# ----------------------------------------------------------------------------------------------
14
convMotorolaHexToAscIIHex() {
15
  in=rom.hex
16
  outtmp=romC.hex
17
 
18
  >$outtmp
19
 
20
  while read line
21
  do
22
    if [[ "$line" != ":00000001FF" ]];then
23
       lenbytes=${line:1:2}
24
       len=`echo $lenbytes | bc`
25
       let bytepos=9
26
       while [[ $len -gt 0 ]]
27
       do
28
          echo ${line:$bytepos:2} >> $outtmp
29
          let bytepos=bytepos+2
30
          let len=len-1
31
       done
32
    fi
33
  done<$in
34
  cp rom.hex rom.hex.bak
35
  mv romC.hex rom.hex
36
}
37
 
38
 
39
file=rom.hex
40
 
41
# Vefify if file is in Motorola Hex format, and converto to HEX Ascii codes
42
 
43
read line < $file
44
 
45
if [[ ${line:0:1} = ":" ]];then
46
   convMotorolaHexToAscIIHex
47
fi
48
 
49
echo "library IEEE;
50
use IEEE.std_logic_1164.all;
51
use ieee.numeric_std.all;
52
 
53
entity rom is
54
        port(
55
                Clk             : in std_logic;
56
                A               : in std_logic_vector(11 downto 0);
57
                D               : out std_logic_vector(7 downto 0)
58
        );
59
end rom;
60
 
61
architecture rtl of rom is
62
begin
63
 
64
process (Clk)
65
begin
66
 if Clk'event and Clk = '1' then
67
        case A is"
68
 
69
 
70
ADDR=0
71
for i in `cat $file | tr ',' ' '`
72
do
73
  BL1="when x\""
74
  BL3="\" => D <= x\"$i\";"
75
  hexaddr="00"`echo "obase=16;ibase=10;$ADDR" | bc`
76
  fixhexaddr=${hexaddr:(-3)}
77
  echo "             "$BL1$fixhexaddr$BL3
78
  let ADDR=ADDR+1
79
done
80
echo "             when others => D <=\"ZZZZZZZZ\";
81
        end case;
82
 end if;
83
end process;
84
end;"
85
 

powered by: WebSVN 2.1.0

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