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

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

revision 42 by dpavlin, Tue Jul 31 09:37:01 2007 UTC revision 51 by dpavlin, Tue Jul 31 12:35:02 2007 UTC
# Line 6  use warnings; Line 6  use warnings;
6  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
7  use Carp qw/confess/;  use Carp qw/confess/;
8  use Exporter 'import';  use Exporter 'import';
9  our @EXPORT = qw'@mem $PC $A $P $X $Y $S $IPeriod $run_for';  our @EXPORT = qw'@mem $PC $A $P $X $Y $S $IPeriod $run_for $debug';
10    
11  =head1 NAME  =head1 NAME
12    
# Line 14  M6502 - perl bindings for 6502 emulator Line 14  M6502 - perl bindings for 6502 emulator
14    
15  =cut  =cut
16    
17  my $debug = 1;  my $debug = 0;
18    
19  our $VERSION = qw(0.0.1);  our $VERSION = qw(0.0.1);
20    
# Line 37  Called before C<Run6502> Line 37  Called before C<Run6502>
37    
38  sub init {  sub init {
39          my $self = shift;          my $self = shift;
         warn dump(@_);  
40          warn "inside init low-level M6502 from $self\n";          warn "inside init low-level M6502 from $self\n";
41  };  };
42    
# Line 52  Read from memory Line 51  Read from memory
51  sub read {  sub read {
52          my ($addr) = @_;          my ($addr) = @_;
53          my $byte = $mem[$addr];          my $byte = $mem[$addr];
54          warn "# read(",dump(@_),") = ",dump( $byte ),"\n" if $debug;          warn "## M6502::read(",dump(@_),") = ",dump( $byte ),"\n" if $debug;
55          return $byte;          return $byte;
56  }  }
57    
# Line 65  Write into emory Line 64  Write into emory
64  =cut  =cut
65    
66  sub write {  sub write {
67          warn "# write(",dump(@_),")\n" if $debug;          warn "## M6502::write(",dump(@_),")\n" if $debug;
68          my ($addr,$byte) = @_;          my ($addr,$byte) = @_;
69          $mem[$addr] = $byte;          $mem[$addr] = $byte;
70  }  }
# Line 82  functions. If you don't want to trigger Line 81  functions. If you don't want to trigger
81  sub poke_code {  sub poke_code {
82          my $self = shift;          my $self = shift;
83          my $addr = shift;          my $addr = shift;
84          warn sprintf("# poke_code(%04x,%s)\n", $addr, dump( @_ )) if $self->debug;          warn sprintf("## M6502::poke_code(%04x,%s)\n", $addr, dump( @_ )) if $self->debug;
85          #$mem[$addr++] = $_ foreach @_;          #$mem[$addr++] = $_ foreach @_;
86          $self->write($addr++, $_) foreach @_;          # call low-level write
87            Arch::write($addr++, $_) foreach @_;
88  }  }
89    
90  =head2 write_chunk  =head2 ram
91    
92  Low-level update of memory, overriding user specified MMU functions C<read> and C<write>  Read series of bytes into memory without MMU interaction
93    
94    $emu->write_chunk( $address, $chunk_of_data );    my @code = $emu->ram( 0xc000, 0xc1000 );
95    
96  =cut  =cut
97    
98  sub write_chunk {  sub ram {
99          my ($self, $addr, $chunk) = @_;          my $self = shift;
100          my $len = length($chunk);          my ( $from, $to ) = @_;
101          splice @mem, $addr, $len, unpack('C*', $chunk);          warn sprintf("## M6502::ram(%04x,%04x)\n", $from, $to) if $self->debug;
102            return @mem[ $from .. $to ];
103  }  }
104    
105  =head2 ram  =head2 write_chunk
106    
107  Read searies of bytes from memory without passing through MMU  Low-level update of memory, overriding user specified MMU functions C<read> and C<write>
108    
109    $emu->ram( $from, $to );    $emu->write_chunk( $address, $chunk_of_data );
110    
111  =cut  =cut
112    
113  sub ram {  sub write_chunk {
114          my $self = shift;          my ($self, $addr, $chunk) = @_;
115          my ($from,$to) = @_;          my $len = length($chunk);
116          warn "ram($from,$to)\n";          splice @mem, $addr, $len, unpack('C*', $chunk);
         if ($from + $to) {  
                 printf "ram %04x - %04x\n", $from, $to;  
                 return @mem[$from .. $to - 1];  
         }  
         printf "ram %04x\n", $from;  
         return $mem[$from] if defined($from);  
         confess "no from address";  
117  }  }
118    
119  =head2 prompt  =head2 prompt
# Line 140  called by C<perl.c> to push changes in r Line 134  called by C<perl.c> to push changes in r
134  =cut  =cut
135    
136  sub push_R {  sub push_R {
137          warn "push_R(",dump(@_),")\n";          warn "## M6502::push_R(",dump(@_),")\n" if $debug;
138          my ( $a, $p, $x, $y, $s, $pc ) = @_;          my ( $a, $p, $x, $y, $s, $pc ) = @_;
139          $PC = $pc;          $PC = $pc;
140          $S=$s; $X=$x; $Y=$y; $P=$p; $A=$a;          $S=$s; $X=$x; $Y=$y; $P=$p; $A=$a;
# Line 154  helper function which dumps registers Line 148  helper function which dumps registers
148  =cut  =cut
149    
150  sub dump_R {  sub dump_R {
151          warn sprintf("PC: %04x A:%02x P:%02x X:%02x Y:%02x S:%02x\n", $PC, $A, $P, $X, $Y, $S);          warn sprintf("## M6502::dump_R PC: %04x A:%02x P:%02x X:%02x Y:%02x S:%02x\n", $PC, $A, $P, $X, $Y, $S) if $debug;
152  }  }
153    
154  1;  1;

Legend:
Removed from v.42  
changed lines
  Added in v.51

  ViewVC Help
Powered by ViewVC 1.1.26