OpenCores
URL https://opencores.org/ocsvn/a-z80/a-z80/trunk

Subversion Repositories a-z80

[/] [a-z80/] [trunk/] [tools/] [zmac/] [bindump.py] - Diff between revs 3 and 8

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 3 Rev 8
Line 1... Line 1...
#!/usr/bin/env python
#!/usr/bin/env python3
#
#
# This script reads a binary file and writes it out in the ASCII format
# This script reads a binary file and writes it out in the ASCII format
# that lists each 8-bit word in a hex format without 0x.
# that lists each 8-bit word in a hex format without 0x.
#
#
# This format can be read by SystemVerilog function $readmemh()
# This format can be read by SystemVerilog function $readmemh()
Line 9... Line 9...
#
#
# If the output file is not given, "out.hex" will be created.
# If the output file is not given, "out.hex" will be created.
#
#
import sys
import sys
 
 
 
if len(sys.argv)<2:
 
    print ("Usage:  python bindump.py <input-file> [<output-file>]")
 
    exit(-1)
 
 
filename = sys.argv[1]
filename = sys.argv[1]
outfile = "out.hex"
outfile = "out.hex"
col = 0;
col = 0;
if len(sys.argv) > 2:
if len(sys.argv)==3:
    outfile  = sys.argv[2]
    outfile  = sys.argv[2]
with open(filename, "rb") as f, open(outfile, "w") as o:
with open(filename, "rb") as f, open(outfile, "w") as o:
    block = f.read(65536)
    block = f.read(65536)
    for ch in block:
    for ch in block:
        #print '{0:02X}'.format(ord(ch))
        #print ('{0:02X}'.format(ch))
        o.write('{0:02X} '.format(ord(ch)))
        o.write('{0:02X} '.format(ch))
        col = col + 1
        col = col + 1
        if col==16:
        if col==16:
            o.write("\n")
            o.write("\n")
            col = 0;
            col = 0;
print "Created " + outfile
print ("Created", outfile)
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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