12 |
use M6502; |
use M6502; |
13 |
|
|
14 |
use base qw(Class::Accessor M6502 Screen Prefs); |
use base qw(Class::Accessor M6502 Screen Prefs); |
15 |
__PACKAGE__->mk_accessors(qw(run_for)); |
__PACKAGE__->mk_accessors(qw(booted run_for)); |
16 |
|
|
17 |
=head1 NAME |
=head1 NAME |
18 |
|
|
20 |
|
|
21 |
=head1 VERSION |
=head1 VERSION |
22 |
|
|
23 |
Version 0.02 |
Version 0.04 |
24 |
|
|
25 |
=cut |
=cut |
26 |
|
|
27 |
our $VERSION = '0.02'; |
our $VERSION = '0.04'; |
28 |
|
|
29 |
=head1 SUMMARY |
=head1 SUMMARY |
30 |
|
|
39 |
0x83FE,0x83FF, |
0x83FE,0x83FF, |
40 |
); |
); |
41 |
|
|
42 |
|
=head1 FUNCTIONS |
43 |
|
|
44 |
=head2 boot |
=head2 boot |
45 |
|
|
46 |
Start emulator, open L<Screen>, load initial ROM images, and render memory |
Start emulator, open L<Screen>, load initial ROM images, and render memory |
57 |
sub boot { |
sub boot { |
58 |
my $self = shift; |
my $self = shift; |
59 |
warn "Orao calling upstream init\n"; |
warn "Orao calling upstream init\n"; |
60 |
$self->SUPER::init( $self, @_ ); |
$self->SUPER::init( |
61 |
|
read => sub { $self->read( @_ ) }, |
62 |
|
write => sub { $self->write( @_ ) }, |
63 |
|
); |
64 |
|
|
65 |
warn "Orao $Orao::VERSION emulation starting\n"; |
warn "Orao $Orao::VERSION emulation starting\n"; |
66 |
|
|
67 |
|
warn "emulating ", $#mem, " bytes of memory\n"; |
68 |
|
|
69 |
$self->open_screen; |
$self->open_screen; |
70 |
$self->load_rom({ |
$self->load_rom({ |
71 |
0x1000 => 'dump/SCRINV.BIN', |
0x1000 => 'dump/SCRINV.BIN', |
126 |
|
|
127 |
M6502::reset(); |
M6502::reset(); |
128 |
|
|
129 |
|
$self->booted( 1 ); |
130 |
} |
} |
131 |
|
|
132 |
|
=head2 run |
133 |
|
|
134 |
|
Run interactive emulation loop |
135 |
|
|
136 |
|
$orao->run; |
137 |
|
|
138 |
|
=cut |
139 |
|
|
140 |
|
sub run { |
141 |
|
my $self = shift; |
142 |
|
|
143 |
|
$self->boot if ( ! $self->booted ); |
144 |
|
|
145 |
|
while ( 1 ) { |
146 |
|
$self->cli; |
147 |
|
M6502::exec($run_for); |
148 |
|
} |
149 |
|
}; |
150 |
|
|
151 |
|
=head1 Helper functions |
152 |
|
|
153 |
=head2 load_rom |
=head2 load_rom |
154 |
|
|
155 |
called to init memory and load initial rom images |
called to init memory and load initial rom images |
165 |
|
|
166 |
foreach my $addr ( sort keys %$loaded_files ) { |
foreach my $addr ( sort keys %$loaded_files ) { |
167 |
my $path = $loaded_files->{$addr}; |
my $path = $loaded_files->{$addr}; |
168 |
$self->load_oraoemu( $path, $addr ); |
$self->load_image( $path, $addr ); |
169 |
} |
} |
170 |
} |
} |
171 |
|
|
193 |
$self->render_mem( @mem ) if $self->show_mem; |
$self->render_mem( @mem ) if $self->show_mem; |
194 |
} |
} |
195 |
|
|
196 |
=head2 load_oraoemu |
=head2 load_image |
197 |
|
|
198 |
Load binary files, ROM images and Orao Emulator files |
Load binary files, ROM images and Orao Emulator files |
199 |
|
|
200 |
$orao->load_oraoemu( '/path/to/file', 0x1000 ); |
$orao->load_image( '/path/to/file', 0x1000 ); |
201 |
|
|
202 |
Returns true on success. |
Returns true on success. |
203 |
|
|
204 |
=cut |
=cut |
205 |
|
|
206 |
sub load_oraoemu { |
sub load_image { |
207 |
my $self = shift; |
my $self = shift; |
208 |
my ( $path, $addr ) = @_; |
my ( $path, $addr ) = @_; |
209 |
|
|
313 |
my $self = shift; |
my $self = shift; |
314 |
my ($addr) = @_; |
my ($addr) = @_; |
315 |
my $byte = $mem[$addr]; |
my $byte = $mem[$addr]; |
316 |
|
confess sprintf("can't find memory at address %04x",$addr) unless defined($byte); |
317 |
warn sprintf("# Orao::read(%04x) = %02x\n", $addr, $byte) if $self->trace; |
warn sprintf("# Orao::read(%04x) = %02x\n", $addr, $byte) if $self->trace; |
318 |
|
|
319 |
# keyboard |
# keyboard |
393 |
} |
} |
394 |
|
|
395 |
if ( $addr > 0xafff ) { |
if ( $addr > 0xafff ) { |
396 |
warn sprintf "write access 0x%04x > 0xafff aborting\n", $addr; |
confess sprintf "write access 0x%04x > 0xafff aborting\n", $addr; |
|
return; |
|
397 |
} |
} |
398 |
|
|
399 |
$self->mmap_pixel( $addr, $byte, 0, 0 ); |
$self->mmap_pixel( $addr, $byte, 0, 0 ); |
495 |
} elsif ( $c =~ m/^l/i ) { |
} elsif ( $c =~ m/^l/i ) { |
496 |
my $to = shift @v || 0x1000; |
my $to = shift @v || 0x1000; |
497 |
$a = $to; |
$a = $to; |
498 |
$self->load_oraoemu( $v, $a ); |
$self->load_image( $v, $a ); |
499 |
$last = ''; |
$last = ''; |
500 |
} elsif ( $c =~ m/^s/i ) { |
} elsif ( $c =~ m/^s/i ) { |
501 |
$self->save_dump( $v || 'mem.dump', @v ); |
$self->save_dump( $v || 'mem.dump', @v ); |