/[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 43 by dpavlin, Tue Jul 31 09:43:21 2007 UTC revision 50 by dpavlin, Tue Jul 31 11:14:19 2007 UTC
# Line 55  sub init { Line 55  sub init {
55                  0xE000 => 'rom/CRT12.ROM',                  0xE000 => 'rom/CRT12.ROM',
56          });          });
57    
58          $self->load_oraoemu( 'dump/orao-1.2' );          $PC = 0xDD11;   # BC
59          $self->load_oraoemu( 'dump/SCRINV.BIN', 0x1000 );  #       $PC = 0xC274;   # MC
         $PC = 0x1000;  
60    
61          $orao = $self;          $orao = $self;
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 105  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 136  sub load_rom { Line 140  sub load_rom {
140    
141  =cut  =cut
142    
143    sub _write_chunk {
144            my $self = shift;
145            my ( $addr, $chunk ) = @_;
146            $self->write_chunk( $addr, $chunk );
147            my $end = $addr + length($chunk);
148            my ( $f, $t ) = ( 0x6000, 0x7fff );
149    
150            if ( $end < $f || $addr >= $t ) {
151                    warn "skip vram update\n";
152                    return;
153            };
154    
155            $f = $addr if ( $addr > $f );
156            $t = $end if ( $end < $t );
157    
158            warn sprintf("refresh video ram %04x-%04x\n", $f, $t);
159            foreach my $a ( $f .. $t ) {
160                    $self->vram( $a - 0x6000 , $mem[ $a ] );
161            }
162    }
163    
164  sub load_oraoemu {  sub load_oraoemu {
165          my $self = shift;          my $self = shift;
166          my ( $path, $addr ) = @_;          my ( $path, $addr ) = @_;
# Line 147  sub load_oraoemu { Line 172  sub load_oraoemu {
172          if ( $size == 65538 ) {          if ( $size == 65538 ) {
173                  $addr = 0;                  $addr = 0;
174                  warn sprintf "loading oraoemu 64k dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size;                  warn sprintf "loading oraoemu 64k dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size;
175                  $self->write_chunk( $addr, substr($buff,2) );                  $self->_write_chunk( $addr, substr($buff,2) );
176                  return;                  return;
177          } elsif ( $size == 32800 ) {          } elsif ( $size == 32800 ) {
178                  $addr = 0;                  $addr = 0;
179                  warn sprintf "loading oraoemu 1.3 dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size;                  warn sprintf "loading oraoemu 1.3 dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size;
180                  $self->write_chunk( $addr, substr($buff,0x20) );                  $self->_write_chunk( $addr, substr($buff,0x20) );
181                  return;                  return;
182          }          }
183          printf "loading %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size;          printf "loading %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size;
184          return $self->write_chunk( $addr, $buff );          return $self->_write_chunk( $addr, $buff );
185    
186          my $chunk;          my $chunk;
187    
# Line 172  sub load_oraoemu { Line 197  sub load_oraoemu {
197                  $pos += 4;                  $pos += 4;
198          }          }
199    
200          $self->write_chunk( $addr, $chunk );          $self->_write_chunk( $addr, $chunk );
201    
202  };  };
203    
# Line 211  sub hexdump { Line 236  sub hexdump {
236                  join(" ",                  join(" ",
237                          map {                          map {
238                                  sprintf( "%02x", $_ )                                  sprintf( "%02x", $_ )
239                          } $self->ram( $a, $a+8 )                          } @mem[ $a .. $a+8 ]
240                  )                  )
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 297  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 312  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 );
# Line 345  __USAGE__ Line 377  __USAGE__
377                          $a = $v;                          $a = $v;
378                          $self->poke_code( $a, @v );                          $self->poke_code( $a, @v );
379                          printf "poke %d bytes at %04x\n", $#v + 1, $a;                          printf "poke %d bytes at %04x\n", $#v + 1, $a;
380                            $last = '+';
381                  } elsif ( $c =~ m/^l/i ) {                  } elsif ( $c =~ m/^l/i ) {
382                          my $to = shift @v || 0x1000;                          my $to = shift @v || 0x1000;
383                          $a = $to;                          $a = $to;
384                          $self->load_oraoemu( $v, $a );                          $self->load_oraoemu( $v, $a );
385                            $last = '';
386                  } elsif ( $c =~ m/^s/i ) {                  } elsif ( $c =~ m/^s/i ) {
387                          $self->save_dump( $v || 'mem.dump', @v );                          $self->save_dump( $v || 'mem.dump', @v );
388                            $last = '';
389                  } elsif ( $c =~ m/^r/i ) {                  } elsif ( $c =~ m/^r/i ) {
390                          $run_for = $v || 1;                          $run_for = $v || 1;
391                          print "run_for $run_for instructions\n";                          print "run_for $run_for instructions\n";
# Line 360  __USAGE__ Line 395  __USAGE__
395                          printf "set pc to %04x\n", $to;                          printf "set pc to %04x\n", $to;
396                          $PC = $to;      # remember for restart                          $PC = $to;      # remember for restart
397                          $run_for = 1;                          $run_for = 1;
398                            $last = sprintf('m %04x', $to);
399                          last;                          last;
400                  } elsif ( $c =~ m/^t/ ) {                  } elsif ( $c =~ m/^t/ ) {
401                          $self->trace( not $self->trace );                          $self->trace( not $self->trace );
402                          print "trace ", $self->trace ? 'on' : 'off', "\n";                          print "trace ", $self->trace ? 'on' : 'off', "\n";
403                    } elsif ( $c =~ m/^d/ ) {
404                            $self->debug( not $self->debug );
405                            print "debug ", $self->debug ? 'on' : 'off', "\n";
406                  } else {                  } else {
407                          warn "# ignore $c\n";                          warn "# ignore $c\n";
408                          last;                          last;

Legend:
Removed from v.43  
changed lines
  Added in v.50

  ViewVC Help
Powered by ViewVC 1.1.26