Fixed bugs in HEX and ASC

This commit is contained in:
Leeland Heins 2018-12-21 09:23:25 -06:00 committed by GitHub
parent f6dcaa682a
commit 7da0931c9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

27
as65.pl
View File

@ -773,11 +773,19 @@ sub generate_24 {
sub generate_bytes { sub generate_bytes {
my ($ofh, $addr, $bytes, $lineno, $line) = @_; my ($ofh, $addr, $bytes, $lineno, $line) = @_;
my $tmpline = $line; my $firstflag = 1;
foreach my $byte (@{$bytes}) { foreach my $byte (@{$bytes}) {
next unless $byte =~ /^[0-9a-fA-F]+/; if ($firstflag) {
generate_8($ofh, $addr, hex(lc($byte)), $lineno, $tmpline); print sprintf("%04x: %02x %-4d %s\n", $addr, ord($byte), $lineno, $line) if $code_listing;
$tmpline = ''; $firstflag = 0;
} else {
print sprintf("%04x: %02x\n", $addr, ord($byte)) if $code_listing;
}
print $ofh pack("C", ord($byte));
calc_checksum(ord($byte));
$addr++;
} }
} }
@ -2380,15 +2388,16 @@ if (open($ifh, "<$input_file")) {
} }
} elsif ($ucmnemonic eq 'HEX') { } elsif ($ucmnemonic eq 'HEX') {
# Unpack hex data. # Unpack hex data.
#my @bytes = map { pack('C', hex($_)) } ($operand =~ /(..)/g);
my @bytes = map { pack('C', hex($_)) } ($operand =~ /(..)/g); my @bytes = map { pack('C', hex($_)) } ($operand =~ /(..)/g);
generate_bytes($ofh, $addr, \@bytes, $lineno, $line); generate_bytes($ofh, $addr, \@bytes, $lineno, $line);
$addr += scalar(@bytes); #$addr += scalar(@bytes);
} elsif ($ucmnemonic eq 'ASC') { } elsif ($ucmnemonic eq 'ASC') {
# Unpack string dats. # Unpack string dats.
my ($str) = $operand =~ /^\"(.+)\"$/; my ($str) = $operand =~ /^\"(.+)\"$/;
my @bytes = map { pack('C', ord($_)) } ($str =~ /(.)/g); my @bytes = map { pack('C', ord($_) | 0x80) } ($str =~ /(.)/g);
generate_bytes($ofh, $addr, \@bytes, $lineno, $line); generate_bytes($ofh, $addr, \@bytes, $lineno, $line);
$addr += scalar(@bytes); #$addr += scalar(@bytes);
} elsif ($ucmnemonic =~ /DFB/i) { } elsif ($ucmnemonic =~ /DFB/i) {
if ($operand =~ /^%([01]{8})/) { if ($operand =~ /^%([01]{8})/) {
my $byte = unpack('C', pack("B8", $1)); my $byte = unpack('C', pack("B8", $1));
@ -2404,13 +2413,13 @@ if (open($ifh, "<$input_file")) {
foreach my $sym (@symbols) { foreach my $sym (@symbols) {
my $symval = get_symval($sym); my $symval = get_symval($sym);
if (defined $symval) { if (defined $symval) {
push @bytes, sprintf("%02x", parse_symval($symval)); push @bytes, pack('C', hex(sprintf("%02x", parse_symval($symval))));
} else { } else {
print "**** $lineno - Unknown symbol '$sym' in '$line'\n"; print "**** $lineno - Unknown symbol '$sym' in '$line'\n";
} }
} }
generate_bytes($ofh, $addr, \@bytes, $lineno, $line); generate_bytes($ofh, $addr, \@bytes, $lineno, $line);
$addr += scalar(@bytes); #$addr += scalar(@bytes);
} else { } else {
print "$line - Bad byte definition '$operand'\n"; print "$line - Bad byte definition '$operand'\n";
} }