3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
|
6 |
use Carp; |
use Carp qw/confess/; |
7 |
use lib './lib'; |
use lib './lib'; |
8 |
#use Time::HiRes qw(time); |
#use Time::HiRes qw(time); |
9 |
use File::Slurp; |
use File::Slurp; |
10 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
11 |
use M6502; |
use M6502; |
12 |
|
|
13 |
use base qw(Class::Accessor M6502 Screen); |
use base qw(Class::Accessor M6502 Screen Prefs); |
14 |
__PACKAGE__->mk_accessors(qw(debug trace run_for mem_dump trace)); |
__PACKAGE__->mk_accessors(qw(run_for)); |
15 |
|
|
16 |
=head1 NAME |
=head1 NAME |
17 |
|
|
33 |
|
|
34 |
=head2 init |
=head2 init |
35 |
|
|
36 |
Start emulator |
Start emulator, open L<Screen>, load initial ROM images, and render memory |
37 |
|
|
38 |
=cut |
=cut |
39 |
|
|
46 |
warn "Orao calling upstream init\n"; |
warn "Orao calling upstream init\n"; |
47 |
$self->SUPER::init( $self, @_ ); |
$self->SUPER::init( $self, @_ ); |
48 |
|
|
49 |
warn "staring Orao $Orao::VERSION emulation\n"; |
warn "Orao $Orao::VERSION emulation starting\n"; |
50 |
|
|
51 |
$self->open_screen; |
$self->open_screen; |
52 |
$self->load_rom({ |
$self->load_rom({ |
135 |
} |
} |
136 |
} |
} |
137 |
|
|
138 |
|
# write chunk directly into memory, updateing vram if needed |
|
=head2 load_oraoemu |
|
|
|
|
|
=cut |
|
|
|
|
139 |
sub _write_chunk { |
sub _write_chunk { |
140 |
my $self = shift; |
my $self = shift; |
141 |
my ( $addr, $chunk ) = @_; |
my ( $addr, $chunk ) = @_; |
157 |
} |
} |
158 |
} |
} |
159 |
|
|
160 |
|
=head2 load_oraoemu |
161 |
|
|
162 |
|
Load binary files, ROM images and Orao Emulator files |
163 |
|
|
164 |
|
$orao->load_oraoemu( '/path/to/file', 0x1000 ); |
165 |
|
|
166 |
|
Returns true on success. |
167 |
|
|
168 |
|
=cut |
169 |
|
|
170 |
sub load_oraoemu { |
sub load_oraoemu { |
171 |
my $self = shift; |
my $self = shift; |
172 |
my ( $path, $addr ) = @_; |
my ( $path, $addr ) = @_; |
173 |
|
|
174 |
|
if ( ! -e $path ) { |
175 |
|
warn "ERROR: file $path doesn't exist\n"; |
176 |
|
return; |
177 |
|
} |
178 |
|
|
179 |
my $size = -s $path || confess "no size for $path: $!"; |
my $size = -s $path || confess "no size for $path: $!"; |
180 |
|
|
181 |
my $buff = read_file( $path ); |
my $buff = read_file( $path ); |
184 |
$addr = 0; |
$addr = 0; |
185 |
warn sprintf "loading oraoemu 64k dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size; |
warn sprintf "loading oraoemu 64k dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size; |
186 |
$self->_write_chunk( $addr, substr($buff,2) ); |
$self->_write_chunk( $addr, substr($buff,2) ); |
187 |
return; |
return 1; |
188 |
} elsif ( $size == 32800 ) { |
} elsif ( $size == 32800 ) { |
189 |
$addr = 0; |
$addr = 0; |
190 |
warn sprintf "loading oraoemu 1.3 dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size; |
warn sprintf "loading oraoemu 1.3 dump %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size; |
191 |
$self->_write_chunk( $addr, substr($buff,0x20) ); |
$self->_write_chunk( $addr, substr($buff,0x20) ); |
192 |
return; |
return 1; |
193 |
} |
} |
194 |
printf "loading %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size; |
printf "loading %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size; |
195 |
return $self->_write_chunk( $addr, $buff ); |
$self->_write_chunk( $addr, $buff ); |
196 |
|
return 1; |
197 |
|
|
198 |
my $chunk; |
my $chunk; |
199 |
|
|
211 |
|
|
212 |
$self->_write_chunk( $addr, $chunk ); |
$self->_write_chunk( $addr, $chunk ); |
213 |
|
|
214 |
|
return 1; |
215 |
}; |
}; |
216 |
|
|
217 |
=head2 save_dump |
=head2 save_dump |
248 |
return sprintf(" %04x %s\n", $a, |
return sprintf(" %04x %s\n", $a, |
249 |
join(" ", |
join(" ", |
250 |
map { |
map { |
251 |
sprintf( "%02x", $_ ) |
if ( defined($_) ) { |
252 |
|
sprintf( "%02x", $_ ) |
253 |
|
} else { |
254 |
|
' ' |
255 |
|
} |
256 |
} @mem[ $a .. $a+8 ] |
} @mem[ $a .. $a+8 ] |
257 |
) |
) |
258 |
); |
); |
299 |
$self->vram( $addr - 0x6000 , $byte ); |
$self->vram( $addr - 0x6000 , $byte ); |
300 |
} |
} |
301 |
|
|
|
if ( $addr > 0xafff ) { |
|
|
warn sprintf "access to %04x above affff aborting\n", $addr; |
|
|
return -1; |
|
|
} |
|
302 |
if ( $addr == 0x8800 ) { |
if ( $addr == 0x8800 ) { |
303 |
warn sprintf "sound ignored: %x\n", $byte; |
warn sprintf "sound ignored: %x\n", $byte; |
304 |
} |
} |
305 |
|
|
306 |
|
if ( $addr > 0xafff ) { |
307 |
|
warn sprintf "write access 0x%04x > 0xafff aborting\n", $addr; |
308 |
|
return; |
309 |
|
} |
310 |
|
|
311 |
$self->mmap_pixel( $addr, $byte, 0, 0 ); |
$self->mmap_pixel( $addr, $byte, 0, 0 ); |
312 |
|
|
313 |
$mem[$addr] = $byte; |
$mem[$addr] = $byte; |
321 |
|
|
322 |
=head2 prompt |
=head2 prompt |
323 |
|
|
324 |
$orao->prompt( $address, $last_command ); |
my ( $entered_line, @p ) = $orao->prompt( $address, $last_command ); |
325 |
|
|
326 |
=cut |
=cut |
327 |
|
|
339 |
warn "## prompt got: $in\n" if $self->debug; |
warn "## prompt got: $in\n" if $self->debug; |
340 |
$in ||= $last; |
$in ||= $last; |
341 |
$last = $in; |
$last = $in; |
342 |
return split(/\s+/, $in) if $in; |
return ( $in, split(/\s+/, $in) ) if $in; |
343 |
} |
} |
344 |
|
|
345 |
=head2 cli |
=head2 cli |
348 |
|
|
349 |
=cut |
=cut |
350 |
|
|
351 |
|
my $show_R = 0; |
352 |
|
|
353 |
sub cli { |
sub cli { |
354 |
my $self = shift; |
my $self = shift; |
355 |
my $a = $PC || confess "no pc?"; |
my $a = $PC || confess "no pc?"; |
356 |
while ( my @v = $self->prompt( $a, $last ) ) { |
warn $self->dump_R() if $show_R; |
357 |
|
while ( my ($line, @v) = $self->prompt( $a, $last ) ) { |
358 |
my $c = shift @v; |
my $c = shift @v; |
359 |
|
next unless defined($c); |
360 |
my $v = shift @v; |
my $v = shift @v; |
361 |
$v = hex($v) if $v && $v =~ m/^[0-9a-f]+$/; |
$v = hex($v) if $v && $v =~ m/^[0-9a-f]+$/; |
362 |
@v = map { hex($_) } @v; |
@v = map { hex($_) } @v; |
378 |
d\t\tdebug [$d] |
d\t\tdebug [$d] |
379 |
|
|
380 |
__USAGE__ |
__USAGE__ |
381 |
warn sprintf(" PC: %04x A:%02x P:%02x X:%02x Y:%02x S:%02x\n", $PC, $A, $P, $X, $Y, $S); |
warn $self->dump_R; |
382 |
} elsif ( $c =~ m/^e/i ) { |
} elsif ( $c =~ m/^e/i ) { |
383 |
$a = $v if defined($v); |
$a = $v if defined($v); |
384 |
my $to = shift @v; |
my $to = shift @v; |
385 |
$to = $a + 32 if ( ! $to || $to <= $a ); |
$to = $a + 32 if ( ! $to || $to <= $a ); |
386 |
my $lines = int( ($to - $a - 8) / 8 ); |
$to = 0xffff if ( $to > 0xffff ); |
387 |
printf "## m %04x %04x lines: %d\n", $a, $to, $lines; |
my $lines = int( ($to - $a + 8) / 8 ); |
388 |
while ( $lines ) { |
printf "## e %04x %04x (%d bytes) lines: %d\n", $a, $to, ($to-$a), $lines; |
389 |
|
while ( --$lines ) { |
390 |
print $self->hexdump( $a ); |
print $self->hexdump( $a ); |
391 |
$a += 8; |
$a += 8; |
|
$lines--; |
|
392 |
} |
} |
393 |
$last = '+'; |
$last = '+'; |
394 |
|
$show_R = 0; |
395 |
} elsif ( $c =~ m/^\+/ ) { |
} elsif ( $c =~ m/^\+/ ) { |
396 |
$a += 8; |
$a += 8; |
397 |
|
$show_R = 0; |
398 |
} elsif ( $c =~ m/^\-/ ) { |
} elsif ( $c =~ m/^\-/ ) { |
399 |
$a -= 8; |
$a -= 8; |
400 |
|
$show_R = 0; |
401 |
} elsif ( $c =~ m/^m/i ) { |
} elsif ( $c =~ m/^m/i ) { |
402 |
$a = $v; |
$a = $v if defined($v); |
403 |
$self->poke_code( $a, @v ); |
$self->poke_code( $a, @v ); |
404 |
printf "poke %d bytes at %04x\n", $#v + 1, $a; |
printf "poke %d bytes at %04x\n", $#v + 1, $a; |
405 |
$last = '+'; |
$last = '+'; |
406 |
|
$show_R = 0; |
407 |
} elsif ( $c =~ m/^l/i ) { |
} elsif ( $c =~ m/^l/i ) { |
408 |
my $to = shift @v || 0x1000; |
my $to = shift @v || 0x1000; |
409 |
$a = $to; |
$a = $to; |
415 |
} elsif ( $c =~ m/^r/i ) { |
} elsif ( $c =~ m/^r/i ) { |
416 |
$run_for = $v || 1; |
$run_for = $v || 1; |
417 |
print "run_for $run_for instructions\n"; |
print "run_for $run_for instructions\n"; |
418 |
|
$show_R = 1; |
419 |
last; |
last; |
420 |
} elsif ( $c =~ m/^(u|j)/ ) { |
} elsif ( $c =~ m/^(u|j)/ ) { |
421 |
my $to = $v || $a; |
my $to = $v || $a; |
422 |
printf "set pc to %04x\n", $to; |
printf "set pc to %04x\n", $to; |
423 |
$PC = $to; # remember for restart |
$PC = $to; # remember for restart |
424 |
$run_for = 1; |
$run_for = 1; |
425 |
$last = sprintf('m %04x', $to); |
$last = "r $run_for"; |
426 |
|
$show_R = 1; |
427 |
last; |
last; |
428 |
} elsif ( $c =~ m/^t/ ) { |
} elsif ( $c =~ m/^t/ ) { |
429 |
$self->trace( not $self->trace ); |
$self->trace( not $self->trace ); |
430 |
print "trace ", $self->trace ? 'on' : 'off', "\n"; |
print "trace ", $self->trace ? 'on' : 'off', "\n"; |
431 |
|
$last = ''; |
432 |
} elsif ( $c =~ m/^d/ ) { |
} elsif ( $c =~ m/^d/ ) { |
433 |
$self->debug( not $self->debug ); |
$self->debug( not $self->debug ); |
434 |
print "debug ", $self->debug ? 'on' : 'off', "\n"; |
print "debug ", $self->debug ? 'on' : 'off', "\n"; |
435 |
|
$last = ''; |
436 |
} else { |
} else { |
437 |
warn "# ignore $c\n"; |
warn "# ignored $line\n" if ($line); |
438 |
last; |
$last = ''; |
439 |
} |
} |
440 |
} |
} |
441 |
|
|
|
|
|
442 |
} |
} |
443 |
|
|
444 |
=head1 AUTHOR |
=head1 AUTHOR |