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); |
15 |
__PACKAGE__->mk_accessors(qw(run_for)); |
__PACKAGE__->mk_accessors(qw(booted)); |
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 |
|
|
32 |
|
|
33 |
=cut |
=cut |
34 |
|
|
35 |
=head2 init |
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 |
|
=head1 FUNCTIONS |
43 |
|
|
44 |
|
=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 |
47 |
|
|
48 |
|
my $orao = Orao->new({}); |
49 |
|
$orao->boot; |
50 |
|
|
51 |
=cut |
=cut |
52 |
|
|
53 |
our $orao; |
our $orao; |
54 |
|
|
55 |
select(STDERR); $| = 1; |
select(STDERR); $| = 1; |
56 |
|
|
57 |
sub init { |
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', |
78 |
# $PC = 0xDD11; # BC |
# $PC = 0xDD11; # BC |
79 |
# $PC = 0xC274; # MC |
# $PC = 0xC274; # MC |
80 |
|
|
81 |
|
$PC = 0xff89; |
82 |
|
|
83 |
$orao = $self; |
$orao = $self; |
84 |
|
|
85 |
# $self->prompt( 0x1000 ); |
# $self->prompt( 0x1000 ); |
107 |
0xE000, 0xFFFF, 'sistemski ROM', |
0xE000, 0xFFFF, 'sistemski ROM', |
108 |
); |
); |
109 |
|
|
|
if(0){ |
|
|
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 ); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
110 |
} else { |
} else { |
111 |
|
|
112 |
warn "rendering video memory\n"; |
warn "rendering video memory\n"; |
|
# for my $a ( 0x6000 .. 0x7fff ) { |
|
|
# $self->vram( $a - 0x6000, $mem[$a] ); |
|
|
# } |
|
113 |
$self->render( @mem[ 0x6000 .. 0x7fff ] ); |
$self->render( @mem[ 0x6000 .. 0x7fff ] ); |
114 |
|
|
115 |
} |
} |
119 |
|
|
120 |
#( $A, $P, $X, $Y, $S, $IPeriod ) = ( 1, 2, 3, 4, 5, 6 ); |
#( $A, $P, $X, $Y, $S, $IPeriod ) = ( 1, 2, 3, 4, 5, 6 ); |
121 |
|
|
122 |
warn "Orao init finished", |
warn "Orao boot finished", |
123 |
$self->trace ? ' trace' : '', |
$self->trace ? ' trace' : '', |
124 |
$self->debug ? ' debug' : '', |
$self->debug ? ' debug' : '', |
125 |
"\n"; |
"\n"; |
126 |
|
|
127 |
|
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 |
|
$self->loop; |
145 |
|
}; |
146 |
|
|
147 |
|
=head1 Helper functions |
148 |
|
|
149 |
=head2 load_rom |
=head2 load_rom |
150 |
|
|
151 |
called to init memory and load initial rom images |
called to init memory and load initial rom images |
161 |
|
|
162 |
foreach my $addr ( sort keys %$loaded_files ) { |
foreach my $addr ( sort keys %$loaded_files ) { |
163 |
my $path = $loaded_files->{$addr}; |
my $path = $loaded_files->{$addr}; |
164 |
$self->load_oraoemu( $path, $addr ); |
$self->load_image( $path, $addr ); |
165 |
} |
} |
166 |
} |
} |
167 |
|
|
186 |
# $self->vram( $a - 0x6000 , $mem[ $a ] ); |
# $self->vram( $a - 0x6000 , $mem[ $a ] ); |
187 |
# } |
# } |
188 |
$self->render( @mem[ 0x6000 .. 0x7fff ] ); |
$self->render( @mem[ 0x6000 .. 0x7fff ] ); |
189 |
|
$self->render_mem( @mem ) if $self->show_mem; |
190 |
} |
} |
191 |
|
|
192 |
=head2 load_oraoemu |
=head2 load_image |
193 |
|
|
194 |
Load binary files, ROM images and Orao Emulator files |
Load binary files, ROM images and Orao Emulator files |
195 |
|
|
196 |
$orao->load_oraoemu( '/path/to/file', 0x1000 ); |
$orao->load_image( '/path/to/file', 0x1000 ); |
197 |
|
|
198 |
Returns true on success. |
Returns true on success. |
199 |
|
|
200 |
=cut |
=cut |
201 |
|
|
202 |
sub load_oraoemu { |
sub load_image { |
203 |
my $self = shift; |
my $self = shift; |
204 |
my ( $path, $addr ) = @_; |
my ( $path, $addr ) = @_; |
205 |
|
|
309 |
my $self = shift; |
my $self = shift; |
310 |
my ($addr) = @_; |
my ($addr) = @_; |
311 |
my $byte = $mem[$addr]; |
my $byte = $mem[$addr]; |
312 |
|
confess sprintf("can't find memory at address %04x",$addr) unless defined($byte); |
313 |
warn sprintf("# Orao::read(%04x) = %02x\n", $addr, $byte) if $self->trace; |
warn sprintf("# Orao::read(%04x) = %02x\n", $addr, $byte) if $self->trace; |
314 |
|
|
315 |
|
# keyboard |
316 |
|
|
317 |
|
if ( first { $addr == $_ } @kbd_ports ) { |
318 |
|
warn sprintf("keyboard port: %04x\n",$addr); |
319 |
|
} elsif ( $addr == 0x87fc ) { |
320 |
|
warn "0x87fc - arrows/back\n"; |
321 |
|
=for pascal |
322 |
|
if VKey=VK_RIGHT then Result:=16; |
323 |
|
if VKey=VK_DOWN then Result:=128; |
324 |
|
if VKey=VK_UP then Result:=192; |
325 |
|
if VKey=VK_LEFT then Result:=224; |
326 |
|
if Ord(KeyPressed)=VK_BACK then Result:=224; |
327 |
|
=cut |
328 |
|
} elsif ( $addr == 0x87fd ) { |
329 |
|
warn "0x87fd - enter\n"; |
330 |
|
=for pascal |
331 |
|
if KeyPressed=Chr(13) then begin |
332 |
|
Mem[$FC]:=13; |
333 |
|
Result:=0; |
334 |
|
end; |
335 |
|
=cut |
336 |
|
} elsif ( $addr == 0x87fa ) { |
337 |
|
warn "0x87fa = F1 - F4\n"; |
338 |
|
=for pascal |
339 |
|
if VKey=VK_F4 then Result:=16; |
340 |
|
if VKey=VK_F3 then Result:=128; |
341 |
|
if VKey=VK_F2 then Result:=192; |
342 |
|
if VKey=VK_F1 then Result:=224; |
343 |
|
=cut |
344 |
|
} elsif ( $addr == 0x87fb ) { |
345 |
|
warn "0x87fb\n"; |
346 |
|
=for pascal |
347 |
|
if KeyPressed=Chr(32) then Result:=32; |
348 |
|
if KeyPressed='"' then Result:=16; |
349 |
|
if KeyPressed='!' then Result:=16; |
350 |
|
if KeyPressed='$' then Result:=16; |
351 |
|
if KeyPressed='%' then Result:=16; |
352 |
|
if KeyPressed='&' then Result:=16; |
353 |
|
if KeyPressed='(' then Result:=16; |
354 |
|
if KeyPressed=')' then Result:=16; |
355 |
|
if KeyPressed='=' then Result:=16; |
356 |
|
if KeyPressed='#' then Result:=16; |
357 |
|
if KeyPressed='+' then Result:=16; |
358 |
|
if KeyPressed='*' then Result:=16; |
359 |
|
if KeyPressed='?' then Result:=16; |
360 |
|
if KeyPressed='<' then Result:=16; |
361 |
|
if KeyPressed='>' then Result:=16; |
362 |
|
if VKey=191 then Result:=16; |
363 |
|
=cut |
364 |
|
} |
365 |
|
|
366 |
$self->mmap_pixel( $addr, 0, $byte, 0 ); |
$self->mmap_pixel( $addr, 0, $byte, 0 ); |
367 |
return $byte; |
return $byte; |
368 |
} |
} |
389 |
} |
} |
390 |
|
|
391 |
if ( $addr > 0xafff ) { |
if ( $addr > 0xafff ) { |
392 |
warn sprintf "write access 0x%04x > 0xafff aborting\n", $addr; |
confess sprintf "write access 0x%04x > 0xafff aborting\n", $addr; |
|
return; |
|
393 |
} |
} |
394 |
|
|
395 |
$self->mmap_pixel( $addr, $byte, 0, 0 ); |
$self->mmap_pixel( $addr, $byte, 0, 0 ); |
437 |
sub cli { |
sub cli { |
438 |
my $self = shift; |
my $self = shift; |
439 |
my $a = $PC || confess "no pc?"; |
my $a = $PC || confess "no pc?"; |
440 |
|
my $run_for = 0; |
441 |
warn $self->dump_R() if $show_R; |
warn $self->dump_R() if $show_R; |
442 |
while ( my ($line, @v) = $self->prompt( $a, $last ) ) { |
while ( my ($line, @v) = $self->prompt( $a, $last ) ) { |
443 |
my $c = shift @v; |
my $c = shift @v; |
492 |
} elsif ( $c =~ m/^l/i ) { |
} elsif ( $c =~ m/^l/i ) { |
493 |
my $to = shift @v || 0x1000; |
my $to = shift @v || 0x1000; |
494 |
$a = $to; |
$a = $to; |
495 |
$self->load_oraoemu( $v, $a ); |
$self->load_image( $v, $a ); |
496 |
$last = ''; |
$last = ''; |
497 |
} elsif ( $c =~ m/^s/i ) { |
} elsif ( $c =~ m/^s/i ) { |
498 |
$self->save_dump( $v || 'mem.dump', @v ); |
$self->save_dump( $v || 'mem.dump', @v ); |
524 |
} |
} |
525 |
} |
} |
526 |
|
|
527 |
|
return $run_for; |
528 |
} |
} |
529 |
|
|
530 |
=head1 AUTHOR |
=head1 AUTHOR |