--- M6502/Orao.pm 2007/07/31 16:06:27 59 +++ M6502/Orao.pm 2007/08/01 13:52:39 78 @@ -8,6 +8,7 @@ #use Time::HiRes qw(time); use File::Slurp; use Data::Dump qw/dump/; +use List::Util qw/first/; use M6502; use base qw(Class::Accessor M6502 Screen Prefs); @@ -31,6 +32,13 @@ =cut +my @kbd_ports = ( + 0x87FC,0x87FD,0x87FA,0x87FB,0x87F6,0x87F7, + 0x87EE,0x87EF,0x87DE,0x87DF,0x87BE,0x87BF, + 0x877E,0x877F,0x86FE,0x86FF,0x85FE,0x85FF, + 0x83FE,0x83FF, +); + =head2 init Start emulator, open L, load initial ROM images, and render memory @@ -51,13 +59,17 @@ $self->open_screen; $self->load_rom({ 0x1000 => 'dump/SCRINV.BIN', + # should be 0x6000, but oraoemu has 2 byte prefix + 0x5FFE => 'dump/screen.dmp', 0xC000 => 'rom/BAS12.ROM', 0xE000 => 'rom/CRT12.ROM', }); - $PC = 0xDD11; # BC +# $PC = 0xDD11; # BC # $PC = 0xC274; # MC + $PC = 0xff89; + $orao = $self; # $self->prompt( 0x1000 ); @@ -66,10 +78,14 @@ $self->trace( 0 ); $self->debug( 0 ); + $self->render( @mem[ 0x6000 .. 0x7fff ] ); + if ( $self->show_mem ) { warn "rendering memory map\n"; + $self->render_mem( @mem ); + my @mmap = ( 0x0000, 0x03FF, 'nulti blok', 0x0400, 0x5FFF, 'korisnički RAM (23K)', @@ -81,26 +97,10 @@ 0xE000, 0xFFFF, 'sistemski ROM', ); - foreach my $i ( 0 .. $#mmap / 3 ) { - my $o = $i * 3; - my ( $from, $to, $desc ) = @mmap[$o,$o+1,$o+2]; - printf "%04x - %04x - %s\n", $from, $to, $desc; - for my $a ( $from .. $to ) { - if ( $a >= 0x6000 && $a < 0x8000 ) { - my $b = $self->read( $a ); - $self->vram( $a - 0x6000, $b ); - } else { - $self->read( $a ); - } - } - } - } else { warn "rendering video memory\n"; - for my $a ( 0x6000 .. 0x7fff ) { - $self->vram( $a - 0x6000, $mem[$a] ); - } + $self->render( @mem[ 0x6000 .. 0x7fff ] ); } $self->sync; @@ -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 ) = @_; @@ -156,15 +152,32 @@ $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 ] ); - } +# foreach my $a ( $f .. $t ) { +# $self->vram( $a - 0x6000 , $mem[ $a ] ); +# } + $self->render( @mem[ 0x6000 .. 0x7fff ] ); + $self->render_mem( @mem ) if $self->show_mem; } +=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 +186,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 +213,7 @@ $self->_write_chunk( $addr, $chunk ); + return 1; }; =head2 save_dump @@ -235,7 +250,11 @@ return sprintf(" %04x %s\n", $a, join(" ", map { - sprintf( "%02x", $_ ) + if ( defined($_) ) { + sprintf( "%02x", $_ ) + } else { + ' ' + } } @mem[ $a .. $a+8 ] ) ); @@ -261,6 +280,58 @@ my ($addr) = @_; my $byte = $mem[$addr]; warn sprintf("# Orao::read(%04x) = %02x\n", $addr, $byte) if $self->trace; + + # keyboard + + if ( first { $addr == $_ } @kbd_ports ) { + warn sprintf("keyboard port: %04x\n",$addr); + } elsif ( $addr == 0x87fc ) { + warn "0x87fc - arrows/back\n"; +=for pascal + if VKey=VK_RIGHT then Result:=16; + if VKey=VK_DOWN then Result:=128; + if VKey=VK_UP then Result:=192; + if VKey=VK_LEFT then Result:=224; + if Ord(KeyPressed)=VK_BACK then Result:=224; +=cut + } elsif ( $addr == 0x87fd ) { + warn "0x87fd - enter\n"; +=for pascal + if KeyPressed=Chr(13) then begin + Mem[$FC]:=13; + Result:=0; + end; +=cut + } elsif ( $addr == 0x87fa ) { + warn "0x87fa = F1 - F4\n"; +=for pascal + if VKey=VK_F4 then Result:=16; + if VKey=VK_F3 then Result:=128; + if VKey=VK_F2 then Result:=192; + if VKey=VK_F1 then Result:=224; +=cut + } elsif ( $addr == 0x87fb ) { + warn "0x87fb\n"; +=for pascal + if KeyPressed=Chr(32) then Result:=32; + if KeyPressed='"' then Result:=16; + if KeyPressed='!' then Result:=16; + if KeyPressed='$' then Result:=16; + if KeyPressed='%' then Result:=16; + if KeyPressed='&' then Result:=16; + if KeyPressed='(' then Result:=16; + if KeyPressed=')' then Result:=16; + if KeyPressed='=' then Result:=16; + if KeyPressed='#' then Result:=16; + if KeyPressed='+' then Result:=16; + if KeyPressed='*' then Result:=16; + if KeyPressed='?' then Result:=16; + if KeyPressed='<' then Result:=16; + if KeyPressed='>' then Result:=16; + if VKey=191 then Result:=16; +=cut + } + $self->mmap_pixel( $addr, 0, $byte, 0 ); return $byte; } @@ -287,7 +358,8 @@ } if ( $addr > 0xafff ) { - confess sprintf "write access 0x%04x > 0xafff aborting\n", $addr; + warn sprintf "write access 0x%04x > 0xafff aborting\n", $addr; + return; } $self->mmap_pixel( $addr, $byte, 0, 0 ); @@ -303,7 +375,7 @@ =head2 prompt - $orao->prompt( $address, $last_command ); + my ( $entered_line, @p ) = $orao->prompt( $address, $last_command ); =cut @@ -321,7 +393,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 @@ -330,11 +402,15 @@ =cut +my $show_R = 0; + sub cli { my $self = shift; my $a = $PC || confess "no pc?"; - while ( my @v = $self->prompt( $a, $last ) ) { + warn $self->dump_R() if $show_R; + 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; @@ -356,11 +432,12 @@ 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); + warn $self->dump_R; } elsif ( $c =~ m/^e/i ) { $a = $v if defined($v); my $to = shift @v; $to = $a + 32 if ( ! $to || $to <= $a ); + $to = 0xffff if ( $to > 0xffff ); my $lines = int( ($to - $a + 8) / 8 ); printf "## e %04x %04x (%d bytes) lines: %d\n", $a, $to, ($to-$a), $lines; while ( --$lines ) { @@ -368,15 +445,19 @@ $a += 8; } $last = '+'; + $show_R = 0; } elsif ( $c =~ m/^\+/ ) { $a += 8; + $show_R = 0; } elsif ( $c =~ m/^\-/ ) { $a -= 8; + $show_R = 0; } elsif ( $c =~ m/^m/i ) { - $a = $v; + $a = $v if defined($v); $self->poke_code( $a, @v ); printf "poke %d bytes at %04x\n", $#v + 1, $a; $last = '+'; + $show_R = 0; } elsif ( $c =~ m/^l/i ) { my $to = shift @v || 0x1000; $a = $to; @@ -388,27 +469,30 @@ } elsif ( $c =~ m/^r/i ) { $run_for = $v || 1; print "run_for $run_for instructions\n"; + $show_R = 1; 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 = sprintf('m %04x', $to); + $last = "r $run_for"; + $show_R = 1; last; } elsif ( $c =~ m/^t/ ) { $self->trace( not $self->trace ); print "trace ", $self->trace ? 'on' : 'off', "\n"; + $last = ''; } elsif ( $c =~ m/^d/ ) { $self->debug( not $self->debug ); print "debug ", $self->debug ? 'on' : 'off', "\n"; + $last = ''; } else { - warn "# ignore $c\n"; - last; + warn "# ignored $line\n" if ($line); + $last = ''; } } - } =head1 AUTHOR