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'@mem $PC $A $P $X $Y $S $IPeriod $run_for'; |
our @EXPORT = qw'@mem $PC $A $P $X $Y $S $IPeriod $run_for $debug'; |
10 |
|
|
11 |
=head1 NAME |
=head1 NAME |
12 |
|
|
14 |
|
|
15 |
=cut |
=cut |
16 |
|
|
17 |
my $debug = 1; |
my $debug = 0; |
18 |
|
|
19 |
our $VERSION = qw(0.0.1); |
our $VERSION = qw(0.0.1); |
20 |
|
|
37 |
|
|
38 |
sub init { |
sub init { |
39 |
my $self = shift; |
my $self = shift; |
|
warn dump(@_); |
|
40 |
warn "inside init low-level M6502 from $self\n"; |
warn "inside init low-level M6502 from $self\n"; |
41 |
}; |
}; |
42 |
|
|
51 |
sub read { |
sub read { |
52 |
my ($addr) = @_; |
my ($addr) = @_; |
53 |
my $byte = $mem[$addr]; |
my $byte = $mem[$addr]; |
54 |
warn "# read(",dump(@_),") = ",dump( $byte ),"\n" if $debug; |
warn "## M6502::read(",dump(@_),") = ",dump( $byte ),"\n" if $debug; |
55 |
return $byte; |
return $byte; |
56 |
} |
} |
57 |
|
|
64 |
=cut |
=cut |
65 |
|
|
66 |
sub write { |
sub write { |
67 |
warn "# write(",dump(@_),")\n" if $debug; |
warn "## M6502::write(",dump(@_),")\n" if $debug; |
68 |
my ($addr,$byte) = @_; |
my ($addr,$byte) = @_; |
69 |
$mem[$addr] = $byte; |
$mem[$addr] = $byte; |
70 |
} |
} |
81 |
sub poke_code { |
sub poke_code { |
82 |
my $self = shift; |
my $self = shift; |
83 |
my $addr = shift; |
my $addr = shift; |
84 |
warn sprintf("# poke_code(%04x,%s)\n", $addr, dump( @_ )) if $self->debug; |
warn sprintf("## M6502::poke_code(%04x,%s)\n", $addr, dump( @_ )) if $self->debug; |
85 |
#$mem[$addr++] = $_ foreach @_; |
#$mem[$addr++] = $_ foreach @_; |
86 |
$self->write($addr++, $_) foreach @_; |
$self->write($addr++, $_) foreach @_; |
87 |
} |
} |
100 |
splice @mem, $addr, $len, unpack('C*', $chunk); |
splice @mem, $addr, $len, unpack('C*', $chunk); |
101 |
} |
} |
102 |
|
|
|
=head2 ram |
|
|
|
|
|
Read searies of bytes from memory without passing through MMU |
|
|
|
|
|
$emu->ram( $from, $to ); |
|
|
|
|
|
=cut |
|
|
|
|
|
sub ram { |
|
|
my $self = shift; |
|
|
my ($from,$to) = @_; |
|
|
warn "ram($from,$to)\n"; |
|
|
if ($from + $to) { |
|
|
printf "ram %04x - %04x\n", $from, $to; |
|
|
return @mem[$from .. $to - 1]; |
|
|
} |
|
|
printf "ram %04x\n", $from; |
|
|
return $mem[$from] if defined($from); |
|
|
confess "no from address"; |
|
|
} |
|
|
|
|
103 |
=head2 prompt |
=head2 prompt |
104 |
|
|
105 |
Call this after C<< $run_for >> cycles have been run on processor |
Call this after C<< $run_for >> cycles have been run on processor |
118 |
=cut |
=cut |
119 |
|
|
120 |
sub push_R { |
sub push_R { |
121 |
warn "push_R(",dump(@_),")\n"; |
warn "## M6502::push_R(",dump(@_),")\n" if $debug; |
122 |
my ( $a, $p, $x, $y, $s, $pc ) = @_; |
my ( $a, $p, $x, $y, $s, $pc ) = @_; |
123 |
$PC = $pc; |
$PC = $pc; |
124 |
$S=$s; $X=$x; $Y=$y; $P=$p; $A=$a; |
$S=$s; $X=$x; $Y=$y; $P=$p; $A=$a; |
132 |
=cut |
=cut |
133 |
|
|
134 |
sub dump_R { |
sub dump_R { |
135 |
warn sprintf("PC: %04x A:%02x P:%02x X:%02x Y:%02x S:%02x\n", $PC, $A, $P, $X, $Y, $S); |
warn sprintf("## M6502::dump_R PC: %04x A:%02x P:%02x X:%02x Y:%02x S:%02x\n", $PC, $A, $P, $X, $Y, $S) if $debug; |
136 |
} |
} |
137 |
|
|
138 |
1; |
1; |