/[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 77 by dpavlin, Wed Aug 1 13:01:17 2007 UTC revision 105 by dpavlin, Thu Aug 2 21:55:06 2007 UTC
# Line 11  use Data::Dump qw/dump/; Line 11  use Data::Dump qw/dump/;
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 19  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 31  Emulator or Orao 8-bit 6502 machine popu Line 31  Emulator or Orao 8-bit 6502 machine popu
31    
32  =cut  =cut
33    
34  =head2 init  =head1 FUNCTIONS
35    
36    =head2 boot
37    
38  Start emulator, open L<Screen>, load initial ROM images, and render memory  Start emulator, open L<Screen>, load initial ROM images, and render memory
39    
40      my $orao = Orao->new({});
41      $orao->boot;
42    
43  =cut  =cut
44    
45  our $orao;  our $orao;
46    
47  select(STDERR); $| = 1;  select(STDERR); $| = 1;
48    
49  sub init {  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 60  sub init { Line 70  sub init {
70  #       $PC = 0xDD11;   # BC  #       $PC = 0xDD11;   # BC
71  #       $PC = 0xC274;   # MC  #       $PC = 0xC274;   # MC
72    
73            $PC = 0xff89;
74    
75          $orao = $self;          $orao = $self;
76    
77  #       $self->prompt( 0x1000 );  #       $self->prompt( 0x1000 );
# Line 99  sub init { Line 111  sub init {
111    
112          #( $A, $P, $X, $Y, $S, $IPeriod ) = ( 1, 2, 3, 4, 5, 6 );          #( $A, $P, $X, $Y, $S, $IPeriod ) = ( 1, 2, 3, 4, 5, 6 );
113    
114          warn "Orao init finished",          warn "Orao boot finished",
115                  $self->trace ? ' trace' : '',                  $self->trace ? ' trace' : '',
116                  $self->debug ? ' debug' : '',                  $self->debug ? ' debug' : '',
117                  "\n";                  "\n";
118    
119            M6502::reset();
120    
121            $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 121  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 149  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 265  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
430    
431            if ( defined( $keyboard->{$addr} ) ) {
432                    warn sprintf("keyboard port: %04x\n",$addr) if $self->trace;
433                    my $key = $self->key_pressed;
434                    if ( defined($key) ) {
435                            my $ret = $keyboard_none;
436                            my $r = $keyboard->{$addr} || confess "no definition for keyboard port found";
437                            if ( ref($r) eq 'CODE' ) {
438                                    $ret = $r->($self, $key);
439                            } elsif ( defined($r->{$key}) ) {
440                                    $ret = $r->{$key};
441                                    if ( ref($ret) eq 'CODE' ) {
442                                            $ret = $ret->($self);
443                                    }
444                            } else {
445                                    warn sprintf("keyboard port: %04x unknown key: '%s'\n", $addr, $key) if $debug;
446                            }
447                            warn sprintf("keyboard port: %04x key:%s code:%d\n",$addr,$key,$ret) if ( $ret != $keyboard_none );
448                            return $ret;
449                    }
450                    return $keyboard_none;
451            }
452    
453          $self->mmap_pixel( $addr, 0, $byte, 0 );          $self->mmap_pixel( $addr, 0, $byte, 0 );
454          return $byte;          return $byte;
455  }  }
# Line 296  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 323  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 345  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 371  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 399  __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 431  __USAGE__ Line 612  __USAGE__
612                  }                  }
613          }          }
614    
615            return $run_for;
616  }  }
617    
618  =head1 AUTHOR  =head1 AUTHOR

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

  ViewVC Help
Powered by ViewVC 1.1.26