4 |
use strict; |
use strict; |
5 |
|
|
6 |
use Carp qw/confess/; |
use Carp qw/confess/; |
|
use lib './lib'; |
|
|
#use Time::HiRes qw(time); |
|
7 |
use File::Slurp; |
use File::Slurp; |
8 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
9 |
use List::Util qw/first/; |
use M6502 '0.0.3'; |
10 |
use M6502; |
use Screen; |
11 |
|
|
12 |
use base qw(Class::Accessor M6502 Screen Prefs); |
use base qw(Class::Accessor VRac M6502 Screen Prefs Tape Session); |
13 |
__PACKAGE__->mk_accessors(qw(run_for)); |
#__PACKAGE__->mk_accessors(qw()); |
14 |
|
|
15 |
=head1 NAME |
=head1 NAME |
16 |
|
|
18 |
|
|
19 |
=head1 VERSION |
=head1 VERSION |
20 |
|
|
21 |
Version 0.03 |
Version 0.06 |
22 |
|
|
23 |
=cut |
=cut |
24 |
|
|
25 |
our $VERSION = '0.03'; |
our $VERSION = '0.06'; |
26 |
|
|
27 |
=head1 SUMMARY |
=head1 SUMMARY |
28 |
|
|
29 |
Emulator or Orao 8-bit 6502 machine popular in Croatia |
Emulator for Orao 8-bit 6502 machine popular in Croatia (especially schools) |
30 |
|
|
31 |
=cut |
=cut |
32 |
|
|
33 |
my @kbd_ports = ( |
=head1 FUNCTIONS |
|
0x87FC,0x87FD,0x87FA,0x87FB,0x87F6,0x87F7, |
|
|
0x87EE,0x87EF,0x87DE,0x87DF,0x87BE,0x87BF, |
|
|
0x877E,0x877F,0x86FE,0x86FF,0x85FE,0x85FF, |
|
|
0x83FE,0x83FF, |
|
|
); |
|
34 |
|
|
35 |
=head2 boot |
=head2 run |
36 |
|
|
37 |
Start emulator, open L<Screen>, load initial ROM images, and render memory |
Start emulator, open L<Screen>, load initial ROM images, and start emulator loop |
|
|
|
|
my $orao = Orao->new({}); |
|
|
$orao->boot; |
|
38 |
|
|
39 |
=cut |
=cut |
40 |
|
|
41 |
our $orao; |
our $emu; |
|
|
|
|
select(STDERR); $| = 1; |
|
42 |
|
|
43 |
sub boot { |
sub run { |
44 |
my $self = shift; |
my $self = shift; |
45 |
|
|
46 |
|
M6502::reset(); |
47 |
|
$self->_init_callbacks; |
48 |
|
|
49 |
warn "Orao calling upstream init\n"; |
warn "Orao calling upstream init\n"; |
50 |
$self->SUPER::init( |
$self->SUPER::init( |
51 |
read => sub { $self->read( @_ ) }, |
read => sub { $self->read( @_ ) }, |
56 |
|
|
57 |
warn "emulating ", $#mem, " bytes of memory\n"; |
warn "emulating ", $#mem, " bytes of memory\n"; |
58 |
|
|
59 |
|
# $self->scale( 2 ); |
60 |
|
$self->show_mem( 1 ); |
61 |
|
$self->load_session( 'sess/current' ); |
62 |
|
|
63 |
$self->open_screen; |
$self->open_screen; |
64 |
$self->load_rom({ |
$self->load_rom({ |
65 |
0x1000 => 'dump/SCRINV.BIN', |
# 0x1000 => 'dump/SCRINV.BIN', |
66 |
# should be 0x6000, but oraoemu has 2 byte prefix |
# should be 0x6000, but oraoemu has 2 byte prefix |
67 |
0x5FFE => 'dump/screen.dmp', |
# 0x5FFE => '/home/dpavlin/orao/dump/screen.dmp', |
68 |
0xC000 => 'rom/BAS12.ROM', |
# 0xC000 => 'rom/Orao/BAS12.ROM', |
69 |
0xE000 => 'rom/CRT12.ROM', |
# 0xE000 => 'rom/Orao/CRT12.ROM', |
70 |
|
0xC000 => 'rom/Orao/BAS13.ROM', |
71 |
|
0xE000 => 'rom/Orao/CRT13.ROM', |
72 |
}); |
}); |
73 |
|
|
74 |
# $PC = 0xDD11; # BC |
# $PC = 0xDD11; # BC |
76 |
|
|
77 |
$PC = 0xff89; |
$PC = 0xff89; |
78 |
|
|
79 |
$orao = $self; |
$emu = $self; |
80 |
|
|
81 |
# $self->prompt( 0x1000 ); |
# $self->prompt( 0x1000 ); |
82 |
|
|
84 |
$self->trace( 0 ); |
$self->trace( 0 ); |
85 |
$self->debug( 0 ); |
$self->debug( 0 ); |
86 |
|
|
87 |
$self->render( @mem[ 0x6000 .. 0x7fff ] ); |
warn "rendering memory\n"; |
88 |
|
$self->render_mem( @mem ); |
89 |
|
|
90 |
if ( $self->show_mem ) { |
if ( $self->show_mem ) { |
91 |
|
|
|
warn "rendering memory map\n"; |
|
|
|
|
|
$self->render_mem( @mem ); |
|
|
|
|
92 |
my @mmap = ( |
my @mmap = ( |
93 |
0x0000, 0x03FF, 'nulti blok', |
0x0000, 0x03FF, 'nulti blok', |
94 |
0x0400, 0x5FFF, 'korisnički RAM (23K)', |
0x0400, 0x5FFF, 'korisnički RAM (23K)', |
100 |
0xE000, 0xFFFF, 'sistemski ROM', |
0xE000, 0xFFFF, 'sistemski ROM', |
101 |
); |
); |
102 |
|
|
103 |
} else { |
print "Orao memory map:"; |
104 |
|
|
105 |
|
while ( @mmap ) { |
106 |
|
my ( $from, $to, $desc ) = splice(@mmap, 0, 3); |
107 |
|
printf("%04x-%04x %s\n", $from, $to, $desc); |
108 |
|
} |
109 |
|
|
|
warn "rendering video memory\n"; |
|
|
$self->render( @mem[ 0x6000 .. 0x7fff ] ); |
|
|
|
|
110 |
} |
} |
111 |
$self->sync; |
|
112 |
$self->trace( $trace ); |
$self->trace( $trace ); |
113 |
$self->debug( $debug ); |
$self->debug( $debug ); |
114 |
|
|
|
#( $A, $P, $X, $Y, $S, $IPeriod ) = ( 1, 2, 3, 4, 5, 6 ); |
|
|
|
|
115 |
warn "Orao boot finished", |
warn "Orao boot finished", |
116 |
$self->trace ? ' trace' : '', |
$self->trace ? ' trace' : '', |
117 |
$self->debug ? ' debug' : '', |
$self->debug ? ' debug' : '', |
118 |
"\n"; |
"\n"; |
119 |
|
|
120 |
M6502::reset(); |
# $self->load_tape( 'tapes/Orao/bdash.tap' ); |
121 |
|
# $self->load_tape( 'tapes/Orao/crtanje.tap' ); |
122 |
} |
$self->load_tape( 'tapes/Orao/jjack.tap' ); |
123 |
|
|
124 |
=head2 load_rom |
$self->render_vram; |
125 |
|
|
126 |
|
$self->loop( sub { |
127 |
|
my $run_for = shift; |
128 |
|
warn sprintf("about to exec from PC %04x for %d cycles\n", $PC, $run_for) if $self->trace; |
129 |
|
M6502::exec( $run_for ); |
130 |
|
# $self->render_vram; |
131 |
|
}); |
132 |
|
}; |
133 |
|
|
|
called to init memory and load initial rom images |
|
134 |
|
|
135 |
$orao->load_rom; |
=head1 Helper functions |
136 |
|
|
137 |
=cut |
=head2 write_chunk |
138 |
|
|
139 |
sub load_rom { |
Write chunk directly into memory, updateing vram if needed |
|
my ($self, $loaded_files) = @_; |
|
140 |
|
|
141 |
#my $time_base = time(); |
$emu->write_chunk( 0x1000, $chunk_data ); |
142 |
|
|
143 |
foreach my $addr ( sort keys %$loaded_files ) { |
=cut |
|
my $path = $loaded_files->{$addr}; |
|
|
$self->load_oraoemu( $path, $addr ); |
|
|
} |
|
|
} |
|
144 |
|
|
145 |
# write chunk directly into memory, updateing vram if needed |
sub write_chunk { |
|
sub _write_chunk { |
|
146 |
my $self = shift; |
my $self = shift; |
147 |
my ( $addr, $chunk ) = @_; |
my ( $addr, $chunk ) = @_; |
148 |
$self->write_chunk( $addr, $chunk ); |
$self->SUPER::write_chunk( $addr, $chunk ); |
149 |
my $end = $addr + length($chunk); |
my $end = $addr + length($chunk); |
150 |
my ( $f, $t ) = ( 0x6000, 0x7fff ); |
my ( $f, $t ) = ( 0x6000, 0x7fff ); |
151 |
|
|
158 |
$t = $end if ( $end < $t ); |
$t = $end if ( $end < $t ); |
159 |
|
|
160 |
warn sprintf("refresh video ram %04x-%04x\n", $f, $t); |
warn sprintf("refresh video ram %04x-%04x\n", $f, $t); |
161 |
# foreach my $a ( $f .. $t ) { |
$self->render_vram; |
162 |
# $self->vram( $a - 0x6000 , $mem[ $a ] ); |
$self->render_mem( @mem ); |
|
# } |
|
|
$self->render( @mem[ 0x6000 .. 0x7fff ] ); |
|
|
$self->render_mem( @mem ) if $self->show_mem; |
|
163 |
} |
} |
164 |
|
|
165 |
=head2 load_oraoemu |
=head2 load_image |
166 |
|
|
167 |
Load binary files, ROM images and Orao Emulator files |
Load binary files, ROM images and Orao Emulator files |
168 |
|
|
169 |
$orao->load_oraoemu( '/path/to/file', 0x1000 ); |
$emu->load_image( '/path/to/file', 0x1000 ); |
170 |
|
|
171 |
Returns true on success. |
Returns true on success. |
172 |
|
|
173 |
=cut |
=cut |
174 |
|
|
175 |
sub load_oraoemu { |
sub load_image { |
176 |
my $self = shift; |
my $self = shift; |
177 |
my ( $path, $addr ) = @_; |
my ( $path, $addr ) = @_; |
178 |
|
|
188 |
if ( $size == 65538 ) { |
if ( $size == 65538 ) { |
189 |
$addr = 0; |
$addr = 0; |
190 |
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; |
191 |
$self->_write_chunk( $addr, substr($buff,2) ); |
$self->write_chunk( $addr, substr($buff,2) ); |
192 |
return 1; |
return 1; |
193 |
} elsif ( $size == 32800 ) { |
} elsif ( $size == 32800 ) { |
194 |
$addr = 0; |
$addr = 0; |
195 |
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; |
196 |
$self->_write_chunk( $addr, substr($buff,0x20) ); |
$self->write_chunk( $addr, substr($buff,0x20) ); |
197 |
return 1; |
return 1; |
198 |
} |
} |
|
printf "loading %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size; |
|
|
$self->_write_chunk( $addr, $buff ); |
|
|
return 1; |
|
|
|
|
|
my $chunk; |
|
|
|
|
|
my $pos = 0; |
|
|
|
|
|
while ( my $long = substr($buff,$pos,4) ) { |
|
|
my @b = split(//, $long, 4); |
|
|
$chunk .= |
|
|
( $b[3] || '' ) . |
|
|
( $b[2] || '' ) . |
|
|
( $b[1] || '' ) . |
|
|
( $b[0] || '' ); |
|
|
$pos += 4; |
|
|
} |
|
|
|
|
|
$self->_write_chunk( $addr, $chunk ); |
|
199 |
|
|
200 |
|
printf "loading %s at %04x - %04x %02x\n", $path, $addr, $addr+$size-1, $size; |
201 |
|
$self->write_chunk( $addr, $buff ); |
202 |
return 1; |
return 1; |
203 |
}; |
}; |
204 |
|
|
|
=head2 save_dump |
|
|
|
|
|
$orao->save_dump( 'filename', $from, $to ); |
|
|
|
|
|
=cut |
|
|
|
|
|
sub save_dump { |
|
|
my $self = shift; |
|
|
|
|
|
my ( $path, $from, $to ) = @_; |
|
|
|
|
|
$from ||= 0; |
|
|
$to ||= 0xffff; |
|
|
|
|
|
open(my $fh, '>', $path) || die "can't open $path: $!"; |
|
|
print $fh $self->read_chunk( $from, $to ); |
|
|
close($fh); |
|
|
|
|
|
my $size = -s $path; |
|
|
warn sprintf "saved %s %d %x bytes\n", $path, $size, $size; |
|
|
} |
|
|
|
|
|
=head2 hexdump |
|
|
|
|
|
$orao->hexdump( $address ); |
|
|
|
|
|
=cut |
|
|
|
|
|
sub hexdump { |
|
|
my $self = shift; |
|
|
my $a = shift; |
|
|
return sprintf(" %04x %s\n", $a, |
|
|
join(" ", |
|
|
map { |
|
|
if ( defined($_) ) { |
|
|
sprintf( "%02x", $_ ) |
|
|
} else { |
|
|
' ' |
|
|
} |
|
|
} @mem[ $a .. $a+8 ] |
|
|
) |
|
|
); |
|
|
} |
|
205 |
|
|
206 |
=head1 Memory management |
=head1 Memory management |
207 |
|
|
218 |
|
|
219 |
=cut |
=cut |
220 |
|
|
221 |
|
my $keyboard_none = 255; |
222 |
|
|
223 |
|
my $keyboard = { |
224 |
|
0x87FC => { |
225 |
|
'right' => 16, |
226 |
|
'down' => 128, |
227 |
|
'up' => 192, |
228 |
|
'left' => 224, |
229 |
|
'backspace' => 224, |
230 |
|
}, |
231 |
|
0x87FD => sub { |
232 |
|
my $self = shift; |
233 |
|
if ( $self->key_active('return') ) { |
234 |
|
# M6502::_write( 0xfc, 13 ); |
235 |
|
warn "return\n"; |
236 |
|
return 0; |
237 |
|
} elsif ( $self->key_active('left ctrl','right ctrl') ) { |
238 |
|
warn "ctrl\n"; |
239 |
|
return 16; |
240 |
|
} |
241 |
|
return $keyboard_none; |
242 |
|
}, |
243 |
|
0x87FA => { |
244 |
|
'f4' => 16, |
245 |
|
'f3' => 128, |
246 |
|
'f2' => 192, |
247 |
|
'f1' => 224, |
248 |
|
}, |
249 |
|
0x87FB => sub { |
250 |
|
my $self = shift; |
251 |
|
if ( $self->key_active('space') ) { |
252 |
|
warn "space\n"; |
253 |
|
return 32; |
254 |
|
} elsif ( $self->key_active('left shift','right shift') ) { |
255 |
|
warn "shift\n"; |
256 |
|
return 16; |
257 |
|
# } elsif ( $self->tape ) { |
258 |
|
# warn "has tape!"; |
259 |
|
# return 0; |
260 |
|
} |
261 |
|
return $keyboard_none; |
262 |
|
}, |
263 |
|
0x87F6 => { |
264 |
|
'6' => 16, |
265 |
|
't' => 128, |
266 |
|
'y' => 192, # hr: z |
267 |
|
'r' => 224, |
268 |
|
}, |
269 |
|
0x87F7 => { |
270 |
|
'5' => 32, |
271 |
|
'4' => 16, |
272 |
|
}, |
273 |
|
0x87EE => { |
274 |
|
'7' => 16, |
275 |
|
'u' => 128, |
276 |
|
'i' => 192, |
277 |
|
'o' => 224, |
278 |
|
}, |
279 |
|
0x87EF => { |
280 |
|
'8' => 32, |
281 |
|
'9' => 16, |
282 |
|
}, |
283 |
|
0x87DE => { |
284 |
|
'1' => 16, |
285 |
|
'w' => 128, |
286 |
|
'q' => 192, |
287 |
|
'e' => 224, |
288 |
|
}, |
289 |
|
0x87DF => { |
290 |
|
'2' => 32, |
291 |
|
'3' => 16, |
292 |
|
}, |
293 |
|
0x87BE => { |
294 |
|
'm' => 16, |
295 |
|
'k' => 128, |
296 |
|
'j' => 192, |
297 |
|
'l' => 224, |
298 |
|
}, |
299 |
|
0x87BF => { |
300 |
|
',' => 32, # < |
301 |
|
'.' => 16, # > |
302 |
|
}, |
303 |
|
0x877E => { |
304 |
|
'z' => 16, # hr:y |
305 |
|
's' => 128, |
306 |
|
'a' => 192, |
307 |
|
'd' => 224, |
308 |
|
}, |
309 |
|
0x877F => { |
310 |
|
'x' => 32, |
311 |
|
'c' => 16, |
312 |
|
}, |
313 |
|
0x86FE => { |
314 |
|
'n' => 16, |
315 |
|
'g' => 128, |
316 |
|
'h' => 192, |
317 |
|
'f' => 224, |
318 |
|
}, |
319 |
|
0x86FF => { |
320 |
|
'b' => 32, |
321 |
|
'v' => 16, |
322 |
|
}, |
323 |
|
0x85FE => { |
324 |
|
'<' => 16, # : |
325 |
|
'\\' => 128, # ľ |
326 |
|
'\'' => 192, # ć |
327 |
|
';' => 224, # č |
328 |
|
}, |
329 |
|
0x85FF => { |
330 |
|
'/' => 32, |
331 |
|
'f11' => 16, # ^ |
332 |
|
}, |
333 |
|
0x83FE => { |
334 |
|
'f12' => 16, # ; |
335 |
|
'[' => 128, # ą |
336 |
|
']' => 192, # đ |
337 |
|
'p' => 224, |
338 |
|
}, |
339 |
|
0x83FF => { |
340 |
|
'-' => 32, |
341 |
|
'0' => 16, |
342 |
|
}, |
343 |
|
}; |
344 |
|
|
345 |
sub read { |
sub read { |
346 |
my $self = shift; |
my $self = shift; |
347 |
my ($addr) = @_; |
my ($addr) = @_; |
348 |
|
die "address over 64k: $addr" if ( $addr > 0xffff ); |
349 |
my $byte = $mem[$addr]; |
my $byte = $mem[$addr]; |
350 |
confess sprintf("can't find memory at address %04x",$addr) unless defined($byte); |
confess sprintf("can't find memory at address %04x",$addr) unless defined($byte); |
351 |
warn sprintf("# Orao::read(%04x) = %02x\n", $addr, $byte) if $self->trace; |
warn sprintf("# Orao::read(%04x) = %02x\n", $addr, $byte) if $self->trace; |
352 |
|
|
353 |
# keyboard |
# keyboard |
354 |
|
|
355 |
if ( first { $addr == $_ } @kbd_ports ) { |
if ( defined( $keyboard->{$addr} ) ) { |
356 |
warn sprintf("keyboard port: %04x\n",$addr); |
warn sprintf("keyboard port: %04x\n",$addr) if $self->trace; |
357 |
} elsif ( $addr == 0x87fc ) { |
|
358 |
warn "0x87fc - arrows/back\n"; |
my $ret = $keyboard_none; |
359 |
=for pascal |
my $r = $keyboard->{$addr} || confess "no definition for keyboard port found"; |
360 |
if VKey=VK_RIGHT then Result:=16; |
if ( ref($r) eq 'CODE' ) { |
361 |
if VKey=VK_DOWN then Result:=128; |
$ret = $r->($self); |
362 |
if VKey=VK_UP then Result:=192; |
} else { |
363 |
if VKey=VK_LEFT then Result:=224; |
foreach my $k ( keys %$r ) { |
364 |
if Ord(KeyPressed)=VK_BACK then Result:=224; |
my $return = 0; |
365 |
=cut |
if ( $self->key_active($k) ) { |
366 |
} elsif ( $addr == 0x87fd ) { |
warn "key '$k' is active\n"; |
367 |
warn "0x87fd - enter\n"; |
$return ||= $r->{$k}; |
368 |
=for pascal |
} |
369 |
if KeyPressed=Chr(13) then begin |
$ret = $return if $return; |
370 |
Mem[$FC]:=13; |
} |
371 |
Result:=0; |
} |
372 |
end; |
warn sprintf("keyboard port: %04x code: %d\n",$addr,$ret) if ( $ret != $keyboard_none ); |
373 |
=cut |
return $ret; |
|
} elsif ( $addr == 0x87fa ) { |
|
|
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 |
|
374 |
} |
} |
375 |
|
|
376 |
$self->mmap_pixel( $addr, 0, $byte, 0 ); |
if ( $addr == 0x87ff ) { |
377 |
|
return $self->read_tape; |
378 |
|
} |
379 |
|
|
380 |
|
$self->mmap_pixel( $addr, 0, $byte, 0 ) if $self->show_mem; |
381 |
return $byte; |
return $byte; |
382 |
} |
} |
383 |
|
|
394 |
my ($addr,$byte) = @_; |
my ($addr,$byte) = @_; |
395 |
warn sprintf("# Orao::write(%04x,%02x)\n", $addr, $byte) if $self->trace; |
warn sprintf("# Orao::write(%04x,%02x)\n", $addr, $byte) if $self->trace; |
396 |
|
|
|
if ( $addr >= 0x6000 && $addr < 0x8000 ) { |
|
|
$self->vram( $addr - 0x6000 , $byte ); |
|
|
} |
|
|
|
|
397 |
if ( $addr == 0x8800 ) { |
if ( $addr == 0x8800 ) { |
398 |
|
$self->write_tape( $byte ); |
399 |
warn sprintf "sound ignored: %x\n", $byte; |
warn sprintf "sound ignored: %x\n", $byte; |
400 |
} |
} |
401 |
|
|
403 |
confess sprintf "write access 0x%04x > 0xafff aborting\n", $addr; |
confess sprintf "write access 0x%04x > 0xafff aborting\n", $addr; |
404 |
} |
} |
405 |
|
|
406 |
$self->mmap_pixel( $addr, $byte, 0, 0 ); |
$self->render_vram if ( $addr >= 0x6000 && $addr <= 0x7fff ); |
407 |
|
|
408 |
|
$self->mmap_pixel( $addr, $byte, 0, 0 ) if $self->show_mem; |
409 |
$mem[$addr] = $byte; |
$mem[$addr] = $byte; |
410 |
return; |
return; |
411 |
} |
} |
412 |
|
|
413 |
=head1 Command Line |
=head1 Architecture specific |
414 |
|
|
415 |
Command-line debugging intrerface is implemented for communication with |
=head2 render_vram |
|
emulated device |
|
416 |
|
|
417 |
=head2 prompt |
Render one frame of video ram |
418 |
|
|
419 |
my ( $entered_line, @p ) = $orao->prompt( $address, $last_command ); |
$self->render_vram; |
420 |
|
|
421 |
=cut |
=cut |
422 |
|
|
423 |
my $last = 'r 1'; |
sub render_vram { |
|
|
|
|
sub prompt { |
|
424 |
my $self = shift; |
my $self = shift; |
425 |
$self->app->sync; |
|
426 |
my $a = shift; |
my $pixels = pack("C*", map { $flip[$_] } @mem[ 0x6000 .. 0x7fff ]); |
427 |
print STDERR $self->hexdump( $a ), |
|
428 |
$last ? "[$last] " : '', |
my $vram = SDL::Surface->new( |
429 |
"> "; |
-width => 256, |
430 |
my $in = <STDIN>; |
-height => 256, |
431 |
chomp($in); |
-depth => 1, # 1 bit per pixel |
432 |
warn "## prompt got: $in\n" if $self->debug; |
-pitch => 32, # bytes per line |
433 |
$in ||= $last; |
-from => $pixels, |
434 |
$last = $in; |
); |
435 |
return ( $in, split(/\s+/, $in) ) if $in; |
$vram->set_colors( 0, $black, $white ); |
436 |
|
|
437 |
|
$self->render_frame( $vram ); |
438 |
|
|
439 |
|
print '.'; |
440 |
} |
} |
441 |
|
|
442 |
=head2 cli |
=head2 cpu_PC |
443 |
|
|
444 |
$orao->cli(); |
Helper metod to set or get PC for current architecture |
445 |
|
|
446 |
=cut |
=cut |
447 |
|
|
448 |
my $show_R = 0; |
sub cpu_PC { |
449 |
|
my ( $self, $addr ) = @_; |
450 |
|
if ( defined($addr) ) { |
451 |
|
$PC = $addr; |
452 |
|
warn sprintf("running from PC %04x\n", $PC); |
453 |
|
}; |
454 |
|
return $PC; |
455 |
|
} |
456 |
|
|
457 |
|
|
458 |
|
=head2 _init_callbacks |
459 |
|
|
460 |
|
Mark memory areas for which we want to get callbacks to perl |
461 |
|
|
462 |
|
=cut |
463 |
|
|
464 |
sub cli { |
sub _init_callbacks { |
465 |
my $self = shift; |
my $self = shift; |
466 |
my $a = $PC || confess "no pc?"; |
warn "set calbacks to perl for memory areas...\n"; |
467 |
warn $self->dump_R() if $show_R; |
|
468 |
while ( my ($line, @v) = $self->prompt( $a, $last ) ) { |
# don't call for anything |
469 |
my $c = shift @v; |
M6502::set_all_callbacks( 0x00 ); |
|
next unless defined($c); |
|
|
my $v = shift @v; |
|
|
$v = hex($v) if $v && $v =~ m/^[0-9a-f]+$/; |
|
|
@v = map { hex($_) } @v; |
|
|
printf "## a: %04x parsed cli: c:%s v:%s %s\n", $a, $c, ($v || 'undef'), join(",",@v) if $self->debug; |
|
|
if ( $c =~ m/^[qx]/i ) { |
|
|
exit; |
|
|
} elsif ( $c eq '?' ) { |
|
|
my $t = $self->trace ? 'on' : 'off' ; |
|
|
my $d = $self->debug ? 'on' : 'off' ; |
|
|
warn <<__USAGE__; |
|
|
Usage: |
|
|
|
|
|
x|q\t\texit |
|
|
e 6000 6010\tdump memory, +/- to walk forward/backward |
|
|
m 1000 ff 00\tput ff 00 on 1000 |
|
|
j|u 1000\t\tjump (change pc) |
|
|
r 42\t\trun 42 instruction opcodes |
|
|
t\t\ttrace [$t] |
|
|
d\t\tdebug [$d] |
|
|
|
|
|
__USAGE__ |
|
|
warn $self->dump_R; |
|
|
} elsif ( $c =~ m/^e/i ) { |
|
|
$a = $v if defined($v); |
|
|
my $to = shift @v; |
|
|
$to = $a + 32 if ( ! $to || $to <= $a ); |
|
|
$to = 0xffff if ( $to > 0xffff ); |
|
|
my $lines = int( ($to - $a + 8) / 8 ); |
|
|
printf "## e %04x %04x (%d bytes) lines: %d\n", $a, $to, ($to-$a), $lines; |
|
|
while ( --$lines ) { |
|
|
print $self->hexdump( $a ); |
|
|
$a += 8; |
|
|
} |
|
|
$last = '+'; |
|
|
$show_R = 0; |
|
|
} elsif ( $c =~ m/^\+/ ) { |
|
|
$a += 8; |
|
|
$show_R = 0; |
|
|
} elsif ( $c =~ m/^\-/ ) { |
|
|
$a -= 8; |
|
|
$show_R = 0; |
|
|
} elsif ( $c =~ m/^m/i ) { |
|
|
$a = $v if defined($v); |
|
|
$self->poke_code( $a, @v ); |
|
|
printf "poke %d bytes at %04x\n", $#v + 1, $a; |
|
|
$last = '+'; |
|
|
$show_R = 0; |
|
|
} elsif ( $c =~ m/^l/i ) { |
|
|
my $to = shift @v || 0x1000; |
|
|
$a = $to; |
|
|
$self->load_oraoemu( $v, $a ); |
|
|
$last = ''; |
|
|
} elsif ( $c =~ m/^s/i ) { |
|
|
$self->save_dump( $v || 'mem.dump', @v ); |
|
|
$last = ''; |
|
|
} elsif ( $c =~ m/^r/i ) { |
|
|
$run_for = $v || 1; |
|
|
print "run_for $run_for instructions\n"; |
|
|
$show_R = 1; |
|
|
last; |
|
|
} elsif ( $c =~ m/^(u|j)/ ) { |
|
|
my $to = $v || $a; |
|
|
printf "set pc to %04x\n", $to; |
|
|
$PC = $to; # remember for restart |
|
|
$run_for = 1; |
|
|
$last = "r $run_for"; |
|
|
$show_R = 1; |
|
|
last; |
|
|
} elsif ( $c =~ m/^t/ ) { |
|
|
$self->trace( not $self->trace ); |
|
|
print "trace ", $self->trace ? 'on' : 'off', "\n"; |
|
|
$last = ''; |
|
|
} elsif ( $c =~ m/^d/ ) { |
|
|
$self->debug( not $self->debug ); |
|
|
print "debug ", $self->debug ? 'on' : 'off', "\n"; |
|
|
$last = ''; |
|
|
} else { |
|
|
warn "# ignored $line\n" if ($line); |
|
|
$last = ''; |
|
|
} |
|
|
} |
|
470 |
|
|
471 |
|
# video ram |
472 |
|
M6502::set_write_callback( $_ ) foreach ( 0x6000 .. 0x7fff ); |
473 |
|
# keyboard |
474 |
|
M6502::set_read_callback( $_ ) foreach ( keys %$keyboard ); |
475 |
|
# tape |
476 |
|
M6502::set_read_callback( 0x87ff ); |
477 |
|
M6502::set_write_callback( 0x8800 ); |
478 |
|
|
479 |
|
my $map = ''; |
480 |
|
foreach ( 0 .. 0xffff ) { |
481 |
|
my $cb = M6502::get_callback( $_ ); |
482 |
|
$map .= sprintf( "%04x: %02x\n", $_, $cb ) if $cb; |
483 |
|
} |
484 |
|
warn "callback map:\n$map\n"; |
485 |
} |
} |
486 |
|
|
487 |
|
=head1 SEE ALSO |
488 |
|
|
489 |
|
L<VRac>, L<M6502>, L<Screen>, L<Tape> |
490 |
|
|
491 |
=head1 AUTHOR |
=head1 AUTHOR |
492 |
|
|
493 |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
494 |
|
|
|
=head1 BUGS |
|
|
|
|
495 |
=head1 ACKNOWLEDGEMENTS |
=head1 ACKNOWLEDGEMENTS |
496 |
|
|
497 |
See also L<http://www.foing.hr/~fng_josip/orao.htm> which is source of all |
See also L<http://www.foing.hr/~fng_josip/orao.htm> which is source of all |