-
Notifications
You must be signed in to change notification settings - Fork 13
/
disasm
executable file
·67 lines (54 loc) · 1.52 KB
/
disasm
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
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
# CSCVon8 disassembler, (C) 2019 Warren Toomey, GPL3
my %Inst;
my @ROM;
# Disassemble the instruction ROM filename on the cmd-line,
# or instr.rom if not given.
my $romfile= (@ARGV == 1) ? $ARGV[0] : "instr.rom";
open( my $IN, "<", "opcodes" ) || die("Cannot read opcodes: $!\n");
while (<$IN>) {
chomp;
my ($opcode, $oplen, $name)= split( m{\s+}, $_);
$Inst{$opcode}= [ $name, $oplen ];
}
close($IN);
open($IN, "<", $romfile) || die("Cannot read $romfile: $!\n");
while (<$IN>) {
chomp; push(@ROM, split(m{\s+}, $_));
}
close($IN);
#print(Dumper(\%Inst));
#print(Dumper(\@ROM));
my $i=0;
while ($i < 0x7FFF) {
my $suffix="";
my $inst= $ROM[$i];
printf("%04x: %02s ", $i, $inst);
# Just print the byte if not a defined instruction
if (!defined($Inst{$inst})) {
print("\n"); $i++; next;
}
my ($name, $len)= @{ $Inst{$inst} };
# Lose the underscores
$name=~ s{_}{ }g;
# Find a suffix
if ($name=~ m{(.*) (,[AB]$)}) {
$suffix= $2; $name=$1;
}
print("$name ");
printf("\$%02s", $ROM[$i+1]) if ($len==2);
printf("\$%02s%02s", $ROM[$i+1], $ROM[$i+2]) if ($len==3);
printf("\$%02s%02s/%02s", $ROM[$i+1], $ROM[$i+2], $ROM[$i+3]) if ($len==4);
printf("\$%02s%02s \$%02s%02s",
$ROM[$i+1], $ROM[$i+2], $ROM[$i+3], $ROM[$i+4]) if ($len==5);
printf("\$%02s%02s \$%02s%02s \$%02s%02s",
$ROM[$i+1], $ROM[$i+2], $ROM[$i+3], $ROM[$i+4], $ROM[$i+5], $ROM[$i+6])
if ($len==7);
print("00$suffix") if ($suffix);
print("\n");
$i += $len;
}
exit(0);