--- M6502/M6502.pm 2007/07/31 13:56:50 55 +++ M6502/M6502.pm 2007/08/01 22:25:37 86 @@ -6,7 +6,10 @@ 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 @@ -14,9 +17,7 @@ =cut -my $debug = 0; - -our $VERSION = qw(0.0.1); +my $debug = 1; our @mem = (0xff) x 0x10000; # 64M @@ -24,8 +25,15 @@ 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; @@ -137,20 +145,26 @@ 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