/[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 31 by dpavlin, Mon Jul 30 18:07:29 2007 UTC revision 32 by dpavlin, Mon Jul 30 18:37:37 2007 UTC
# Line 7  use Carp; Line 7  use Carp;
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/;
11    
12  use base qw(Class::Accessor M6502 Screen);  use base qw(Class::Accessor M6502 Screen);
13  __PACKAGE__->mk_accessors(qw(debug trace run_for mem_dump trace));  __PACKAGE__->mk_accessors(qw(debug trace run_for mem_dump trace));
# Line 35  Start emulator Line 36  Start emulator
36    
37  =cut  =cut
38    
39    our $orao;
40    
41  sub init {  sub init {
42          my $self = shift;          my $self = shift;
43          warn "call upstream init\n";          warn "call upstream init\n";
# Line 44  sub init { Line 47  sub init {
47    
48          $self->open_screen;          $self->open_screen;
49          $self->load_rom;          $self->load_rom;
50    
51            $orao = $self;
52    
53            $self->prompt( 0x1000 );
54  }  }
55    
56  my $loaded_files = {  my $loaded_files = {
# Line 66  sub load_rom { Line 73  sub load_rom {
73    
74          foreach my $addr ( sort keys %$loaded_files ) {          foreach my $addr ( sort keys %$loaded_files ) {
75                  my $path = $loaded_files->{$addr};                  my $path = $loaded_files->{$addr};
76                  printf "loading '%s' at %04x\n", $path, $addr;                  warn sprintf "loading '%s' at %04x\n", $path, $addr;
77                  $self->load_oraoemu( $path, $addr );                  $self->load_oraoemu( $path, $addr );
78          }          }
79  }  }
# Line 86  sub load_oraoemu { Line 93  sub load_oraoemu {
93    
94          if ( $size == 65538 ) {          if ( $size == 65538 ) {
95                  $addr = 0;                  $addr = 0;
96                  printf "loading oraoemu 64k dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size, $size;                  warn sprintf "loading oraoemu 64k dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size, $size;
97                  $self->write_chunk( $addr, substr($buff,2) );                  $self->write_chunk( $addr, substr($buff,2) );
98                  return;                  return;
99          } elsif ( $size == 32800 ) {          } elsif ( $size == 32800 ) {
100                  $addr = 0;                  $addr = 0;
101                  printf "loading oraoemu 1.3 dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size, $size;                  warn sprintf "loading oraoemu 1.3 dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size, $size;
102                  #$self->write_chunk( $addr, substr($buff,0x20) );                  #$self->write_chunk( $addr, substr($buff,0x20) );
103                  $self->poke_code( $addr, map { ord($_) } split(//,substr($buff,0x20)) );                  $self->poke_code( $addr, map { ord($_) } split(//,substr($buff,0x20)) );
104                  return;                  return;
# Line 136  sub save_dump { Line 143  sub save_dump {
143          close($fh);          close($fh);
144    
145          my $size = -s $path;          my $size = -s $path;
146          printf "saved %s %d %x bytes\n", $path, $size, $size;          warn sprintf "saved %s %d %x bytes\n", $path, $size, $size;
147  }  }
148    
149  =head2 hexdump  =head2 hexdump
# Line 167  sub prompt { Line 174  sub prompt {
174          my $self = shift;          my $self = shift;
175          my $a = shift;          my $a = shift;
176          my $last = shift;          my $last = shift;
177          print $self->hexdump( $a ),          print STDERR $self->hexdump( $a ),
178                  $last ? "[$last] " : '',                  $last ? "[$last] " : '',
179                  "> ";                  "> ";
180          my $in = <STDIN>;          my $in = <STDIN>;
# Line 177  sub prompt { Line 184  sub prompt {
184          return split(/\s+/, $in) if $in;          return split(/\s+/, $in) if $in;
185  }  }
186    
187    =head1 Memory management
188    
189    Orao implements all I/O using mmap addresses. This was main reason why
190    L<Acme::6502> was just too slow to handle it.
191    
192    =cut
193    
194    my @mem = (0xff) x 0x100000; # 64Mb
195    
196    =head2 read
197    
198    Read from memory
199    
200      $byte = read( $address );
201    
202    =cut
203    
204    sub read {
205            my $self = $orao;
206            my ($addr) = @_;
207            my $byte = $mem[$addr];
208            warn "# Orao::read(",dump(@_),") = ",dump( $byte ),"\n" if $self->debug;
209            mmap_pixel( $addr, 0, $byte, 0 );
210            return $byte;
211    }
212    
213    =head2 write
214    
215    Write into emory
216    
217      write( $address, $byte );
218    
219    =cut
220    
221    sub write {
222            my $self = $orao;
223            warn "# Orao::write(",dump(@_),")\n" if $self->debug;
224            my ($addr,$byte) = @_;
225    
226            if ( $addr >= 0x6000 && $addr < 0x8000 ) {
227                    $self->vram( $addr - 0x6000 , $byte );
228            }
229    
230            if ( $addr > 0xafff ) {
231                    warn sprintf "access to %04x above affff aborting\n", $addr;
232                    return -1;
233            }
234            if ( $addr == 0x8800 ) {
235                    warn sprintf "sound ignored: %x\n", $byte;
236            }
237    
238            mmap_pixel( $addr, $byte, 0, 0 );
239    
240            $mem[$addr] = $byte;
241    }
242    
243    
244  =head1 AUTHOR  =head1 AUTHOR
245    

Legend:
Removed from v.31  
changed lines
  Added in v.32

  ViewVC Help
Powered by ViewVC 1.1.26