/[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 82 by dpavlin, Wed Aug 1 21:40:17 2007 UTC revision 110 by dpavlin, Fri Aug 3 12:21:47 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(run_for));  __PACKAGE__->mk_accessors(qw(booted));
15    
16  =head1 NAME  =head1 NAME
17    
# Line 20  Orao - Orao emulator Line 19  Orao - Orao emulator
19    
20  =head1 VERSION  =head1 VERSION
21    
22  Version 0.02  Version 0.04
23    
24  =cut  =cut
25    
26  our $VERSION = '0.02';  our $VERSION = '0.04';
27    
28  =head1 SUMMARY  =head1 SUMMARY
29    
# 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    
34  my @kbd_ports = (  =head1 FUNCTIONS
     0x87FC,0x87FD,0x87FA,0x87FB,0x87F6,0x87F7,  
     0x87EE,0x87EF,0x87DE,0x87DF,0x87BE,0x87BF,  
     0x877E,0x877F,0x86FE,0x86FF,0x85FE,0x85FF,  
     0x83FE,0x83FF,  
 );  
35    
36  =head2 boot  =head2 boot
37    
# Line 55  select(STDERR); $| = 1; Line 49  select(STDERR); $| = 1;
49  sub boot {  sub boot {
50          my $self = shift;          my $self = shift;
51          warn "Orao calling upstream init\n";          warn "Orao calling upstream init\n";
52          $self->SUPER::init( $self, @_ );          $self->SUPER::init(
53                    read => sub { $self->read( @_ ) },
54                    write => sub { $self->write( @_ ) },
55            );
56    
57          warn "Orao $Orao::VERSION emulation starting\n";          warn "Orao $Orao::VERSION emulation starting\n";
58    
59            warn "emulating ", $#mem, " bytes of memory\n";
60    
61          $self->open_screen;          $self->open_screen;
62          $self->load_rom({          $self->load_rom({
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 81  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 100  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 119  sub boot { Line 116  sub boot {
116    
117          M6502::reset();          M6502::reset();
118    
119          warn dump( M6502->run );          $self->booted( 1 );
120  }  }
121    
122    =head2 run
123    
124    Run interactive emulation loop
125    
126      $orao->run;
127    
128    =cut
129    
130    sub run {
131            my $self = shift;
132    
133            $self->boot if ( ! $self->booted );
134    
135            $self->load_tape( '../oraoigre/bdash.tap' );
136    
137            $self->loop;
138    };
139    
140    =head1 Helper functions
141    
142  =head2 load_rom  =head2 load_rom
143    
144  called to init memory and load initial rom images  called to init memory and load initial rom images
# Line 137  sub load_rom { Line 154  sub load_rom {
154    
155          foreach my $addr ( sort keys %$loaded_files ) {          foreach my $addr ( sort keys %$loaded_files ) {
156                  my $path = $loaded_files->{$addr};                  my $path = $loaded_files->{$addr};
157                  $self->load_oraoemu( $path, $addr );                  $self->load_image( $path, $addr );
158          }          }
159  }  }
160    
# Line 158  sub _write_chunk { Line 175  sub _write_chunk {
175          $t = $end if ( $end < $t );          $t = $end if ( $end < $t );
176    
177          warn sprintf("refresh video ram %04x-%04x\n", $f, $t);          warn sprintf("refresh video ram %04x-%04x\n", $f, $t);
178  #       foreach my $a ( $f .. $t ) {          $self->render_vram( @mem[ 0x6000 .. 0x7fff ] );
 #               $self->vram( $a - 0x6000 , $mem[ $a ] );  
 #       }  
         $self->render( @mem[ 0x6000 .. 0x7fff ] );  
179          $self->render_mem( @mem ) if $self->show_mem;          $self->render_mem( @mem ) if $self->show_mem;
180  }  }
181    
182  =head2 load_oraoemu  =head2 load_image
183    
184  Load binary files, ROM images and Orao Emulator files  Load binary files, ROM images and Orao Emulator files
185    
186    $orao->load_oraoemu( '/path/to/file', 0x1000 );    $orao->load_image( '/path/to/file', 0x1000 );
187    
188  Returns true on success.  Returns true on success.
189    
190  =cut  =cut
191    
192  sub load_oraoemu {  sub load_image {
193          my $self = shift;          my $self = shift;
194          my ( $path, $addr ) = @_;          my ( $path, $addr ) = @_;
195    
# Line 281  Read from memory Line 295  Read from memory
295    
296  =cut  =cut
297    
298    my $keyboard_none = 255;
299    
300    my $keyboard = {
301            0x87FC => {
302                    'right'         => 16,
303                    'down'          => 128,
304                    'up'            => 192,
305                    'left'          => 224,
306                    'backspace' => 224,
307            },
308            0x87FD => sub {
309                    my ( $self, $key ) = @_;
310                    if ( $key eq 'return' ) {
311                            M6502::_write( 0xfc, 13 );
312                            warn "return\n";
313                            return 0;
314                    } elsif ( $key =~ m/ ctrl/ || $self->key_down( 'left ctrl' ) || $self->key_down( 'right ctrl' ) ) {
315                            warn "ctrl\n";
316                            return 16;
317                    }
318                    return $keyboard_none;
319            },
320            0x87FA => {
321                    'f4' => 16,
322                    'f3' => 128,
323                    'f2' => 192,
324                    'f1' => 224,
325            },
326            0x87FB => sub {
327                    my ( $self, $key ) = @_;
328                    if ( $key eq 'space' ) {
329                            return 32;
330                    } elsif ( $self->key_down( 'left shift' ) || $self->key_down( 'right shift' ) ) {
331                            warn "shift\n";
332                            return 16;
333    #               } elsif ( $self->tape ) {
334    #                       warn "has tape!";
335    #                       return 0;
336                    }
337                    return $keyboard_none;
338            },
339            0x87F6 => {
340                    '6' => 16,
341                    't' => 128,
342                    'y' => 192,     # hr: z
343                    'r' => 224,
344            },
345            0x87F7 => {
346                    '5' => 32,
347                    '4' => 16,
348            },
349            0x87EE => {
350                    '7' => 16,
351                    'u' => 128,
352                    'i' => 192,
353                    'o' => 224,
354            },
355            0x87EF => {
356                    '8' => 32,
357                    '9' => 16,
358            },
359            0x87DE => {
360                    '1' => 16,
361                    'w' => 128,
362                    'q' => 192,
363                    'e' => 224,
364            },
365            0x87DF => {
366                    '2' => 32,
367                    '3' => 16,
368            },
369            0x87BE => {
370                    'm' => 16,
371                    'k' => 128,
372                    'j' => 192,
373                    'l' => 224,
374            },
375            0x87BF => {
376                    ',' => 32,      # <
377                    '.' => 16,      # >
378            },
379            0x877E => {
380                    'z' => 16,      # hr:y
381                    's' => 128,
382                    'a' => 192,
383                    'd' => 224,
384            },
385            0x877F => {
386                    'x' => 32,
387                    'c' => 16,
388            },
389            0x86FE => {
390                    'n' => 16,
391                    'g' => 128,
392                    'h' => 192,
393                    'f' => 224,
394            },
395            0x86FF => {
396                    'b' => 32,
397                    'v' => 16,
398            },
399            0x85FE => {
400                    '<' => 16,              # :
401                    '\\' => 128,    # ¾
402                    '\'' => 192,    # æ
403                    ';' => 224,             # è
404            },
405            0x85FF => {
406                    '/' => 32,
407                    'f11' => 16,    # ^
408            },
409            0x83FE => {
410                    'f12' => 16,    # ;
411                    '[' => 128,             # ¹
412                    ']' => 192,             # ð
413                    'p' => 224,
414            },
415            0x83FF => {
416                    '-' => 32,
417                    '0' => 16,
418            },
419    };
420    
421  sub read {  sub read {
422          my $self = shift;          my $self = shift;
423          my ($addr) = @_;          my ($addr) = @_;
424          my $byte = $mem[$addr];          my $byte = $mem[$addr];
425            confess sprintf("can't find memory at address %04x",$addr) unless defined($byte);
426          warn sprintf("# Orao::read(%04x) = %02x\n", $addr, $byte) if $self->trace;          warn sprintf("# Orao::read(%04x) = %02x\n", $addr, $byte) if $self->trace;
427    
428          # keyboard          # keyboard
429    
430          if ( first { $addr == $_ } @kbd_ports ) {          if ( defined( $keyboard->{$addr} ) ) {
431                  warn sprintf("keyboard port: %04x\n",$addr);                  warn sprintf("keyboard port: %04x\n",$addr) if $self->trace;
432          } elsif ( $addr == 0x87fc ) {                  my $key = $self->key_pressed;
433                  warn "0x87fc - arrows/back\n";                  if ( defined($key) ) {
434  =for pascal                          my $ret = $keyboard_none;
435                  if VKey=VK_RIGHT then Result:=16;                          my $r = $keyboard->{$addr} || confess "no definition for keyboard port found";
436                  if VKey=VK_DOWN then Result:=128;                          if ( ref($r) eq 'CODE' ) {
437                  if VKey=VK_UP then Result:=192;                                  $ret = $r->($self, $key);
438                  if VKey=VK_LEFT then Result:=224;                          } elsif ( defined($r->{$key}) ) {
439                  if Ord(KeyPressed)=VK_BACK then Result:=224;                                  $ret = $r->{$key};
440  =cut                                  if ( ref($ret) eq 'CODE' ) {
441          } elsif ( $addr == 0x87fd ) {                                          $ret = $ret->($self);
442                  warn "0x87fd - enter\n";                                  }
443  =for pascal                          } else {
444      if KeyPressed=Chr(13) then begin                                  warn sprintf("keyboard port: %04x unknown key: '%s'\n", $addr, $key) if $debug;
445        Mem[$FC]:=13;                          }
446        Result:=0;                          warn sprintf("keyboard port: %04x key:%s code:%d\n",$addr,$key,$ret) if ( $ret != $keyboard_none );
447      end;                          return $ret;
448  =cut                  }
449          } elsif ( $addr == 0x87fa ) {                  return $keyboard_none;
450                  warn "0x87fa = F1 - F4\n";          }
451  =for pascal  
452      if VKey=VK_F4 then Result:=16;          if ( $addr == 0x87ff ) {
453      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  
454          }          }
455    
456          $self->mmap_pixel( $addr, 0, $byte, 0 );          $self->mmap_pixel( $addr, 0, $byte, 0 );
# Line 355  sub write { Line 470  sub write {
470          my ($addr,$byte) = @_;          my ($addr,$byte) = @_;
471          warn sprintf("# Orao::write(%04x,%02x)\n", $addr, $byte) if $self->trace;          warn sprintf("# Orao::write(%04x,%02x)\n", $addr, $byte) if $self->trace;
472    
         if ( $addr >= 0x6000 && $addr < 0x8000 ) {  
                 $self->vram( $addr - 0x6000 , $byte );  
         }  
   
473          if ( $addr == 0x8800 ) {          if ( $addr == 0x8800 ) {
474                  warn sprintf "sound ignored: %x\n", $byte;                  warn sprintf "sound ignored: %x\n", $byte;
475          }          }
476    
477          if ( $addr > 0xafff ) {          if ( $addr > 0xafff ) {
478                  warn sprintf "write access 0x%04x > 0xafff aborting\n", $addr;                  confess sprintf "write access 0x%04x > 0xafff aborting\n", $addr;
                 return;  
479          }          }
480    
481          $self->mmap_pixel( $addr, $byte, 0, 0 );          $self->mmap_pixel( $addr, $byte, 0, 0 );
# Line 391  sub prompt { Line 501  sub prompt {
501          my $self = shift;          my $self = shift;
502          $self->app->sync;          $self->app->sync;
503          my $a = shift;          my $a = shift;
504          print STDERR $self->hexdump( $a ),          print $self->hexdump( $a ),
505                  $last ? "[$last] " : '',                  $last ? "[$last] " : '',
506                  "> ";                  "> ";
507          my $in = <STDIN>;          my $in = <STDIN>;
# Line 413  my $show_R = 0; Line 523  my $show_R = 0;
523  sub cli {  sub cli {
524          my $self = shift;          my $self = shift;
525          my $a = $PC || confess "no pc?";          my $a = $PC || confess "no pc?";
526            my $run_for = 0;
527          warn $self->dump_R() if $show_R;          warn $self->dump_R() if $show_R;
528          while ( my ($line, @v) = $self->prompt( $a, $last ) ) {          while ( my ($line, @v) = $self->prompt( $a, $last ) ) {
529                  my $c = shift @v;                  my $c = shift @v;
# Line 439  d\t\tdebug [$d] Line 550  d\t\tdebug [$d]
550    
551  __USAGE__  __USAGE__
552                          warn $self->dump_R;                          warn $self->dump_R;
553                            $last = '';
554                  } elsif ( $c =~ m/^e/i ) {                  } elsif ( $c =~ m/^e/i ) {
555                          $a = $v if defined($v);                          $a = $v if defined($v);
556                          my $to = shift @v;                          my $to = shift @v;
# Line 467  __USAGE__ Line 579  __USAGE__
579                  } elsif ( $c =~ m/^l/i ) {                  } elsif ( $c =~ m/^l/i ) {
580                          my $to = shift @v || 0x1000;                          my $to = shift @v || 0x1000;
581                          $a = $to;                          $a = $to;
582                          $self->load_oraoemu( $v, $a );                          $self->load_image( $v, $a );
583                          $last = '';                          $last = '';
584                  } elsif ( $c =~ m/^s/i ) {                  } elsif ( $c =~ m/^s/i ) {
585                          $self->save_dump( $v || 'mem.dump', @v );                          $self->save_dump( $v || 'mem.dump', @v );
586                          $last = '';                          $last = '';
587                  } elsif ( $c =~ m/^r/i ) {                  } elsif ( $c =~ m/^re/i ) { # reset
588                            M6502::reset();
589                            $last = 'r 1';
590                    } elsif ( $c =~ m/^r/i ) {      # run
591                          $run_for = $v || 1;                          $run_for = $v || 1;
592                          print "run_for $run_for instructions\n";                          print "run_for $run_for instructions\n";
593                          $show_R = 1;                          $show_R = 1;
594                          last;                          last;
595                  } elsif ( $c =~ m/^(u|j)/ ) {                  } elsif ( $c =~ m/^(u|j)/i ) {
596                          my $to = $v || $a;                          my $to = $v || $a;
597                          printf "set pc to %04x\n", $to;                          printf "set pc to %04x\n", $to;
598                          $PC = $to;      # remember for restart                          $PC = $to;      # remember for restart
# Line 485  __USAGE__ Line 600  __USAGE__
600                          $last = "r $run_for";                          $last = "r $run_for";
601                          $show_R = 1;                          $show_R = 1;
602                          last;                          last;
603                  } elsif ( $c =~ m/^t/ ) {                  } elsif ( $c =~ m/^tape/ ) {
604                            if ( $c =~ m/rate/ ) {
605                                    $self->tape_rate( $v );
606                                    warn "will read table with rate $v\n";
607                            } elsif ( ! $v ) {
608                                    warn "ERROR: please specify tape name!\n";
609                            } elsif ( ! -e $v ) {
610                                    warn "ERROR: tape $v: $!\n";
611                            } else {
612                                    $self->load_tape( $v );
613                            }
614                            $last = '';
615                    } elsif ( $c =~ m/^t/i ) {
616                          $self->trace( not $self->trace );                          $self->trace( not $self->trace );
617                          print "trace ", $self->trace ? 'on' : 'off', "\n";                          print "trace ", $self->trace ? 'on' : 'off', "\n";
618                          $last = '';                          $last = '';
619                  } elsif ( $c =~ m/^d/ ) {                  } elsif ( $c =~ m/^d/i ) {
620                          $self->debug( not $self->debug );                          $self->debug( not $self->debug );
621                          print "debug ", $self->debug ? 'on' : 'off', "\n";                          print "debug ", $self->debug ? 'on' : 'off', "\n";
622                          $last = '';                          $last = '';
# Line 499  __USAGE__ Line 626  __USAGE__
626                  }                  }
627          }          }
628    
629            return $run_for;
630  }  }
631    
632  =head1 AUTHOR  =head1 AUTHOR

Legend:
Removed from v.82  
changed lines
  Added in v.110

  ViewVC Help
Powered by ViewVC 1.1.26