/[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 40 - (hide annotations)
Tue Jul 31 08:41:06 2007 UTC (16 years, 9 months ago) by dpavlin
File size: 2364 byte(s)
fetch cycles to run from M6502::run_for
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 40 our @EXPORT = qw'@mem $PC $A $P $X $Y $S $IPeriod $run_for';
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 40 # Exec6502 cycles
30     our $run_for = 1;
31     $run_for = 0x42;
32 dpavlin 24
33 dpavlin 26 =head1 init
34    
35     Called before C<Run6502>
36    
37     =cut
38    
39     sub init {
40 dpavlin 33 my $self = shift;
41     warn dump(@_);
42     warn "inside init low-level M6502 from $self\n";
43 dpavlin 26 };
44 dpavlin 27
45     =head2 read
46    
47     Read from memory
48    
49     $byte = read( $address );
50    
51     =cut
52    
53     sub read {
54     my ($addr) = @_;
55     my $byte = $mem[$addr];
56     warn "# read(",dump(@_),") = ",dump( $byte ),"\n" if $debug;
57     return $byte;
58     }
59    
60     =head2 write
61    
62     Write into emory
63    
64     write( $address, $byte );
65    
66     =cut
67    
68     sub write {
69     warn "# write(",dump(@_),")\n" if $debug;
70     my ($addr,$byte) = @_;
71     $mem[$addr] = $byte;
72     }
73 dpavlin 29
74     =head2 poke_code
75    
76     Write series of bytes into memory without passing through MMU
77    
78     $emu->poke_code( 0xbeef, 0xff, 0x00, 0xff, 0x00, 0xaa );
79    
80     =cut
81    
82     sub poke_code {
83     my $self = shift;
84     my $addr = shift;
85     warn sprintf("# poke_code(%04x,%s)\n", $addr, dump( @_ )) if $self->debug;
86     $mem[$addr++] = $_ foreach @_;
87     }
88    
89 dpavlin 31 =head2 write_chunk
90    
91     $emu->write_chunk( $address, $chunk_of_data );
92    
93     =cut
94    
95     sub write_chunk {
96     my ($self, $addr, $chunk) = @_;
97     my $len = length($chunk);
98     splice @mem, $addr, $len, unpack('C*', $chunk);
99     }
100    
101 dpavlin 29 =head2 ram
102    
103     Read searies of bytes from memory without passing through MMU
104    
105     $emu->ram( $from, $to );
106    
107     =cut
108    
109     sub ram {
110     my $self = shift;
111     my ($from,$to) = @_;
112 dpavlin 35 warn "ram($from,$to)\n";
113 dpavlin 29 if ($from + $to) {
114 dpavlin 30 printf "ram %04x - %04x\n", $from, $to;
115 dpavlin 35 return @mem[$from .. $to - 1];
116 dpavlin 29 }
117 dpavlin 30 printf "ram %04x\n", $from;
118 dpavlin 29 return $mem[$from] if defined($from);
119     confess "no from address";
120     }
121    
122 dpavlin 38 =head2 push_R
123    
124     called by C<perl.c> to push changes in registars back to perl variables
125    
126     =cut
127    
128     sub push_R {
129     warn "push_R(",dump(@_),")\n";
130     my ( $a, $p, $x, $y, $s, $pc ) = @_;
131     $PC = $pc;
132     $S=$s; $X=$x; $Y=$y; $P=$p; $A=$a;
133     dump_R();
134     }
135    
136     =head2 dump_R
137    
138     helper function which dumps registers
139    
140     =cut
141    
142     sub dump_R {
143     warn sprintf("PC: %04x A:%02x P:%02x X:%02x Y:%02x S:%02x\n", $PC, $A, $P, $X, $Y, $S);
144     }
145    
146 dpavlin 24 1;

  ViewVC Help
Powered by ViewVC 1.1.26