--- M6502/Orao.pm 2007/07/31 15:03:23 56 +++ M6502/Orao.pm 2007/07/31 16:24:49 62 @@ -135,11 +135,7 @@ } } - -=head2 load_oraoemu - -=cut - +# write chunk directly into memory, updateing vram if needed sub _write_chunk { my $self = shift; my ( $addr, $chunk ) = @_; @@ -161,10 +157,25 @@ } } +=head2 load_oraoemu + +Load binary files, ROM images and Orao Emulator files + + $orao->load_oraoemu( '/path/to/file', 0x1000 ); + +Returns true on success. + +=cut + sub load_oraoemu { my $self = shift; my ( $path, $addr ) = @_; + if ( ! -e $path ) { + warn "ERROR: file $path doesn't exist\n"; + return; + } + my $size = -s $path || confess "no size for $path: $!"; my $buff = read_file( $path ); @@ -173,15 +184,16 @@ $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) ); - return; + return 1; } 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) ); - return; + return 1; } printf "loading %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size; - return $self->_write_chunk( $addr, $buff ); + $self->_write_chunk( $addr, $buff ); + return 1; my $chunk; @@ -199,6 +211,7 @@ $self->_write_chunk( $addr, $chunk ); + return 1; }; =head2 save_dump @@ -303,7 +316,7 @@ =head2 prompt - $orao->prompt( $address, $last_command ); + my ( $entered_line, @p ) = $orao->prompt( $address, $last_command ); =cut @@ -321,7 +334,7 @@ warn "## prompt got: $in\n" if $self->debug; $in ||= $last; $last = $in; - return split(/\s+/, $in) if $in; + return ( $in, split(/\s+/, $in) ) if $in; } =head2 cli @@ -333,8 +346,9 @@ sub cli { my $self = shift; my $a = $PC || confess "no pc?"; - while ( my @v = $self->prompt( $a, $last ) ) { + 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; @@ -361,12 +375,11 @@ $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/^\+/ ) { @@ -395,7 +408,7 @@ printf "set pc to %04x\n", $to; $PC = $to; # remember for restart $run_for = 1; - $last = sprintf('m %04x', $to); + $last = "r $run_for"; last; } elsif ( $c =~ m/^t/ ) { $self->trace( not $self->trace ); @@ -404,12 +417,11 @@ $self->debug( not $self->debug ); print "debug ", $self->debug ? 'on' : 'off', "\n"; } else { - warn "# ignore $c\n"; - last; + warn "# ignored $line\n" if ($line); + $last = ''; } } - } =head1 AUTHOR