--- M6502/M6502.pm 2007/07/31 11:14:19 50 +++ M6502/M6502.pm 2007/08/01 22:25:37 86 @@ -6,17 +6,18 @@ use Data::Dump qw/dump/; use Carp qw/confess/; use Exporter 'import'; -our @EXPORT = qw'@mem $PC $A $P $X $Y $S $IPeriod $run_for $debug'; +our @EXPORT = qw'dump_R @mem $PC $A $P $X $Y $S $IPeriod $ICount $IRequest $IAutoReset $TrapBadOps $Trap $Trace $run_for $debug'; +our $VERSION = '0.0.2'; +require XSLoader; +XSLoader::load('M6502', $VERSION); =head1 NAME -M6502 - perl bindings for 6502 emulator +M6502 - perl bindings for M6502 CPU emulator =cut -my $debug = 0; - -our $VERSION = qw(0.0.1); +my $debug = 1; our @mem = (0xff) x 0x10000; # 64M @@ -24,12 +25,21 @@ our $PC = 0xbeef; # CPU registars our ( $A, $P, $X, $Y, $S ) = (0) x 5; -# Set IPeriod to number of CPU cycles between calls to Loop6502 -our $IPeriod = 1; + +our $IPeriod=1; # Set IPeriod to number of CPU cycles between calls to Loop6502 +our $ICount; +our $IRequest; # Set to the INT_IRQ when pending IRQ +our $IAutoReset; # Set to 1 to autom. reset IRequest +our $TrapBadOps=1; # Set to 1 to warn of illegal opcodes +our $Trap; # Set Trap to address to trace from +our $Trace; # Set Trace=1 to start tracing + # Exec6502 cycles our $run_for = 0; -=head1 init +=head1 FUNCTIONS + +=head2 init Called before C @@ -83,7 +93,23 @@ my $addr = shift; warn sprintf("## M6502::poke_code(%04x,%s)\n", $addr, dump( @_ )) if $self->debug; #$mem[$addr++] = $_ foreach @_; - $self->write($addr++, $_) foreach @_; + # call low-level write + Arch::write($addr++, $_) foreach @_; +} + +=head2 ram + +Read series of bytes into memory without MMU interaction + + my @code = $emu->ram( 0xc000, 0xc1000 ); + +=cut + +sub ram { + my $self = shift; + my ( $from, $to ) = @_; + warn sprintf("## M6502::ram(%04x,%04x)\n", $from, $to) if $self->debug; + return @mem[ $from .. $to ]; } =head2 write_chunk @@ -119,20 +145,42 @@ sub push_R { warn "## M6502::push_R(",dump(@_),")\n" if $debug; - my ( $a, $p, $x, $y, $s, $pc ) = @_; - $PC = $pc; - $S=$s; $X=$x; $Y=$y; $P=$p; $A=$a; + ( $A, $P, $X, $Y, $S, $PC, $IPeriod, $ICount, $IRequest, $IAutoReset, $TrapBadOps, $Trap, $Trace ) = @_; dump_R(); } =head2 dump_R -helper function which dumps registers +helper function which dumps registers in humanly readable form + + my $dump = dump_R; =cut sub dump_R { - 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; + my $dump = sprintf(" PC: %04x A:%02x P:%02x X:%02x Y:%02x S:%02x " + . "IPeriod:%d ICount:%d IRequest:%02x IAutoReset:%02x TrapBadOps:%d Trap:%d Trace:%d" + . "\n", + $PC, $A, $P, $X, $Y, $S, $IPeriod, $ICount, $IRequest, $IAutoReset, $TrapBadOps, $Trap, $Trace, + ); + warn "## M6502::dump_R $dump" if $debug; + return $dump; } +=head1 SEE ALSO + +L is sample implementation using this module + +=head1 AUTHOR + +Dobrica Pavlinusic, C<< >> + +=head1 COPYRIGHT & LICENSE + +Copyright 2007 Dobrica Pavlinusic, All Rights Reserved. + +This program is free software; you can redistribute it and/or modify it +under the same terms as Perl itself. + +=cut 1;