3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
|
6 |
use Carp qw/confess croak/; |
use Carp qw/confess croak cluck carp/; |
7 |
use File::Slurp; |
use File::Slurp; |
8 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
9 |
|
|
29 |
This project is homage to 8-bit computers in Croatia and former Yugoslavia |
This project is homage to 8-bit computers in Croatia and former Yugoslavia |
30 |
from 1980-1990. Word B<vrac> means also I<wizard> in Croatian. |
from 1980-1990. Word B<vrac> means also I<wizard> in Croatian. |
31 |
|
|
32 |
|
This project should enable anyone with limited knowledge of perl and 8-bit |
33 |
|
arhitecture of some machine to write emulator in an afternoon. To achieve this, |
34 |
|
code is written is as cleanly as possible. |
35 |
|
|
36 |
|
Porting existing emulators should be especially easy: you need passive |
37 |
|
understaning of language in which emulator is written and you can be on your |
38 |
|
way C<:-)> |
39 |
|
|
40 |
=cut |
=cut |
41 |
|
|
42 |
=head1 FUNCTIONS |
=head1 FUNCTIONS |
201 |
my $path = shift || confess "no path?"; |
my $path = shift || confess "no path?"; |
202 |
my $bytes = join('', @_); |
my $bytes = join('', @_); |
203 |
|
|
204 |
|
my $size = -s $path || 0; |
205 |
|
my $len = length($bytes); |
206 |
|
|
207 |
open(my $fh, '>>', $path) || confess "can't open $path: $!"; |
open(my $fh, '>>', $path) || confess "can't open $path: $!"; |
208 |
|
print($fh $bytes); |
209 |
|
my $pos = tell($fh); |
210 |
|
|
211 |
|
my $expected = $size + $len; |
212 |
|
if ( $pos != $expected ) { |
213 |
|
cluck "BUG: file grows too big got $pos, expected $expected !"; |
214 |
|
truncate $fh, $expected; |
215 |
|
} |
216 |
|
|
217 |
|
close($fh); |
218 |
|
|
|
print $fh $bytes; |
|
219 |
warn sprintf("## append_to_file('%s',%s)\n", $path, dump($bytes)); |
warn sprintf("## append_to_file('%s',%s)\n", $path, dump($bytes)); |
220 |
} |
} |
221 |
|
|
366 |
|
|
367 |
=head1 SEE ALSO |
=head1 SEE ALSO |
368 |
|
|
369 |
Components: L<M6502>, L<Z80>, L<Screen>, L<Tape> |
Components: L<M6502>, L<Z80>, L<Screen>, L<Tape>, L<Session> |
370 |
|
|
371 |
Emulators: L<Orao>, L<Galaksija> |
Emulators: L<Orao>, L<Galaksija> |
372 |
|
|
374 |
|
|
375 |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
376 |
|
|
|
=head1 BUGS |
|
|
|
|
377 |
=head1 ACKNOWLEDGEMENTS |
=head1 ACKNOWLEDGEMENTS |
378 |
|
|
379 |
|
Structure and Interpretation of Computer Programs by Abelson, Sussman, and |
380 |
|
Sussman L<http://mitpress.mit.edu/sicp/> is a great book. It gave me idea |
381 |
|
that you should have wizard powers over your computer, even if it's 8 bit |
382 |
|
one. |
383 |
|
|
384 |
=head1 COPYRIGHT & LICENSE |
=head1 COPYRIGHT & LICENSE |
385 |
|
|
386 |
Copyright 2007 Dobrica Pavlinusic, All Rights Reserved. |
Copyright 2007 Dobrica Pavlinusic, All Rights Reserved. |