| 1 | #!perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use CPU::Z80::Disassembler; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Getopt::Std; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | our $opt_a; # address | |||||||||||||||||||||||||||
| 12 | 3 | our $opt_c; # use control file | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | getopts('a:c') && @ARGV == 1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
&getopts("a:c") and @ARGV == 1
MC/DC0%0/2
&getopts("a:c") and @ARGV == 1
&getopts("a:c")
@ARGV == 1
Truth table33%1/3
A and B
A= &getopts("a:c")B= @ARGV == 1
| |||||||||||||||||||||||||||||
| 15 | or die "Usage: ",basename($0)," [-a hexaddr] [-c] file\n"; | ||||||||||||||||||||||||||||
| 16 | 3 | my $file = shift; | |||||||||||||||||||||||||||
| 17 | 3 | ▶ | $opt_a = (defined $opt_a) ? hex($opt_a) : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 3 | ▶ | if ($opt_c) { # use a control file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 3 | my $ctl_file = replace_ext($file, ".ctl"); | |||||||||||||||||||||||||||
| 21 | 3 | my $asm_file = replace_ext($file, ".asm"); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | ▶ | if (! -f $ctl_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 1 | print "Create new control file $ctl_file to disassemble $file\n"; | |||||||||||||||||||||||||||
| 25 | 1 | CPU::Z80::Disassembler->create_control_file($ctl_file, $file, $opt_a); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | else { | ||||||||||||||||||||||||||||
| 28 | 2 | print "Read $ctl_file\n"; | |||||||||||||||||||||||||||
| 29 | 2 | my $dis = CPU::Z80::Disassembler->new; | |||||||||||||||||||||||||||
| 30 | 2 | $dis->load_control_file($ctl_file); | |||||||||||||||||||||||||||
| 31 | 2 | print "Write $asm_file\n"; | |||||||||||||||||||||||||||
| 32 | 2 | $dis->write_asm($asm_file); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | else { | ||||||||||||||||||||||||||||
| 36 | 0 | my $dump_file = replace_ext($file, ".dump"); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | my $dis = CPU::Z80::Disassembler->new; | |||||||||||||||||||||||||||
| 39 | 0 | $dis->memory->load_file($file, $opt_a); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | print "Write $dump_file\n"; | |||||||||||||||||||||||||||
| 42 | 0 | $dis->write_dump($dump_file); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 46 | sub replace_ext { | ||||||||||||||||||||||||||||
| 47 | 6 | ▶ | my($file, $new_ext) = @_; | ||||||||||||||||||||||||||
|
Subroutine
replace_ext: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | 6 | $file =~ s/\.\w+$/$new_ext/; | |||||||||||||||||||||||||||
| 49 | 6 | return path($file); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||