/[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 87 by dpavlin, Thu Aug 2 11:08:10 2007 UTC revision 94 by dpavlin, Thu Aug 2 13:04:29 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  our $debug = 0;  our $debug = 0;
# 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  
45    
46  Read from memory    $init->(
47            read => sub {
48    $byte = read( $address );                  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];                  warn sprintf("# callback read(%04x) not implemented\n", @_) if $debug;
60          warn "## M6502::read(",dump(@_),") = ",dump( $byte ),"\n" if $debug;                  return $mem[$_[0]];
61          return $byte;          },
62  }          write => sub {
63                    warn sprintf("# callback write(%04x,%02x) not implemented", @_) if $debug;
64  =head2 write                  $mem[$_[0]] = $_[1];
65            },
66    };
67    
68  Write into emory  sub init {
69            my $self = shift;
70            my $args = {@_};
71            warn "inside init low-level M6502 from ",ref($self),"\n";
72    
73    write( $address, $byte );          foreach my $p ( qw/read write/ ) {
74                    confess "need $p argument as coderef" unless ( $args->{$p} && ref($args->{$p}) eq 'CODE' );
75                    $_rw_hooks->{$p} = $args->{$p};
76            }
77    
78  =cut  };
   
 sub write {  
         warn "## M6502::write(",dump(@_),")\n" if $debug;  
         my ($addr,$byte) = @_;  
         $mem[$addr] = $byte;  
 }  
79    
80  =head2 poke_code  =head2 poke_code
81    
# Line 94  sub poke_code { Line 92  sub poke_code {
92          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;
93          #$mem[$addr++] = $_ foreach @_;          #$mem[$addr++] = $_ foreach @_;
94          # call low-level write          # call low-level write
95          Arch::write($addr++, $_) foreach @_;          $_rw_hooks->{write}->( $addr++, $_ ) foreach @_;
96  }  }
97    
98  =head2 ram  =head2 ram
# Line 137  sub prompt { Line 135  sub prompt {
135          return 1;          return 1;
136  }  }
137    
138    =head1 XS Callbacks
139    
140    This functions are called from C<M6502.xs>
141    
142    =head2 _read
143    
144    Read from memory C callback
145    
146      $byte = M6502::_read( $address );
147    
148    =cut
149    
150    sub _read {
151            return $_rw_hooks->{read}->( @_ );
152    }
153    
154    =head2 _write
155    
156    Write into memory C callback
157    
158      M6502:_write( $address, $byte );
159    
160    =cut
161    
162    sub _write {
163            return $_rw_hooks->{write}->( @_ );
164    }
165    
166  =head2 _update_perl_R  =head2 _update_perl_R
167    
168  called by C<M6502.xs> to push changes in registars back to perl variables  called by C<M6502.xs> to push changes in registars back to perl variables
# Line 149  sub _update_perl_R { Line 175  sub _update_perl_R {
175          dump_R();          dump_R();
176  }  }
177    
178    =head1 XS
179    
180    Following functions are implemented in C<M6502.xs> and exported to perl.
181    
182    =head2 set_debug
183    
184      M6502::set_debug( 0 );
185    
186    =head2 get_debug
187    
188      my $debug = M6502::set_debug();
189    
190    =head2 reset
191    
192    Reset 6502 CPU, reading PC from C<0xfffc>
193    
194      M6502::reset();
195    
196    =head2 update_C_R
197    
198    Push perl notion of register values to CPU emulator
199    
200      M6502::update_C_R();
201    
202    =head2 update_perl_R
203    
204    Update perl notion of register values
205    
206      M6502::update_perl_R();
207    
208    =head2 exec
209    
210    Execute cpu for specified number of cycles
211    
212      my $cycles_left = M6502::exec( $execute_cpu_cycles );
213    
214    =head1 Helpers
215    
216  =head2 dump_R  =head2 dump_R
217    
218  helper function which dumps registers in humanly readable form  helper function which dumps registers in humanly readable form

Legend:
Removed from v.87  
changed lines
  Added in v.94

  ViewVC Help
Powered by ViewVC 1.1.26