1 #!/usr/local/bin/perl -w
3 print "\tORG\t\$8000\n";
5 my %transtable = ( '02' => 'IDIV' ,
45 my %twobytefirst = ( '18' => '1' );
47 my %twobytesecond = ( '18 38' => 'PULY',
51 my %onewitharg = ('63' => "COM\t\$%s,X",
52 '6A' => "DEC\t\$%s,X",
53 '6C' => "INC\t\$%s,X",
54 '6D' => "TST\t\$%s,X",
55 '6E' => "JMP\t\$%s,X",
56 '6F' => "CLR\t\$%s,X",
57 '80' => "SUBA\t#\$%s",
58 '81' => "CMPA\t#\$%s",
59 '82' => "SBCA\t#\$%s",
60 '84' => "ANDA\t#\$%s",
61 '85' => "BITA\t#\$%s",
62 '86' => "LDAA\t#\$%s",
63 '88' => "EORA\t#\$%s",
65 'A3' => "SUBD\t\$%s,X",
66 'A7' => "STA\t\$%s,X",
67 'C0' => "SUBB\t#\$%s",
68 'C1' => "CMPB\t#\$%s",
69 'C2' => "SBCB\t#\$%s",
70 'C4' => "ANDB\t#\$%s",
71 'C5' => "BITB\t#\$%s",
72 'C6' => "LDAB\t#\$%s",
73 'C8' => "EORB\t#\$%s",
75 'E3' => "ADDD\t\$%s,X",
76 'EC' => "LDD\t\$%s,X",
77 'ED' => "STAD\t\$%s,X" );
128 # if blank line, print blank line
129 if (/^\s*$/) { print "\n"; next LINE; }
131 # if comment line, pass straight through
132 if (/^\s*;/) { print; next LINE; }
134 # if duplicate label - rename uniquely
135 if (/^\s*((loop|jump82|goto91):)/) { print "${1}_$.\n"; next LINE; }
137 # if it's a label, print label
138 if (/^\s*(\w*:)/) { print "$1\n"; next LINE; }
140 # if it's a vector table, print words
141 if (/^\t\.word\t([a-f0-9]{4})$/) { print "\tFDB\t\$\U$1\n"; next LINE; }
143 # otherwise, catch all, print bytes
144 if (/^([A-F0-9]{4}) ((([A-F0-9]{2}) )*[A-F0-9]{2})/) {
149 # if control Z, remove it
150 if (/^\cZ$/) { next LINE; }
152 # FINAL print commented out
156 # Process one instruction
157 # Usage: instruction line
162 $instruction = substr($line,5,2);
164 if (defined $transtable{$instruction}) {
165 print "\t$transtable{$instruction}";
166 $line =~ /$transtable{$instruction}(.*)$/i;
171 if (defined $twobytefirst{$instruction}) {
172 $thing = substr($line,5,5);
173 if (defined $twobytesecond{$thing}) {
174 print "\t" . $twobytesecond{$thing};
175 $line =~ /$twobytesecond{$thing}(.*)$/i;
181 if (defined $onewitharg{$instruction}) {
182 $thing = substr($line,8,2);
184 printf "\t$onewitharg{$instruction}", $thing;
185 $line =~ /$onewitharg{$instruction} [0-9A-F][0-9A-F](.*)$/i;
190 if (defined $onewithword{$instruction}) {
191 $thing = substr($line,8,2);
192 $thing2 = substr($line,11,2);
193 if (!($thing2 =~ /\s+/)) {
194 $curraddr = substr($line,0,4);
195 printf "FOO%s\tEQU\t\$%s%s\n", $curraddr,$thing,$thing2;
196 printf "\t$onewithword{$instruction}", ">FOO$curraddr";
197 $line =~ /$onewithword{$instruction} [0-9A-F][0-9A-F][0-9A-F][0-9A-F](.*)$/i;
203 if ($line =~ /^([A-F0-9]{4}) ((([A-F0-9]{2}) )*[A-F0-9]{2})/) {
205 print "\tFCB\t\$".join(', $',@_)."\n";