aboutsummaryrefslogtreecommitdiff
path: root/f65/asm2fake65.pl
diff options
context:
space:
mode:
Diffstat (limited to 'f65/asm2fake65.pl')
-rwxr-xr-xf65/asm2fake65.pl72
1 files changed, 72 insertions, 0 deletions
diff --git a/f65/asm2fake65.pl b/f65/asm2fake65.pl
new file mode 100755
index 0000000..78031a7
--- /dev/null
+++ b/f65/asm2fake65.pl
@@ -0,0 +1,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";
+}