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

Subversion Repositories a-z80

[/] [a-z80/] [trunk/] [tools/] [zmac/] [bindump.py] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 gdevic
#!/usr/bin/env python3
2 3 gdevic
#
3
# This script reads a binary file and writes it out in the ASCII format
4
# that lists each 8-bit word in a hex format without 0x.
5
#
6
# This format can be read by SystemVerilog function $readmemh()
7
#
8
# Usage:  python bindump.py <input-file> [<output-file>]
9
#
10
# If the output file is not given, "out.hex" will be created.
11
#
12
import sys
13
 
14 8 gdevic
if len(sys.argv)<2:
15
    print ("Usage:  python bindump.py <input-file> [<output-file>]")
16
    exit(-1)
17
 
18 3 gdevic
filename = sys.argv[1]
19
outfile = "out.hex"
20
col = 0;
21 8 gdevic
if len(sys.argv)==3:
22
    outfile = sys.argv[2]
23 3 gdevic
with open(filename, "rb") as f, open(outfile, "w") as o:
24
    block = f.read(65536)
25
    for ch in block:
26 8 gdevic
        #print ('{0:02X}'.format(ch))
27
        o.write('{0:02X} '.format(ch))
28 3 gdevic
        col = col + 1
29
        if col==16:
30
            o.write("\n")
31
            col = 0;
32 8 gdevic
print ("Created", outfile)

powered by: WebSVN 2.1.0

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