15 |
|
|
16 |
M6502 - perl bindings for M6502 CPU emulator |
M6502 - perl bindings for M6502 CPU emulator |
17 |
|
|
18 |
|
=head1 FUNCTIONS |
19 |
|
|
20 |
=cut |
=cut |
21 |
|
|
22 |
our $debug = 0; |
our $debug = 0; |
39 |
# Exec6502 cycles |
# Exec6502 cycles |
40 |
our $run_for = 0; |
our $run_for = 0; |
41 |
|
|
|
=head1 FUNCTIONS |
|
|
|
|
42 |
=head2 init |
=head2 init |
43 |
|
|
44 |
Called before C<Run6502> |
Setup read and write memory hooks (to implement memory mapped devices) |
|
|
|
|
=cut |
|
|
|
|
|
sub init { |
|
|
my $self = shift; |
|
|
warn "inside init low-level M6502 from $self\n"; |
|
|
}; |
|
45 |
|
|
46 |
=head2 read |
$init->( |
47 |
|
read => sub { |
48 |
Read from memory |
return $mem[$_[0]]; |
49 |
|
}, |
50 |
$byte = read( $address ); |
write => sub { |
51 |
|
$mem[$_[0]] = $_[1]; |
52 |
|
}, |
53 |
|
); |
54 |
|
|
55 |
=cut |
=cut |
56 |
|
|
57 |
sub read { |
our $_rw_hooks = { |
58 |
my ($addr) = @_; |
read => sub { |
59 |
my $byte = $mem[$addr]; |
return $mem[$_[0]]; |
60 |
warn "## M6502::read(",dump(@_),") = ",dump( $byte ),"\n" if $debug; |
}, |
61 |
return $byte; |
write => sub { |
62 |
} |
$mem[$_[0]] = $_[1]; |
63 |
|
}, |
64 |
=head2 write |
}; |
|
|
|
|
Write into emory |
|
65 |
|
|
66 |
write( $address, $byte ); |
sub init { |
67 |
|
my $self = shift; |
68 |
|
my $args = {@_}; |
69 |
|
warn "inside init low-level M6502 from ",ref($self),"\n"; |
70 |
|
|
71 |
=cut |
foreach my $p ( qw/read write/ ) { |
72 |
|
confess "need $p argument as coderef" unless ( $args->{$p} && ref($args->{$p}) eq 'CODE' ); |
73 |
|
$_rw_hooks->{$p} = $args->{$p}; |
74 |
|
} |
75 |
|
|
76 |
sub write { |
}; |
|
warn "## M6502::write(",dump(@_),")\n" if $debug; |
|
|
my ($addr,$byte) = @_; |
|
|
$mem[$addr] = $byte; |
|
|
} |
|
77 |
|
|
78 |
=head2 poke_code |
=head2 poke_code |
79 |
|
|
90 |
warn sprintf("## M6502::poke_code(%04x,%s)\n", $addr, dump( @_ )) if $self->debug; |
warn sprintf("## M6502::poke_code(%04x,%s)\n", $addr, dump( @_ )) if $self->debug; |
91 |
#$mem[$addr++] = $_ foreach @_; |
#$mem[$addr++] = $_ foreach @_; |
92 |
# call low-level write |
# call low-level write |
93 |
Arch::write($addr++, $_) foreach @_; |
M6502::write($addr++, $_) foreach @_; |
94 |
} |
} |
95 |
|
|
96 |
=head2 ram |
=head2 ram |
133 |
return 1; |
return 1; |
134 |
} |
} |
135 |
|
|
136 |
|
=head1 XS Callbacks |
137 |
|
|
138 |
|
This functions are called from C<M6502.xs> |
139 |
|
|
140 |
|
=head2 _read |
141 |
|
|
142 |
|
Read from memory C callback |
143 |
|
|
144 |
|
$byte = M6502::_read( $address ); |
145 |
|
|
146 |
|
=cut |
147 |
|
|
148 |
|
sub _read { |
149 |
|
return $_rw_hooks->{read}->( @_ ); |
150 |
|
} |
151 |
|
|
152 |
|
=head2 _write |
153 |
|
|
154 |
|
Write into memory C callback |
155 |
|
|
156 |
|
M6502:_write( $address, $byte ); |
157 |
|
|
158 |
|
=cut |
159 |
|
|
160 |
|
sub _write { |
161 |
|
return $_rw_hooks->{write}->( @_ ); |
162 |
|
} |
163 |
|
|
164 |
=head2 _update_perl_R |
=head2 _update_perl_R |
165 |
|
|
166 |
called by C<M6502.xs> to push changes in registars back to perl variables |
called by C<M6502.xs> to push changes in registars back to perl variables |