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

Subversion Repositories lattice6502

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 stanley82
#!/usr/bin/perl
2
#       This 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
$add_delta = $romadd - $progadd;
15
 
16
print "Processing $name.asm \n";
17
#       run crasm to generate *.o and *.lst
18
`crasm -o $name.o -x $name.asm > $name.lst`;
19
 
20
open(OBJfile, "< $name.o");
21
open(MEMfile, "> $name.mem");
22
 
23
print(MEMfile "#Format=Hex \n");
24
print(MEMfile "#Depth=1024 \n");
25
print(MEMfile "#Width=8 \n");
26
print(MEMfile "#AddrRadix=3 \n");
27
print(MEMfile "#DataRadix=3 \n");
28
print(MEMfile "#Data \n");
29
 
30
$n = 0;
31
@file = <OBJfile>;
32
 
33
foreach $line (@file)   {
34
        if (substr($line, 0, 2) = "S1") {
35
                $bytes = hex(substr($line, 2, 2));
36
                        $HEXadd = substr($line, 4, 4);
37
                        $address = hex("$HEXadd");
38
                        $runningadd = $address + $add_delta;
39
                        $len = length($line);
40
                        $substring = substr($line, 8, ($len-11));
41
                print "$line";
42
                print "n = $n, Address = $address, runAddress = $runningadd, del =  $add_delta \n";
43
 
44
                        while ($n < $runningadd) {
45
                                        print (MEMfile "EA \n");
46
                                        $n++;
47
                                        print("n is $n \n");
48
                                        }
49
 
50
                $a = 0;
51
#               while ($a < ($len - 11) and ($address > hex("FC00"))) {
52
                while ($a < ($len - 11) and ($address > 64511)) {
53
#               while ($a < ($len - 11)) {
54
                        $byte = substr($substring, $a, 2);
55
                        print (MEMfile "$byte \n");
56
                        $a = $a + 2;
57
                        $n++ ;
58
                        }
59
                }
60
        }
61
print " n is $n \n";
62
while ($n < $romsize) {
63
        print (MEMfile "EA \n");
64
        $n++;
65
        }
66
 
67
close(OBJfile);
68
close(MEMfile);
69
 
70
#       end

powered by: WebSVN 2.1.0

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