mirror of
https://github.com/MiSTer-devel/MultiComp_MiSTer.git
synced 2026-04-19 03:04:38 +00:00
- add warm/cold reset option for the 6809 - add tools and docs to build 6809 interpreter - revert the basMon files
44 lines
1.4 KiB
Perl
44 lines
1.4 KiB
Perl
#!/usr/bin/perl -w
|
|
#
|
|
# read .HEX file. Apply offset to each record's address field and
|
|
# recompute the checksum accordingly.
|
|
# Application: .HEX file has absolute address. To go into a ROM, needs to
|
|
# relative address (ie relative to the start of the ROM)
|
|
#
|
|
# usage: hex_addr_remap <hex-offset> foo.hex > foo2.hex
|
|
#
|
|
# The offset, which should be in hex, is SUBTRACTED from each entry. Eg
|
|
# ROM assembled at 0xE000 will be
|
|
# hex_addr_remap e000 foo.hex > foo2.hex
|
|
|
|
$offset = hex($ARGV[0]);
|
|
open INFILE, $ARGV[1] or die "Could not open input file $ARGV[1]";
|
|
while (my $line = <INFILE>) {
|
|
$line =~/(\:)([0-9A-F][0-9A-F])([0-9A-F][0-9A-F][0-9A-F][0-9A-F])([0-9A-F][0-9A-F])(\w+)/;
|
|
my $len=hex($2); # 2 digits
|
|
my $adr=hex($3); # 4 digits
|
|
my $typ=hex($4); # 2 digits
|
|
my $dat=$5; # data and checksum
|
|
my $char = length $dat;
|
|
|
|
# adjust addresss
|
|
$adr = 0xffff & ($adr - $offset);
|
|
|
|
# do len adr typ
|
|
my $sum = $len + ($adr & 0xff) + (($adr>>8) & 0xff) + $typ;
|
|
printf ":%02X%04X%02X", $len, $adr, $typ;
|
|
|
|
# process the rest upto but excluding the last byte (the old checksum)
|
|
for (my $i=0; $i<($char-2); $i=$i+2) {
|
|
my $hex=substr $dat, $i, 2;
|
|
printf "%02X", hex($hex);
|
|
$sum = $sum + hex($hex);
|
|
}
|
|
|
|
my $current_csum = hex(substr $dat, $char -2, 2);
|
|
my $new_csum = (($sum ^ 0xff) + 1) & 0xff;
|
|
printf "%02X\r\n", $new_csum;
|
|
}
|
|
close INFILE;
|
|
|