5 |
|
|
6 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
7 |
use Carp qw/confess/; |
use Carp qw/confess/; |
8 |
|
use Exporter 'import'; |
9 |
|
our @EXPORT = qw'@mem $PC $A $P $X $Y $S $IPeriod $run_for'; |
10 |
|
|
11 |
=head1 NAME |
=head1 NAME |
12 |
|
|
26 |
our ( $A, $P, $X, $Y, $S ) = (0) x 5; |
our ( $A, $P, $X, $Y, $S ) = (0) x 5; |
27 |
# Set IPeriod to number of CPU cycles between calls to Loop6502 |
# Set IPeriod to number of CPU cycles between calls to Loop6502 |
28 |
our $IPeriod = 1; |
our $IPeriod = 1; |
29 |
|
# Exec6502 cycles |
30 |
|
our $run_for = 0; |
31 |
|
|
32 |
=head1 init |
=head1 init |
33 |
|
|
36 |
=cut |
=cut |
37 |
|
|
38 |
sub init { |
sub init { |
39 |
warn "inside init\n"; |
my $self = shift; |
40 |
print "stdout\n"; |
warn dump(@_); |
41 |
|
warn "inside init low-level M6502 from $self\n"; |
42 |
}; |
}; |
43 |
|
|
44 |
=head2 read |
=head2 read |
72 |
|
|
73 |
=head2 poke_code |
=head2 poke_code |
74 |
|
|
75 |
Write series of bytes into memory without passing through MMU |
Write series of bytes into memory passing through MMU (C<read> and C<write>) |
76 |
|
functions. If you don't want to trigger MMU, use C<write_chunk>. |
77 |
|
|
78 |
$emu->poke_code( 0xbeef, 0xff, 0x00, 0xff, 0x00, 0xaa ); |
$emu->poke_code( 0xbeef, 0xff, 0x00, 0xff, 0x00, 0xaa ); |
79 |
|
|
83 |
my $self = shift; |
my $self = shift; |
84 |
my $addr = shift; |
my $addr = shift; |
85 |
warn sprintf("# poke_code(%04x,%s)\n", $addr, dump( @_ )) if $self->debug; |
warn sprintf("# poke_code(%04x,%s)\n", $addr, dump( @_ )) if $self->debug; |
86 |
$mem[$addr++] = $_ foreach @_; |
#$mem[$addr++] = $_ foreach @_; |
87 |
|
$self->write($addr++, $_) foreach @_; |
88 |
|
} |
89 |
|
|
90 |
|
=head2 write_chunk |
91 |
|
|
92 |
|
Low-level update of memory, overriding user specified MMU functions C<read> and C<write> |
93 |
|
|
94 |
|
$emu->write_chunk( $address, $chunk_of_data ); |
95 |
|
|
96 |
|
=cut |
97 |
|
|
98 |
|
sub write_chunk { |
99 |
|
my ($self, $addr, $chunk) = @_; |
100 |
|
my $len = length($chunk); |
101 |
|
splice @mem, $addr, $len, unpack('C*', $chunk); |
102 |
} |
} |
103 |
|
|
104 |
=head2 ram |
=head2 ram |
112 |
sub ram { |
sub ram { |
113 |
my $self = shift; |
my $self = shift; |
114 |
my ($from,$to) = @_; |
my ($from,$to) = @_; |
115 |
|
warn "ram($from,$to)\n"; |
116 |
if ($from + $to) { |
if ($from + $to) { |
117 |
printf "ram %04x - %04x\n", $from, $to; |
printf "ram %04x - %04x\n", $from, $to; |
118 |
return $mem[$from .. $to - 1]; |
return @mem[$from .. $to - 1]; |
119 |
} |
} |
120 |
printf "ram %04x\n", $from; |
printf "ram %04x\n", $from; |
121 |
return $mem[$from] if defined($from); |
return $mem[$from] if defined($from); |
122 |
confess "no from address"; |
confess "no from address"; |
123 |
} |
} |
124 |
|
|
125 |
|
=head2 prompt |
126 |
|
|
127 |
|
Call this after C<< $run_for >> cycles have been run on processor |
128 |
|
|
129 |
|
=cut |
130 |
|
|
131 |
|
sub prompt { |
132 |
|
warn "prompt -- you should override this\n"; |
133 |
|
return 1; |
134 |
|
} |
135 |
|
|
136 |
|
=head2 push_R |
137 |
|
|
138 |
|
called by C<perl.c> to push changes in registars back to perl variables |
139 |
|
|
140 |
|
=cut |
141 |
|
|
142 |
|
sub push_R { |
143 |
|
warn "push_R(",dump(@_),")\n"; |
144 |
|
my ( $a, $p, $x, $y, $s, $pc ) = @_; |
145 |
|
$PC = $pc; |
146 |
|
$S=$s; $X=$x; $Y=$y; $P=$p; $A=$a; |
147 |
|
dump_R(); |
148 |
|
} |
149 |
|
|
150 |
|
=head2 dump_R |
151 |
|
|
152 |
|
helper function which dumps registers |
153 |
|
|
154 |
|
=cut |
155 |
|
|
156 |
|
sub dump_R { |
157 |
|
warn sprintf("PC: %04x A:%02x P:%02x X:%02x Y:%02x S:%02x\n", $PC, $A, $P, $X, $Y, $S); |
158 |
|
} |
159 |
|
|
160 |
1; |
1; |