/[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 86 by dpavlin, Wed Aug 1 22:25:37 2007 UTC revision 90 by dpavlin, Thu Aug 2 12:23:18 2007 UTC
# Line 15  XSLoader::load('M6502', $VERSION); Line 15  XSLoader::load('M6502', $VERSION);
15    
16  M6502 - perl bindings for M6502 CPU emulator  M6502 - perl bindings for M6502 CPU emulator
17    
18    =head1 FUNCTIONS
19    
20  =cut  =cut
21    
22  my $debug = 1;  our $debug = 0;
23    
24  our @mem = (0xff) x 0x10000;    # 64M  our @mem = (0xff) x 0x10000;    # 64M
25    
# Line 37  our $Trace;                    # Set Trace=1 to start tra Line 39  our $Trace;                    # Set Trace=1 to start tra
39  # Exec6502 cycles  # Exec6502 cycles
40  our $run_for = 0;  our $run_for = 0;
41    
 =head1 FUNCTIONS  
   
42  =head2 init  =head2 init
43    
44  Called before C<Run6502>  Setup read and write memory hooks (to implement memory mapped devices)
   
 =cut  
   
 sub init {  
         my $self = shift;  
         warn "inside init low-level M6502 from $self\n";  
 };  
   
 =head2 read  
   
 Read from memory  
45    
46    $byte = read( $address );    $init->(
47            read => sub {
48                    return $mem[$_[0]];
49            },
50            write => sub {
51                    $mem[$_[0]] = $_[1];
52            },
53      );
54    
55  =cut  =cut
56    
57  sub read {  our $_rw_hooks = {
58          my ($addr) = @_;          read => sub {
59          my $byte = $mem[$addr];                  return $mem[$_[0]];
60          warn "## M6502::read(",dump(@_),") = ",dump( $byte ),"\n" if $debug;          },
61          return $byte;          write => sub {
62  }                  $mem[$_[0]] = $_[1];
63            },
64  =head2 write  };
65    
66  Write into emory  sub init {
67            my $self = shift;
68            my $args = {@_};
69            warn "inside init low-level M6502 from ",ref($self),"\n";
70    
71    write( $address, $byte );          foreach my $p ( qw/read write/ ) {
72                    confess "need $p argument as coderef" unless ( $args->{$p} && ref($args->{$p}) eq 'CODE' );
73                    $_rw_hooks->{$p} = $args->{$p};
74            }
75    
76  =cut  };
   
 sub write {  
         warn "## M6502::write(",dump(@_),")\n" if $debug;  
         my ($addr,$byte) = @_;  
         $mem[$addr] = $byte;  
 }  
77    
78  =head2 poke_code  =head2 poke_code
79    
# Line 94  sub poke_code { Line 90  sub poke_code {
90          warn sprintf("## M6502::poke_code(%04x,%s)\n", $addr, dump( @_ )) if $self->debug;          warn sprintf("## M6502::poke_code(%04x,%s)\n", $addr, dump( @_ )) if $self->debug;
91          #$mem[$addr++] = $_ foreach @_;          #$mem[$addr++] = $_ foreach @_;
92          # call low-level write          # call low-level write
93          Arch::write($addr++, $_) foreach @_;          $_rw_hooks->{write}->( $addr++, $_ ) foreach @_;
94  }  }
95    
96  =head2 ram  =head2 ram
# Line 137  sub prompt { Line 133  sub prompt {
133          return 1;          return 1;
134  }  }
135    
136  =head2 push_R  =head1 XS Callbacks
137    
138    This functions are called from C<M6502.xs>
139    
140    =head2 _read
141    
142  called by C<perl.c> to push changes in registars back to perl variables  Read from memory C callback
143    
144      $byte = M6502::_read( $address );
145    
146    =cut
147    
148    sub _read {
149            return $_rw_hooks->{read}->( @_ );
150    }
151    
152    =head2 _write
153    
154    Write into memory C callback
155    
156      M6502:_write( $address, $byte );
157    
158    =cut
159    
160    sub _write {
161            return $_rw_hooks->{write}->( @_ );
162    }
163    
164    =head2 _update_perl_R
165    
166    called by C<M6502.xs> to push changes in registars back to perl variables
167    
168  =cut  =cut
169    
170  sub push_R {  sub _update_perl_R {
171          warn "## M6502::push_R(",dump(@_),")\n" if $debug;          warn "## M6502::update_perl_R(",dump(@_),")\n" if $debug;
172          ( $A, $P, $X, $Y, $S, $PC, $IPeriod, $ICount, $IRequest, $IAutoReset, $TrapBadOps, $Trap, $Trace ) = @_;          ( $A, $P, $X, $Y, $S, $PC, $IPeriod, $ICount, $IRequest, $IAutoReset, $TrapBadOps, $Trap, $Trace ) = @_;
173          dump_R();          dump_R();
174  }  }
# Line 167  sub dump_R { Line 191  sub dump_R {
191          return $dump;          return $dump;
192  }  }
193    
194    =head2 debug
195    
196    Turn perl and C-level debugging on/off
197    
198      $emu->debug( 0 );
199      $emu->debug( 1 );
200      print $emu->debug;
201    
202    =cut
203    
204    sub debug {
205            my $self = shift;
206            my $value = shift;
207            if (defined($value)) {
208                    $debug = M6502::set_debug($value);
209            } else {
210                    $debug = M6502::get_debug();
211            }
212            return $debug;
213    }
214    
215  =head1 SEE ALSO  =head1 SEE ALSO
216    
217  L<Orao> is sample implementation using this module  L<Orao> is sample implementation using this module

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

  ViewVC Help
Powered by ViewVC 1.1.26