summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2014-06-17 15:54:23 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2014-06-17 15:54:23 (GMT)
commit9313ff1d17e0f76e99ba50a5729fca5edb1a6b67 (patch)
tree8ecf9e1da18cb0da2cff66f7ea58209d45a29550
parent459c20bafb008dce1076597edb7e1fe07216fe4e (diff)
downloadabc80-9313ff1d17e0f76e99ba50a5729fca5edb1a6b67.zip
abc80-9313ff1d17e0f76e99ba50a5729fca5edb1a6b67.tar.gz
abc80-9313ff1d17e0f76e99ba50a5729fca5edb1a6b67.tar.bz2
abc80-9313ff1d17e0f76e99ba50a5729fca5edb1a6b67.tar.xz
bin2bac: Simplify the code
Simplify the code by computing $bldlen in a common loop. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rwxr-xr-xdata/bin2bac.pl16
1 files changed, 7 insertions, 9 deletions
diff --git a/data/bin2bac.pl b/data/bin2bac.pl
index 29b5ebc..8ea4fec 100755
--- a/data/bin2bac.pl
+++ b/data/bin2bac.pl
@@ -27,7 +27,6 @@ sub bacstmt($$$) {
sub makebac($$$) {
my($data, $addr, $entrypt) = @_;
- my $bldlen;
my @bld;
if (defined($addr)) {
@@ -39,12 +38,9 @@ sub makebac($$$) {
$bld[2] = "\x06\x00\x3e\xf8\x86\xd2";
# 16-bit entry point
$bld[3] = "\x0e\x06\x09\x4f\xed\xb0\x23\x23\x18\xf0";
+
# 0x00C9 is the address for END in all ABC80 BASIC interpreters
$entrypt = 0x00c9 unless(defined($entrypt));
-
- # +2 for the final 0xbb + CR
- $bldlen = length($bld[0]) + 2 + length($bld[1]) + 2 +
- length($bld[2]) + 2 + length($bld[3]) + 2;
} else {
# <bacldr2.asm> - relocatable data loaded at BOFA
$bld[0] = "\x2a\x1c\xfe\xe5\x5d\x54\x01";
@@ -58,10 +54,13 @@ sub makebac($$$) {
# Default to entry = BOFA
$entrypt = 0 unless(defined($entrypt));
+ }
- # +2 for the final 0xbb + CR
- $bldlen = length($bld[0]) + 2 + length($bld[1]) + 2 +
- length($bld[2]) + 2;
+ my $bld;
+ my $bldlen = 0;
+ foreach $bld (@bld) {
+ # +2 for a 16-bit value between each chunk, +2 for final BB 0D
+ $bldlen += length($bld) + 2;
}
my $q = "\x82"; # Output (program start marker)
@@ -76,7 +75,6 @@ sub makebac($$$) {
pack("v",$bldlen)."\xf8\xce\x3a\xb7");
my $pfxlen = length($q) - 1; # The initial 0x82 isn't stored in RAM
- my $bld;
die if ($pfxlen > 255); # Should not happen