--- M6502/Orao.pm 2007/08/01 12:57:15 76 +++ M6502/Orao.pm 2007/08/02 14:07:52 97 @@ -8,10 +8,11 @@ #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); -__PACKAGE__->mk_accessors(qw(run_for)); +__PACKAGE__->mk_accessors(qw(booted)); =head1 NAME @@ -19,11 +20,11 @@ =head1 VERSION -Version 0.02 +Version 0.04 =cut -our $VERSION = '0.02'; +our $VERSION = '0.04'; =head1 SUMMARY @@ -31,23 +32,40 @@ =cut -=head2 init +my @kbd_ports = ( + 0x87FC,0x87FD,0x87FA,0x87FB,0x87F6,0x87F7, + 0x87EE,0x87EF,0x87DE,0x87DF,0x87BE,0x87BF, + 0x877E,0x877F,0x86FE,0x86FF,0x85FE,0x85FF, + 0x83FE,0x83FF, +); + +=head1 FUNCTIONS + +=head2 boot Start emulator, open L, load initial ROM images, and render memory + my $orao = Orao->new({}); + $orao->boot; + =cut our $orao; select(STDERR); $| = 1; -sub init { +sub boot { my $self = shift; warn "Orao calling upstream init\n"; - $self->SUPER::init( $self, @_ ); + $self->SUPER::init( + read => sub { $self->read( @_ ) }, + write => sub { $self->write( @_ ) }, + ); warn "Orao $Orao::VERSION emulation starting\n"; + warn "emulating ", $#mem, " bytes of memory\n"; + $self->open_screen; $self->load_rom({ 0x1000 => 'dump/SCRINV.BIN', @@ -60,6 +78,8 @@ # $PC = 0xDD11; # BC # $PC = 0xC274; # MC + $PC = 0xff89; + $orao = $self; # $self->prompt( 0x1000 ); @@ -87,28 +107,9 @@ 0xE000, 0xFFFF, 'sistemski ROM', ); -if(0){ - 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 ] ); } @@ -118,13 +119,35 @@ #( $A, $P, $X, $Y, $S, $IPeriod ) = ( 1, 2, 3, 4, 5, 6 ); - warn "Orao init finished", + warn "Orao boot finished", $self->trace ? ' trace' : '', $self->debug ? ' debug' : '', "\n"; + M6502::reset(); + + $self->booted( 1 ); } +=head2 run + +Run interactive emulation loop + + $orao->run; + +=cut + +sub run { + my $self = shift; + + $self->show_mem( 1 ); + + $self->boot if ( ! $self->booted ); + $self->loop; +}; + +=head1 Helper functions + =head2 load_rom called to init memory and load initial rom images @@ -140,7 +163,7 @@ foreach my $addr ( sort keys %$loaded_files ) { my $path = $loaded_files->{$addr}; - $self->load_oraoemu( $path, $addr ); + $self->load_image( $path, $addr ); } } @@ -165,19 +188,20 @@ # $self->vram( $a - 0x6000 , $mem[ $a ] ); # } $self->render( @mem[ 0x6000 .. 0x7fff ] ); + $self->render_mem( @mem ) if $self->show_mem; } -=head2 load_oraoemu +=head2 load_image Load binary files, ROM images and Orao Emulator files - $orao->load_oraoemu( '/path/to/file', 0x1000 ); + $orao->load_image( '/path/to/file', 0x1000 ); Returns true on success. =cut -sub load_oraoemu { +sub load_image { my $self = shift; my ( $path, $addr ) = @_; @@ -287,7 +311,60 @@ my $self = shift; my ($addr) = @_; my $byte = $mem[$addr]; + confess sprintf("can't find memory at address %04x",$addr) unless defined($byte); 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) if $self->trace; + } 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; } @@ -314,8 +391,7 @@ } if ( $addr > 0xafff ) { - warn sprintf "write access 0x%04x > 0xafff aborting\n", $addr; - return; + confess sprintf "write access 0x%04x > 0xafff aborting\n", $addr; } $self->mmap_pixel( $addr, $byte, 0, 0 ); @@ -341,7 +417,7 @@ my $self = shift; $self->app->sync; my $a = shift; - print STDERR $self->hexdump( $a ), + print $self->hexdump( $a ), $last ? "[$last] " : '', "> "; my $in = ; @@ -363,6 +439,7 @@ sub cli { my $self = shift; my $a = $PC || confess "no pc?"; + my $run_for = 0; warn $self->dump_R() if $show_R; while ( my ($line, @v) = $self->prompt( $a, $last ) ) { my $c = shift @v; @@ -389,6 +466,7 @@ __USAGE__ warn $self->dump_R; + $last = ''; } elsif ( $c =~ m/^e/i ) { $a = $v if defined($v); my $to = shift @v; @@ -417,7 +495,7 @@ } elsif ( $c =~ m/^l/i ) { my $to = shift @v || 0x1000; $a = $to; - $self->load_oraoemu( $v, $a ); + $self->load_image( $v, $a ); $last = ''; } elsif ( $c =~ m/^s/i ) { $self->save_dump( $v || 'mem.dump', @v ); @@ -449,6 +527,7 @@ } } + return $run_for; } =head1 AUTHOR