--- VRac.pm 2007/08/04 20:28:51 128 +++ VRac.pm 2007/08/05 13:27:27 145 @@ -12,7 +12,7 @@ =head1 NAME -VRac - Virtualno Računalo +VRac - Virtualno Računalo =head1 VERSION @@ -27,7 +27,7 @@ Emulator of 8-bit architectures based on L or L emulation. This project is homage to 8-bit computers in Croatia and former Yugoslavia -from 1980-1990. Word B means also I in Croatian. +from 1980-1990. Word B means also I in Croatian. =cut @@ -49,17 +49,43 @@ confess "please implement $self::run\n"; } -=head2 jump -Start execution from some location (modify PC) +=head1 Memory management + +VRac implements callback for all I/O operations. This was main reason why +L module with tied memory was too slow to emulate L, so I +had to write C binding for L. + +B. They should be +implemented for each architecture. =cut -sub jump { +=head2 read + +Read from memory + + $byte = read( $address ); + +=cut + +sub read { my $self = shift; - confess "please implement $self::jump\n"; + confess "please implement $self::read()"; } +=head2 write + +Write into emory + + write( $address, $byte ); + +=cut + +sub write { + my $self = shift; + confess "please implement $self::write()"; +} =head1 Helper functions @@ -121,12 +147,16 @@ $from ||= 0; $to ||= 0xffff; - open(my $fh, '>', $path) || die "can't open $path: $!"; - print $fh $self->read_chunk( $from, $to ); - close($fh); + if ( open(my $fh, '>', $path) ) { + print $fh $self->read_chunk( $from, $to ); + close($fh); + + my $size = -s $path; + warn sprintf "saved %s %04x-%04x %d %x bytes\n", $path, $from, $to, $size, $size; + } else { + warn "can't create $path: $!"; + } - my $size = -s $path; - warn sprintf "saved %s %d %x bytes\n", $path, $size, $size; } =head2 hexdump @@ -152,37 +182,21 @@ ); } -=head1 Memory management +=head2 append_to_file -VRac implements all I/O using mmap addresses. This was main reason why -L was just too slow to handle it. + $self->append_to_file( '/path/to/file', $byte, $byte ... ); =cut -=head2 read - -Read from memory - - $byte = read( $address ); - -=cut - -sub read { +sub append_to_file { my $self = shift; - confess "please implement $self::read()"; -} + my $path = shift || confess "no path?"; + my $bytes = join('', @_); -=head2 write + open(my $fh, '>>', $path) || confess "can't open $path: $!"; -Write into emory - - write( $address, $byte ); - -=cut - -sub write { - my $self = shift; - confess "please implement $self::write()"; + print $fh $bytes; + warn sprintf("## append_to_file('%s',%s)\n", $path, dump($bytes)); } =head1 Command Line @@ -330,6 +344,12 @@ return $run_for; } +=head1 SEE ALSO + +Components: L, L, L, L + +Emulators: L, L + =head1 AUTHOR Dobrica Pavlinusic, C<< >>