/[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 64 by dpavlin, Tue Jul 31 16:33:41 2007 UTC revision 90 by dpavlin, Thu Aug 2 12:23:18 2007 UTC
# Line 8  use lib './lib'; Line 8  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 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);
# Line 19  Orao - Orao emulator Line 20  Orao - Orao emulator
20    
21  =head1 VERSION  =head1 VERSION
22    
23  Version 0.02  Version 0.03
24    
25  =cut  =cut
26    
27  our $VERSION = '0.02';  our $VERSION = '0.03';
28    
29  =head1 SUMMARY  =head1 SUMMARY
30    
# Line 31  Emulator or Orao 8-bit 6502 machine popu Line 32  Emulator or Orao 8-bit 6502 machine popu
32    
33  =cut  =cut
34    
35  =head2 init  my @kbd_ports = (
36        0x87FC,0x87FD,0x87FA,0x87FB,0x87F6,0x87F7,
37        0x87EE,0x87EF,0x87DE,0x87DF,0x87BE,0x87BF,
38        0x877E,0x877F,0x86FE,0x86FF,0x85FE,0x85FF,
39        0x83FE,0x83FF,
40    );
41    
42    =head2 boot
43    
44  Start emulator, open L<Screen>, load initial ROM images, and render memory  Start emulator, open L<Screen>, load initial ROM images, and render memory
45    
46      my $orao = Orao->new({});
47      $orao->boot;
48    
49  =cut  =cut
50    
51  our $orao;  our $orao;
52    
53  select(STDERR); $| = 1;  select(STDERR); $| = 1;
54    
55  sub init {  sub boot {
56          my $self = shift;          my $self = shift;
57          warn "Orao calling upstream init\n";          warn "Orao calling upstream init\n";
58          $self->SUPER::init( $self, @_ );          $self->SUPER::init(
59                    read => sub { $self->read( @_ ) },
60                    write => sub { $self->write( @_ ) },
61            );
62    
63          warn "Orao $Orao::VERSION emulation starting\n";          warn "Orao $Orao::VERSION emulation starting\n";
64    
65            warn "emulating ", $#mem, " bytes of memory\n";
66    
67          $self->open_screen;          $self->open_screen;
68          $self->load_rom({          $self->load_rom({
69                  0x1000 => 'dump/SCRINV.BIN',                  0x1000 => 'dump/SCRINV.BIN',
70                    # should be 0x6000, but oraoemu has 2 byte prefix
71                    0x5FFE => 'dump/screen.dmp',
72                  0xC000 => 'rom/BAS12.ROM',                  0xC000 => 'rom/BAS12.ROM',
73                  0xE000 => 'rom/CRT12.ROM',                  0xE000 => 'rom/CRT12.ROM',
74          });          });
75    
76          $PC = 0xDD11;   # BC  #       $PC = 0xDD11;   # BC
77  #       $PC = 0xC274;   # MC  #       $PC = 0xC274;   # MC
78    
79            $PC = 0xff89;
80    
81          $orao = $self;          $orao = $self;
82    
83  #       $self->prompt( 0x1000 );  #       $self->prompt( 0x1000 );
# Line 66  sub init { Line 86  sub init {
86          $self->trace( 0 );          $self->trace( 0 );
87          $self->debug( 0 );          $self->debug( 0 );
88    
89            $self->render( @mem[ 0x6000 .. 0x7fff ] );
90    
91          if ( $self->show_mem ) {          if ( $self->show_mem ) {
92    
93                  warn "rendering memory map\n";                  warn "rendering memory map\n";
94    
95                    $self->render_mem( @mem );
96    
97                  my @mmap = (                  my @mmap = (
98                          0x0000, 0x03FF, 'nulti blok',                          0x0000, 0x03FF, 'nulti blok',
99                          0x0400, 0x5FFF, 'korisnički RAM (23K)',                          0x0400, 0x5FFF, 'korisnički RAM (23K)',
# Line 81  sub init { Line 105  sub init {
105                          0xE000, 0xFFFF, 'sistemski ROM',                          0xE000, 0xFFFF, 'sistemski ROM',
106                  );                  );
107    
                 foreach my $i ( 0 .. $#mmap / 3 ) {  
                         my $o = $i * 3;  
                         my ( $from, $to, $desc ) = @mmap[$o,$o+1,$o+2];  
                         printf "%04x - %04x - %s\n", $from, $to, $desc;  
                         for my $a ( $from .. $to ) {  
                                 if ( $a >= 0x6000 && $a < 0x8000 ) {  
                                         my $b = $self->read( $a );  
                                         $self->vram( $a - 0x6000, $b );  
                                 } else {  
                                         $self->read( $a );  
                                 }  
                         }  
                 }  
   
108          } else {          } else {
109    
110                  warn "rendering video memory\n";                  warn "rendering video memory\n";
111                  for my $a ( 0x6000 .. 0x7fff ) {                  $self->render( @mem[ 0x6000 .. 0x7fff ] );
                         $self->vram( $a - 0x6000, $mem[$a] );  
                 }  
112                    
113          }          }
114          $self->sync;          $self->sync;
# Line 109  sub init { Line 117  sub init {
117    
118          #( $A, $P, $X, $Y, $S, $IPeriod ) = ( 1, 2, 3, 4, 5, 6 );          #( $A, $P, $X, $Y, $S, $IPeriod ) = ( 1, 2, 3, 4, 5, 6 );
119    
120          warn "Orao init finished",          warn "Orao boot finished",
121                  $self->trace ? ' trace' : '',                  $self->trace ? ' trace' : '',
122                  $self->debug ? ' debug' : '',                  $self->debug ? ' debug' : '',
123                  "\n";                  "\n";
124    
125            M6502::reset();
126    
127  }  }
128    
129  =head2 load_rom  =head2 load_rom
# Line 152  sub _write_chunk { Line 162  sub _write_chunk {
162          $t = $end if ( $end < $t );          $t = $end if ( $end < $t );
163    
164          warn sprintf("refresh video ram %04x-%04x\n", $f, $t);          warn sprintf("refresh video ram %04x-%04x\n", $f, $t);
165          foreach my $a ( $f .. $t ) {  #       foreach my $a ( $f .. $t ) {
166                  $self->vram( $a - 0x6000 , $mem[ $a ] );  #               $self->vram( $a - 0x6000 , $mem[ $a ] );
167          }  #       }
168            $self->render( @mem[ 0x6000 .. 0x7fff ] );
169            $self->render_mem( @mem ) if $self->show_mem;
170  }  }
171    
172  =head2 load_oraoemu  =head2 load_oraoemu
# Line 248  sub hexdump { Line 260  sub hexdump {
260          return sprintf(" %04x %s\n", $a,          return sprintf(" %04x %s\n", $a,
261                  join(" ",                  join(" ",
262                          map {                          map {
263                                  sprintf( "%02x", $_ )                                  if ( defined($_) ) {
264                                            sprintf( "%02x", $_ )
265                                    } else {
266                                            '  '
267                                    }
268                          } @mem[ $a .. $a+8 ]                          } @mem[ $a .. $a+8 ]
269                  )                  )
270          );          );
# Line 273  sub read { Line 289  sub read {
289          my $self = shift;          my $self = shift;
290          my ($addr) = @_;          my ($addr) = @_;
291          my $byte = $mem[$addr];          my $byte = $mem[$addr];
292            confess sprintf("can't find memory at address %04x",$addr) unless defined($byte);
293          warn sprintf("# Orao::read(%04x) = %02x\n", $addr, $byte) if $self->trace;          warn sprintf("# Orao::read(%04x) = %02x\n", $addr, $byte) if $self->trace;
294    
295            # keyboard
296    
297            if ( first { $addr == $_ } @kbd_ports ) {
298                    warn sprintf("keyboard port: %04x\n",$addr);
299            } elsif ( $addr == 0x87fc ) {
300                    warn "0x87fc - arrows/back\n";
301    =for pascal
302                    if VKey=VK_RIGHT then Result:=16;
303                    if VKey=VK_DOWN then Result:=128;
304                    if VKey=VK_UP then Result:=192;
305                    if VKey=VK_LEFT then Result:=224;
306                    if Ord(KeyPressed)=VK_BACK then Result:=224;
307    =cut
308            } elsif ( $addr == 0x87fd ) {
309                    warn "0x87fd - enter\n";
310    =for pascal
311        if KeyPressed=Chr(13) then begin
312          Mem[$FC]:=13;
313          Result:=0;
314        end;
315    =cut
316            } elsif ( $addr == 0x87fa ) {
317                    warn "0x87fa = F1 - F4\n";
318    =for pascal
319        if VKey=VK_F4 then Result:=16;
320        if VKey=VK_F3 then Result:=128;
321        if VKey=VK_F2 then Result:=192;
322        if VKey=VK_F1 then Result:=224;
323    =cut
324            } elsif ( $addr == 0x87fb ) {
325                    warn "0x87fb\n";
326    =for pascal
327        if KeyPressed=Chr(32) then Result:=32;
328        if KeyPressed='"' then Result:=16;
329        if KeyPressed='!' then Result:=16;
330        if KeyPressed='$' then Result:=16;
331        if KeyPressed='%' then Result:=16;
332        if KeyPressed='&' then Result:=16;
333        if KeyPressed='(' then Result:=16;
334        if KeyPressed=')' then Result:=16;
335        if KeyPressed='=' then Result:=16;
336        if KeyPressed='#' then Result:=16;
337        if KeyPressed='+' then Result:=16;
338        if KeyPressed='*' then Result:=16;
339        if KeyPressed='?' then Result:=16;
340        if KeyPressed='<' then Result:=16;
341        if KeyPressed='>' then Result:=16;
342        if VKey=191 then Result:=16;
343    =cut
344            }
345    
346          $self->mmap_pixel( $addr, 0, $byte, 0 );          $self->mmap_pixel( $addr, 0, $byte, 0 );
347          return $byte;          return $byte;
348  }  }
# Line 343  sub prompt { Line 412  sub prompt {
412    
413  =cut  =cut
414    
415    my $show_R = 0;
416    
417  sub cli {  sub cli {
418          my $self = shift;          my $self = shift;
419          my $a = $PC || confess "no pc?";          my $a = $PC || confess "no pc?";
420            warn $self->dump_R() if $show_R;
421          while ( my ($line, @v) = $self->prompt( $a, $last ) ) {          while ( my ($line, @v) = $self->prompt( $a, $last ) ) {
422                  my $c = shift @v;                  my $c = shift @v;
423                  next unless defined($c);                  next unless defined($c);
# Line 370  t\t\ttrace [$t] Line 442  t\t\ttrace [$t]
442  d\t\tdebug [$d]  d\t\tdebug [$d]
443    
444  __USAGE__  __USAGE__
445                          warn sprintf(" PC: %04x A:%02x P:%02x X:%02x Y:%02x S:%02x\n", $PC, $A, $P, $X, $Y, $S);                          warn $self->dump_R;
446                  } elsif ( $c =~ m/^e/i ) {                  } elsif ( $c =~ m/^e/i ) {
447                          $a = $v if defined($v);                          $a = $v if defined($v);
448                          my $to = shift @v;                          my $to = shift @v;
449                          $to = $a + 32 if ( ! $to || $to <= $a );                          $to = $a + 32 if ( ! $to || $to <= $a );
450                            $to = 0xffff if ( $to > 0xffff );
451                          my $lines = int( ($to - $a + 8) / 8 );                          my $lines = int( ($to - $a + 8) / 8 );
452                          printf "## e %04x %04x (%d bytes) lines: %d\n", $a, $to, ($to-$a), $lines;                          printf "## e %04x %04x (%d bytes) lines: %d\n", $a, $to, ($to-$a), $lines;
453                          while ( --$lines ) {                          while ( --$lines ) {
# Line 382  __USAGE__ Line 455  __USAGE__
455                                  $a += 8;                                  $a += 8;
456                          }                          }
457                          $last = '+';                          $last = '+';
458                            $show_R = 0;
459                  } elsif ( $c =~ m/^\+/ ) {                  } elsif ( $c =~ m/^\+/ ) {
460                          $a += 8;                          $a += 8;
461                            $show_R = 0;
462                  } elsif ( $c =~ m/^\-/ ) {                  } elsif ( $c =~ m/^\-/ ) {
463                          $a -= 8;                          $a -= 8;
464                            $show_R = 0;
465                  } elsif ( $c =~ m/^m/i ) {                  } elsif ( $c =~ m/^m/i ) {
466                          $a = $v;                          $a = $v if defined($v);
467                          $self->poke_code( $a, @v );                          $self->poke_code( $a, @v );
468                          printf "poke %d bytes at %04x\n", $#v + 1, $a;                          printf "poke %d bytes at %04x\n", $#v + 1, $a;
469                          $last = '+';                          $last = '+';
470                            $show_R = 0;
471                  } elsif ( $c =~ m/^l/i ) {                  } elsif ( $c =~ m/^l/i ) {
472                          my $to = shift @v || 0x1000;                          my $to = shift @v || 0x1000;
473                          $a = $to;                          $a = $to;
# Line 402  __USAGE__ Line 479  __USAGE__
479                  } elsif ( $c =~ m/^r/i ) {                  } elsif ( $c =~ m/^r/i ) {
480                          $run_for = $v || 1;                          $run_for = $v || 1;
481                          print "run_for $run_for instructions\n";                          print "run_for $run_for instructions\n";
482                            $show_R = 1;
483                          last;                          last;
484                  } elsif ( $c =~ m/^(u|j)/ ) {                  } elsif ( $c =~ m/^(u|j)/ ) {
485                          my $to = $v || $a;                          my $to = $v || $a;
# Line 409  __USAGE__ Line 487  __USAGE__
487                          $PC = $to;      # remember for restart                          $PC = $to;      # remember for restart
488                          $run_for = 1;                          $run_for = 1;
489                          $last = "r $run_for";                          $last = "r $run_for";
490                            $show_R = 1;
491                          last;                          last;
492                  } elsif ( $c =~ m/^t/ ) {                  } elsif ( $c =~ m/^t/ ) {
493                          $self->trace( not $self->trace );                          $self->trace( not $self->trace );

Legend:
Removed from v.64  
changed lines
  Added in v.90

  ViewVC Help
Powered by ViewVC 1.1.26