/[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 105 by dpavlin, Thu Aug 2 21:55:06 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);
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',
# Line 119  sub boot { Line 118  sub boot {
118    
119          M6502::reset();          M6502::reset();
120    
121          warn dump( M6502->run );          $self->booted( 1 );
122  }  }
123    
124    =head2 run
125    
126    Run interactive emulation loop
127    
128      $orao->run;
129    
130    =cut
131    
132    sub run {
133            my $self = shift;
134    
135            $self->show_mem( 1 );
136    
137            $self->boot if ( ! $self->booted );
138            $self->loop;
139    };
140    
141    =head1 Helper functions
142    
143  =head2 load_rom  =head2 load_rom
144    
145  called to init memory and load initial rom images  called to init memory and load initial rom images
# Line 137  sub load_rom { Line 155  sub load_rom {
155    
156          foreach my $addr ( sort keys %$loaded_files ) {          foreach my $addr ( sort keys %$loaded_files ) {
157                  my $path = $loaded_files->{$addr};                  my $path = $loaded_files->{$addr};
158                  $self->load_oraoemu( $path, $addr );                  $self->load_image( $path, $addr );
159          }          }
160  }  }
161    
# Line 165  sub _write_chunk { Line 183  sub _write_chunk {
183          $self->render_mem( @mem ) if $self->show_mem;          $self->render_mem( @mem ) if $self->show_mem;
184  }  }
185    
186  =head2 load_oraoemu  =head2 load_image
187    
188  Load binary files, ROM images and Orao Emulator files  Load binary files, ROM images and Orao Emulator files
189    
190    $orao->load_oraoemu( '/path/to/file', 0x1000 );    $orao->load_image( '/path/to/file', 0x1000 );
191    
192  Returns true on success.  Returns true on success.
193    
194  =cut  =cut
195    
196  sub load_oraoemu {  sub load_image {
197          my $self = shift;          my $self = shift;
198          my ( $path, $addr ) = @_;          my ( $path, $addr ) = @_;
199    
# Line 281  Read from memory Line 299  Read from memory
299    
300  =cut  =cut
301    
302    my $keyboard_none = 255;
303    
304    my $keyboard = {
305            0x87FC => {
306                    'right'         => 16,
307                    'down'          => 128,
308                    'up'            => 192,
309                    'left'          => 224,
310                    'backspace' => 224,
311            },
312            0x87FD => sub {
313                    my ( $self, $key ) = @_;
314                    if ( $key eq 'return' ) {
315                            M6502::_write( 0xfc, 13 );
316                            warn "return\n";
317                            return 0;
318                    } elsif ( $key =~ m/ ctrl/ || $self->key_down( 'left ctrl' ) || $self->key_down( 'right ctrl' ) ) {
319                            warn "ctrl\n";
320                            return 16;
321                    }
322                    return $keyboard_none;
323            },
324            0x87FA => {
325                    'f4' => 16,
326                    'f3' => 128,
327                    'f2' => 192,
328                    'f1' => 224,
329            },
330            0x87FB => sub {
331                    my ( $self, $key ) = @_;
332                    if ( $key eq 'space' ) {
333                            return 32;
334                    } elsif ( $self->key_down( 'left shift' ) || $self->key_down( 'right shift' ) ) {
335                            warn "shift\n";
336                            return 16;
337                    }
338                    return $keyboard_none;
339            },
340            0x87F6 => {
341                    '6' => 16,
342                    't' => 128,
343                    'y' => 192,     # hr: z
344                    'r' => 224,
345            },
346            0x87F7 => {
347                    '5' => 32,
348                    '4' => 16,
349            },
350            0x87EE => {
351                    '7' => 16,
352                    'u' => 128,
353                    'i' => 192,
354                    'o' => 224,
355            },
356            0x87EF => {
357                    '8' => 32,
358                    '9' => 16,
359            },
360            0x87DE => {
361                    '1' => 16,
362                    'w' => 128,
363                    'q' => 192,
364                    'e' => 224,
365            },
366            0x87DF => {
367                    '2' => 32,
368                    '3' => 16,
369            },
370            0x87BE => {
371                    'm' => 16,
372                    'k' => 128,
373                    'j' => 192,
374                    'l' => 224,
375            },
376            0x87BF => {
377                    ',' => 32,      # <
378                    '.' => 16,      # >
379            },
380            0x877E => {
381                    'z' => 16,      # hr:y
382                    's' => 128,
383                    'a' => 192,
384                    'd' => 224,
385            },
386            0x877F => {
387                    'x' => 32,
388                    'c' => 16,
389            },
390            0x86FE => {
391                    'n' => 16,
392                    'g' => 128,
393                    'h' => 192,
394                    'f' => 224,
395            },
396            0x86FF => {
397                    'b' => 32,
398                    'v' => 16,
399            },
400            0x85FE => {
401                    '<' => 16,              # :
402                    '\\' => 128,    # ¾
403                    '\'' => 192,    # æ
404                    ';' => 224,             # è
405            },
406            0x85FF => {
407                    '/' => 32,
408                    'f11' => 16,    # ^
409            },
410            0x83FE => {
411                    'f12' => 16,    # ;
412                    '[' => 128,             # ¹
413                    ']' => 192,             # ð
414                    'p' => 224,
415            },
416            0x83FF => {
417                    '-' => 32,
418                    '0' => 16,
419            },
420    };
421    
422  sub read {  sub read {
423          my $self = shift;          my $self = shift;
424          my ($addr) = @_;          my ($addr) = @_;
425          my $byte = $mem[$addr];          my $byte = $mem[$addr];
426            confess sprintf("can't find memory at address %04x",$addr) unless defined($byte);
427          warn sprintf("# Orao::read(%04x) = %02x\n", $addr, $byte) if $self->trace;          warn sprintf("# Orao::read(%04x) = %02x\n", $addr, $byte) if $self->trace;
428    
429          # keyboard          # keyboard
430    
431          if ( first { $addr == $_ } @kbd_ports ) {          if ( defined( $keyboard->{$addr} ) ) {
432                  warn sprintf("keyboard port: %04x\n",$addr);                  warn sprintf("keyboard port: %04x\n",$addr) if $self->trace;
433          } elsif ( $addr == 0x87fc ) {                  my $key = $self->key_pressed;
434                  warn "0x87fc - arrows/back\n";                  if ( defined($key) ) {
435  =for pascal                          my $ret = $keyboard_none;
436                  if VKey=VK_RIGHT then Result:=16;                          my $r = $keyboard->{$addr} || confess "no definition for keyboard port found";
437                  if VKey=VK_DOWN then Result:=128;                          if ( ref($r) eq 'CODE' ) {
438                  if VKey=VK_UP then Result:=192;                                  $ret = $r->($self, $key);
439                  if VKey=VK_LEFT then Result:=224;                          } elsif ( defined($r->{$key}) ) {
440                  if Ord(KeyPressed)=VK_BACK then Result:=224;                                  $ret = $r->{$key};
441  =cut                                  if ( ref($ret) eq 'CODE' ) {
442          } elsif ( $addr == 0x87fd ) {                                          $ret = $ret->($self);
443                  warn "0x87fd - enter\n";                                  }
444  =for pascal                          } else {
445      if KeyPressed=Chr(13) then begin                                  warn sprintf("keyboard port: %04x unknown key: '%s'\n", $addr, $key) if $debug;
446        Mem[$FC]:=13;                          }
447        Result:=0;                          warn sprintf("keyboard port: %04x key:%s code:%d\n",$addr,$key,$ret) if ( $ret != $keyboard_none );
448      end;                          return $ret;
449  =cut                  }
450          } elsif ( $addr == 0x87fa ) {                  return $keyboard_none;
                 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  
451          }          }
452    
453          $self->mmap_pixel( $addr, 0, $byte, 0 );          $self->mmap_pixel( $addr, 0, $byte, 0 );
# Line 364  sub write { Line 476  sub write {
476          }          }
477    
478          if ( $addr > 0xafff ) {          if ( $addr > 0xafff ) {
479                  warn sprintf "write access 0x%04x > 0xafff aborting\n", $addr;                  confess sprintf "write access 0x%04x > 0xafff aborting\n", $addr;
                 return;  
480          }          }
481    
482          $self->mmap_pixel( $addr, $byte, 0, 0 );          $self->mmap_pixel( $addr, $byte, 0, 0 );
# Line 391  sub prompt { Line 502  sub prompt {
502          my $self = shift;          my $self = shift;
503          $self->app->sync;          $self->app->sync;
504          my $a = shift;          my $a = shift;
505          print STDERR $self->hexdump( $a ),          print $self->hexdump( $a ),
506                  $last ? "[$last] " : '',                  $last ? "[$last] " : '',
507                  "> ";                  "> ";
508          my $in = <STDIN>;          my $in = <STDIN>;
# Line 413  my $show_R = 0; Line 524  my $show_R = 0;
524  sub cli {  sub cli {
525          my $self = shift;          my $self = shift;
526          my $a = $PC || confess "no pc?";          my $a = $PC || confess "no pc?";
527            my $run_for = 0;
528          warn $self->dump_R() if $show_R;          warn $self->dump_R() if $show_R;
529          while ( my ($line, @v) = $self->prompt( $a, $last ) ) {          while ( my ($line, @v) = $self->prompt( $a, $last ) ) {
530                  my $c = shift @v;                  my $c = shift @v;
# Line 439  d\t\tdebug [$d] Line 551  d\t\tdebug [$d]
551    
552  __USAGE__  __USAGE__
553                          warn $self->dump_R;                          warn $self->dump_R;
554                            $last = '';
555                  } elsif ( $c =~ m/^e/i ) {                  } elsif ( $c =~ m/^e/i ) {
556                          $a = $v if defined($v);                          $a = $v if defined($v);
557                          my $to = shift @v;                          my $to = shift @v;
# Line 467  __USAGE__ Line 580  __USAGE__
580                  } elsif ( $c =~ m/^l/i ) {                  } elsif ( $c =~ m/^l/i ) {
581                          my $to = shift @v || 0x1000;                          my $to = shift @v || 0x1000;
582                          $a = $to;                          $a = $to;
583                          $self->load_oraoemu( $v, $a );                          $self->load_image( $v, $a );
584                          $last = '';                          $last = '';
585                  } elsif ( $c =~ m/^s/i ) {                  } elsif ( $c =~ m/^s/i ) {
586                          $self->save_dump( $v || 'mem.dump', @v );                          $self->save_dump( $v || 'mem.dump', @v );
# Line 499  __USAGE__ Line 612  __USAGE__
612                  }                  }
613          }          }
614    
615            return $run_for;
616  }  }
617    
618  =head1 AUTHOR  =head1 AUTHOR

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

  ViewVC Help
Powered by ViewVC 1.1.26