--- M6502/Orao.pm 2007/08/02 13:58:26 96 +++ M6502/Orao.pm 2007/08/02 17:15:07 101 @@ -140,6 +140,8 @@ sub run { my $self = shift; + $self->show_mem( 1 ); + $self->boot if ( ! $self->booted ); $self->loop; }; @@ -305,6 +307,119 @@ =cut +my $keyboard = { + 0x87FC => { + 'right' => 16, + 'down' => 128, + 'up' => 192, + 'left' => 224, + 'backspace' => 224, + }, + 0x87FD => { + 'return' => sub { + M6502::_write( 0xfc, 13 ); + return 0; + }, + 'left ctrl' => 16, + 'right ctrl' => 16, + }, + 0x87FA => { + 'f4' => 16, + 'f3' => 128, + 'f2' => 192, + 'f1' => 224, + }, + 0x87FB => { + 'space' => 32, + 'left shift' => 16, + 'right shift' => 16, + }, + 0x87F6 => { + '6' => 16, + 't' => 128, + 'z' => 192, + 'r' => 224, + }, + 0x87F7 => { + '5' => 32, + '4' => 16, + }, + 0x87EE => { + '7' => 16, + 'u' => 128, + 'i' => 192, + 'o' => 224, + }, + 0x87EF => { + '8' => 32, + '9' => 16, + }, + 0x87DE => { + '1' => 16, + 'w' => 128, + 'q' => 192, + 'e' => 224, + }, + 0x87DF => { + '2' => 32, + '3' => 16, + }, + 0x87BE => { + 'm' => 16, + 'k' => 128, + 'j' => 192, + 'l' => 224, + }, + 0x87BF => { + ',' => 32, + '.' => 16, + }, + 0x877E => { + 'y' => 16, + 's' => 128, + 'a' => 192, + 'd' => 224, + }, + 0x877F => { + 'x' => 32, + 'c' => 16, + }, + 0x86FE => { + 'n' => 16, + 'g' => 128, + 'h' => 192, + 'f' => 224, + }, + 0x86FF => { + 'b' => 32, + 'c' => 16, + }, + 0x85FE => { + ':' => 16, + '\\' => 128, + '\'' => 192, + ';' => 224, + '8' => 16, # FIXME? + }, + 0x85FF => { + '/' => 32, + '6' => 16, # FIXME? + }, + 0x83FE => { + ';' => 16, + '[' => 128, + ']' => 192, + 'p' => 224, + '=' => 16, # FIXME? + }, + 0x83FF => { + '-' => 32, + '0' => 16, + }, +}; + +my $keyboard_none = 255; + sub read { my $self = shift; my ($addr) = @_; @@ -315,52 +430,26 @@ # 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 + warn sprintf("keyboard port: %04x\n",$addr) if $self->trace; + my $key = $self->key_pressed; + if ( defined($key) ) { + my $r = $keyboard->{$addr} || confess "no definition for keyboard port found"; + if ( my $ret = $r->{$key} ) { + if ( ref($ret) eq 'CODE' ) { + $ret = $ret->(); + warn "executed $key and got: $ret\n"; + } else { + warn sprintf("keyboard port: %04x key: '%s' code: %02x\n", $addr, $key, $ret); + } + $mem[$addr] = $ret; + warn "keypress: $key = $ret\n"; + return $ret; + } else { + warn sprintf("keyboard port: %04x unknown key: '%s'\n", $addr, $key) if $debug; + } + warn sprintf("keyboard port: %04x %s\n",$addr,dump( $r )) if $self->trace; + } + return $keyboard_none; } $self->mmap_pixel( $addr, 0, $byte, 0 ); @@ -415,7 +504,7 @@ my $self = shift; $self->app->sync; my $a = shift; - print STDERR $self->hexdump( $a ), + print $self->hexdump( $a ), $last ? "[$last] " : '', "> "; my $in = ; @@ -464,6 +553,7 @@ __USAGE__ warn $self->dump_R; + $last = ''; } elsif ( $c =~ m/^e/i ) { $a = $v if defined($v); my $to = shift @v;