[stella] BLINT: Branch, Conditional Lint

Subject: [stella] BLINT: Branch, Conditional Lint
From: KirkIsrael@xxxxxxxxxxxxx
Date: 17 Oct 2002 02:15:24 -0000
Hey Gang...
I was ever-so-slightly bummed that my idea about a "Lint"
that could inspect a DASM list file and find any conditional
branches over page boundaries didn't generate much further 
talk...I figure either people aren't *that* troubled by the 
core issue, or maybe people don't really take interest in
stuff 'til it's past the vaporware stage...

So I put on my Perl hat, and made the script I'm
including below. I also made an exe version, available at
http://alienbill.com/vgames/blint.zip

Running it with no arguments brings up the following info:
BLINT: Tool for Atari VCS ASM by Kirk Israel <kisrael.com>
find conditional branches that cross page boundaries
Usage:
        blint ASMFILE
        (must have DASM in current directory)
        blint -l LISTFILE
        (file generated by -lLISTFILE argument to DASM)

So if you put it in the same directory as DASM, it'll
run DASM for you, or you can generate the list file 
yourself and run it against that. It prints up any lines
that are suspect.

So I'm still open for suggestions, like I think there might
be some other boundary conditions that I could check for...
*IF* someone with a deeper knowledge of 6507 code can suggest 
what to look for...
If people think it'd be useful, I could even try to adapt
it so people could always invoke DASM through this script,
so it would always keep an eye out for these issues. Or maybe 
I should just keep it for when people are having weird problems...

-------------snip-here-----------------
#!/usr/bin/perl


if(! defined($ARGV[0])){
	print<<__EOQ__;
BLINT: Tool for Atari VCS ASM by Kirk Israel <kisrael@xxxxxxxxxxxxx>
find conditional branches that cross page boundaries
Usage:	
	blint ASMFILE
	(must have DASM in current directory)
	blint -l LISTFILE
	(file generated by -lLISTFILE argument to DASM)
__EOQ__
} else  {


if($ARGV[0] eq "-l") {
	$rundasm = 0;
	$filename = $ARGV[1];
} else {
	$rundasm = 1;
	$timestamp = time;
	$filename = substr($timestamp, 0,$length - 3).".".substr($timestamp, $length - 3);
	print "running dasm $ARGV[0] -f3\n";
	print "-----------------\n";
	print `dasm $ARGV[0] -f3 -l$filename \n`;
	print "-----------------\n";
}



open(READ, "< $filename") || die "Can't Open $filename $!";


#prepopulate hash, keys are hex code
#for conditional branches, value is mnemonic

%branches = (
"10"=>"BPL",
"30"=>"BMI",
"50"=>"BVC",
"70"=>"BVS",
"90"=>"BCC",
"B0"=>"BCS",
"D0"=>"BNE",
"F0"=>"BEQ"
);





$bgwhite = "CCFFCC";
$bgblue = "#CCCCFF";

while($nextline = <READ>){
	chomp $nextline;
	
	($linenum,$memloc,$hexcommand,$label,$nuthin,$command,$target,@rest) = split(/\t/,$nextline);
	
	if($memloc ne $oldmemloc){
		
		
		if($color eq $bgwhite){
			$color = $bgblue;
		} else {
			$color = $bgwhite;
		}
		$oldmemloc = $memloc;
		
	}


	
	$linenum =~ s/^\s+//;
	if(!($linenum =~ /\D/ )){
		if($memloc ne "????"){

			
			if(defined($branches{uc(substr($hexcommand,0,2))})){
				
			

				
				$memoffset = substr($memloc,2);
				$memoffsetdec = (hex($memoffset));
				
				
				$offset = substr($hexcommand,3);
				$offsetdec = (hex($offset));
				if($offsetdec >= 128) {
					$offsetdec -= 256;
				}
				$offsetdec += 2;
				
				$dest = $memoffsetdec + $offsetdec;
				
				if($dest < 0 || $dest >= 256) { 
					print "FOUND AN ISSUE: Line $linenum of ASM branches across page boundary:\n",join("\t",($label,$nuthin,$command,$target,@rest)),"\n";
					$issues = 1;
				
				}
				
			} 			
			
		}
	}	
	
}


close READ;



if($rundasm){ 
	unlink($filename ) || die "can't remove $filename $!";
}


if($issues == 0){
	print "No Problems Found\n";
}

} #end else, there are arguments....








----------------------------------------------------------------------------------------------
Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://www.biglist.com/lists/stella/


Current Thread