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

Subversion Repositories oks8

[/] [oks8/] [trunk/] [sw/] [hex2rom.tcl] - Blame information for rev 10

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 kongzilee
#####################################################################
2
####                                                             ####
3
####  SASM Hex to Verilog converter.                             ####
4
####                                                             ####
5
####  This file is part of the oks8 cores project                ####
6
####  http://www.opencores.org/cvsweb.shtml/oks8/                ####
7
####                                                             ####
8
#### Copyright (C) 2006 Jian Li                                  ####
9
####                    kongzilee@yahoo.com.cn                   ####
10
####                                                             ####
11
#### This source file may be used and distributed without        ####
12
#### restriction provided that this copyright statement is not   ####
13
#### removed from the file and that any derivative work contains ####
14
#### the original copyright notice and the associated disclaimer.####
15
####                                                             ####
16
####     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ####
17
#### EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ####
18
#### TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ####
19
#### FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ####
20
#### OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ####
21
#### INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ####
22
#### (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ####
23
#### GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ####
24
#### BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ####
25
#### LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ####
26
#### (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ####
27
#### OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ####
28
#### POSSIBILITY OF SUCH DAMAGE.                                 ####
29
####                                                             ####
30
#####################################################################
31
 
32
puts stderr "****************************************************"
33
puts stderr "***         SASM Hex to Verilog converter.       ***"
34
puts stderr "*** Usage: tclsh83 hex2rom.tcl \[*\].hex > \[*\].rom ***"
35
puts stderr "****************************************************"
36
 
37
# Open the source file to converter
38
set chan [open [lindex $argv 0]]
39
set LineNumber 0
40
set state 1
41
 
42
# Get the lines
43
while {[gets $chan line] >= 0} {
44
  # Only check the even lines
45
  if {[expr $LineNumber % 2] == 0} {
46
        if {[string first ":" $line 0] != 0} {
47
          puts stderr "$LineNumber: The first char is not \[:\] >> \[$line\]"
48
          break
49
        }
50
        set slen [string length $line]
51
        # Check the end line
52
        if {[string first "00" $line 1] == 1} {
53
          if {$slen == 11} {
54
                set state 0;
55
          } else {
56
                puts stderr "$LineNumber: Bad end line >> \[$line\]"
57
          }
58
          break
59
        }
60
        # Get the position where the code begin
61
        set hexcode [string range $line 3 6]
62
        if {[string is xdigit -strict $hexcode] == 0} {
63
          puts stderr "$LineNumber: Bad Hex Format >> \[$hexcode\]"
64
          break
65
        }
66
        puts "@$hexcode"
67
        # Get the hexcode and write to the ROM file
68
        set c 9
69
        incr slen -11
70
        while {$slen > 0} {
71
          set hexcode [string range $line $c [incr c]]
72
          if {[string is xdigit -strict $hexcode] == 1} {
73
                puts $hexcode
74
                incr c
75
          } else {
76
                puts stderr "$LineNumber: Bad Hex Format >> \[$hexcode\]"
77
                set state 2
78
                break
79
          }
80
          incr slen -2
81
        }
82
        if {$state == 2} {
83
          break;
84
        }
85
  }
86
  incr LineNumber
87
}
88
 
89
# Finish
90
if {$state == 0} {
91
  puts stderr "Finish !!!"
92
} else {
93
  puts stderr "Finish with Error(s) !!!"
94
}
95
 
96
close $chan

powered by: WebSVN 2.1.0

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