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/; |
|
use List::Util qw/first/; |
|
11 |
use M6502; |
use M6502; |
12 |
|
|
13 |
use base qw(Class::Accessor M6502 Screen Prefs); |
use base qw(Class::Accessor M6502 Screen Prefs); |
31 |
|
|
32 |
=cut |
=cut |
33 |
|
|
|
my @kbd_ports = ( |
|
|
0x87FC,0x87FD,0x87FA,0x87FB,0x87F6,0x87F7, |
|
|
0x87EE,0x87EF,0x87DE,0x87DF,0x87BE,0x87BF, |
|
|
0x877E,0x877F,0x86FE,0x86FF,0x85FE,0x85FF, |
|
|
0x83FE,0x83FF, |
|
|
); |
|
|
|
|
34 |
=head1 FUNCTIONS |
=head1 FUNCTIONS |
35 |
|
|
36 |
=head2 boot |
=head2 boot |
63 |
0x1000 => 'dump/SCRINV.BIN', |
0x1000 => 'dump/SCRINV.BIN', |
64 |
# should be 0x6000, but oraoemu has 2 byte prefix |
# should be 0x6000, but oraoemu has 2 byte prefix |
65 |
0x5FFE => 'dump/screen.dmp', |
0x5FFE => 'dump/screen.dmp', |
66 |
0xC000 => 'rom/BAS12.ROM', |
# 0xC000 => 'rom/BAS12.ROM', |
67 |
0xE000 => 'rom/CRT12.ROM', |
# 0xE000 => 'rom/CRT12.ROM', |
68 |
|
0xC000 => 'rom/BAS13.ROM', |
69 |
|
0xE000 => 'rom/CRT13.ROM', |
70 |
}); |
}); |
71 |
|
|
72 |
# $PC = 0xDD11; # BC |
# $PC = 0xDD11; # BC |
82 |
$self->trace( 0 ); |
$self->trace( 0 ); |
83 |
$self->debug( 0 ); |
$self->debug( 0 ); |
84 |
|
|
85 |
$self->render( @mem[ 0x6000 .. 0x7fff ] ); |
warn "rendering video memory\n"; |
86 |
|
$self->render_vram( @mem[ 0x6000 .. 0x7fff ] ); |
87 |
|
|
88 |
if ( $self->show_mem ) { |
if ( $self->show_mem ) { |
89 |
|
|
102 |
0xE000, 0xFFFF, 'sistemski ROM', |
0xE000, 0xFFFF, 'sistemski ROM', |
103 |
); |
); |
104 |
|
|
|
} else { |
|
|
|
|
|
warn "rendering video memory\n"; |
|
|
$self->render( @mem[ 0x6000 .. 0x7fff ] ); |
|
|
|
|
105 |
} |
} |
106 |
$self->sync; |
$self->sync; |
107 |
$self->trace( $trace ); |
$self->trace( $trace ); |
130 |
sub run { |
sub run { |
131 |
my $self = shift; |
my $self = shift; |
132 |
|
|
|
$self->show_mem( 1 ); |
|
|
|
|
133 |
$self->boot if ( ! $self->booted ); |
$self->boot if ( ! $self->booted ); |
134 |
$self->loop; |
$self->loop; |
135 |
}; |
}; |
172 |
$t = $end if ( $end < $t ); |
$t = $end if ( $end < $t ); |
173 |
|
|
174 |
warn sprintf("refresh video ram %04x-%04x\n", $f, $t); |
warn sprintf("refresh video ram %04x-%04x\n", $f, $t); |
175 |
# foreach my $a ( $f .. $t ) { |
$self->render_vram( @mem[ 0x6000 .. 0x7fff ] ); |
|
# $self->vram( $a - 0x6000 , $mem[ $a ] ); |
|
|
# } |
|
|
$self->render( @mem[ 0x6000 .. 0x7fff ] ); |
|
176 |
$self->render_mem( @mem ) if $self->show_mem; |
$self->render_mem( @mem ) if $self->show_mem; |
177 |
} |
} |
178 |
|
|
292 |
|
|
293 |
=cut |
=cut |
294 |
|
|
295 |
|
my $keyboard_none = 255; |
296 |
|
|
297 |
|
my $keyboard = { |
298 |
|
0x87FC => { |
299 |
|
'right' => 16, |
300 |
|
'down' => 128, |
301 |
|
'up' => 192, |
302 |
|
'left' => 224, |
303 |
|
'backspace' => 224, |
304 |
|
}, |
305 |
|
0x87FD => sub { |
306 |
|
my ( $self, $key ) = @_; |
307 |
|
if ( $key eq 'return' ) { |
308 |
|
M6502::_write( 0xfc, 13 ); |
309 |
|
warn "return\n"; |
310 |
|
return 0; |
311 |
|
} elsif ( $key =~ m/ ctrl/ || $self->key_down( 'left ctrl' ) || $self->key_down( 'right ctrl' ) ) { |
312 |
|
warn "ctrl\n"; |
313 |
|
return 16; |
314 |
|
} |
315 |
|
return $keyboard_none; |
316 |
|
}, |
317 |
|
0x87FA => { |
318 |
|
'f4' => 16, |
319 |
|
'f3' => 128, |
320 |
|
'f2' => 192, |
321 |
|
'f1' => 224, |
322 |
|
}, |
323 |
|
0x87FB => sub { |
324 |
|
my ( $self, $key ) = @_; |
325 |
|
if ( $key eq 'space' ) { |
326 |
|
return 32; |
327 |
|
} elsif ( $self->key_down( 'left shift' ) || $self->key_down( 'right shift' ) ) { |
328 |
|
warn "shift\n"; |
329 |
|
return 16; |
330 |
|
} |
331 |
|
return $keyboard_none; |
332 |
|
}, |
333 |
|
0x87F6 => { |
334 |
|
'6' => 16, |
335 |
|
't' => 128, |
336 |
|
'y' => 192, # hr: z |
337 |
|
'r' => 224, |
338 |
|
}, |
339 |
|
0x87F7 => { |
340 |
|
'5' => 32, |
341 |
|
'4' => 16, |
342 |
|
}, |
343 |
|
0x87EE => { |
344 |
|
'7' => 16, |
345 |
|
'u' => 128, |
346 |
|
'i' => 192, |
347 |
|
'o' => 224, |
348 |
|
}, |
349 |
|
0x87EF => { |
350 |
|
'8' => 32, |
351 |
|
'9' => 16, |
352 |
|
}, |
353 |
|
0x87DE => { |
354 |
|
'1' => 16, |
355 |
|
'w' => 128, |
356 |
|
'q' => 192, |
357 |
|
'e' => 224, |
358 |
|
}, |
359 |
|
0x87DF => { |
360 |
|
'2' => 32, |
361 |
|
'3' => 16, |
362 |
|
}, |
363 |
|
0x87BE => { |
364 |
|
'm' => 16, |
365 |
|
'k' => 128, |
366 |
|
'j' => 192, |
367 |
|
'l' => 224, |
368 |
|
}, |
369 |
|
0x87BF => { |
370 |
|
',' => 32, # < |
371 |
|
'.' => 16, # > |
372 |
|
}, |
373 |
|
0x877E => { |
374 |
|
'z' => 16, # hr:y |
375 |
|
's' => 128, |
376 |
|
'a' => 192, |
377 |
|
'd' => 224, |
378 |
|
}, |
379 |
|
0x877F => { |
380 |
|
'x' => 32, |
381 |
|
'c' => 16, |
382 |
|
}, |
383 |
|
0x86FE => { |
384 |
|
'n' => 16, |
385 |
|
'g' => 128, |
386 |
|
'h' => 192, |
387 |
|
'f' => 224, |
388 |
|
}, |
389 |
|
0x86FF => { |
390 |
|
'b' => 32, |
391 |
|
'v' => 16, |
392 |
|
}, |
393 |
|
0x85FE => { |
394 |
|
'<' => 16, # : |
395 |
|
'\\' => 128, # ¾ |
396 |
|
'\'' => 192, # æ |
397 |
|
';' => 224, # è |
398 |
|
}, |
399 |
|
0x85FF => { |
400 |
|
'/' => 32, |
401 |
|
'f11' => 16, # ^ |
402 |
|
}, |
403 |
|
0x83FE => { |
404 |
|
'f12' => 16, # ; |
405 |
|
'[' => 128, # ¹ |
406 |
|
']' => 192, # ð |
407 |
|
'p' => 224, |
408 |
|
}, |
409 |
|
0x83FF => { |
410 |
|
'-' => 32, |
411 |
|
'0' => 16, |
412 |
|
}, |
413 |
|
}; |
414 |
|
|
415 |
sub read { |
sub read { |
416 |
my $self = shift; |
my $self = shift; |
417 |
my ($addr) = @_; |
my ($addr) = @_; |
421 |
|
|
422 |
# keyboard |
# keyboard |
423 |
|
|
424 |
if ( first { $addr == $_ } @kbd_ports ) { |
if ( defined( $keyboard->{$addr} ) ) { |
425 |
warn sprintf("keyboard port: %04x\n",$addr) if $self->trace; |
warn sprintf("keyboard port: %04x\n",$addr) if $self->trace; |
426 |
} elsif ( $addr == 0x87fc ) { |
my $key = $self->key_pressed; |
427 |
warn "0x87fc - arrows/back\n"; |
if ( defined($key) ) { |
428 |
=for pascal |
my $ret = $keyboard_none; |
429 |
if VKey=VK_RIGHT then Result:=16; |
my $r = $keyboard->{$addr} || confess "no definition for keyboard port found"; |
430 |
if VKey=VK_DOWN then Result:=128; |
if ( ref($r) eq 'CODE' ) { |
431 |
if VKey=VK_UP then Result:=192; |
$ret = $r->($self, $key); |
432 |
if VKey=VK_LEFT then Result:=224; |
} elsif ( defined($r->{$key}) ) { |
433 |
if Ord(KeyPressed)=VK_BACK then Result:=224; |
$ret = $r->{$key}; |
434 |
=cut |
if ( ref($ret) eq 'CODE' ) { |
435 |
} elsif ( $addr == 0x87fd ) { |
$ret = $ret->($self); |
436 |
warn "0x87fd - enter\n"; |
} |
437 |
=for pascal |
} else { |
438 |
if KeyPressed=Chr(13) then begin |
warn sprintf("keyboard port: %04x unknown key: '%s'\n", $addr, $key) if $debug; |
439 |
Mem[$FC]:=13; |
} |
440 |
Result:=0; |
warn sprintf("keyboard port: %04x key:%s code:%d\n",$addr,$key,$ret) if ( $ret != $keyboard_none ); |
441 |
end; |
return $ret; |
442 |
=cut |
} |
443 |
} elsif ( $addr == 0x87fa ) { |
return $keyboard_none; |
|
warn "0x87fa = F1 - F4\n"; |
|
|
=for pascal |
|
|
if VKey=VK_F4 then Result:=16; |
|
|
if VKey=VK_F3 then Result:=128; |
|
|
if VKey=VK_F2 then Result:=192; |
|
|
if VKey=VK_F1 then Result:=224; |
|
|
=cut |
|
|
} elsif ( $addr == 0x87fb ) { |
|
|
warn "0x87fb\n"; |
|
|
=for pascal |
|
|
if KeyPressed=Chr(32) then Result:=32; |
|
|
if KeyPressed='"' then Result:=16; |
|
|
if KeyPressed='!' then Result:=16; |
|
|
if KeyPressed='$' then Result:=16; |
|
|
if KeyPressed='%' then Result:=16; |
|
|
if KeyPressed='&' then Result:=16; |
|
|
if KeyPressed='(' then Result:=16; |
|
|
if KeyPressed=')' then Result:=16; |
|
|
if KeyPressed='=' then Result:=16; |
|
|
if KeyPressed='#' then Result:=16; |
|
|
if KeyPressed='+' then Result:=16; |
|
|
if KeyPressed='*' then Result:=16; |
|
|
if KeyPressed='?' then Result:=16; |
|
|
if KeyPressed='<' then Result:=16; |
|
|
if KeyPressed='>' then Result:=16; |
|
|
if VKey=191 then Result:=16; |
|
|
=cut |
|
444 |
} |
} |
445 |
|
|
446 |
$self->mmap_pixel( $addr, 0, $byte, 0 ); |
$self->mmap_pixel( $addr, 0, $byte, 0 ); |
460 |
my ($addr,$byte) = @_; |
my ($addr,$byte) = @_; |
461 |
warn sprintf("# Orao::write(%04x,%02x)\n", $addr, $byte) if $self->trace; |
warn sprintf("# Orao::write(%04x,%02x)\n", $addr, $byte) if $self->trace; |
462 |
|
|
|
if ( $addr >= 0x6000 && $addr < 0x8000 ) { |
|
|
$self->vram( $addr - 0x6000 , $byte ); |
|
|
} |
|
|
|
|
463 |
if ( $addr == 0x8800 ) { |
if ( $addr == 0x8800 ) { |
464 |
warn sprintf "sound ignored: %x\n", $byte; |
warn sprintf "sound ignored: %x\n", $byte; |
465 |
} |
} |