/[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

M6502/Orao.pm revision 106 by dpavlin, Fri Aug 3 08:44:45 2007 UTC Orao.pm revision 124 by dpavlin, Sat Aug 4 14:13:28 2007 UTC
# Line 10  use File::Slurp; Line 10  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 Prefs);  use base qw(Class::Accessor VRac M6502 Screen Prefs Tape);
14  __PACKAGE__->mk_accessors(qw(booted));  #__PACKAGE__->mk_accessors(qw());
15    
16  =head1 NAME  =head1 NAME
17    
# Line 37  Emulator or Orao 8-bit 6502 machine popu Line 37  Emulator or Orao 8-bit 6502 machine popu
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({});    my $emu = Orao->new({});
41    $orao->boot;    $emu->boot;
42    
43  =cut  =cut
44    
45  our $orao;  our $emu;
46    
47  select(STDERR); $| = 1;  select(STDERR); $| = 1;
48    
# Line 60  sub boot { Line 60  sub boot {
60    
61          $self->open_screen;          $self->open_screen;
62          $self->load_rom({          $self->load_rom({
63                  0x1000 => 'dump/SCRINV.BIN',  #               0x1000 => 'dump/SCRINV.BIN',
64                  # should be 0x6000, but oraoemu has 2 byte prefix                  # should be 0x6000, but oraoemu has 2 byte prefix
65                  0x5FFE => 'dump/screen.dmp',  #               0x5FFE => 'dump/screen.dmp',
66  #               0xC000 => 'rom/BAS12.ROM',  #               0xC000 => 'rom/Orao/BAS12.ROM',
67  #               0xE000 => 'rom/CRT12.ROM',  #               0xE000 => 'rom/Orao/CRT12.ROM',
68                  0xC000 => 'rom/BAS13.ROM',                  0xC000 => 'rom/Orao/BAS13.ROM',
69                  0xE000 => 'rom/CRT13.ROM',                  0xE000 => 'rom/Orao/CRT13.ROM',
70          });          });
71    
72  #       $PC = 0xDD11;   # BC  #       $PC = 0xDD11;   # BC
# Line 74  sub boot { Line 74  sub boot {
74    
75          $PC = 0xff89;          $PC = 0xff89;
76    
77          $orao = $self;          $emu = $self;
78    
79  #       $self->prompt( 0x1000 );  #       $self->prompt( 0x1000 );
80    
# Line 82  sub boot { Line 82  sub boot {
82          $self->trace( 0 );          $self->trace( 0 );
83          $self->debug( 0 );          $self->debug( 0 );
84    
85          $self->render( @mem[ 0x6000 .. 0x7fff ] );          warn "rendering video memory\n";
86            $self->render_vram( @mem[ 0x6000 .. 0x7fff ] );
87    
88          if ( $self->show_mem ) {          if ( $self->show_mem ) {
89    
# Line 101  sub boot { Line 102  sub boot {
102                          0xE000, 0xFFFF, 'sistemski ROM',                          0xE000, 0xFFFF, 'sistemski ROM',
103                  );                  );
104    
         } else {  
   
                 warn "rendering video memory\n";  
                 $self->render( @mem[ 0x6000 .. 0x7fff ] );  
           
105          }          }
106          $self->sync;          $self->sync;
107          $self->trace( $trace );          $self->trace( $trace );
# Line 127  sub boot { Line 123  sub boot {
123    
124  Run interactive emulation loop  Run interactive emulation loop
125    
126    $orao->run;    $emu->run;
127    
128  =cut  =cut
129    
# Line 135  sub run { Line 131  sub run {
131          my $self = shift;          my $self = shift;
132    
133          $self->boot if ( ! $self->booted );          $self->boot if ( ! $self->booted );
134    
135    #       $self->load_tape( '../oraoigre/bdash.tap' );
136    
137          $self->loop;          $self->loop;
138  };  };
139    
140  =head1 Helper functions  =head1 Helper functions
141    
 =head2 load_rom  
   
 called to init memory and load initial rom images  
   
   $orao->load_rom;  
   
142  =cut  =cut
143    
 sub load_rom {  
     my ($self, $loaded_files) = @_;  
   
     #my $time_base = time();  
   
         foreach my $addr ( sort keys %$loaded_files ) {  
                 my $path = $loaded_files->{$addr};  
                 $self->load_image( $path, $addr );  
         }  
 }  
   
144  # write chunk directly into memory, updateing vram if needed  # write chunk directly into memory, updateing vram if needed
145  sub _write_chunk {  sub _write_chunk {
146          my $self = shift;          my $self = shift;
# Line 176  sub _write_chunk { Line 158  sub _write_chunk {
158          $t = $end if ( $end < $t );          $t = $end if ( $end < $t );
159    
160          warn sprintf("refresh video ram %04x-%04x\n", $f, $t);          warn sprintf("refresh video ram %04x-%04x\n", $f, $t);
161  #       foreach my $a ( $f .. $t ) {          $self->render_vram( @mem[ 0x6000 .. 0x7fff ] );
 #               $self->vram( $a - 0x6000 , $mem[ $a ] );  
 #       }  
         $self->render( @mem[ 0x6000 .. 0x7fff ] );  
162          $self->render_mem( @mem ) if $self->show_mem;          $self->render_mem( @mem ) if $self->show_mem;
163  }  }
164    
# Line 187  sub _write_chunk { Line 166  sub _write_chunk {
166    
167  Load binary files, ROM images and Orao Emulator files  Load binary files, ROM images and Orao Emulator files
168    
169    $orao->load_image( '/path/to/file', 0x1000 );    $emu->load_image( '/path/to/file', 0x1000 );
170    
171  Returns true on success.  Returns true on success.
172    
# Line 240  sub load_image { Line 219  sub load_image {
219          return 1;          return 1;
220  };  };
221    
 =head2 save_dump  
   
   $orao->save_dump( 'filename', $from, $to );  
   
 =cut  
   
 sub save_dump {  
         my $self = shift;  
   
         my ( $path, $from, $to ) = @_;  
   
         $from ||= 0;  
         $to ||= 0xffff;  
   
         open(my $fh, '>', $path) || die "can't open $path: $!";  
         print $fh $self->read_chunk( $from, $to );  
         close($fh);  
   
         my $size = -s $path;  
         warn sprintf "saved %s %d %x bytes\n", $path, $size, $size;  
 }  
   
 =head2 hexdump  
   
   $orao->hexdump( $address );  
   
 =cut  
   
 sub hexdump {  
         my $self = shift;  
         my $a = shift;  
         return sprintf(" %04x %s\n", $a,  
                 join(" ",  
                         map {  
                                 if ( defined($_) ) {  
                                         sprintf( "%02x", $_ )  
                                 } else {  
                                         '  '  
                                 }  
                         } @mem[ $a .. $a+8 ]  
                 )  
         );  
 }  
222    
223  =head1 Memory management  =head1 Memory management
224    
# Line 334  my $keyboard = { Line 270  my $keyboard = {
270                  } elsif ( $self->key_down( 'left shift' ) || $self->key_down( 'right shift' ) ) {                  } elsif ( $self->key_down( 'left shift' ) || $self->key_down( 'right shift' ) ) {
271                          warn "shift\n";                          warn "shift\n";
272                          return 16;                          return 16;
273    #               } elsif ( $self->tape ) {
274    #                       warn "has tape!";
275    #                       return 0;
276                  }                  }
277                  return $keyboard_none;                  return $keyboard_none;
278          },          },
# Line 450  sub read { Line 389  sub read {
389                  return $keyboard_none;                  return $keyboard_none;
390          }          }
391    
392            if ( $addr == 0x87ff ) {
393                    return $self->read_tape;
394            }
395    
396          $self->mmap_pixel( $addr, 0, $byte, 0 );          $self->mmap_pixel( $addr, 0, $byte, 0 );
397          return $byte;          return $byte;
398  }  }
# Line 467  sub write { Line 410  sub write {
410          my ($addr,$byte) = @_;          my ($addr,$byte) = @_;
411          warn sprintf("# Orao::write(%04x,%02x)\n", $addr, $byte) if $self->trace;          warn sprintf("# Orao::write(%04x,%02x)\n", $addr, $byte) if $self->trace;
412    
         if ( $addr >= 0x6000 && $addr < 0x8000 ) {  
 #               $self->vram( $addr - 0x6000 , $byte );  
         }  
   
413          if ( $addr == 0x8800 ) {          if ( $addr == 0x8800 ) {
414                  warn sprintf "sound ignored: %x\n", $byte;                  warn sprintf "sound ignored: %x\n", $byte;
415          }          }
# Line 485  sub write { Line 424  sub write {
424          return;          return;
425  }  }
426    
 =head1 Command Line  
   
 Command-line debugging intrerface is implemented for communication with  
 emulated device  
   
 =head2 prompt  
   
   my ( $entered_line, @p ) = $orao->prompt( $address, $last_command );  
   
 =cut  
   
 my $last = 'r 1';  
   
 sub prompt {  
         my $self = shift;  
         $self->app->sync;  
         my $a = shift;  
         print $self->hexdump( $a ),  
                 $last ? "[$last] " : '',  
                 "> ";  
         my $in = <STDIN>;  
         chomp($in);  
         warn "## prompt got: $in\n" if $self->debug;  
         $in ||= $last;  
         $last = $in;  
         return ( $in, split(/\s+/, $in) ) if $in;  
 }  
   
 =head2 cli  
   
   $orao->cli();  
   
 =cut  
   
 my $show_R = 0;  
   
 sub cli {  
         my $self = shift;  
         my $a = $PC || confess "no pc?";  
         my $run_for = 0;  
         warn $self->dump_R() if $show_R;  
         while ( my ($line, @v) = $self->prompt( $a, $last ) ) {  
                 my $c = shift @v;  
                 next unless defined($c);  
                 my $v = shift @v;  
                 $v = hex($v) if $v && $v =~ m/^[0-9a-f]+$/;  
                 @v = map { hex($_) } @v;  
                 printf "## a: %04x parsed cli: c:%s v:%s %s\n", $a, $c, ($v || 'undef'), join(",",@v) if $self->debug;  
                 if ( $c =~ m/^[qx]/i ) {  
                         exit;  
                 } elsif ( $c eq '?' ) {  
                         my $t = $self->trace ? 'on' : 'off' ;  
                         my $d = $self->debug ? 'on' : 'off' ;  
                         warn <<__USAGE__;  
 Usage:  
   
 x|q\t\texit  
 e 6000 6010\tdump memory, +/- to walk forward/backward  
 m 1000 ff 00\tput ff 00 on 1000  
 j|u 1000\t\tjump (change pc)  
 r 42\t\trun 42 instruction opcodes  
 t\t\ttrace [$t]  
 d\t\tdebug [$d]  
   
 __USAGE__  
                         warn $self->dump_R;  
                         $last = '';  
                 } elsif ( $c =~ m/^e/i ) {  
                         $a = $v if defined($v);  
                         my $to = shift @v;  
                         $to = $a + 32 if ( ! $to || $to <= $a );  
                         $to = 0xffff if ( $to > 0xffff );  
                         my $lines = int( ($to - $a + 8) / 8 );  
                         printf "## e %04x %04x (%d bytes) lines: %d\n", $a, $to, ($to-$a), $lines;  
                         while ( --$lines ) {  
                                 print $self->hexdump( $a );  
                                 $a += 8;  
                         }  
                         $last = '+';  
                         $show_R = 0;  
                 } elsif ( $c =~ m/^\+/ ) {  
                         $a += 8;  
                         $show_R = 0;  
                 } elsif ( $c =~ m/^\-/ ) {  
                         $a -= 8;  
                         $show_R = 0;  
                 } elsif ( $c =~ m/^m/i ) {  
                         $a = $v if defined($v);  
                         $self->poke_code( $a, @v );  
                         printf "poke %d bytes at %04x\n", $#v + 1, $a;  
                         $last = '+';  
                         $show_R = 0;  
                 } elsif ( $c =~ m/^l/i ) {  
                         my $to = shift @v || 0x1000;  
                         $a = $to;  
                         $self->load_image( $v, $a );  
                         $last = '';  
                 } elsif ( $c =~ m/^s/i ) {  
                         $self->save_dump( $v || 'mem.dump', @v );  
                         $last = '';  
                 } elsif ( $c =~ m/^r/i ) {  
                         $run_for = $v || 1;  
                         print "run_for $run_for instructions\n";  
                         $show_R = 1;  
                         last;  
                 } elsif ( $c =~ m/^(u|j)/ ) {  
                         my $to = $v || $a;  
                         printf "set pc to %04x\n", $to;  
                         $PC = $to;      # remember for restart  
                         $run_for = 1;  
                         $last = "r $run_for";  
                         $show_R = 1;  
                         last;  
                 } elsif ( $c =~ m/^t/ ) {  
                         $self->trace( not $self->trace );  
                         print "trace ", $self->trace ? 'on' : 'off', "\n";  
                         $last = '';  
                 } elsif ( $c =~ m/^d/ ) {  
                         $self->debug( not $self->debug );  
                         print "debug ", $self->debug ? 'on' : 'off', "\n";  
                         $last = '';  
                 } else {  
                         warn "# ignored $line\n" if ($line);  
                         $last = '';  
                 }  
         }  
   
         return $run_for;  
 }  
   
427  =head1 AUTHOR  =head1 AUTHOR
428    
429  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>  Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>

Legend:
Removed from v.106  
changed lines
  Added in v.124

  ViewVC Help
Powered by ViewVC 1.1.26