--- M6502/Orao.pm 2007/07/31 16:06:27 59 +++ M6502/Orao.pm 2007/07/31 16:22:10 61 @@ -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; @@ -403,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