/[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 51 by dpavlin, Tue Jul 31 12:35:02 2007 UTC revision 87 by dpavlin, Thu Aug 2 11:08:10 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 $debug';  our @EXPORT = qw'dump_R @mem $PC $A $P $X $Y $S $IPeriod $ICount $IRequest $IAutoReset $TrapBadOps $Trap $Trace $run_for $debug';
10    our $VERSION = '0.0.2';
11    require XSLoader;
12    XSLoader::load('M6502', $VERSION);
13    
14  =head1 NAME  =head1 NAME
15    
16  M6502 - perl bindings for 6502 emulator  M6502 - perl bindings for M6502 CPU emulator
17    
18  =cut  =cut
19    
20  my $debug = 0;  our $debug = 0;
   
 our $VERSION = qw(0.0.1);  
21    
22  our @mem = (0xff) x 0x10000;    # 64M  our @mem = (0xff) x 0x10000;    # 64M
23    
# Line 24  our @mem = (0xff) x 0x10000;   # 64M Line 25  our @mem = (0xff) x 0x10000;   # 64M
25  our $PC = 0xbeef;  our $PC = 0xbeef;
26  # CPU registars  # CPU registars
27  our ( $A, $P, $X, $Y, $S ) = (0) x 5;  our ( $A, $P, $X, $Y, $S ) = (0) x 5;
28  # Set IPeriod to number of CPU cycles between calls to Loop6502  
29  our $IPeriod = 1;  our $IPeriod=1;         # Set IPeriod to number of CPU cycles between calls to Loop6502
30    our $ICount;
31    our $IRequest;          # Set to the INT_IRQ when pending IRQ
32    our $IAutoReset;        # Set to 1 to autom. reset IRequest
33    our $TrapBadOps=1;      # Set to 1 to warn of illegal opcodes
34    our $Trap;                      # Set Trap to address to trace from
35    our $Trace;                     # Set Trace=1 to start tracing
36    
37  # Exec6502 cycles  # Exec6502 cycles
38  our $run_for = 0;  our $run_for = 0;
39    
40  =head1 init  =head1 FUNCTIONS
41    
42    =head2 init
43    
44  Called before C<Run6502>  Called before C<Run6502>
45    
# Line 127  sub prompt { Line 137  sub prompt {
137          return 1;          return 1;
138  }  }
139    
140  =head2 push_R  =head2 _update_perl_R
141    
142  called by C<perl.c> to push changes in registars back to perl variables  called by C<M6502.xs> to push changes in registars back to perl variables
143    
144  =cut  =cut
145    
146  sub push_R {  sub _update_perl_R {
147          warn "## M6502::push_R(",dump(@_),")\n" if $debug;          warn "## M6502::update_perl_R(",dump(@_),")\n" if $debug;
148          my ( $a, $p, $x, $y, $s, $pc ) = @_;          ( $A, $P, $X, $Y, $S, $PC, $IPeriod, $ICount, $IRequest, $IAutoReset, $TrapBadOps, $Trap, $Trace ) = @_;
         $PC = $pc;  
         $S=$s; $X=$x; $Y=$y; $P=$p; $A=$a;  
149          dump_R();          dump_R();
150  }  }
151    
152  =head2 dump_R  =head2 dump_R
153    
154  helper function which dumps registers  helper function which dumps registers in humanly readable form
155    
156      my $dump = dump_R;
157    
158  =cut  =cut
159    
160  sub dump_R {  sub dump_R {
161          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;          my $dump = sprintf(" PC: %04x A:%02x P:%02x X:%02x Y:%02x S:%02x "
162                    . "IPeriod:%d ICount:%d IRequest:%02x IAutoReset:%02x TrapBadOps:%d Trap:%d Trace:%d"
163                    . "\n",
164                    $PC, $A, $P, $X, $Y, $S, $IPeriod, $ICount, $IRequest, $IAutoReset, $TrapBadOps, $Trap, $Trace,
165            );
166            warn "## M6502::dump_R $dump" if $debug;
167            return $dump;
168  }  }
169    
170    =head2 debug
171    
172    Turn perl and C-level debugging on/off
173    
174      $emu->debug( 0 );
175      $emu->debug( 1 );
176      print $emu->debug;
177    
178    =cut
179    
180    sub debug {
181            my $self = shift;
182            my $value = shift;
183            if (defined($value)) {
184                    $debug = M6502::set_debug($value);
185            } else {
186                    $debug = M6502::get_debug();
187            }
188            return $debug;
189    }
190    
191    =head1 SEE ALSO
192    
193    L<Orao> is sample implementation using this module
194    
195    =head1 AUTHOR
196    
197    Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
198    
199    =head1 COPYRIGHT & LICENSE
200    
201    Copyright 2007 Dobrica Pavlinusic, All Rights Reserved.
202    
203    This program is free software; you can redistribute it and/or modify it
204    under the same terms as Perl itself.
205    
206    =cut
207  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26