--- M6502/M6502.pm 2007/07/30 17:56:13 30 +++ M6502/M6502.pm 2007/07/30 21:53:04 35 @@ -5,6 +5,8 @@ use Data::Dump qw/dump/; use Carp qw/confess/; +use Exporter 'import'; +our @EXPORT = qw'@mem $PC $A $P $X $Y $S $IPeriod'; =head1 NAME @@ -21,7 +23,7 @@ # program counter our $PC = 0xbeef; # CPU registars -our ( $A, $P, $X, $Y, $S ) = (0) x 5; +our ( $A, $P, $X, $Y, $S ) = (0x42) x 5; # Set IPeriod to number of CPU cycles between calls to Loop6502 our $IPeriod = 1; @@ -32,8 +34,9 @@ =cut sub init { - warn "inside init\n"; - print "stdout\n"; + my $self = shift; + warn dump(@_); + warn "inside init low-level M6502 from $self\n"; }; =head2 read @@ -80,6 +83,18 @@ $mem[$addr++] = $_ foreach @_; } +=head2 write_chunk + + $emu->write_chunk( $address, $chunk_of_data ); + +=cut + +sub write_chunk { + my ($self, $addr, $chunk) = @_; + my $len = length($chunk); + splice @mem, $addr, $len, unpack('C*', $chunk); +} + =head2 ram Read searies of bytes from memory without passing through MMU @@ -91,9 +106,10 @@ 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]; + return @mem[$from .. $to - 1]; } printf "ram %04x\n", $from; return $mem[$from] if defined($from);