/[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 94 by dpavlin, Thu Aug 2 13:04:29 2007 UTC revision 208 by dpavlin, Mon Apr 14 19:40:02 2008 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'dump_R @mem $PC $A $P $X $Y $S $IPeriod $ICount $IRequest $IAutoReset $TrapBadOps $Trap $Trace $run_for $debug';  our @EXPORT = qw'dump_R @mem $PC $A $P $X $Y $S $IPeriod $ICount $IRequest $IAutoReset $TrapBadOps $Trap $Trace $debug';
10  our $VERSION = '0.0.2';  our $VERSION = '0.0.4';
11  require XSLoader;  require XSLoader;
12  XSLoader::load('M6502', $VERSION);  XSLoader::load('M6502', $VERSION);
13    
# Line 21  M6502 - perl bindings for M6502 CPU emul Line 21  M6502 - perl bindings for M6502 CPU emul
21    
22  our $debug = 0;  our $debug = 0;
23    
24  our @mem = (0xff) x 0x10000;    # 64M  our @mem;
25    #@mem = (0xff) x 0x10000;       # 64M
26    tie @mem, 'M6502::TieMem';
27    
28  # program counter  # program counter
29  our $PC = 0xbeef;  our $PC = 0xbeef;
# Line 36  our $TrapBadOps=1;     # Set to 1 to warn of Line 38  our $TrapBadOps=1;     # Set to 1 to warn of
38  our $Trap;                      # Set Trap to address to trace from  our $Trap;                      # Set Trap to address to trace from
39  our $Trace;                     # Set Trace=1 to start tracing  our $Trace;                     # Set Trace=1 to start tracing
40    
 # Exec6502 cycles  
 our $run_for = 0;  
   
41  =head2 init  =head2 init
42    
43  Setup read and write memory hooks (to implement memory mapped devices)  Setup read and write memory hooks (to implement memory mapped devices)
# Line 90  sub poke_code { Line 89  sub poke_code {
89          my $self = shift;          my $self = shift;
90          my $addr = shift;          my $addr = shift;
91          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;
         #$mem[$addr++] = $_ foreach @_;  
92          # call low-level write          # call low-level write
93          $_rw_hooks->{write}->( $addr++, $_ ) foreach @_;          #$_rw_hooks->{write}->( $addr++, $_ ) foreach @_;
94            $mem[$addr++] = $_ foreach @_;
95  }  }
96    
97  =head2 ram  =head2 ram
# Line 107  sub ram { Line 106  sub ram {
106          my $self = shift;          my $self = shift;
107          my ( $from, $to ) = @_;          my ( $from, $to ) = @_;
108          warn sprintf("## M6502::ram(%04x,%04x)\n", $from, $to) if $self->debug;          warn sprintf("## M6502::ram(%04x,%04x)\n", $from, $to) if $self->debug;
109          return @mem[ $from .. $to ];  #       return @mem[ $from .. $to ];
110            return unpack('C*', M6502::mem_peek_region( $from, $to ));
111  }  }
112    
113  =head2 write_chunk  =head2 write_chunk
# Line 124  sub write_chunk { Line 124  sub write_chunk {
124          splice @mem, $addr, $len, unpack('C*', $chunk);          splice @mem, $addr, $len, unpack('C*', $chunk);
125  }  }
126    
 =head2 prompt  
   
 Call this after C<< $run_for >> cycles have been run on processor  
   
 =cut  
   
 sub prompt {  
         warn "prompt -- you should override this\n";  
         return 1;  
 }  
   
127  =head1 XS Callbacks  =head1 XS Callbacks
128    
129  This functions are called from C<M6502.xs>  This functions are called from C<M6502.xs>
# Line 262  Dobrica Pavlinusic, C<< <dpavlin@rot13.o Line 251  Dobrica Pavlinusic, C<< <dpavlin@rot13.o
251    
252  =head1 COPYRIGHT & LICENSE  =head1 COPYRIGHT & LICENSE
253    
254  Copyright 2007 Dobrica Pavlinusic, All Rights Reserved.  Copyright 2007-8 Dobrica Pavlinusic, All Rights Reserved.
255    
256  This program is free software; you can redistribute it and/or modify it  This program is free software; you can redistribute it and/or modify it
257  under the same terms as Perl itself.  under the same terms as Perl itself.
258    
259  =cut  =cut
260    
261    package M6502::TieMem;
262    
263    use strict;
264    use warnings;
265    use Tie::Array;
266    use base qw(Tie::Array);
267    
268    #
269    sub TIEARRAY {
270            my $class = shift;
271    #       my $opt   = shift;
272    #       my $self  = { %$opt };
273            my $self = {};
274            bless($self, __PACKAGE__);
275            return $self;
276    }
277    
278    sub DESTROY {}
279    
280    #
281    sub FETCH {
282            my $self = shift;
283            my $n    = shift;
284            my $val = M6502::mem_peek( $n );
285    #       warn sprintf("FETCH %04x = %02x\n", $n, $val);
286            return $val;
287    }
288    
289    #
290    sub FETCHSIZE {
291            return 0xffff;
292    }
293    
294    #
295    sub STORE {
296            my $self = shift;
297            my $n    = shift;
298            my $val  = shift;
299            if ( $n > 0xffff ) {
300                    warn "over 64k: $n\n";
301                    return;
302            }
303            M6502::mem_poke( $n, $val );
304    #       warn sprintf("STORE %04x <- %02x\n",$n, $val);
305            return $val;
306    }
307    
308    #
309    sub STORESIZE {
310            die('not allowed (yet)');
311    }
312    
313    sub PUSH {
314            die('not allowed (yet)');
315    }
316    
317    sub POP {
318            die('not allowed (yet)');
319    }
320    
321    sub SHIFT {
322            die('not allowed (yet)');
323    }
324    
325    sub UNSHIFT {
326            die('not allowed (yet)');
327    }
328    
329    sub DELETE {
330            my $self = shift;
331            my $n    = shift;
332            $self->STORE($n, 0);
333    }
334    
335    sub EXISTS {
336            my $self = shift;
337            my $n    = shift;
338            return 0 if $n > 0xffff;
339            return 1;
340    }
341    
342  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26