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 List::Util qw/first/; |
12 |
use M6502; |
use M6502; |
13 |
|
|
14 |
use base qw(Class::Accessor M6502 Screen Prefs); |
use base qw(Class::Accessor M6502 Screen Prefs); |
32 |
|
|
33 |
=cut |
=cut |
34 |
|
|
35 |
|
my @kbd_ports = ( |
36 |
|
0x87FC,0x87FD,0x87FA,0x87FB,0x87F6,0x87F7, |
37 |
|
0x87EE,0x87EF,0x87DE,0x87DF,0x87BE,0x87BF, |
38 |
|
0x877E,0x877F,0x86FE,0x86FF,0x85FE,0x85FF, |
39 |
|
0x83FE,0x83FF, |
40 |
|
); |
41 |
|
|
42 |
=head2 init |
=head2 init |
43 |
|
|
44 |
Start emulator, open L<Screen>, load initial ROM images, and render memory |
Start emulator, open L<Screen>, load initial ROM images, and render memory |
59 |
$self->open_screen; |
$self->open_screen; |
60 |
$self->load_rom({ |
$self->load_rom({ |
61 |
0x1000 => 'dump/SCRINV.BIN', |
0x1000 => 'dump/SCRINV.BIN', |
62 |
|
# should be 0x6000, but oraoemu has 2 byte prefix |
63 |
|
0x5FFE => 'dump/screen.dmp', |
64 |
0xC000 => 'rom/BAS12.ROM', |
0xC000 => 'rom/BAS12.ROM', |
65 |
0xE000 => 'rom/CRT12.ROM', |
0xE000 => 'rom/CRT12.ROM', |
66 |
}); |
}); |
67 |
|
|
68 |
$PC = 0xDD11; # BC |
# $PC = 0xDD11; # BC |
69 |
# $PC = 0xC274; # MC |
# $PC = 0xC274; # MC |
70 |
|
|
71 |
|
$PC = 0xff89; |
72 |
|
|
73 |
$orao = $self; |
$orao = $self; |
74 |
|
|
75 |
# $self->prompt( 0x1000 ); |
# $self->prompt( 0x1000 ); |
78 |
$self->trace( 0 ); |
$self->trace( 0 ); |
79 |
$self->debug( 0 ); |
$self->debug( 0 ); |
80 |
|
|
81 |
|
$self->render( @mem[ 0x6000 .. 0x7fff ] ); |
82 |
|
|
83 |
if ( $self->show_mem ) { |
if ( $self->show_mem ) { |
84 |
|
|
85 |
warn "rendering memory map\n"; |
warn "rendering memory map\n"; |
86 |
|
|
87 |
|
$self->render_mem( @mem ); |
88 |
|
|
89 |
my @mmap = ( |
my @mmap = ( |
90 |
0x0000, 0x03FF, 'nulti blok', |
0x0000, 0x03FF, 'nulti blok', |
91 |
0x0400, 0x5FFF, 'korisnički RAM (23K)', |
0x0400, 0x5FFF, 'korisnički RAM (23K)', |
97 |
0xE000, 0xFFFF, 'sistemski ROM', |
0xE000, 0xFFFF, 'sistemski ROM', |
98 |
); |
); |
99 |
|
|
|
foreach my $i ( 0 .. $#mmap / 3 ) { |
|
|
my $o = $i * 3; |
|
|
my ( $from, $to, $desc ) = @mmap[$o,$o+1,$o+2]; |
|
|
printf "%04x - %04x - %s\n", $from, $to, $desc; |
|
|
for my $a ( $from .. $to ) { |
|
|
if ( $a >= 0x6000 && $a < 0x8000 ) { |
|
|
my $b = $self->read( $a ); |
|
|
$self->vram( $a - 0x6000, $b ); |
|
|
} else { |
|
|
$self->read( $a ); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
100 |
} else { |
} else { |
101 |
|
|
102 |
warn "rendering video memory\n"; |
warn "rendering video memory\n"; |
103 |
for my $a ( 0x6000 .. 0x7fff ) { |
$self->render( @mem[ 0x6000 .. 0x7fff ] ); |
|
$self->vram( $a - 0x6000, $mem[$a] ); |
|
|
} |
|
104 |
|
|
105 |
} |
} |
106 |
$self->sync; |
$self->sync; |
152 |
$t = $end if ( $end < $t ); |
$t = $end if ( $end < $t ); |
153 |
|
|
154 |
warn sprintf("refresh video ram %04x-%04x\n", $f, $t); |
warn sprintf("refresh video ram %04x-%04x\n", $f, $t); |
155 |
foreach my $a ( $f .. $t ) { |
# foreach my $a ( $f .. $t ) { |
156 |
$self->vram( $a - 0x6000 , $mem[ $a ] ); |
# $self->vram( $a - 0x6000 , $mem[ $a ] ); |
157 |
} |
# } |
158 |
|
$self->render( @mem[ 0x6000 .. 0x7fff ] ); |
159 |
|
$self->render_mem( @mem ) if $self->show_mem; |
160 |
} |
} |
161 |
|
|
162 |
=head2 load_oraoemu |
=head2 load_oraoemu |
250 |
return sprintf(" %04x %s\n", $a, |
return sprintf(" %04x %s\n", $a, |
251 |
join(" ", |
join(" ", |
252 |
map { |
map { |
253 |
sprintf( "%02x", $_ ) |
if ( defined($_) ) { |
254 |
|
sprintf( "%02x", $_ ) |
255 |
|
} else { |
256 |
|
' ' |
257 |
|
} |
258 |
} @mem[ $a .. $a+8 ] |
} @mem[ $a .. $a+8 ] |
259 |
) |
) |
260 |
); |
); |
280 |
my ($addr) = @_; |
my ($addr) = @_; |
281 |
my $byte = $mem[$addr]; |
my $byte = $mem[$addr]; |
282 |
warn sprintf("# Orao::read(%04x) = %02x\n", $addr, $byte) if $self->trace; |
warn sprintf("# Orao::read(%04x) = %02x\n", $addr, $byte) if $self->trace; |
283 |
|
|
284 |
|
# keyboard |
285 |
|
|
286 |
|
if ( first { $addr == $_ } @kbd_ports ) { |
287 |
|
warn sprintf("keyboard port: %04x\n",$addr); |
288 |
|
} elsif ( $addr == 0x87fc ) { |
289 |
|
warn "0x87fc - arrows/back\n"; |
290 |
|
=for pascal |
291 |
|
if VKey=VK_RIGHT then Result:=16; |
292 |
|
if VKey=VK_DOWN then Result:=128; |
293 |
|
if VKey=VK_UP then Result:=192; |
294 |
|
if VKey=VK_LEFT then Result:=224; |
295 |
|
if Ord(KeyPressed)=VK_BACK then Result:=224; |
296 |
|
=cut |
297 |
|
} elsif ( $addr == 0x87fd ) { |
298 |
|
warn "0x87fd - enter\n"; |
299 |
|
=for pascal |
300 |
|
if KeyPressed=Chr(13) then begin |
301 |
|
Mem[$FC]:=13; |
302 |
|
Result:=0; |
303 |
|
end; |
304 |
|
=cut |
305 |
|
} elsif ( $addr == 0x87fa ) { |
306 |
|
warn "0x87fa = F1 - F4\n"; |
307 |
|
=for pascal |
308 |
|
if VKey=VK_F4 then Result:=16; |
309 |
|
if VKey=VK_F3 then Result:=128; |
310 |
|
if VKey=VK_F2 then Result:=192; |
311 |
|
if VKey=VK_F1 then Result:=224; |
312 |
|
=cut |
313 |
|
} elsif ( $addr == 0x87fb ) { |
314 |
|
warn "0x87fb\n"; |
315 |
|
=for pascal |
316 |
|
if KeyPressed=Chr(32) then Result:=32; |
317 |
|
if KeyPressed='"' then Result:=16; |
318 |
|
if KeyPressed='!' then Result:=16; |
319 |
|
if KeyPressed='$' then Result:=16; |
320 |
|
if KeyPressed='%' then Result:=16; |
321 |
|
if KeyPressed='&' then Result:=16; |
322 |
|
if KeyPressed='(' then Result:=16; |
323 |
|
if KeyPressed=')' then Result:=16; |
324 |
|
if KeyPressed='=' then Result:=16; |
325 |
|
if KeyPressed='#' then Result:=16; |
326 |
|
if KeyPressed='+' then Result:=16; |
327 |
|
if KeyPressed='*' then Result:=16; |
328 |
|
if KeyPressed='?' then Result:=16; |
329 |
|
if KeyPressed='<' then Result:=16; |
330 |
|
if KeyPressed='>' then Result:=16; |
331 |
|
if VKey=191 then Result:=16; |
332 |
|
=cut |
333 |
|
} |
334 |
|
|
335 |
$self->mmap_pixel( $addr, 0, $byte, 0 ); |
$self->mmap_pixel( $addr, 0, $byte, 0 ); |
336 |
return $byte; |
return $byte; |
337 |
} |
} |
358 |
} |
} |
359 |
|
|
360 |
if ( $addr > 0xafff ) { |
if ( $addr > 0xafff ) { |
361 |
confess sprintf "write access 0x%04x > 0xafff aborting\n", $addr; |
warn sprintf "write access 0x%04x > 0xafff aborting\n", $addr; |
362 |
|
return; |
363 |
} |
} |
364 |
|
|
365 |
$self->mmap_pixel( $addr, $byte, 0, 0 ); |
$self->mmap_pixel( $addr, $byte, 0, 0 ); |
402 |
|
|
403 |
=cut |
=cut |
404 |
|
|
405 |
|
my $show_R = 0; |
406 |
|
|
407 |
sub cli { |
sub cli { |
408 |
my $self = shift; |
my $self = shift; |
409 |
my $a = $PC || confess "no pc?"; |
my $a = $PC || confess "no pc?"; |
410 |
|
warn $self->dump_R() if $show_R; |
411 |
while ( my ($line, @v) = $self->prompt( $a, $last ) ) { |
while ( my ($line, @v) = $self->prompt( $a, $last ) ) { |
412 |
my $c = shift @v; |
my $c = shift @v; |
413 |
next unless defined($c); |
next unless defined($c); |
432 |
d\t\tdebug [$d] |
d\t\tdebug [$d] |
433 |
|
|
434 |
__USAGE__ |
__USAGE__ |
435 |
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; |
436 |
} elsif ( $c =~ m/^e/i ) { |
} elsif ( $c =~ m/^e/i ) { |
437 |
$a = $v if defined($v); |
$a = $v if defined($v); |
438 |
my $to = shift @v; |
my $to = shift @v; |
439 |
$to = $a + 32 if ( ! $to || $to <= $a ); |
$to = $a + 32 if ( ! $to || $to <= $a ); |
440 |
|
$to = 0xffff if ( $to > 0xffff ); |
441 |
my $lines = int( ($to - $a + 8) / 8 ); |
my $lines = int( ($to - $a + 8) / 8 ); |
442 |
printf "## e %04x %04x (%d bytes) lines: %d\n", $a, $to, ($to-$a), $lines; |
printf "## e %04x %04x (%d bytes) lines: %d\n", $a, $to, ($to-$a), $lines; |
443 |
while ( --$lines ) { |
while ( --$lines ) { |
445 |
$a += 8; |
$a += 8; |
446 |
} |
} |
447 |
$last = '+'; |
$last = '+'; |
448 |
|
$show_R = 0; |
449 |
} elsif ( $c =~ m/^\+/ ) { |
} elsif ( $c =~ m/^\+/ ) { |
450 |
$a += 8; |
$a += 8; |
451 |
|
$show_R = 0; |
452 |
} elsif ( $c =~ m/^\-/ ) { |
} elsif ( $c =~ m/^\-/ ) { |
453 |
$a -= 8; |
$a -= 8; |
454 |
|
$show_R = 0; |
455 |
} elsif ( $c =~ m/^m/i ) { |
} elsif ( $c =~ m/^m/i ) { |
456 |
$a = $v; |
$a = $v if defined($v); |
457 |
$self->poke_code( $a, @v ); |
$self->poke_code( $a, @v ); |
458 |
printf "poke %d bytes at %04x\n", $#v + 1, $a; |
printf "poke %d bytes at %04x\n", $#v + 1, $a; |
459 |
$last = '+'; |
$last = '+'; |
460 |
|
$show_R = 0; |
461 |
} elsif ( $c =~ m/^l/i ) { |
} elsif ( $c =~ m/^l/i ) { |
462 |
my $to = shift @v || 0x1000; |
my $to = shift @v || 0x1000; |
463 |
$a = $to; |
$a = $to; |
469 |
} elsif ( $c =~ m/^r/i ) { |
} elsif ( $c =~ m/^r/i ) { |
470 |
$run_for = $v || 1; |
$run_for = $v || 1; |
471 |
print "run_for $run_for instructions\n"; |
print "run_for $run_for instructions\n"; |
472 |
|
$show_R = 1; |
473 |
last; |
last; |
474 |
} elsif ( $c =~ m/^(u|j)/ ) { |
} elsif ( $c =~ m/^(u|j)/ ) { |
475 |
my $to = $v || $a; |
my $to = $v || $a; |
477 |
$PC = $to; # remember for restart |
$PC = $to; # remember for restart |
478 |
$run_for = 1; |
$run_for = 1; |
479 |
$last = "r $run_for"; |
$last = "r $run_for"; |
480 |
|
$show_R = 1; |
481 |
last; |
last; |
482 |
} elsif ( $c =~ m/^t/ ) { |
} elsif ( $c =~ m/^t/ ) { |
483 |
$self->trace( not $self->trace ); |
$self->trace( not $self->trace ); |