/[VRac]/M6502/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 /M6502/Orao.pm

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

revision 47 by dpavlin, Tue Jul 31 10:16:36 2007 UTC revision 59 by dpavlin, Tue Jul 31 16:06:27 2007 UTC
# Line 3  package Orao; Line 3  package Orao;
3  use warnings;  use warnings;
4  use strict;  use strict;
5    
6  use Carp;  use Carp qw/confess/;
7  use lib './lib';  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/;
11  use M6502;  use M6502;
12    
13  use base qw(Class::Accessor M6502 Screen);  use base qw(Class::Accessor M6502 Screen Prefs);
14  __PACKAGE__->mk_accessors(qw(debug trace run_for mem_dump trace));  __PACKAGE__->mk_accessors(qw(run_for));
15    
16  =head1 NAME  =head1 NAME
17    
# Line 33  Emulator or Orao 8-bit 6502 machine popu Line 33  Emulator or Orao 8-bit 6502 machine popu
33    
34  =head2 init  =head2 init
35    
36  Start emulator  Start emulator, open L<Screen>, load initial ROM images, and render memory
37    
38  =cut  =cut
39    
# Line 46  sub init { Line 46  sub init {
46          warn "Orao calling upstream init\n";          warn "Orao calling upstream init\n";
47          $self->SUPER::init( $self, @_ );          $self->SUPER::init( $self, @_ );
48    
49          warn "staring Orao $Orao::VERSION emulation\n";          warn "Orao $Orao::VERSION emulation starting\n";
50    
51          $self->open_screen;          $self->open_screen;
52          $self->load_rom({          $self->load_rom({
# Line 62  sub init { Line 62  sub init {
62    
63  #       $self->prompt( 0x1000 );  #       $self->prompt( 0x1000 );
64    
65          my $trace = $self->trace;          my ( $trace, $debug ) = ( $self->trace, $self->debug );
66          $self->trace( 0 );          $self->trace( 0 );
67            $self->debug( 0 );
68    
69          if ( $self->show_mem ) {          if ( $self->show_mem ) {
70    
# Line 104  sub init { Line 105  sub init {
105          }          }
106          $self->sync;          $self->sync;
107          $self->trace( $trace );          $self->trace( $trace );
108            $self->debug( $debug );
109    
110          #( $A, $P, $X, $Y, $S, $IPeriod ) = ( 1, 2, 3, 4, 5, 6 );          #( $A, $P, $X, $Y, $S, $IPeriod ) = ( 1, 2, 3, 4, 5, 6 );
111    
112          warn "Orao init finished", $self->trace ? ' trace on' : '', "\n";          warn "Orao init finished",
113                    $self->trace ? ' trace' : '',
114                    $self->debug ? ' debug' : '',
115                    "\n";
116    
117  }  }
118    
# Line 236  sub hexdump { Line 241  sub hexdump {
241          );          );
242  }  }
243    
 =head2 prompt  
   
   $orao->prompt( $address, $last_command );  
   
 =cut  
   
 sub prompt {  
         my $self = shift;  
         $self->app->sync;  
         my $a = shift;  
         my $last = shift;  
         print STDERR $self->hexdump( $a ),  
                 $last ? "[$last] " : '',  
                 "> ";  
         my $in = <STDIN>;  
         chomp($in);  
         $in ||= $last;  
         $last = $in;  
         return split(/\s+/, $in) if $in;  
 }  
   
244  =head1 Memory management  =head1 Memory management
245    
246  Orao implements all I/O using mmap addresses. This was main reason why  Orao implements all I/O using mmap addresses. This was main reason why
# Line 298  sub write { Line 282  sub write {
282                  $self->vram( $addr - 0x6000 , $byte );                  $self->vram( $addr - 0x6000 , $byte );
283          }          }
284    
         if ( $addr > 0xafff ) {  
                 warn sprintf "access to %04x above affff aborting\n", $addr;  
                 return -1;  
         }  
285          if ( $addr == 0x8800 ) {          if ( $addr == 0x8800 ) {
286                  warn sprintf "sound ignored: %x\n", $byte;                  warn sprintf "sound ignored: %x\n", $byte;
287          }          }
288    
289            if ( $addr > 0xafff ) {
290                    confess sprintf "write access 0x%04x > 0xafff aborting\n", $addr;
291            }
292    
293          $self->mmap_pixel( $addr, $byte, 0, 0 );          $self->mmap_pixel( $addr, $byte, 0, 0 );
294    
295          $mem[$addr] = $byte;          $mem[$addr] = $byte;
# Line 317  sub write { Line 301  sub write {
301  Command-line debugging intrerface is implemented for communication with  Command-line debugging intrerface is implemented for communication with
302  emulated device  emulated device
303    
304  =head2 cli  =head2 prompt
305    
306    $orao->cli();    $orao->prompt( $address, $last_command );
307    
308  =cut  =cut
309    
310  my $last = 'r 1';  my $last = 'r 1';
311    
312    sub prompt {
313            my $self = shift;
314            $self->app->sync;
315            my $a = shift;
316            print STDERR $self->hexdump( $a ),
317                    $last ? "[$last] " : '',
318                    "> ";
319            my $in = <STDIN>;
320            chomp($in);
321            warn "## prompt got: $in\n" if $self->debug;
322            $in ||= $last;
323            $last = $in;
324            return split(/\s+/, $in) if $in;
325    }
326    
327    =head2 cli
328    
329      $orao->cli();
330    
331    =cut
332    
333  sub cli {  sub cli {
334          my $self = shift;          my $self = shift;
335          my $a = $PC || confess "no pc?";          my $a = $PC || confess "no pc?";
# Line 332  sub cli { Line 337  sub cli {
337                  my $c = shift @v;                  my $c = shift @v;
338                  my $v = shift @v;                  my $v = shift @v;
339                  $v = hex($v) if $v && $v =~ m/^[0-9a-f]+$/;                  $v = hex($v) if $v && $v =~ m/^[0-9a-f]+$/;
                 printf "## [%s] %s\n", ($v || 'undef'), join(",",@v) if $self->debug;  
340                  @v = map { hex($_) } @v;                  @v = map { hex($_) } @v;
341                    printf "## a: %04x parsed cli: c:%s v:%s %s\n", $a, $c, ($v || 'undef'), join(",",@v) if $self->debug;
342                  if ( $c =~ m/^[qx]/i ) {                  if ( $c =~ m/^[qx]/i ) {
343                          exit;                          exit;
344                  } elsif ( $c eq '?' ) {                  } elsif ( $c eq '?' ) {
345                            my $t = $self->trace ? 'on' : 'off' ;
346                            my $d = $self->debug ? 'on' : 'off' ;
347                          warn <<__USAGE__;                          warn <<__USAGE__;
348  uage:  Usage:
349    
350  x|q\t\texit  x|q\t\texit
351  e 6000 6010\tdump memory, +/- to walk forward/backward  e 6000 6010\tdump memory, +/- to walk forward/backward
352  m 1000 ff 00\tput ff 00 on 1000  m 1000 ff 00\tput ff 00 on 1000
353  j|u 1000\t\tjump (change pc)  j|u 1000\t\tjump (change pc)
354  r 42\t\trun 42 instruction opcodes  r 42\t\trun 42 instruction opcodes
355    t\t\ttrace [$t]
356    d\t\tdebug [$d]
357    
358  __USAGE__  __USAGE__
359                            warn sprintf(" PC: %04x A:%02x P:%02x X:%02x Y:%02x S:%02x\n", $PC, $A, $P, $X, $Y, $S);
360                  } elsif ( $c =~ m/^e/i ) {                  } elsif ( $c =~ m/^e/i ) {
361                          $a ||= $v;                          $a = $v if defined($v);
362                          my $to = shift @v;                          my $to = shift @v;
363                          $to = $a + 32 if ( ! $to || $to <= $a );                          $to = $a + 32 if ( ! $to || $to <= $a );
364                          my $lines = int( ($to - $a - 8) / 8 );                          my $lines = int( ($to - $a + 8) / 8 );
365                          printf "## m %04x %04x lines: %d\n", $a, $to, $lines;                          printf "## e %04x %04x (%d bytes) lines: %d\n", $a, $to, ($to-$a), $lines;
366                          while ( $lines ) {                          while ( --$lines ) {
367                                  print $self->hexdump( $a );                                  print $self->hexdump( $a );
368                                  $a += 8;                                  $a += 8;
                                 $lines--;  
369                          }                          }
370                          $last = '+';                          $last = '+';
371                  } elsif ( $c =~ m/^\+/ ) {                  } elsif ( $c =~ m/^\+/ ) {
# Line 365  __USAGE__ Line 376  __USAGE__
376                          $a = $v;                          $a = $v;
377                          $self->poke_code( $a, @v );                          $self->poke_code( $a, @v );
378                          printf "poke %d bytes at %04x\n", $#v + 1, $a;                          printf "poke %d bytes at %04x\n", $#v + 1, $a;
379                            $last = '+';
380                  } elsif ( $c =~ m/^l/i ) {                  } elsif ( $c =~ m/^l/i ) {
381                          my $to = shift @v || 0x1000;                          my $to = shift @v || 0x1000;
382                          $a = $to;                          $a = $to;
383                          $self->load_oraoemu( $v, $a );                          $self->load_oraoemu( $v, $a );
384                            $last = '';
385                  } elsif ( $c =~ m/^s/i ) {                  } elsif ( $c =~ m/^s/i ) {
386                          $self->save_dump( $v || 'mem.dump', @v );                          $self->save_dump( $v || 'mem.dump', @v );
387                            $last = '';
388                  } elsif ( $c =~ m/^r/i ) {                  } elsif ( $c =~ m/^r/i ) {
389                          $run_for = $v || 1;                          $run_for = $v || 1;
390                          print "run_for $run_for instructions\n";                          print "run_for $run_for instructions\n";
# Line 380  __USAGE__ Line 394  __USAGE__
394                          printf "set pc to %04x\n", $to;                          printf "set pc to %04x\n", $to;
395                          $PC = $to;      # remember for restart                          $PC = $to;      # remember for restart
396                          $run_for = 1;                          $run_for = 1;
397                            $last = sprintf('m %04x', $to);
398                          last;                          last;
399                  } elsif ( $c =~ m/^t/ ) {                  } elsif ( $c =~ m/^t/ ) {
400                          $self->trace( not $self->trace );                          $self->trace( not $self->trace );
401                          print "trace ", $self->trace ? 'on' : 'off', "\n";                          print "trace ", $self->trace ? 'on' : 'off', "\n";
402                    } elsif ( $c =~ m/^d/ ) {
403                            $self->debug( not $self->debug );
404                            print "debug ", $self->debug ? 'on' : 'off', "\n";
405                  } else {                  } else {
406                          warn "# ignore $c\n";                          warn "# ignore $c\n";
407                          last;                          last;

Legend:
Removed from v.47  
changed lines
  Added in v.59

  ViewVC Help
Powered by ViewVC 1.1.26