/[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 26 by dpavlin, Mon Jul 30 14:23:22 2007 UTC revision 33 by dpavlin, Mon Jul 30 21:00:36 2007 UTC
# Line 3  package M6502; Line 3  package M6502;
3  use strict;  use strict;
4  use warnings;  use warnings;
5    
6  # Dobrica Pavlinusic, <dpavlin@rot13.org> 07/30/07 13:23:19 CEST  use Data::Dump qw/dump/;
7  #  use Carp qw/confess/;
 # Simple Orao emulation  
8    
9  my $mem = (0) x 0x10000;        # 64M  =head1 NAME
10    
11    M6502 - perl bindings for 6502 emulator
12    
13    =cut
14    
15    my $debug = 1;
16    
17    our $VERSION = qw(0.0.1);
18    
19    our @mem = (0xff) x 0x10000;    # 64M
20    
21  # program counter  # program counter
22  our $PC = 0xbeef;  our $PC = 0xdd11;
23  # CPU registars  # CPU registars
24  our ( $A, $P, $X, $Y, $S ) = (0) x 5;  our ( $A, $P, $X, $Y, $S ) = (0) x 5;
25  # Set IPeriod to number of CPU cycles between calls to Loop6502  # Set IPeriod to number of CPU cycles between calls to Loop6502
26  our $IPeriod = 20000;  our $IPeriod = 1;
27    
28  =head1 init  =head1 init
29    
# Line 23  Called before C<Run6502> Line 32  Called before C<Run6502>
32  =cut  =cut
33    
34  sub init {  sub init {
35          warn "inside init\n";          my $self = shift;
36          print "stdout\n";          warn dump(@_);
37            warn "inside init low-level M6502 from $self\n";
38  };  };
39    
40    =head2 read
41    
42    Read from memory
43    
44      $byte = read( $address );
45    
46    =cut
47    
48    sub read {
49            my ($addr) = @_;
50            my $byte = $mem[$addr];
51            warn "# read(",dump(@_),") = ",dump( $byte ),"\n" if $debug;
52            return $byte;
53    }
54    
55    =head2 write
56    
57    Write into emory
58    
59      write( $address, $byte );
60    
61    =cut
62    
63    sub write {
64            warn "# write(",dump(@_),")\n" if $debug;
65            my ($addr,$byte) = @_;
66            $mem[$addr] = $byte;
67    }
68    
69    =head2 poke_code
70    
71    Write series of bytes into memory without passing through MMU
72    
73      $emu->poke_code( 0xbeef, 0xff, 0x00, 0xff, 0x00, 0xaa );
74    
75    =cut
76    
77    sub poke_code {
78            my $self = shift;
79            my $addr = shift;
80            warn sprintf("# poke_code(%04x,%s)\n", $addr, dump( @_ )) if $self->debug;
81            $mem[$addr++] = $_ foreach @_;
82    }
83    
84    =head2 write_chunk
85    
86      $emu->write_chunk( $address, $chunk_of_data );
87    
88    =cut
89    
90    sub write_chunk {
91            my ($self, $addr, $chunk) = @_;
92            my $len = length($chunk);
93            splice @mem, $addr, $len, unpack('C*', $chunk);
94    }
95    
96    =head2 ram
97    
98    Read searies of bytes from memory without passing through MMU
99    
100      $emu->ram( $from, $to );
101    
102    =cut
103    
104    sub ram {
105            my $self = shift;
106            my ($from,$to) = @_;
107            if ($from + $to) {
108                    printf "ram %04x - %04x\n", $from, $to;
109                    return $mem[$from .. $to - 1];
110            }
111            printf "ram %04x\n", $from;
112            return $mem[$from] if defined($from);
113            confess "no from address";
114    }
115    
116  1;  1;

Legend:
Removed from v.26  
changed lines
  Added in v.33

  ViewVC Help
Powered by ViewVC 1.1.26