#!/usr/bin/perl
|
#!/usr/bin/perl
|
# This and asm2bin converts asm file foo.asm into rom files.
|
# This and asm2bin converts asm file foo.asm into rom files.
|
# 1st type foo.bin used with ghld roms
|
# 1st type foo.bin used with ghld roms
|
# 2nd type foo.mem used with Lattice roms
|
# 2nd type foo.mem used with Lattice roms
|
# This perl script call crasm to do the assembly.
|
# This perl script call crasm to do the assembly.
|
# crsasm generates the program listing foo.lst
|
# crsasm generates the program listing foo.lst
|
|
|
$name = "$ARGV[0]";
|
$name = "$ARGV[0]";
|
# The program was compilled at start address
|
# The program was compilled at start address
|
$progadd = hex("FC00");
|
$progadd = hex("FC00");
|
# The code is packed into ROM start address
|
# The code is packed into ROM start address
|
$romadd = hex("0");
|
$romadd = hex("0");
|
$romsize = 1024;
|
$romsize = 1024;
|
# was 128
|
# was 128
|
$add_delta = $romadd - $progadd;
|
$add_delta = $romadd - $progadd;
|
|
|
print "Processing $name.asm \n";
|
print "Processing $name.asm \n";
|
# run crasm to generate *.o and *.lst
|
# run crasm to generate *.o and *.lst
|
`crasm -o $name.o -x $name.asm > $name.lst`;
|
`crasm -o $name.o -x $name.asm > $name.lst`;
|
|
|
open(OBJfile, "< $name.o");
|
open(OBJfile, "< $name.o");
|
open(BINfile, "> $name.bin");
|
open(BINfile, "> $name.bin");
|
|
|
$n = 0;
|
$n = 0;
|
@file = <OBJfile>;
|
@file = <OBJfile>;
|
|
|
foreach $line (@file) {
|
foreach $line (@file) {
|
if (substr($line, 0, 2) = "S1") {
|
if (substr($line, 0, 2) = "S1") {
|
$bytes = hex(substr($line, 2, 2));
|
$bytes = hex(substr($line, 2, 2));
|
$HEXadd = substr($line, 4, 4);
|
$HEXadd = substr($line, 4, 4);
|
$address = hex("$HEXadd");
|
$address = hex("$HEXadd");
|
$runningadd = $address + $add_delta;
|
$runningadd = $address + $add_delta;
|
$len = length($line);
|
$len = length($line);
|
$substring = substr($line, 8, ($len-11));
|
$substring = substr($line, 8, ($len-11));
|
print "$line";
|
print "$line";
|
print "n = $n, Address = $address, runAddress = $runningadd, del = $add_delta \n";
|
print "n = $n, Address = $address, runAddress = $runningadd, del = $add_delta \n";
|
|
|
while ($n < $runningadd) {
|
while ($n < $runningadd) {
|
print (BINfile "X\"EA\", \n");
|
print (BINfile "X\"EA\", \n");
|
$n++;
|
$n++;
|
print("n is $n \n");
|
print("n is $n \n");
|
}
|
}
|
|
|
$a = 0;
|
$a = 0;
|
# while ($a < ($len - 11)) {
|
# while ($a < ($len - 11)) {
|
while ($a < ($len - 11) and ($address > 64513)) {
|
while ($a < ($len - 11) and ($address > 64511)) {
|
$byte = substr($substring, $a, 2);
|
$byte = substr($substring, $a, 2);
|
if ($n eq ($romsize - 1)) {
|
if ($n eq ($romsize - 1)) {
|
print (BINfile "X\"$byte\" ) ; \n");
|
print (BINfile "X\"$byte\" ) ; \n");
|
}
|
}
|
else {
|
else {
|
print (BINfile "X\"$byte\", \n");
|
print (BINfile "X\"$byte\", \n");
|
}
|
}
|
$a = $a + 2;
|
$a = $a + 2;
|
$n++ ;
|
$n++ ;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
|
|
close(OBJfile);
|
close(OBJfile);
|
close(BINfile);
|
close(BINfile);
|
|
|
# end
|
# end
|
|
|