/[VRac]/Orao.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /Orao.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 95 by dpavlin, Thu Aug 2 13:19:19 2007 UTC revision 109 by dpavlin, Fri Aug 3 10:29:33 2007 UTC
# Line 8  use lib './lib'; Line 8  use lib './lib';
8  #use Time::HiRes qw(time);  #use Time::HiRes qw(time);
9  use File::Slurp;  use File::Slurp;
10  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
 use List::Util qw/first/;  
11  use M6502;  use M6502;
12    
13  use base qw(Class::Accessor M6502 Screen Prefs);  use base qw(Class::Accessor M6502 Screen Prefs Tape);
14  __PACKAGE__->mk_accessors(qw(booted run_for));  __PACKAGE__->mk_accessors(qw(booted));
15    
16  =head1 NAME  =head1 NAME
17    
# Line 32  Emulator or Orao 8-bit 6502 machine popu Line 31  Emulator or Orao 8-bit 6502 machine popu
31    
32  =cut  =cut
33    
 my @kbd_ports = (  
     0x87FC,0x87FD,0x87FA,0x87FB,0x87F6,0x87F7,  
     0x87EE,0x87EF,0x87DE,0x87DF,0x87BE,0x87BF,  
     0x877E,0x877F,0x86FE,0x86FF,0x85FE,0x85FF,  
     0x83FE,0x83FF,  
 );  
   
34  =head1 FUNCTIONS  =head1 FUNCTIONS
35    
36  =head2 boot  =head2 boot
# Line 71  sub boot { Line 63  sub boot {
63                  0x1000 => 'dump/SCRINV.BIN',                  0x1000 => 'dump/SCRINV.BIN',
64                  # should be 0x6000, but oraoemu has 2 byte prefix                  # should be 0x6000, but oraoemu has 2 byte prefix
65                  0x5FFE => 'dump/screen.dmp',                  0x5FFE => 'dump/screen.dmp',
66                  0xC000 => 'rom/BAS12.ROM',  #               0xC000 => 'rom/BAS12.ROM',
67                  0xE000 => 'rom/CRT12.ROM',  #               0xE000 => 'rom/CRT12.ROM',
68                    0xC000 => 'rom/BAS13.ROM',
69                    0xE000 => 'rom/CRT13.ROM',
70          });          });
71    
72  #       $PC = 0xDD11;   # BC  #       $PC = 0xDD11;   # BC
# Line 88  sub boot { Line 82  sub boot {
82          $self->trace( 0 );          $self->trace( 0 );
83          $self->debug( 0 );          $self->debug( 0 );
84    
85          $self->render( @mem[ 0x6000 .. 0x7fff ] );          warn "rendering video memory\n";
86            $self->render_vram( @mem[ 0x6000 .. 0x7fff ] );
87    
88          if ( $self->show_mem ) {          if ( $self->show_mem ) {
89    
# Line 107  sub boot { Line 102  sub boot {
102                          0xE000, 0xFFFF, 'sistemski ROM',                          0xE000, 0xFFFF, 'sistemski ROM',
103                  );                  );
104    
         } else {  
   
                 warn "rendering video memory\n";  
                 $self->render( @mem[ 0x6000 .. 0x7fff ] );  
           
105          }          }
106          $self->sync;          $self->sync;
107          $self->trace( $trace );          $self->trace( $trace );
# Line 141  sub run { Line 131  sub run {
131          my $self = shift;          my $self = shift;
132    
133          $self->boot if ( ! $self->booted );          $self->boot if ( ! $self->booted );
134            $self->loop;
         while ( 1 ) {  
                 $self->cli;  
                 M6502::exec($run_for);  
         }  
135  };  };
136    
137  =head1 Helper functions  =head1 Helper functions
# Line 186  sub _write_chunk { Line 172  sub _write_chunk {
172          $t = $end if ( $end < $t );          $t = $end if ( $end < $t );
173    
174          warn sprintf("refresh video ram %04x-%04x\n", $f, $t);          warn sprintf("refresh video ram %04x-%04x\n", $f, $t);
175  #       foreach my $a ( $f .. $t ) {          $self->render_vram( @mem[ 0x6000 .. 0x7fff ] );
 #               $self->vram( $a - 0x6000 , $mem[ $a ] );  
 #       }  
         $self->render( @mem[ 0x6000 .. 0x7fff ] );  
176          $self->render_mem( @mem ) if $self->show_mem;          $self->render_mem( @mem ) if $self->show_mem;
177  }  }
178    
# Line 309  Read from memory Line 292  Read from memory
292    
293  =cut  =cut
294    
295    my $keyboard_none = 255;
296    
297    my $keyboard = {
298            0x87FC => {
299                    'right'         => 16,
300                    'down'          => 128,
301                    'up'            => 192,
302                    'left'          => 224,
303                    'backspace' => 224,
304            },
305            0x87FD => sub {
306                    my ( $self, $key ) = @_;
307                    if ( $key eq 'return' ) {
308                            M6502::_write( 0xfc, 13 );
309                            warn "return\n";
310                            return 0;
311                    } elsif ( $key =~ m/ ctrl/ || $self->key_down( 'left ctrl' ) || $self->key_down( 'right ctrl' ) ) {
312                            warn "ctrl\n";
313                            return 16;
314                    }
315                    return $keyboard_none;
316            },
317            0x87FA => {
318                    'f4' => 16,
319                    'f3' => 128,
320                    'f2' => 192,
321                    'f1' => 224,
322            },
323            0x87FB => sub {
324                    my ( $self, $key ) = @_;
325                    if ( $key eq 'space' ) {
326                            return 32;
327                    } elsif ( $self->key_down( 'left shift' ) || $self->key_down( 'right shift' ) ) {
328                            warn "shift\n";
329                            return 16;
330                    }
331                    return $keyboard_none;
332            },
333            0x87F6 => {
334                    '6' => 16,
335                    't' => 128,
336                    'y' => 192,     # hr: z
337                    'r' => 224,
338            },
339            0x87F7 => {
340                    '5' => 32,
341                    '4' => 16,
342            },
343            0x87EE => {
344                    '7' => 16,
345                    'u' => 128,
346                    'i' => 192,
347                    'o' => 224,
348            },
349            0x87EF => {
350                    '8' => 32,
351                    '9' => 16,
352            },
353            0x87DE => {
354                    '1' => 16,
355                    'w' => 128,
356                    'q' => 192,
357                    'e' => 224,
358            },
359            0x87DF => {
360                    '2' => 32,
361                    '3' => 16,
362            },
363            0x87BE => {
364                    'm' => 16,
365                    'k' => 128,
366                    'j' => 192,
367                    'l' => 224,
368            },
369            0x87BF => {
370                    ',' => 32,      # <
371                    '.' => 16,      # >
372            },
373            0x877E => {
374                    'z' => 16,      # hr:y
375                    's' => 128,
376                    'a' => 192,
377                    'd' => 224,
378            },
379            0x877F => {
380                    'x' => 32,
381                    'c' => 16,
382            },
383            0x86FE => {
384                    'n' => 16,
385                    'g' => 128,
386                    'h' => 192,
387                    'f' => 224,
388            },
389            0x86FF => {
390                    'b' => 32,
391                    'v' => 16,
392            },
393            0x85FE => {
394                    '<' => 16,              # :
395                    '\\' => 128,    # ¾
396                    '\'' => 192,    # æ
397                    ';' => 224,             # è
398            },
399            0x85FF => {
400                    '/' => 32,
401                    'f11' => 16,    # ^
402            },
403            0x83FE => {
404                    'f12' => 16,    # ;
405                    '[' => 128,             # ¹
406                    ']' => 192,             # ð
407                    'p' => 224,
408            },
409            0x83FF => {
410                    '-' => 32,
411                    '0' => 16,
412            },
413    };
414    
415  sub read {  sub read {
416          my $self = shift;          my $self = shift;
417          my ($addr) = @_;          my ($addr) = @_;
# Line 318  sub read { Line 421  sub read {
421    
422          # keyboard          # keyboard
423    
424          if ( first { $addr == $_ } @kbd_ports ) {          if ( defined( $keyboard->{$addr} ) ) {
425                  warn sprintf("keyboard port: %04x\n",$addr);                  warn sprintf("keyboard port: %04x\n",$addr) if $self->trace;
426          } elsif ( $addr == 0x87fc ) {                  my $key = $self->key_pressed;
427                  warn "0x87fc - arrows/back\n";                  if ( defined($key) ) {
428  =for pascal                          my $ret = $keyboard_none;
429                  if VKey=VK_RIGHT then Result:=16;                          my $r = $keyboard->{$addr} || confess "no definition for keyboard port found";
430                  if VKey=VK_DOWN then Result:=128;                          if ( ref($r) eq 'CODE' ) {
431                  if VKey=VK_UP then Result:=192;                                  $ret = $r->($self, $key);
432                  if VKey=VK_LEFT then Result:=224;                          } elsif ( defined($r->{$key}) ) {
433                  if Ord(KeyPressed)=VK_BACK then Result:=224;                                  $ret = $r->{$key};
434  =cut                                  if ( ref($ret) eq 'CODE' ) {
435          } elsif ( $addr == 0x87fd ) {                                          $ret = $ret->($self);
436                  warn "0x87fd - enter\n";                                  }
437  =for pascal                          } else {
438      if KeyPressed=Chr(13) then begin                                  warn sprintf("keyboard port: %04x unknown key: '%s'\n", $addr, $key) if $debug;
439        Mem[$FC]:=13;                          }
440        Result:=0;                          warn sprintf("keyboard port: %04x key:%s code:%d\n",$addr,$key,$ret) if ( $ret != $keyboard_none );
441      end;                          return $ret;
442  =cut                  }
443          } elsif ( $addr == 0x87fa ) {                  return $keyboard_none;
444                  warn "0x87fa = F1 - F4\n";          }
445  =for pascal  
446      if VKey=VK_F4 then Result:=16;          if ( $addr == 0x87ff ) {
447      if VKey=VK_F3 then Result:=128;                  return $self->read_tape;
     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  
448          }          }
449    
450          $self->mmap_pixel( $addr, 0, $byte, 0 );          $self->mmap_pixel( $addr, 0, $byte, 0 );
# Line 384  sub write { Line 464  sub write {
464          my ($addr,$byte) = @_;          my ($addr,$byte) = @_;
465          warn sprintf("# Orao::write(%04x,%02x)\n", $addr, $byte) if $self->trace;          warn sprintf("# Orao::write(%04x,%02x)\n", $addr, $byte) if $self->trace;
466    
         if ( $addr >= 0x6000 && $addr < 0x8000 ) {  
                 $self->vram( $addr - 0x6000 , $byte );  
         }  
   
467          if ( $addr == 0x8800 ) {          if ( $addr == 0x8800 ) {
468                  warn sprintf "sound ignored: %x\n", $byte;                  warn sprintf "sound ignored: %x\n", $byte;
469          }          }
# Line 419  sub prompt { Line 495  sub prompt {
495          my $self = shift;          my $self = shift;
496          $self->app->sync;          $self->app->sync;
497          my $a = shift;          my $a = shift;
498          print STDERR $self->hexdump( $a ),          print $self->hexdump( $a ),
499                  $last ? "[$last] " : '',                  $last ? "[$last] " : '',
500                  "> ";                  "> ";
501          my $in = <STDIN>;          my $in = <STDIN>;
# Line 441  my $show_R = 0; Line 517  my $show_R = 0;
517  sub cli {  sub cli {
518          my $self = shift;          my $self = shift;
519          my $a = $PC || confess "no pc?";          my $a = $PC || confess "no pc?";
520            my $run_for = 0;
521          warn $self->dump_R() if $show_R;          warn $self->dump_R() if $show_R;
522          while ( my ($line, @v) = $self->prompt( $a, $last ) ) {          while ( my ($line, @v) = $self->prompt( $a, $last ) ) {
523                  my $c = shift @v;                  my $c = shift @v;
# Line 467  d\t\tdebug [$d] Line 544  d\t\tdebug [$d]
544    
545  __USAGE__  __USAGE__
546                          warn $self->dump_R;                          warn $self->dump_R;
547                            $last = '';
548                  } elsif ( $c =~ m/^e/i ) {                  } elsif ( $c =~ m/^e/i ) {
549                          $a = $v if defined($v);                          $a = $v if defined($v);
550                          my $to = shift @v;                          my $to = shift @v;
# Line 505  __USAGE__ Line 583  __USAGE__
583                          print "run_for $run_for instructions\n";                          print "run_for $run_for instructions\n";
584                          $show_R = 1;                          $show_R = 1;
585                          last;                          last;
586                  } elsif ( $c =~ m/^(u|j)/ ) {                  } elsif ( $c =~ m/^(u|j)/i ) {
587                          my $to = $v || $a;                          my $to = $v || $a;
588                          printf "set pc to %04x\n", $to;                          printf "set pc to %04x\n", $to;
589                          $PC = $to;      # remember for restart                          $PC = $to;      # remember for restart
# Line 513  __USAGE__ Line 591  __USAGE__
591                          $last = "r $run_for";                          $last = "r $run_for";
592                          $show_R = 1;                          $show_R = 1;
593                          last;                          last;
594                  } elsif ( $c =~ m/^t/ ) {                  } elsif ( $c =~ m/^tape/ ) {
595                            if ( ! $v ) {
596                                    warn "ERROR: please specify tape name!\n";
597                            } elsif ( ! -e $v ) {
598                                    warn "ERROR: tape $v: $!\n";
599                            } else {
600                                    $self->load_tape( $v );
601                            }
602                            $last = '';
603                    } elsif ( $c =~ m/^t/i ) {
604                          $self->trace( not $self->trace );                          $self->trace( not $self->trace );
605                          print "trace ", $self->trace ? 'on' : 'off', "\n";                          print "trace ", $self->trace ? 'on' : 'off', "\n";
606                          $last = '';                          $last = '';
607                  } elsif ( $c =~ m/^d/ ) {                  } elsif ( $c =~ m/^d/i ) {
608                          $self->debug( not $self->debug );                          $self->debug( not $self->debug );
609                          print "debug ", $self->debug ? 'on' : 'off', "\n";                          print "debug ", $self->debug ? 'on' : 'off', "\n";
610                          $last = '';                          $last = '';
# Line 527  __USAGE__ Line 614  __USAGE__
614                  }                  }
615          }          }
616    
617            return $run_for;
618  }  }
619    
620  =head1 AUTHOR  =head1 AUTHOR

Legend:
Removed from v.95  
changed lines
  Added in v.109

  ViewVC Help
Powered by ViewVC 1.1.26