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 '8B' => "ADDA\t#\$%s",
73 'A0' => "SUBA\t\$%s,X",
74 'A1' => "CMPA\t\$%s,X",
75 'A2' => "SBCA\t\$%s,X",
76 'A3' => "SUBD\t\$%s,X",
77 'A4' => "ANDA\t\$%s,X",
78 'A6' => "LDAA\t\$%s,X",
79 'A7' => "STA\t\$%s,X",
80 'A8' => "EORA\t\$%s,X",
81 'A9' => "ADCA\t\$%s,X",
82 'AA' => "ORAA\t\$%s,X",
83 'AB' => "ADDA\t\$%s,X",
84 'AC' => "CPX\t\$%s,X",
85 'AD' => "JSR\t\$%s,X",
86 'AE' => "LDS\t\$%s,X",
87 'AF' => "STS\t\$%s,X",
88 'C0' => "SUBB\t#\$%s",
89 'C1' => "CMPB\t#\$%s",
90 'C2' => "SBCB\t#\$%s",
91 'C4' => "ANDB\t#\$%s",
92 'C5' => "BITB\t#\$%s",
93 'C6' => "LDAB\t#\$%s",
94 'C8' => "EORB\t#\$%s",
95 'C9' => "ADCB\t#\$%s",
97 'CB' => "ADDB\t#\$%s",
98 'E0' => "SUBB\t\$%s,X",
99 'E1' => "CMPB\t\$%s,X",
100 'E2' => "SBCB\t\$%s,X",
101 'E3' => "ADDD\t\$%s,X",
102 'E4' => "ANDB\t\$%s,X",
103 'E6' => "LDAB\t\$%s,X",
104 'E7' => "STAB\t\$%s,X",
105 'E8' => "EORB\t\$%s,X",
106 'E9' => "ADCB\t\$%s,X",
107 'EA' => "ORAB\t\$%s,X",
108 'EB' => "ADDB\t\$%s,X",
109 'EC' => "LDD\t\$%s,X",
110 'ED' => "STD\t\$%s,X",
111 'EE' => "LDX\t\$%s,X",
112 'EF' => "STX\t\$%s,X" );
123 # '78' => "ASL\t>%s",
129 # '95' => "BITA\t<%s",
161 'FF' => "STX\t>%s" );
165 # if blank line, print blank line
166 if (/^\s*$/) { print "\n"; next LINE; }
168 # if comment line, pass straight through
169 if (/^\s*;/) { print; next LINE; }
171 # if duplicate label - rename uniquely
172 if (/^\s*((loop|jump82|goto91):)/) { print "${1}_$.\n"; next LINE; }
174 # if it's a label, print label
175 if (/^\s*(\w*:)/) { print "$1\n"; next LINE; }
177 # if it's a vector table, print words
178 if (/^\t\.word\t([a-f0-9]{4})$/) { print "\tFDB\t\$\U$1\n"; next LINE; }
180 # otherwise, catch all, print bytes
181 if (/^([A-F0-9]{4}) ((([A-F0-9]{2}) )*[A-F0-9]{2})/) {
186 # if control Z, remove it
187 if (/^\cZ$/) { next LINE; }
189 # FINAL print commented out
193 # Process one instruction
194 # Usage: instruction line
198 $instruction = substr($line,5,2);
200 if (defined $transtable{$instruction}) {
202 print "\t$transtable{$instruction}";
203 $line =~ /$transtable{$instruction}(.*)$/i;
208 if (defined $twobytefirst{$instruction}) {
210 $thing = substr($line,5,5);
211 if (defined $twobytesecond{$thing}) {
212 print "\t" . $twobytesecond{$thing};
213 $line =~ /$twobytesecond{$thing}(.*)$/i;
218 if (defined $twobytesecondword{$thing}) {
219 $athing = substr($line,11,2);
220 $athing2 = substr($line,14,2);
221 if (!($athing2 =~ /\s+/)) {
222 $curraddr = substr($line,0,4);
223 printf "FOO%s\tEQU\t\$%s%s\n", $curraddr,$athing,$athing2;
224 printf "\t$twobytesecondword{$thing}", "FOO$curraddr";
225 $line =~ /$twobytesecondword{$thing} [0-9A-F][0-9A-F][0-9A-F][0-9A-F](.*)$/i;
232 if (defined $onewitharg{$instruction}) {
234 $thing = substr($line,8,2);
236 printf "\t$onewitharg{$instruction}", $thing;
237 $line =~ /$onewitharg{$instruction} [0-9A-F][0-9A-F](.*)$/i;
242 if (defined $onewithword{$instruction}) {
244 $thing = substr($line,8,2);
245 $thing2 = substr($line,11,2);
246 if (!($thing2 =~ /\s+/)) {
247 $curraddr = substr($line,0,4);
248 printf "FOO%s\tEQU\t\$%s%s\n", $curraddr,$thing,$thing2;
249 printf "\t$onewithword{$instruction}", "FOO$curraddr";
250 $line =~ /$onewithword{$instruction} [0-9A-F][0-9A-F][0-9A-F][0-9A-F](.*)$/i;
257 if ($line =~ /^([A-F0-9]{4}) ((([A-F0-9]{2}) )*[A-F0-9]{2})/) {
259 print "\tFCB\t\$".join(', $',@_)."\n";