Modified to start pushing instructions through to as11/vend.asm
[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                         '30' => 'TSX',
15                         '31' => 'INS',
16                         '32' => 'PULA',
17                         '33' => 'PULB',
18                         '34' => 'DES',
19                         '35' => 'TXS',
20                         '36' => 'PSHA',
21                         '37' => 'PSHB',
22                         '3C' => 'PSHX',
23                         '38' => 'PULX',
24                         '3B' => 'RTI',
25                         '3E' => 'WAI',
26                         '43' => 'COMA',
27                         '46' => 'RORA',
28                         '49' => 'ROLA',
29                         '4A' => 'DECA',
30                         '4C' => 'INCA',
31                         '4F' => 'CLRA',
32                         '53' => 'COMB',
33                         '56' => 'RORB',
34                         '59' => 'ROLB',
35                         '5A' => 'DECB',
36                         '5F' => 'CLRB',
37                         '8F' => 'XGDX',
38                         '39' => 'RTS' );
39
40                 #       '10' => 'SBA',
41
42
43 LINE: while (<>) {
44
45 # if blank line, print blank line
46   if (/^\s*$/) { print "\n"; next LINE; }
47
48 # if comment line, pass straight through
49   if (/^\s*;/) { print; next LINE; }
50
51 # if duplicate label - rename uniquely
52   if (/^\s*((loop|jump82|goto91):)/) { print "${1}_$.\n"; next LINE; }
53
54 # if it's a label, print label
55   if (/^\s*(\w*:)/) { print "$1\n"; next LINE; }
56
57 # if it's a vector table, print words
58   if (/^\t\.word\t([a-f0-9]{4})$/) { print "\tFDB\t\$\U$1\n"; next LINE; }
59
60 # otherwise, catch all, print bytes
61   if (/^([A-F0-9]{4}) ((([A-F0-9]{2}) )*[A-F0-9]{2})/) {
62     instruction($_);
63     next LINE;
64   }
65
66 # if control Z, remove it
67   if (/^\cZ$/) { next LINE; }
68
69 # FINAL print commented out
70   print ";$_";
71 }
72
73 # Process one instruction
74 # Usage: instruction line
75 sub instruction {
76     my ($line) = @_;
77     print ";$line";
78
79     $instruction = substr($line,5,2);
80
81     if (defined $transtable{$instruction}) {
82         print "\t$transtable{$instruction}";
83         $line =~ /$transtable{$instruction}(.*)$/i;
84         print "$1\n";
85         return;
86     }
87    
88     # FIXME: parse instruction
89     #if (defined($transtable{$instruction})) {
90     #   print "\t$transtable{$instruction}";
91 #       if (defined($comment)) { print "; $comment"; }
92 #       print "\n";
93 #       return;
94 #    }
95
96 #        chomp;
97 #        $l = length;
98 #        if ($l == 42) {
99 #                print "$_\n";
100 #                next;
101 #        } elsif ($l != 33) {
102 #                print "$_\n";
103 #                next;
104 #        } else {
105
106 #        $addr = substr($_,0,4);
107 #        $inst = substr($_,27,3);
108 #        $val = substr($_,31,2);
109
110 #        #print "$val\n";
111 #        $daddr = (hex $addr) + 2 + convert($val);
112
113
114 #        if (defined $commands{$inst}) {
115 #                print "$_\t\t;";
116 #                printf "%4X", $daddr;
117 #                #print " $addr $inst $val\n";
118 #                print "\n";
119 #        }
120 #        }
121
122     if ($line =~ /^([A-F0-9]{4}) ((([A-F0-9]{2}) )*[A-F0-9]{2})/) {
123         @_=split(' ',$2);
124         print "\tFCB\t\$".join(', $',@_)."\n";
125     }
126 }

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