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.3'; |
11 |
require XSLoader; |
require XSLoader; |
12 |
XSLoader::load('M6502', $VERSION); |
XSLoader::load('M6502', $VERSION); |
13 |
|
|
21 |
|
|
22 |
our $debug = 0; |
our $debug = 0; |
23 |
|
|
24 |
our @mem = (0xff) x 0x10000; # 64M |
our @mem; # = (0xff) x 0x10000; # 64M |
25 |
|
tie @mem, 'M6502::TieMem'; |
26 |
|
|
27 |
# program counter |
# program counter |
28 |
our $PC = 0xbeef; |
our $PC = 0xbeef; |
37 |
our $Trap; # Set Trap to address to trace from |
our $Trap; # Set Trap to address to trace from |
38 |
our $Trace; # Set Trace=1 to start tracing |
our $Trace; # Set Trace=1 to start tracing |
39 |
|
|
|
# Exec6502 cycles |
|
|
our $run_for = 0; |
|
|
|
|
40 |
=head2 init |
=head2 init |
41 |
|
|
42 |
Setup read and write memory hooks (to implement memory mapped devices) |
Setup read and write memory hooks (to implement memory mapped devices) |
122 |
splice @mem, $addr, $len, unpack('C*', $chunk); |
splice @mem, $addr, $len, unpack('C*', $chunk); |
123 |
} |
} |
124 |
|
|
|
=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; |
|
|
} |
|
|
|
|
125 |
=head1 XS Callbacks |
=head1 XS Callbacks |
126 |
|
|
127 |
This functions are called from C<M6502.xs> |
This functions are called from C<M6502.xs> |
249 |
|
|
250 |
=head1 COPYRIGHT & LICENSE |
=head1 COPYRIGHT & LICENSE |
251 |
|
|
252 |
Copyright 2007 Dobrica Pavlinusic, All Rights Reserved. |
Copyright 2007-8 Dobrica Pavlinusic, All Rights Reserved. |
253 |
|
|
254 |
This program is free software; you can redistribute it and/or modify it |
This program is free software; you can redistribute it and/or modify it |
255 |
under the same terms as Perl itself. |
under the same terms as Perl itself. |
256 |
|
|
257 |
=cut |
=cut |
258 |
|
|
259 |
|
package M6502::TieMem; |
260 |
|
|
261 |
|
use strict; |
262 |
|
use warnings; |
263 |
|
use Tie::Array; |
264 |
|
use base qw(Tie::Array); |
265 |
|
|
266 |
|
# |
267 |
|
sub TIEARRAY { |
268 |
|
my $class = shift; |
269 |
|
# my $opt = shift; |
270 |
|
# my $self = { %$opt }; |
271 |
|
my $self = {}; |
272 |
|
bless($self, __PACKAGE__); |
273 |
|
return $self; |
274 |
|
} |
275 |
|
|
276 |
|
sub DESTROY {} |
277 |
|
|
278 |
|
# |
279 |
|
sub FETCH { |
280 |
|
my $self = shift; |
281 |
|
my $n = shift; |
282 |
|
my $val = M6502::mem_peek( $n ); |
283 |
|
warn sprintf("FETCH %04x = %02x\n", $n, $val); |
284 |
|
return $val; |
285 |
|
} |
286 |
|
|
287 |
|
# |
288 |
|
sub FETCHSIZE { |
289 |
|
return 0xffff; |
290 |
|
} |
291 |
|
|
292 |
|
# |
293 |
|
sub STORE { |
294 |
|
my $self = shift; |
295 |
|
my $n = shift; |
296 |
|
my $val = shift; |
297 |
|
if ( $n > 0xffff ) { |
298 |
|
warn "over 64k: $n\n"; |
299 |
|
return; |
300 |
|
} |
301 |
|
M6502::mem_poke( $n, $val ); |
302 |
|
warn sprintf("STORE %04x <- %02x\n",$n, $val); |
303 |
|
return $val; |
304 |
|
} |
305 |
|
|
306 |
|
# |
307 |
|
sub STORESIZE { |
308 |
|
die('not allowed (yet)'); |
309 |
|
} |
310 |
|
|
311 |
|
sub PUSH { |
312 |
|
die('not allowed (yet)'); |
313 |
|
} |
314 |
|
|
315 |
|
sub POP { |
316 |
|
die('not allowed (yet)'); |
317 |
|
} |
318 |
|
|
319 |
|
sub SHIFT { |
320 |
|
die('not allowed (yet)'); |
321 |
|
} |
322 |
|
|
323 |
|
sub UNSHIFT { |
324 |
|
die('not allowed (yet)'); |
325 |
|
} |
326 |
|
|
327 |
|
sub DELETE { |
328 |
|
my $self = shift; |
329 |
|
my $n = shift; |
330 |
|
$self->STORE($n, 0); |
331 |
|
} |
332 |
|
|
333 |
|
sub EXISTS { |
334 |
|
my $self = shift; |
335 |
|
my $n = shift; |
336 |
|
return 0 if $n > 0xffff; |
337 |
|
return 1; |
338 |
|
} |
339 |
|
|
340 |
1; |
1; |