--- M6502/Orao.pm 2007/07/31 10:16:36 47 +++ M6502/Orao.pm 2007/07/31 16:06:27 59 @@ -3,15 +3,15 @@ use warnings; use strict; -use Carp; +use Carp qw/confess/; use lib './lib'; #use Time::HiRes qw(time); use File::Slurp; use Data::Dump qw/dump/; use M6502; -use base qw(Class::Accessor M6502 Screen); -__PACKAGE__->mk_accessors(qw(debug trace run_for mem_dump trace)); +use base qw(Class::Accessor M6502 Screen Prefs); +__PACKAGE__->mk_accessors(qw(run_for)); =head1 NAME @@ -33,7 +33,7 @@ =head2 init -Start emulator +Start emulator, open L, load initial ROM images, and render memory =cut @@ -46,7 +46,7 @@ warn "Orao calling upstream init\n"; $self->SUPER::init( $self, @_ ); - warn "staring Orao $Orao::VERSION emulation\n"; + warn "Orao $Orao::VERSION emulation starting\n"; $self->open_screen; $self->load_rom({ @@ -62,8 +62,9 @@ # $self->prompt( 0x1000 ); - my $trace = $self->trace; + my ( $trace, $debug ) = ( $self->trace, $self->debug ); $self->trace( 0 ); + $self->debug( 0 ); if ( $self->show_mem ) { @@ -104,10 +105,14 @@ } $self->sync; $self->trace( $trace ); + $self->debug( $debug ); #( $A, $P, $X, $Y, $S, $IPeriod ) = ( 1, 2, 3, 4, 5, 6 ); - warn "Orao init finished", $self->trace ? ' trace on' : '', "\n"; + warn "Orao init finished", + $self->trace ? ' trace' : '', + $self->debug ? ' debug' : '', + "\n"; } @@ -236,27 +241,6 @@ ); } -=head2 prompt - - $orao->prompt( $address, $last_command ); - -=cut - -sub prompt { - my $self = shift; - $self->app->sync; - my $a = shift; - my $last = shift; - print STDERR $self->hexdump( $a ), - $last ? "[$last] " : '', - "> "; - my $in = ; - chomp($in); - $in ||= $last; - $last = $in; - return split(/\s+/, $in) if $in; -} - =head1 Memory management Orao implements all I/O using mmap addresses. This was main reason why @@ -298,14 +282,14 @@ $self->vram( $addr - 0x6000 , $byte ); } - if ( $addr > 0xafff ) { - warn sprintf "access to %04x above affff aborting\n", $addr; - return -1; - } if ( $addr == 0x8800 ) { warn sprintf "sound ignored: %x\n", $byte; } + if ( $addr > 0xafff ) { + confess sprintf "write access 0x%04x > 0xafff aborting\n", $addr; + } + $self->mmap_pixel( $addr, $byte, 0, 0 ); $mem[$addr] = $byte; @@ -317,14 +301,35 @@ Command-line debugging intrerface is implemented for communication with emulated device -=head2 cli +=head2 prompt - $orao->cli(); + $orao->prompt( $address, $last_command ); =cut my $last = 'r 1'; +sub prompt { + my $self = shift; + $self->app->sync; + my $a = shift; + print STDERR $self->hexdump( $a ), + $last ? "[$last] " : '', + "> "; + my $in = ; + chomp($in); + warn "## prompt got: $in\n" if $self->debug; + $in ||= $last; + $last = $in; + return split(/\s+/, $in) if $in; +} + +=head2 cli + + $orao->cli(); + +=cut + sub cli { my $self = shift; my $a = $PC || confess "no pc?"; @@ -332,29 +337,35 @@ my $c = shift @v; my $v = shift @v; $v = hex($v) if $v && $v =~ m/^[0-9a-f]+$/; - printf "## [%s] %s\n", ($v || 'undef'), join(",",@v) if $self->debug; @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__; -uage: +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 sprintf(" PC: %04x A:%02x P:%02x X:%02x Y:%02x S:%02x\n", $PC, $A, $P, $X, $Y, $S); } elsif ( $c =~ m/^e/i ) { - $a ||= $v; + $a = $v if defined($v); my $to = shift @v; $to = $a + 32 if ( ! $to || $to <= $a ); - my $lines = int( ($to - $a - 8) / 8 ); - printf "## m %04x %04x lines: %d\n", $a, $to, $lines; - while ( $lines ) { + 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; - $lines--; } $last = '+'; } elsif ( $c =~ m/^\+/ ) { @@ -365,12 +376,15 @@ $a = $v; $self->poke_code( $a, @v ); printf "poke %d bytes at %04x\n", $#v + 1, $a; + $last = '+'; } elsif ( $c =~ m/^l/i ) { my $to = shift @v || 0x1000; $a = $to; $self->load_oraoemu( $v, $a ); + $last = ''; } elsif ( $c =~ m/^s/i ) { $self->save_dump( $v || 'mem.dump', @v ); + $last = ''; } elsif ( $c =~ m/^r/i ) { $run_for = $v || 1; print "run_for $run_for instructions\n"; @@ -380,10 +394,14 @@ printf "set pc to %04x\n", $to; $PC = $to; # remember for restart $run_for = 1; + $last = sprintf('m %04x', $to); last; } elsif ( $c =~ m/^t/ ) { $self->trace( not $self->trace ); print "trace ", $self->trace ? 'on' : 'off', "\n"; + } elsif ( $c =~ m/^d/ ) { + $self->debug( not $self->debug ); + print "debug ", $self->debug ? 'on' : 'off', "\n"; } else { warn "# ignore $c\n"; last;