# X_to_A_mif_conversion.tcl # This script will convert a Xilinx mif file to an Intel PSG (Altera) mif file # mif files are often used as initialization files for FPGA RAM implementations # # usage from a tcl console window in Quartus or from a tcl shell # > X_to_A_mif_conversion.tcl # No arguments will print out all options needed for the script # X_to_A_mif_conversion.tcl # # Example # > X_to_A_mif_conversion.tcl 1024 16 X_1024x16.mif a_1024x16.mif # if {$argc == 0} { puts "" puts "Usage:" puts "X_to_A_mif_conversion.tcl " puts "" exit } elseif {$argc != 4} { puts "" puts "Incorrect number of arguments" puts "X_to_A_mif_conversion.tcl " puts "" exit } set depth [lindex $argv 0] set width [lindex $argv 1] set filein [lindex $argv 2] set fileout [lindex $argv 3] if {[file exists $filein] == 0} { puts "input file $filein does not exist" exit } set fin [open $filein r] set fout [open $fileout w] set timestamp_decimal [clock format [clock seconds] -format {%Y %m %d %H %M %S}] puts $fout "-- Created by X_to_A_mif_conversion.tcl" puts $fout "-- MIF CREATION TIMESTAMP = $timestamp_decimal" puts $fout "DEPTH = $depth; -- The size of memory in words" puts $fout "WIDTH = $width; -- The size of data in bits" puts $fout "ADDRESS_RADIX = DEC; -- The radix for address values" puts $fout "DATA_RADIX = BIN; -- The radix for data values" puts $fout "CONTENT -- start of (address : data pairs)" puts $fout "BEGIN" puts $fout "" set i 0 while { [gets $fin data] >= 0 } { puts $fout "$i : $data;" incr i } puts $fout "END;" close $fin close $fout