/[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 97 by dpavlin, Thu Aug 2 14:07:52 2007 UTC
# Line 12  use List::Util qw/first/; Line 12  use List::Util qw/first/;
12  use M6502;  use M6502;
13    
14  use base qw(Class::Accessor M6502 Screen Prefs);  use base qw(Class::Accessor M6502 Screen Prefs);
15  __PACKAGE__->mk_accessors(qw(run_for));  __PACKAGE__->mk_accessors(qw(booted));
16    
17  =head1 NAME  =head1 NAME
18    
# Line 20  Orao - Orao emulator Line 20  Orao - Orao emulator
20    
21  =head1 VERSION  =head1 VERSION
22    
23  Version 0.02  Version 0.04
24    
25  =cut  =cut
26    
27  our $VERSION = '0.02';  our $VERSION = '0.04';
28    
29  =head1 SUMMARY  =head1 SUMMARY
30    
# Line 39  my @kbd_ports = ( Line 39  my @kbd_ports = (
39      0x83FE,0x83FF,      0x83FE,0x83FF,
40  );  );
41    
42    =head1 FUNCTIONS
43    
44  =head2 boot  =head2 boot
45    
46  Start emulator, open L<Screen>, load initial ROM images, and render memory  Start emulator, open L<Screen>, load initial ROM images, and render memory
# Line 55  select(STDERR); $| = 1; Line 57  select(STDERR); $| = 1;
57  sub boot {  sub boot {
58          my $self = shift;          my $self = shift;
59          warn "Orao calling upstream init\n";          warn "Orao calling upstream init\n";
60          $self->SUPER::init( $self, @_ );          $self->SUPER::init(
61                    read => sub { $self->read( @_ ) },
62                    write => sub { $self->write( @_ ) },
63            );
64    
65          warn "Orao $Orao::VERSION emulation starting\n";          warn "Orao $Orao::VERSION emulation starting\n";
66    
67            warn "emulating ", $#mem, " bytes of memory\n";
68    
69          $self->open_screen;          $self->open_screen;
70          $self->load_rom({          $self->load_rom({
71                  0x1000 => 'dump/SCRINV.BIN',                  0x1000 => 'dump/SCRINV.BIN',
# Line 119  sub boot { Line 126  sub boot {
126    
127          M6502::reset();          M6502::reset();
128    
129          warn dump( M6502->run );          $self->booted( 1 );
130  }  }
131    
132    =head2 run
133    
134    Run interactive emulation loop
135    
136      $orao->run;
137    
138    =cut
139    
140    sub run {
141            my $self = shift;
142    
143            $self->show_mem( 1 );
144    
145            $self->boot if ( ! $self->booted );
146            $self->loop;
147    };
148    
149    =head1 Helper functions
150    
151  =head2 load_rom  =head2 load_rom
152    
153  called to init memory and load initial rom images  called to init memory and load initial rom images
# Line 137  sub load_rom { Line 163  sub load_rom {
163    
164          foreach my $addr ( sort keys %$loaded_files ) {          foreach my $addr ( sort keys %$loaded_files ) {
165                  my $path = $loaded_files->{$addr};                  my $path = $loaded_files->{$addr};
166                  $self->load_oraoemu( $path, $addr );                  $self->load_image( $path, $addr );
167          }          }
168  }  }
169    
# Line 165  sub _write_chunk { Line 191  sub _write_chunk {
191          $self->render_mem( @mem ) if $self->show_mem;          $self->render_mem( @mem ) if $self->show_mem;
192  }  }
193    
194  =head2 load_oraoemu  =head2 load_image
195    
196  Load binary files, ROM images and Orao Emulator files  Load binary files, ROM images and Orao Emulator files
197    
198    $orao->load_oraoemu( '/path/to/file', 0x1000 );    $orao->load_image( '/path/to/file', 0x1000 );
199    
200  Returns true on success.  Returns true on success.
201    
202  =cut  =cut
203    
204  sub load_oraoemu {  sub load_image {
205          my $self = shift;          my $self = shift;
206          my ( $path, $addr ) = @_;          my ( $path, $addr ) = @_;
207    
# Line 285  sub read { Line 311  sub read {
311          my $self = shift;          my $self = shift;
312          my ($addr) = @_;          my ($addr) = @_;
313          my $byte = $mem[$addr];          my $byte = $mem[$addr];
314            confess sprintf("can't find memory at address %04x",$addr) unless defined($byte);
315          warn sprintf("# Orao::read(%04x) = %02x\n", $addr, $byte) if $self->trace;          warn sprintf("# Orao::read(%04x) = %02x\n", $addr, $byte) if $self->trace;
316    
317          # keyboard          # keyboard
318    
319          if ( first { $addr == $_ } @kbd_ports ) {          if ( first { $addr == $_ } @kbd_ports ) {
320                  warn sprintf("keyboard port: %04x\n",$addr);                  warn sprintf("keyboard port: %04x\n",$addr) if $self->trace;
321          } elsif ( $addr == 0x87fc ) {          } elsif ( $addr == 0x87fc ) {
322                  warn "0x87fc - arrows/back\n";                  warn "0x87fc - arrows/back\n";
323  =for pascal  =for pascal
# Line 364  sub write { Line 391  sub write {
391          }          }
392    
393          if ( $addr > 0xafff ) {          if ( $addr > 0xafff ) {
394                  warn sprintf "write access 0x%04x > 0xafff aborting\n", $addr;                  confess sprintf "write access 0x%04x > 0xafff aborting\n", $addr;
                 return;  
395          }          }
396    
397          $self->mmap_pixel( $addr, $byte, 0, 0 );          $self->mmap_pixel( $addr, $byte, 0, 0 );
# Line 391  sub prompt { Line 417  sub prompt {
417          my $self = shift;          my $self = shift;
418          $self->app->sync;          $self->app->sync;
419          my $a = shift;          my $a = shift;
420          print STDERR $self->hexdump( $a ),          print $self->hexdump( $a ),
421                  $last ? "[$last] " : '',                  $last ? "[$last] " : '',
422                  "> ";                  "> ";
423          my $in = <STDIN>;          my $in = <STDIN>;
# Line 413  my $show_R = 0; Line 439  my $show_R = 0;
439  sub cli {  sub cli {
440          my $self = shift;          my $self = shift;
441          my $a = $PC || confess "no pc?";          my $a = $PC || confess "no pc?";
442            my $run_for = 0;
443          warn $self->dump_R() if $show_R;          warn $self->dump_R() if $show_R;
444          while ( my ($line, @v) = $self->prompt( $a, $last ) ) {          while ( my ($line, @v) = $self->prompt( $a, $last ) ) {
445                  my $c = shift @v;                  my $c = shift @v;
# Line 439  d\t\tdebug [$d] Line 466  d\t\tdebug [$d]
466    
467  __USAGE__  __USAGE__
468                          warn $self->dump_R;                          warn $self->dump_R;
469                            $last = '';
470                  } elsif ( $c =~ m/^e/i ) {                  } elsif ( $c =~ m/^e/i ) {
471                          $a = $v if defined($v);                          $a = $v if defined($v);
472                          my $to = shift @v;                          my $to = shift @v;
# Line 467  __USAGE__ Line 495  __USAGE__
495                  } elsif ( $c =~ m/^l/i ) {                  } elsif ( $c =~ m/^l/i ) {
496                          my $to = shift @v || 0x1000;                          my $to = shift @v || 0x1000;
497                          $a = $to;                          $a = $to;
498                          $self->load_oraoemu( $v, $a );                          $self->load_image( $v, $a );
499                          $last = '';                          $last = '';
500                  } elsif ( $c =~ m/^s/i ) {                  } elsif ( $c =~ m/^s/i ) {
501                          $self->save_dump( $v || 'mem.dump', @v );                          $self->save_dump( $v || 'mem.dump', @v );
# Line 499  __USAGE__ Line 527  __USAGE__
527                  }                  }
528          }          }
529    
530            return $run_for;
531  }  }
532    
533  =head1 AUTHOR  =head1 AUTHOR

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

  ViewVC Help
Powered by ViewVC 1.1.26