bdc48a9a47b4eda69aa52d797d81a65ff3aa8ad5
[uccvend-snackrom.git] / ROM / makeasm.pl
1 #!/usr/local/bin/perl -w
2
3 print "\tORG\t\$8000\n";
4
5 my %transtable = ( '02' => 'IDIV' ,
6                         '03' => 'FDIV' ,
7                         '08' => 'INX' , 
8                         '09' => 'DEX',
9                         '0A' => 'CLV',
10                         '0D' => 'SEC',
11                         '0E' => 'CLI',
12                         '0F' => 'SEI',
13                         '19' => 'DAA',
14                         '1B' => 'ABA',
15                         '30' => 'TSX',
16                         '31' => 'INS',
17                         '32' => 'PULA',
18                         '33' => 'PULB',
19                         '34' => 'DES',
20                         '35' => 'TXS',
21                         '36' => 'PSHA',
22                         '37' => 'PSHB',
23                         '3C' => 'PSHX',
24                         '38' => 'PULX',
25                         '3A' => 'ABX',
26                         '3B' => 'RTI',
27                         '3E' => 'WAI',
28                         '43' => 'COMA',
29                         '46' => 'RORA',
30                         '49' => 'ROLA',
31                         '4A' => 'DECA',
32                         '4C' => 'INCA',
33                         '4F' => 'CLRA',
34                         '53' => 'COMB',
35                         '56' => 'RORB',
36                         '59' => 'ROLB',
37                         '5A' => 'DECB',
38                         '5F' => 'CLRB',
39                         '8F' => 'XGDX',
40                         '39' => 'RTS' );
41
42                 #       '10' => 'SBA',
43
44
45 my %twobytefirst = ( '18' => '1' );
46
47 my %twobytesecond = ( '18 38' => 'PULY',
48                         '18 3A' => 'ABY',
49                         '18 3C' => 'PSHY');
50
51 LINE: while (<>) {
52
53 # if blank line, print blank line
54   if (/^\s*$/) { print "\n"; next LINE; }
55
56 # if comment line, pass straight through
57   if (/^\s*;/) { print; next LINE; }
58
59 # if duplicate label - rename uniquely
60   if (/^\s*((loop|jump82|goto91):)/) { print "${1}_$.\n"; next LINE; }
61
62 # if it's a label, print label
63   if (/^\s*(\w*:)/) { print "$1\n"; next LINE; }
64
65 # if it's a vector table, print words
66   if (/^\t\.word\t([a-f0-9]{4})$/) { print "\tFDB\t\$\U$1\n"; next LINE; }
67
68 # otherwise, catch all, print bytes
69   if (/^([A-F0-9]{4}) ((([A-F0-9]{2}) )*[A-F0-9]{2})/) {
70     instruction($_);
71     next LINE;
72   }
73
74 # if control Z, remove it
75   if (/^\cZ$/) { next LINE; }
76
77 # FINAL print commented out
78   print ";$_";
79 }
80
81 # Process one instruction
82 # Usage: instruction line
83 sub instruction {
84     my ($line) = @_;
85     print ";$line";
86
87     $instruction = substr($line,5,2);
88
89     if (defined $transtable{$instruction}) {
90         print "\t$transtable{$instruction}";
91         $line =~ /$transtable{$instruction}(.*)$/i;
92         print "$1\n";
93         return;
94     }
95    
96     if (defined $twobytefirst{$instruction}) {
97         $thing = substr($line,5,5);
98         if (defined $twobytesecond{$thing}) {
99                 print "\t" . $twobytesecond{$thing};
100                 $line =~ /$twobytesecond{$thing}(.*)$/i;
101                 print "$1\n";
102                 return;
103         }
104     }
105    
106     if ($line =~ /^([A-F0-9]{4}) ((([A-F0-9]{2}) )*[A-F0-9]{2})/) {
107         @_=split(' ',$2);
108         print "\tFCB\t\$".join(', $',@_)."\n";
109     }
110 }

UCC git Repository :: git.ucc.asn.au