#!/usr/bin/perl -w

# from src/atari.cfg:
my $stack_size = 0x0100;
my $p20_start = 0x2000;
my $p20_end = 0x3360;

# from memsetup.asm:
my $ramtop = 0xc000;

open MAP, "client.xex.map" or die $!;
while(<MAP>) {
	next unless /^[A-Z]+\s+[0-9A-F]{6}  /;
	($name, $start, $end, $size) = split /\s+/;
	$name = lc $name;
	$start{$name} = hex $start;
	$end{$name} = hex $end;
	$size{$name} = hex $size;
}
close MAP;

$free_hi = ($ramtop - $stack_size) - $end{code} + 1;
$code_size = $size{code};
$p20_free = $p20_end - $end{bss} + 1;
$p20_size = $end{bss} - $p20_start + 1;

printf "===> stack starts at \$%04x\n", $ramtop - $stack_size;
printf "===>  code ends   at \$%04x (size %d, %.1fK)\n", $end{code}, $code_size, $code_size / 1024;
printf "===>  data ends   at \$%04x (size %d, %.1fK)\n", $end{bss}, $p20_size, $p20_size / 1024;
printf "===> free code space \$%04x (%d, %.1fK)\n", $free_hi, $free_hi, $free_hi / 1024;
printf "===> free data space \$%04x (%d, %.1fK)\n", $p20_free, $p20_free, $p20_free / 1024;
