blob: 78031a76e01376b115c60ad4610604499fe07c72 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#!/usr/bin/perl -w
LINE: while(<>) {
chomp;
next if /^\s*$/;
next if /^\s+\.byte/;
next if /^\s+\.setcpu/;
next if /^\s+;/;
# join lone label: with next line
if(/^[a-zA-Z0-9_]+:\s*$/) {
$_ .= <>;
redo LINE;
}
# comment-only lines:
if(/^;\s+(.*)/) {
print "/* $1 */\n";
next;
}
if(s/(^[a-zA-Z0-9_]+):?//) {
my $label = $1;
if(/:=\s*\$([0-9A-F]{4})/) {
print "u16 $label = 0x$1;\n";
next;
} elsif(/\.byte/) {
/; ([0-9A-F]{4})\s/;
print "u16 $label = 0x$1;\n";
next;
} else {
print "$label:\n";
}
}
s/\s+;.*//;
s/^\s*([a-z]{3})\s*//;
my $mnem = $1;
s/\s*$//;
my $operand = $_;
my $arg = "";
print "\t";
if(!$operand) {
$mnem .= "_a" if $mnem =~ /asl|lsr|rol|ror/;
print $mnem . "();\n";
next;
}
$operand =~ s,\$,0x,;
$operand =~ s,;.*,,;
#print "mnem '$mnem', operand '$operand'\n";
if($operand =~ /#(.*)/) {
print $mnem . "_i(" . $1 . ");\n";
next;
}
if($operand =~ /\(([^)]+)\),y/) {
print $mnem . "_ind_y(" . $1 . ");\n";
next;
}
if($operand =~ /(.+),([xy])/) {
print $mnem . "_abs_" . $2 . "(" . $1 . ");\n";
next;
}
print $mnem . "(" . $operand . ");\n";
}
|