# Various constants extracted from the bbc executable my $bbcbase=0x1100; # Base address of executable my $bbcmaps=0x4a00; # Address where first map is found my $bbcnames=0x2ca9; # Address where first name is found my $namestrlen=0x14; # Length of name (These are padded centered with spaces my $namelen=0x17; # Total length of map name my $maplen=0x200; # Total length of mapdata my $maplayoutlen=0x1c2; # Total length of the layout part of the map data my $mapbaseaddr=0x900; # Address where the fully expanded map is stored, other pointers are relative to this. Actually 32 less than really since everything seems to be offset my $buffer; my %symbols = ( 0 => " ", 5 => ".", 1 => "#", 11 => "@", 6 => "~", 4 => "!", 12 => "E", 3 => "Q", 2 => "M", 7 => "F", 8 => "C", 9 => "H", 10 => "V", 13 => "D", 15 => "S", 14 => "B", ); open (OUTFILE,">original.xml"); open (INFILE,"\n"; for ($mapcount=0;$mapcount<15;$mapcount++) { #if ($mapcount == 1) {last;} my $mapname = substr($buffer,$bbcnames-$bbcbase+($mapcount*$namelen),$namestrlen); $mapname =~ s/\s*$//; $mapname =~ s/^\s*//; print "$mapname\n"; my $mapbase = $bbcmaps-$bbcbase-($mapcount*$maplen); my $mapbuffer = substr($buffer,$mapbase,$maplayoutlen); #Top line + first side wall print "################################\n#"; my $mapstr="#################################"; my $column=0; foreach(split(//,$mapbuffer)) { $column++; my $byte=ord($_); my $lownyb=$symbols{$byte&15}; my $hinyb=$symbols{$byte>>4}; print $lownyb.$hinyb; $mapstr=$mapstr.$lownyb.$hinyb; if ($column==15) { $column=0; $mapstr=$mapstr."##"; print "#\n#"; } } #Finish bottom wall print "###############################\n"; $mapstr=$mapstr."###############################"; my $mapdata = substr($buffer, $mapbase + $maplayoutlen, $maplen-$maplayoutlen); my $maptilecount; for ($maptilecount=0;$maptilecount<4;$maptilecount++) { my $mapoffset = ord(substr($mapdata,$maptilecount*2,1)) + (ord(substr($mapdata,($maptilecount*2)+1,1)) * 256) - $mapbaseaddr + 32; my $mapno = $maptilecount+1; substr($mapstr,$mapoffset,1) = "$mapno"; } my $magusoffset = ord(substr($mapdata,8,1)) + (ord(substr($mapdata,9,1)) * 256) - $mapbaseaddr; my $magusposoffset = ord(substr($mapdata,8+6,1)) + (ord(substr($mapdata,9+6,1)) * 256) - $mapbaseaddr; my $magusposx = $magusposoffset % 32; my $magusposy = ($magusposoffset-$magusposx) / 32; my $questoroffset = ord(substr($mapdata,16,1)) + (ord(substr($mapdata,17,1)) * 256) - $mapbaseaddr; my $questorposoffset = ord(substr($mapdata,16+6,1)) + (ord(substr($mapdata,17+6,1)) * 256) - $mapbaseaddr; my $questorposx = $questorposoffset % 32; my $questorposy = ($questorposoffset-$questorposx) / 32; print OUTFILE ""; print OUTFILE $mapstr; print OUTFILE "\n"; } print OUTFILE "\n"; close OUTFILE; close INFILE;