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'dump_R @mem $PC $A $P $X $Y $S $IPeriod $ICount $IRequest $IAutoReset $TrapBadOps $Trap $Trace $run_for $debug'; |
our @EXPORT = qw'dump_R @mem $PC $A $P $X $Y $S $IPeriod $ICount $IRequest $IAutoReset $TrapBadOps $Trap $Trace $debug'; |
10 |
our $VERSION = '0.0.2'; |
our $VERSION = '0.0.2'; |
11 |
require XSLoader; |
require XSLoader; |
12 |
XSLoader::load('M6502', $VERSION); |
XSLoader::load('M6502', $VERSION); |
36 |
our $Trap; # Set Trap to address to trace from |
our $Trap; # Set Trap to address to trace from |
37 |
our $Trace; # Set Trace=1 to start tracing |
our $Trace; # Set Trace=1 to start tracing |
38 |
|
|
|
# Exec6502 cycles |
|
|
our $run_for = 0; |
|
|
|
|
39 |
=head2 init |
=head2 init |
40 |
|
|
41 |
Setup read and write memory hooks (to implement memory mapped devices) |
Setup read and write memory hooks (to implement memory mapped devices) |
53 |
|
|
54 |
our $_rw_hooks = { |
our $_rw_hooks = { |
55 |
read => sub { |
read => sub { |
56 |
warn sprintf("# callback read(%04x) not implemented", @_) if $debug; |
warn sprintf("# callback read(%04x) not implemented\n", @_) if $debug; |
57 |
return $mem[$_[0]]; |
return $mem[$_[0]]; |
58 |
}, |
}, |
59 |
write => sub { |
write => sub { |
121 |
splice @mem, $addr, $len, unpack('C*', $chunk); |
splice @mem, $addr, $len, unpack('C*', $chunk); |
122 |
} |
} |
123 |
|
|
|
=head2 prompt |
|
|
|
|
|
Call this after C<< $run_for >> cycles have been run on processor |
|
|
|
|
|
=cut |
|
|
|
|
|
sub prompt { |
|
|
warn "prompt -- you should override this\n"; |
|
|
return 1; |
|
|
} |
|
|
|
|
124 |
=head1 XS Callbacks |
=head1 XS Callbacks |
125 |
|
|
126 |
This functions are called from C<M6502.xs> |
This functions are called from C<M6502.xs> |
161 |
dump_R(); |
dump_R(); |
162 |
} |
} |
163 |
|
|
164 |
|
=head1 XS |
165 |
|
|
166 |
|
Following functions are implemented in C<M6502.xs> and exported to perl. |
167 |
|
|
168 |
|
=head2 set_debug |
169 |
|
|
170 |
|
M6502::set_debug( 0 ); |
171 |
|
|
172 |
|
=head2 get_debug |
173 |
|
|
174 |
|
my $debug = M6502::set_debug(); |
175 |
|
|
176 |
|
=head2 reset |
177 |
|
|
178 |
|
Reset 6502 CPU, reading PC from C<0xfffc> |
179 |
|
|
180 |
|
M6502::reset(); |
181 |
|
|
182 |
|
=head2 update_C_R |
183 |
|
|
184 |
|
Push perl notion of register values to CPU emulator |
185 |
|
|
186 |
|
M6502::update_C_R(); |
187 |
|
|
188 |
|
=head2 update_perl_R |
189 |
|
|
190 |
|
Update perl notion of register values |
191 |
|
|
192 |
|
M6502::update_perl_R(); |
193 |
|
|
194 |
|
=head2 exec |
195 |
|
|
196 |
|
Execute cpu for specified number of cycles |
197 |
|
|
198 |
|
my $cycles_left = M6502::exec( $execute_cpu_cycles ); |
199 |
|
|
200 |
|
=head1 Helpers |
201 |
|
|
202 |
=head2 dump_R |
=head2 dump_R |
203 |
|
|
204 |
helper function which dumps registers in humanly readable form |
helper function which dumps registers in humanly readable form |