10 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
11 |
use M6502; |
use M6502; |
12 |
|
|
13 |
use base qw(Class::Accessor M6502 Screen Prefs Tape); |
use base qw(Class::Accessor VRac M6502 Screen Prefs Tape); |
14 |
__PACKAGE__->mk_accessors(qw(booted)); |
#__PACKAGE__->mk_accessors(qw()); |
15 |
|
|
16 |
=head1 NAME |
=head1 NAME |
17 |
|
|
60 |
|
|
61 |
$self->open_screen; |
$self->open_screen; |
62 |
$self->load_rom({ |
$self->load_rom({ |
63 |
0x1000 => 'dump/SCRINV.BIN', |
# 0x1000 => 'dump/SCRINV.BIN', |
64 |
# should be 0x6000, but oraoemu has 2 byte prefix |
# should be 0x6000, but oraoemu has 2 byte prefix |
65 |
0x5FFE => 'dump/screen.dmp', |
# 0x5FFE => 'dump/screen.dmp', |
66 |
# 0xC000 => 'rom/BAS12.ROM', |
# 0xC000 => 'rom/Orao/BAS12.ROM', |
67 |
# 0xE000 => 'rom/CRT12.ROM', |
# 0xE000 => 'rom/Orao/CRT12.ROM', |
68 |
0xC000 => 'rom/BAS13.ROM', |
0xC000 => 'rom/Orao/BAS13.ROM', |
69 |
0xE000 => 'rom/CRT13.ROM', |
0xE000 => 'rom/Orao/CRT13.ROM', |
70 |
}); |
}); |
71 |
|
|
72 |
# $PC = 0xDD11; # BC |
# $PC = 0xDD11; # BC |
139 |
|
|
140 |
=head1 Helper functions |
=head1 Helper functions |
141 |
|
|
|
=head2 load_rom |
|
|
|
|
|
called to init memory and load initial rom images |
|
|
|
|
|
$emu->load_rom; |
|
|
|
|
142 |
=cut |
=cut |
143 |
|
|
|
sub load_rom { |
|
|
my ($self, $loaded_files) = @_; |
|
|
|
|
|
#my $time_base = time(); |
|
|
|
|
|
foreach my $addr ( sort keys %$loaded_files ) { |
|
|
my $path = $loaded_files->{$addr}; |
|
|
$self->load_image( $path, $addr ); |
|
|
} |
|
|
} |
|
|
|
|
144 |
# write chunk directly into memory, updateing vram if needed |
# write chunk directly into memory, updateing vram if needed |
145 |
sub _write_chunk { |
sub _write_chunk { |
146 |
my $self = shift; |
my $self = shift; |
219 |
return 1; |
return 1; |
220 |
}; |
}; |
221 |
|
|
|
=head2 save_dump |
|
|
|
|
|
$emu->save_dump( 'filename', $from, $to ); |
|
|
|
|
|
=cut |
|
|
|
|
|
sub save_dump { |
|
|
my $self = shift; |
|
|
|
|
|
my ( $path, $from, $to ) = @_; |
|
|
|
|
|
$from ||= 0; |
|
|
$to ||= 0xffff; |
|
|
|
|
|
open(my $fh, '>', $path) || die "can't open $path: $!"; |
|
|
print $fh $self->read_chunk( $from, $to ); |
|
|
close($fh); |
|
|
|
|
|
my $size = -s $path; |
|
|
warn sprintf "saved %s %d %x bytes\n", $path, $size, $size; |
|
|
} |
|
|
|
|
|
=head2 hexdump |
|
|
|
|
|
$emu->hexdump( $address ); |
|
|
|
|
|
=cut |
|
|
|
|
|
sub hexdump { |
|
|
my $self = shift; |
|
|
my $a = shift; |
|
|
return sprintf(" %04x %s\n", $a, |
|
|
join(" ", |
|
|
map { |
|
|
if ( defined($_) ) { |
|
|
sprintf( "%02x", $_ ) |
|
|
} else { |
|
|
' ' |
|
|
} |
|
|
} @mem[ $a .. $a+8 ] |
|
|
) |
|
|
); |
|
|
} |
|
222 |
|
|
223 |
=head1 Memory management |
=head1 Memory management |
224 |
|
|
424 |
return; |
return; |
425 |
} |
} |
426 |
|
|
|
=head1 Command Line |
|
|
|
|
|
Command-line debugging intrerface is implemented for communication with |
|
|
emulated device |
|
|
|
|
|
=head2 prompt |
|
|
|
|
|
my ( $entered_line, @p ) = $emu->prompt( $address, $last_command ); |
|
|
|
|
|
=cut |
|
|
|
|
|
my $last = 'r 1'; |
|
|
|
|
|
sub prompt { |
|
|
my $self = shift; |
|
|
$self->app->sync; |
|
|
my $a = shift; |
|
|
print $self->hexdump( $a ), |
|
|
$last ? "[$last] " : '', |
|
|
"> "; |
|
|
my $in = <STDIN>; |
|
|
chomp($in); |
|
|
warn "## prompt got: $in\n" if $self->debug; |
|
|
$in ||= $last; |
|
|
$last = $in; |
|
|
return ( $in, split(/\s+/, $in) ) if $in; |
|
|
} |
|
|
|
|
|
=head2 cli |
|
|
|
|
|
$emu->cli(); |
|
|
|
|
|
=cut |
|
|
|
|
|
my $show_R = 0; |
|
|
|
|
|
sub cli { |
|
|
my $self = shift; |
|
|
my $a = $PC || confess "no pc?"; |
|
|
my $run_for = 0; |
|
|
warn $self->dump_R() if $show_R; |
|
|
while ( my ($line, @v) = $self->prompt( $a, $last ) ) { |
|
|
my $c = shift @v; |
|
|
next unless defined($c); |
|
|
my $v = shift @v; |
|
|
$v = hex($v) if $v && $v =~ m/^[0-9a-f]+$/; |
|
|
@v = map { hex($_) } @v; |
|
|
printf "## a: %04x parsed cli: c:%s v:%s %s\n", $a, $c, ($v || 'undef'), join(",",@v) if $self->debug; |
|
|
if ( $c =~ m/^[qx]/i ) { |
|
|
exit; |
|
|
} elsif ( $c eq '?' ) { |
|
|
my $t = $self->trace ? 'on' : 'off' ; |
|
|
my $d = $self->debug ? 'on' : 'off' ; |
|
|
warn <<__USAGE__; |
|
|
Usage: |
|
|
|
|
|
x|q\t\texit |
|
|
e 6000 6010\tdump memory, +/- to walk forward/backward |
|
|
m 1000 ff 00\tput ff 00 on 1000 |
|
|
j|u 1000\t\tjump (change pc) |
|
|
r 42\t\trun 42 instruction opcodes |
|
|
t\t\ttrace [$t] |
|
|
d\t\tdebug [$d] |
|
|
|
|
|
__USAGE__ |
|
|
warn $self->dump_R; |
|
|
$last = ''; |
|
|
} elsif ( $c =~ m/^e/i ) { |
|
|
$a = $v if defined($v); |
|
|
my $to = shift @v; |
|
|
$to = $a + 32 if ( ! $to || $to <= $a ); |
|
|
$to = 0xffff if ( $to > 0xffff ); |
|
|
my $lines = int( ($to - $a + 8) / 8 ); |
|
|
printf "## e %04x %04x (%d bytes) lines: %d\n", $a, $to, ($to-$a), $lines; |
|
|
while ( --$lines ) { |
|
|
print $self->hexdump( $a ); |
|
|
$a += 8; |
|
|
} |
|
|
$last = '+'; |
|
|
$show_R = 0; |
|
|
} elsif ( $c =~ m/^\+/ ) { |
|
|
$a += 8; |
|
|
$show_R = 0; |
|
|
} elsif ( $c =~ m/^\-/ ) { |
|
|
$a -= 8; |
|
|
$show_R = 0; |
|
|
} elsif ( $c =~ m/^m/i ) { |
|
|
$a = $v if defined($v); |
|
|
$self->poke_code( $a, @v ); |
|
|
printf "poke %d bytes at %04x\n", $#v + 1, $a; |
|
|
$last = '+'; |
|
|
$show_R = 0; |
|
|
} elsif ( $c =~ m/^l/i ) { |
|
|
my $to = shift @v || 0x1000; |
|
|
$a = $to; |
|
|
$self->load_image( $v, $a ); |
|
|
$last = ''; |
|
|
} elsif ( $c =~ m/^s/i ) { |
|
|
$self->save_dump( $v || 'mem.dump', @v ); |
|
|
$last = ''; |
|
|
} elsif ( $c =~ m/^re/i ) { # reset |
|
|
M6502::reset(); |
|
|
$last = 'r 1'; |
|
|
} elsif ( $c =~ m/^r/i ) { # run |
|
|
$run_for = $v || 1; |
|
|
print "run_for $run_for instructions\n"; |
|
|
$show_R = 1; |
|
|
last; |
|
|
} elsif ( $c =~ m/^(u|j)/i ) { |
|
|
my $to = $v || $a; |
|
|
printf "set pc to %04x\n", $to; |
|
|
$PC = $to; # remember for restart |
|
|
$run_for = 1; |
|
|
$last = "r $run_for"; |
|
|
$show_R = 1; |
|
|
last; |
|
|
} elsif ( $c =~ m/^tape/ ) { |
|
|
if ( $c =~ m/rate/ ) { |
|
|
$self->tape_rate( $v ); |
|
|
warn "will read table with rate $v\n"; |
|
|
} elsif ( ! $v ) { |
|
|
warn "ERROR: please specify tape name!\n"; |
|
|
} elsif ( ! -e $v ) { |
|
|
warn "ERROR: tape $v: $!\n"; |
|
|
} else { |
|
|
$self->load_tape( $v ); |
|
|
} |
|
|
$last = ''; |
|
|
} elsif ( $c =~ m/^t/i ) { |
|
|
$self->trace( not $self->trace ); |
|
|
print "trace ", $self->trace ? 'on' : 'off', "\n"; |
|
|
$last = ''; |
|
|
} elsif ( $c =~ m/^d/i ) { |
|
|
$self->debug( not $self->debug ); |
|
|
print "debug ", $self->debug ? 'on' : 'off', "\n"; |
|
|
$last = ''; |
|
|
} else { |
|
|
warn "# ignored $line\n" if ($line); |
|
|
$last = ''; |
|
|
} |
|
|
} |
|
|
|
|
|
return $run_for; |
|
|
} |
|
|
|
|
427 |
=head1 AUTHOR |
=head1 AUTHOR |
428 |
|
|
429 |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |