Fixed immediate mode bugs

This commit is contained in:
Leeland Heins 2018-12-27 13:57:10 -06:00 committed by GitHub
parent 8cde8f4a17
commit ec8a503f5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

128
as65.pl
View File

@ -1037,8 +1037,11 @@ sub is_Immediate {
} elsif ($operand =~ /^#[<>]*([A-Za-z\.\?:][A-Za-z0-9_\.\?:]*)$/) { } elsif ($operand =~ /^#[<>]*([A-Za-z\.\?:][A-Za-z0-9_\.\?:]*)$/) {
return 2; return 2;
# Allow arithmetic on symbol # Allow arithmetic on symbol
} elsif ($operand =~ /^#[<>]*([A-Za-z\.\?:][A-Za-z0-9_\.\?:]*)\s*[+-]\s*(\$[0-9a-fA-F]+)$/) { } elsif ($operand =~ /^#[<>]*([A-Za-z\.\?:][A-Za-z0-9_\.\?:]*)\s*[+-]\s*(\$*[0-9a-fA-F]+)$/) {
#print "GOT HERE IMMEDIATE '$1' '$2'\n";
return 2; return 2;
#} else {
#print "NOT IMMEDIATE! '$operand'\n";
} }
return 0; return 0;
@ -1062,12 +1065,12 @@ sub generate_Immediate {
} elsif ($operand =~ /^#([<>]*[A-Za-z\.\?:][A-Za-z0-9_\.\?:]*)/) { } elsif ($operand =~ /^#([<>]*[A-Za-z\.\?:][A-Za-z0-9_\.\?:]*)/) {
handle_8_bit_symbol($ofh, $lineno, $addr, $opcode, $1, $line); handle_8_bit_symbol($ofh, $lineno, $addr, $opcode, $1, $line);
# Allow arithmetic on symbol # Allow arithmetic on symbol
} elsif ($operand =~ /^#([<>]*)([A-Za-z\.\?:][A-Za-z0-9_\.\?:]*)\s*[+]\s*(\$[0-9a-fA-F]+)$/) { } elsif ($operand =~ /^#([<>]*)([A-Za-z\.\?:][A-Za-z0-9_\.\?:]*)\s*[+]\s*(\$*[0-9a-fA-F]+)$/) {
print "foo $1 $2 $3\n"; #print "foo $1 $2 $3\n";
# Add # Add
handle_8_bit_symbol_add($ofh, $lineno, $addr, $opcode, $1, $2, $3, $line); handle_8_bit_symbol_add($ofh, $lineno, $addr, $opcode, $1, $2, $3, $line);
} elsif ($operand =~ /^#([<>]*)([A-Za-z\.\?:][A-Za-z0-9_\.\?:]*)\s*[-]\s*(\$[0-9a-fA-F]+)$/) { } elsif ($operand =~ /^#([<>]*)([A-Za-z\.\?:][A-Za-z0-9_\.\?:]*)\s*[-]\s*(\$*[0-9a-fA-F]+)$/) {
print "foo $1 $2 $3\n"; #print "foo $1 $2 $3\n";
# Subtract # Subtract
handle_8_bit_symbol_sub($ofh, $lineno, $addr, $opcode, $1, $2, $3, $line); handle_8_bit_symbol_sub($ofh, $lineno, $addr, $opcode, $1, $2, $3, $line);
} else { } else {
@ -1804,31 +1807,33 @@ sub is_Indirect_Zero_Page_Y {
return 2; return 2;
} elsif ($operand =~ /^\(([A-Za-z\.\?:][A-Za-z0-9_\.\?:]*)\),[Yy]$/) { } elsif ($operand =~ /^\(([A-Za-z\.\?:][A-Za-z0-9_\.\?:]*)\),[Yy]$/) {
# Not Indirect Zero Page,Y if the symbol is not 8 bits. # Not Indirect Zero Page,Y if the symbol is not 8 bits.
my $symval = $symbols{$1}; ##FIXME -- FNORD
if (defined $symval) { #my $symval = $symbols{$1};
if ($symval =~ /^\d+$/) { #if (defined $symval) {
return 0 if ($symval > 255); # if ($symval =~ /^\d+$/) {
} else { # return 0 if ($symval > 255);
return 0 unless $symval =~ /^\$[0-9a-fA-F][0-9a-fA-F]$|^%[01]{8}$/; # } else {
} # return 0 unless $symval =~ /^\$[0-9a-fA-F][0-9a-fA-F]$|^%[01]{8}$/;
} else { # }
# Assume that forward declared symbols are addresses. #} else {
return 0; # # Assume that forward declared symbols are addresses.
} # return 0;
#}
return 2; return 2;
} elsif ($operand =~ /^\(([A-Za-z\.\?:][A-Za-z0-9_\.\?:]*)\s*[+-]\s*(\$*[0-9a-fA-F]+)\),[Yy]/) { } elsif ($operand =~ /^\(([A-Za-z\.\?:][A-Za-z0-9_\.\?:]*)\s*[+-]\s*(\$*[0-9a-fA-F]+)\),[Yy]/) {
# Not Indirect Zero Page,Y if the symbol is not 8 bits. # Not Indirect Zero Page,Y if the symbol is not 8 bits.
my $symval = $symbols{$1}; ##FIXME -- FNORD
if (defined $symval) { #my $symval = $symbols{$1};
if ($symval =~ /^\d+$/) { #if (defined $symval) {
return 0 if ($symval > 255); # if ($symval =~ /^\d+$/) {
} else { # return 0 if ($symval > 255);
return 0 unless $symval =~ /^\$[0-9a-fA-F][0-9a-fA-F]$|^%[01]{8}$/; # } else {
} # return 0 unless $symval =~ /^\$[0-9a-fA-F][0-9a-fA-F]$|^%[01]{8}$/;
} else { # }
# Assume that forward declared symbols are addresses. #} else {
return 0; # # Assume that forward declared symbols are addresses.
} # return 0;
#}
return 2; return 2;
} }
@ -2320,7 +2325,43 @@ if (open($ifh, "<$input_file")) {
# define constant # define constant
my $symbol = $label; my $symbol = $label;
print "%%%% Saving Symbol $symbol $operand\n" if $verbose; print "%%%% Saving Symbol $symbol $operand\n" if $verbose;
$symbols{$symbol} = $operand; if ($operand =~ /\$([0-9a-fA-F]+)/) {
$symbols{$symbol} = $operand;
# 8 bit binary
} elsif ($operand =~ /^%([01]{8})$/) {
$symbols{$symbol} = '$' . sprintf("%02x", pack("B8", $1));
# 16 bit binary
} elsif ($operand =~ /^%([01]{8})([01]{8})$/) {
$symbols{$symbol} = '$' . sprintf("%02x", pack("B8", $1)) . sprintf("%02x", pack("B8", $2));
# Handle symbol
} elsif ($operand =~ /^([<>]*[A-Za-z\.\?:][A-Za-z0-9_\.\?:]*)/) {
$symbols{$symbol} = $symbols{$operand};
# Allow arithmetic on symbol
} elsif ($operand =~ /^([<>]*)([A-Za-z\.\?:][A-Za-z0-9_\.\?:]*)\s*[+]\s*(\$[0-9a-fA-F]+)$/) {
# Add
my $opval = $1;
my $opval2 = $2;
my $opv2 = $opval2;
# Hex
if ($opval2 =~ /^\$([0-9a-fA-F]+)/) {
##FIXME -- need to handle binary, etc
$opv2 = hex(lc($1));
}
$symbols{$symbol} = $symbols{$opval} + $opv2;
} elsif ($operand =~ /^([<>]*)([A-Za-z\.\?:][A-Za-z0-9_\.\?:]*)\s*[+]\s*(\$[0-9a-fA-F]+)$/) {
# Subtract
my $opval = $1;
my $opval2 = $2;
my $opv2 = $opval2;
# Hex
if ($opval2 =~ /^\$([0-9a-fA-F]+)/) {
##FIXME -- need to handle binary, etc
$opv2 = hex(lc($1));
}
$symbols{$symbol} = $symbols{$opval} - $opv2;
} else {
$symbols{$symbol} = $operand;
}
} elsif ($ucmnemonic =~ /HEX/i) { } elsif ($ucmnemonic =~ /HEX/i) {
if ($label ne '') { if ($label ne '') {
my $symbol = $label; my $symbol = $label;
@ -2340,11 +2381,23 @@ if (open($ifh, "<$input_file")) {
$addr += $1; $addr += $1;
} }
} elsif ($ucmnemonic =~ /^DB$/i) { } elsif ($ucmnemonic =~ /^DB$/i) {
if ($label ne '') {
my $symbol = $label;
$symbols{$symbol} = sprintf("\$%04x", $addr);
}
#print "GOT HERE 1\n"; #print "GOT HERE 1\n";
$addr++; $addr++;
} elsif ($ucmnemonic =~ /^DA$/i) { } elsif ($ucmnemonic =~ /^DA$/i) {
if ($label ne '') {
my $symbol = $label;
$symbols{$symbol} = sprintf("\$%04x", $addr);
}
$addr += 2; $addr += 2;
} elsif ($ucmnemonic =~ /DFB/) { } elsif ($ucmnemonic =~ /DFB/) {
if ($label ne '') {
my $symbol = $label;
$symbols{$symbol} = sprintf("\$%04x", $addr);
}
if ($operand =~ /^%([01]{8})/) { if ($operand =~ /^%([01]{8})/) {
$addr++; $addr++;
} elsif ($operand =~ /^\$([0-9a-fA-F][0-9a-fA-F])/) { } elsif ($operand =~ /^\$([0-9a-fA-F][0-9a-fA-F])/) {
@ -2354,6 +2407,7 @@ if (open($ifh, "<$input_file")) {
} elsif ($operand =~ /^#>(.+)/) { } elsif ($operand =~ /^#>(.+)/) {
$addr++; $addr++;
} else { } else {
##FIXME -- allow symbol arithmatic here
my @symbols = split(',', $operand); my @symbols = split(',', $operand);
my @bytes; my @bytes;
foreach my $sym (@symbols) { foreach my $sym (@symbols) {
@ -2375,12 +2429,24 @@ if (open($ifh, "<$input_file")) {
$addr += length($str); $addr += length($str);
$addr++ if defined $2; $addr++ if defined $2;
} elsif ($ucmnemonic =~ /HBY/) { } elsif ($ucmnemonic =~ /HBY/) {
if ($label ne '') {
my $symbol = $label;
$symbols{$symbol} = sprintf("\$%04x", $addr);
}
##FIXME -- implement this ##FIXME -- implement this
} elsif ($ucmnemonic =~ /BYT/) { } elsif ($ucmnemonic =~ /BYT/) {
if ($label ne '') {
my $symbol = $label;
$symbols{$symbol} = sprintf("\$%04x", $addr);
}
##FIXME -- implement this ##FIXME -- implement this
} elsif ($ucmnemonic =~ /DFS/) { } elsif ($ucmnemonic =~ /DFS/) {
if ($label ne '') {
my $symbol = $label;
$symbols{$symbol} = sprintf("\$%04x", $addr);
}
##FIXME -- implement this ##FIXME -- implement this
} elsif ($ucmnemonic =~ /OBJ|CHK|LST/) { } elsif ($ucmnemonic =~ /OBJ|CHK|LST|END/) {
# Just ignore this # Just ignore this
} elsif ($ucmnemonic =~ /MAC/) { } elsif ($ucmnemonic =~ /MAC/) {
print "**** Unsupported **** '$line'\n"; print "**** Unsupported **** '$line'\n";
@ -2453,7 +2519,7 @@ if (open($ifh, "<$input_file")) {
my $ucmnemonic = uc($mnemonic); my $ucmnemonic = uc($mnemonic);
# Skip ORG, EQU and OBJ on pass 2. # Skip ORG, EQU and OBJ on pass 2.
if ($ucmnemonic =~ /ORG|EQU|\.EQ|OBJ|LST|^=$/) { if ($ucmnemonic =~ /ORG|EQU|\.EQ|OBJ|LST|^=$|END/) {
print sprintf(" %-4d %s\n", $lineno, $line) if $code_listing; print sprintf(" %-4d %s\n", $lineno, $line) if $code_listing;
next; next;
} }
@ -2504,7 +2570,7 @@ if (open($ifh, "<$input_file")) {
generate_8($ofh, $addr, $byte, $lineno, $line); generate_8($ofh, $addr, $byte, $lineno, $line);
$addr++; $addr++;
} elsif ($operand =~ /^\$([0-9a-fA-F][0-9a-fA-F])/) { } elsif ($operand =~ /^\$([0-9a-fA-F][0-9a-fA-F])/) {
generate_8($ofh, $addr, $1, $lineno, $line); generate_8($ofh, $addr, hex(lc($1)), $lineno, $line);
$addr++; $addr++;
} elsif ($operand =~ /^#<(.+)/) { } elsif ($operand =~ /^#<(.+)/) {
#print "symbol=$1'\n"; #print "symbol=$1'\n";