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

Subversion Repositories lattice6502

[/] [lattice6502/] [ghdl/] [asm2rom.pl] - Rev 2

Compare with Previous | Blame | View Log

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

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

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