4 |
use warnings; |
use warnings; |
5 |
|
|
6 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
7 |
|
use Carp qw/confess/; |
8 |
|
use Exporter 'import'; |
9 |
|
our @EXPORT = qw'@mem'; |
10 |
|
|
11 |
# Dobrica Pavlinusic, <dpavlin@rot13.org> 07/30/07 13:23:19 CEST |
=head1 NAME |
12 |
# |
|
13 |
# Simple Orao emulation |
M6502 - perl bindings for 6502 emulator |
14 |
|
|
15 |
|
=cut |
16 |
|
|
17 |
my $debug = 1; |
my $debug = 1; |
18 |
|
|
19 |
my @mem = (0x42) x 0x10000; # 64M |
our $VERSION = qw(0.0.1); |
20 |
|
|
21 |
|
our @mem = (0xff) x 0x10000; # 64M |
22 |
|
|
23 |
# program counter |
# program counter |
24 |
our $PC = 0xbeef; |
our $PC = 0xbeef; |
25 |
# CPU registars |
# CPU registars |
26 |
our ( $A, $P, $X, $Y, $S ) = (0) x 5; |
our ( $A, $P, $X, $Y, $S ) = (0x42) x 5; |
27 |
# Set IPeriod to number of CPU cycles between calls to Loop6502 |
# Set IPeriod to number of CPU cycles between calls to Loop6502 |
28 |
our $IPeriod = 1; |
our $IPeriod = 1; |
29 |
|
|
34 |
=cut |
=cut |
35 |
|
|
36 |
sub init { |
sub init { |
37 |
warn "inside init\n"; |
my $self = shift; |
38 |
print "stdout\n"; |
warn dump(@_); |
39 |
|
warn "inside init low-level M6502 from $self\n"; |
40 |
}; |
}; |
41 |
|
|
42 |
=head2 read |
=head2 read |
67 |
my ($addr,$byte) = @_; |
my ($addr,$byte) = @_; |
68 |
$mem[$addr] = $byte; |
$mem[$addr] = $byte; |
69 |
} |
} |
70 |
|
|
71 |
|
=head2 poke_code |
72 |
|
|
73 |
|
Write series of bytes into memory without passing through MMU |
74 |
|
|
75 |
|
$emu->poke_code( 0xbeef, 0xff, 0x00, 0xff, 0x00, 0xaa ); |
76 |
|
|
77 |
|
=cut |
78 |
|
|
79 |
|
sub poke_code { |
80 |
|
my $self = shift; |
81 |
|
my $addr = shift; |
82 |
|
warn sprintf("# poke_code(%04x,%s)\n", $addr, dump( @_ )) if $self->debug; |
83 |
|
$mem[$addr++] = $_ foreach @_; |
84 |
|
} |
85 |
|
|
86 |
|
=head2 write_chunk |
87 |
|
|
88 |
|
$emu->write_chunk( $address, $chunk_of_data ); |
89 |
|
|
90 |
|
=cut |
91 |
|
|
92 |
|
sub write_chunk { |
93 |
|
my ($self, $addr, $chunk) = @_; |
94 |
|
my $len = length($chunk); |
95 |
|
splice @mem, $addr, $len, unpack('C*', $chunk); |
96 |
|
} |
97 |
|
|
98 |
|
=head2 ram |
99 |
|
|
100 |
|
Read searies of bytes from memory without passing through MMU |
101 |
|
|
102 |
|
$emu->ram( $from, $to ); |
103 |
|
|
104 |
|
=cut |
105 |
|
|
106 |
|
sub ram { |
107 |
|
my $self = shift; |
108 |
|
my ($from,$to) = @_; |
109 |
|
if ($from + $to) { |
110 |
|
printf "ram %04x - %04x\n", $from, $to; |
111 |
|
return $mem[$from .. $to - 1]; |
112 |
|
} |
113 |
|
printf "ram %04x\n", $from; |
114 |
|
return $mem[$from] if defined($from); |
115 |
|
confess "no from address"; |
116 |
|
} |
117 |
|
|
118 |
1; |
1; |