--- M6502/Orao.pm 2007/07/30 23:39:57 39 +++ M6502/Orao.pm 2007/07/31 10:16:36 47 @@ -39,6 +39,8 @@ our $orao; +select(STDERR); $| = 1; + sub init { my $self = shift; warn "Orao calling upstream init\n"; @@ -53,9 +55,8 @@ 0xE000 => 'rom/CRT12.ROM', }); - $self->load_oraoemu( 'dump/orao-1.2' ); - $self->load_oraoemu( 'dump/SCRINV.BIN', 0x1000 ); - $PC = 0x1000; + $PC = 0xDD11; # BC +# $PC = 0xC274; # MC $orao = $self; @@ -134,6 +135,27 @@ =cut +sub _write_chunk { + my $self = shift; + my ( $addr, $chunk ) = @_; + $self->write_chunk( $addr, $chunk ); + my $end = $addr + length($chunk); + my ( $f, $t ) = ( 0x6000, 0x7fff ); + + if ( $end < $f || $addr >= $t ) { + warn "skip vram update\n"; + return; + }; + + $f = $addr if ( $addr > $f ); + $t = $end if ( $end < $t ); + + warn sprintf("refresh video ram %04x-%04x\n", $f, $t); + foreach my $a ( $f .. $t ) { + $self->vram( $a - 0x6000 , $mem[ $a ] ); + } +} + sub load_oraoemu { my $self = shift; my ( $path, $addr ) = @_; @@ -145,18 +167,16 @@ if ( $size == 65538 ) { $addr = 0; warn sprintf "loading oraoemu 64k dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size; - $self->write_chunk( $addr, substr($buff,2) ); + $self->_write_chunk( $addr, substr($buff,2) ); return; } 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 ); + return $self->_write_chunk( $addr, $buff ); my $chunk; @@ -172,7 +192,7 @@ $pos += 4; } - $self->write_chunk( $addr, $chunk ); + $self->_write_chunk( $addr, $chunk ); }; @@ -211,7 +231,7 @@ join(" ", map { sprintf( "%02x", $_ ) - } $self->ram( $a, $a+8 ) + } @mem[ $a .. $a+8 ] ) ); } @@ -224,6 +244,7 @@ sub prompt { my $self = shift; + $self->app->sync; my $a = shift; my $last = shift; print STDERR $self->hexdump( $a ), @@ -255,7 +276,7 @@ my $self = shift; my ($addr) = @_; my $byte = $mem[$addr]; - warn "# Orao::read(",dump(@_),") = ",dump( $byte ),"\n" if $self->trace; + warn sprintf("# Orao::read(%04x) = %02x\n", $addr, $byte) if $self->trace; $self->mmap_pixel( $addr, 0, $byte, 0 ); return $byte; } @@ -270,8 +291,8 @@ sub write { my $self = shift; - warn "# Orao::write(",dump(@_),")\n" if $self->trace; my ($addr,$byte) = @_; + warn sprintf("# Orao::write(%04x,%02x)\n", $addr, $byte) if $self->trace; if ( $addr >= 0x6000 && $addr < 0x8000 ) { $self->vram( $addr - 0x6000 , $byte ); @@ -291,6 +312,86 @@ 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?"; + while ( my @v = $self->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