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

Subversion Repositories lattice6502

[/] [lattice6502/] [ghdl/] [asm2bin.pl] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 stanley82
#!/usr/bin/perl
2
#       This and asm2bin converts asm file foo.asm into rom files.
3
#       1st type foo.bin used with ghld roms
4
#       2nd type foo.mem used with Lattice roms
5
#       This perl script call crasm to do the assembly.
6
#       crsasm generates the program listing foo.lst
7
 
8
$name = "$ARGV[0]";
9
#       The program was compilled at start address
10
$progadd = hex("FC00");
11
#       The code is packed into ROM start address
12
$romadd = hex("0");
13
$romsize = 1024;
14
#       was 128
15
$add_delta = $romadd - $progadd;
16
 
17
print "Processing $name.asm \n";
18
#       run crasm to generate *.o and *.lst
19
`crasm -o $name.o -x $name.asm > $name.lst`;
20
 
21
open(OBJfile, "< $name.o");
22
open(BINfile, "> $name.bin");
23
 
24
$n = 0;
25
@file = <OBJfile>;
26
 
27
foreach $line (@file)   {
28
        if (substr($line, 0, 2) = "S1") {
29
                $bytes = hex(substr($line, 2, 2));
30
                        $HEXadd = substr($line, 4, 4);
31
                        $address = hex("$HEXadd");
32
                        $runningadd = $address + $add_delta;
33
                        $len = length($line);
34
                        $substring = substr($line, 8, ($len-11));
35
                print "$line";
36
                print "n = $n, Address = $address, runAddress = $runningadd, del =  $add_delta \n";
37
 
38
                        while ($n < $runningadd) {
39
                                        print (BINfile "X\"EA\", \n");
40
                                        $n++;
41
                                        print("n is $n \n");
42
                                        }
43
 
44
                $a = 0;
45
#               while ($a < ($len - 11)) {
46
                while ($a < ($len - 11) and ($address > 64513)) {
47
                        $byte = substr($substring, $a, 2);
48
                        if ($n eq ($romsize - 1)) {
49
                                print (BINfile "X\"$byte\" )  ; \n");
50
                        }
51
                        else    {
52
                                print (BINfile "X\"$byte\", \n");
53
                                }
54
                        $a = $a + 2;
55
                        $n++ ;
56
                        }
57
                }
58
        }
59
 
60
 
61
close(OBJfile);
62
close(BINfile);
63
 
64
#       end

powered by: WebSVN 2.1.0

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