summaryrefslogtreecommitdiffstats
path: root/game/build/ps2/mapfind.pl
blob: 2590040f0fa2a3a9d2830596b3830b68155bc6d9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
$mapfilename = "..\\..\\cd\\ps2\\srr2.map";

print "Arg count is $#ARGV\n";

if( $#ARGV < 0 )
{
	print "Syntax: perl mapfile.pl <address> [mapfile]";
	exit;
}

$address = hex("@ARGV[0]");

if( $#ARGV > 0 )
{
	$mapfilename = $ARGV[1];
}

print "Address: $address\n";
print "Mapfile: $mapfilename\n";

$mapname = $mapfilename;

print "Mapname: $mapname\n";

$found = 0;

open MAPFILE, $mapname or die "Couldn't find mapfile $mapname";
while (<MAPFILE>)
{
	#
	# Tokenize
	#
	@Tokens = split;

	if( $#Tokens >= 2 )
	{
		$baseaddress = "0x" . $Tokens[0];
		$baseaddress =~ tr/a-f/A-F/;
		$baseaddress = hex("$baseaddress");

		$size = "0x" . $Tokens[1];
		$size =~ tr/a-f/A-F/;
		$size = hex("$size");

		$sum = $baseaddress + $size;

		if( ( $baseaddress > 0 ) && ( $size > 0 ) )
		{
			if( ( $address >= $baseaddress ) && ( $address <= $sum ) )
			{
				print $_;
				$found = 1;
			}
		}
	}
}

#
# Line not found
#
close MAPFILE;
if( $found == 0 )
{
	print "Couldn't find specified address in the mapfile.  Uh-oh.";
}