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 %twobytesecondword = ( '18 FE' => 'LDY\t%s',
52 '18 FF' => 'STY\t%s');
54 my %onewitharg = ('60' => "NEG\t\$%s,X",
55 '63' => "COM\t\$%s,X",
56 '64' => "LSR\t\$%s,X",
57 '67' => "ASR\t\$%s,X",
58 '68' => "ASL\t\$%s,X",
59 '6A' => "DEC\t\$%s,X",
60 '6C' => "INC\t\$%s,X",
61 '6D' => "TST\t\$%s,X",
62 '6E' => "JMP\t\$%s,X",
63 '6F' => "CLR\t\$%s,X",
64 '80' => "SUBA\t#\$%s",
65 '81' => "CMPA\t#\$%s",
66 '82' => "SBCA\t#\$%s",
67 '84' => "ANDA\t#\$%s",
68 '85' => "BITA\t#\$%s",
69 '86' => "LDAA\t#\$%s",
70 '88' => "EORA\t#\$%s",
72 'A0' => "SUBA\t\$%s,X",
73 'A1' => "CMPA\t\$%s,X",
74 'A2' => "SBCA\t\$%s,X",
75 'A3' => "SUBD\t\$%s,X",
76 'A4' => "ANDA\t\$%s,X",
77 'A6' => "LDAA\t\$%s,X",
78 'A7' => "STA\t\$%s,X",
79 'A8' => "EORA\t\$%s,X",
80 'A9' => "ADCA\t\$%s,X",
81 'AA' => "ORAA\t\$%s,X",
82 'AB' => "ADDA\t\$%s,X",
83 'AC' => "CPX\t\$%s,X",
84 'AD' => "JSR\t\$%s,X",
85 'AE' => "LDS\t\$%s,X",
86 'AF' => "STS\t\$%s,X",
87 'C0' => "SUBB\t#\$%s",
88 'C1' => "CMPB\t#\$%s",
89 'C2' => "SBCB\t#\$%s",
90 'C4' => "ANDB\t#\$%s",
91 'C5' => "BITB\t#\$%s",
92 'C6' => "LDAB\t#\$%s",
93 'C8' => "EORB\t#\$%s",
95 'E0' => "SUBB\t\$%s,X",
96 'E1' => "CMPB\t\$%s,X",
97 'E2' => "SBCB\t\$%s,X",
98 'E3' => "ADDD\t\$%s,X",
99 'E4' => "ANDB\t\$%s,X",
100 'E6' => "LDAB\t\$%s,X",
101 'E7' => "STAB\t\$%s,X",
102 'E8' => "EORB\t\$%s,X",
103 'E9' => "ADCB\t\$%s,X",
104 'EA' => "ORAB\t\$%s,X",
105 'EB' => "ADDB\t\$%s,X",
106 'EC' => "LDD\t\$%s,X",
107 'ED' => "STD\t\$%s,X",
108 'EE' => "LDX\t\$%s,X",
109 'EF' => "STX\t\$%s,X" );
160 # if blank line, print blank line
161 if (/^\s*$/) { print "\n"; next LINE; }
163 # if comment line, pass straight through
164 if (/^\s*;/) { print; next LINE; }
166 # if duplicate label - rename uniquely
167 if (/^\s*((loop|jump82|goto91):)/) { print "${1}_$.\n"; next LINE; }
169 # if it's a label, print label
170 if (/^\s*(\w*:)/) { print "$1\n"; next LINE; }
172 # if it's a vector table, print words
173 if (/^\t\.word\t([a-f0-9]{4})$/) { print "\tFDB\t\$\U$1\n"; next LINE; }
175 # otherwise, catch all, print bytes
176 if (/^([A-F0-9]{4}) ((([A-F0-9]{2}) )*[A-F0-9]{2})/) {
181 # if control Z, remove it
182 if (/^\cZ$/) { next LINE; }
184 # FINAL print commented out
188 # Process one instruction
189 # Usage: instruction line
193 $instruction = substr($line,5,2);
195 if (defined $transtable{$instruction}) {
196 print "\t$transtable{$instruction}";
197 $line =~ /$transtable{$instruction}(.*)$/i;
202 if (defined $twobytefirst{$instruction}) {
203 $thing = substr($line,5,5);
204 if (defined $twobytesecond{$thing}) {
205 print "\t" . $twobytesecond{$thing};
206 $line =~ /$twobytesecond{$thing}(.*)$/i;
211 if (defined $twobytesecondword{$thing}) {
212 $athing = substr($line,11,2);
213 $athing2 = substr($line,14,2);
214 if (!($athing2 =~ /\s+/)) {
215 $curraddr = substr($line,0,4);
216 printf "FOO%s\tEQU\t\$%s%s\n", $curraddr,$athing,$athing2;
217 printf "\t$twobytesecondword{$thing}", ">FOO$curraddr";
218 $line =~ /$twobytesecondword{$thing} [0-9A-F][0-9A-F][0-9A-F][0-9A-F](.*)$/i;
225 if (defined $onewitharg{$instruction}) {
226 $thing = substr($line,8,2);
228 printf "\t$onewitharg{$instruction}", $thing;
229 $line =~ /$onewitharg{$instruction} [0-9A-F][0-9A-F](.*)$/i;
234 if (defined $onewithword{$instruction}) {
235 $thing = substr($line,8,2);
236 $thing2 = substr($line,11,2);
237 if (!($thing2 =~ /\s+/)) {
238 $curraddr = substr($line,0,4);
239 printf "FOO%s\tEQU\t\$%s%s\n", $curraddr,$thing,$thing2;
240 printf "\t$onewithword{$instruction}", ">FOO$curraddr";
241 $line =~ /$onewithword{$instruction} [0-9A-F][0-9A-F][0-9A-F][0-9A-F](.*)$/i;
248 if ($line =~ /^([A-F0-9]{4}) ((([A-F0-9]{2}) )*[A-F0-9]{2})/) {
250 print "\tFCB\t\$".join(', $',@_)."\n";