/[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

Annotation of /M6502/M6502.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26