--- M6502/Orao.pm 2007/07/31 08:49:22 41 +++ M6502/Orao.pm 2007/07/31 09:37:01 42 @@ -39,6 +39,8 @@ our $orao; +select(STDERR); $| = 1; + sub init { my $self = shift; warn "Orao calling upstream init\n"; @@ -150,12 +152,10 @@ } elsif ( $size == 32800 ) { $addr = 0; warn sprintf "loading oraoemu 1.3 dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size; - #$self->write_chunk( $addr, substr($buff,0x20) ); - $self->poke_code( $addr, map { ord($_) } split(//,substr($buff,0x20)) ); + $self->write_chunk( $addr, substr($buff,0x20) ); return; } printf "loading %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size; - return $self->poke_code( $addr, map { ord($_) } split(//,$buff) ); return $self->write_chunk( $addr, $buff ); my $chunk; @@ -291,6 +291,87 @@ return; } +=head1 Command Line + +Command-line debugging intrerface is implemented for communication with +emulated device + +=head2 cli + + $orao->cli(); + +=cut + +my $last = 'r 1'; + +sub cli { + my $self = shift; + my $a = $PC || confess "no pc?"; + $self->app->sync; + while ( my @v = $orao->prompt( $a, $last ) ) { + 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; + if ( $c =~ m/^[qx]/i ) { + exit; + } elsif ( $c eq '?' ) { + warn <<__USAGE__; +uage: +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 +__USAGE__ + } elsif ( $c =~ m/^e/i ) { + $a ||= $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 ) { + print $self->hexdump( $a ); + $a += 8; + $lines--; + } + $last = '+'; + } elsif ( $c =~ m/^\+/ ) { + $a += 8; + } elsif ( $c =~ m/^\-/ ) { + $a -= 8; + } elsif ( $c =~ m/^m/i ) { + $a = $v; + $self->poke_code( $a, @v ); + printf "poke %d bytes at %04x\n", $#v + 1, $a; + } elsif ( $c =~ m/^l/i ) { + my $to = shift @v || 0x1000; + $a = $to; + $self->load_oraoemu( $v, $a ); + } elsif ( $c =~ m/^s/i ) { + $self->save_dump( $v || 'mem.dump', @v ); + } elsif ( $c =~ m/^r/i ) { + $run_for = $v || 1; + print "run_for $run_for instructions\n"; + last; + } elsif ( $c =~ m/^(u|j)/ ) { + my $to = $v || $a; + printf "set pc to %04x\n", $to; + $PC = $to; # remember for restart + $run_for = 1; + last; + } elsif ( $c =~ m/^t/ ) { + $self->trace( not $self->trace ); + print "trace ", $self->trace ? 'on' : 'off', "\n"; + } else { + warn "# ignore $c\n"; + last; + } + } + + +} =head1 AUTHOR