/[VRac]/Tape.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /Tape.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 110 - (show annotations)
Fri Aug 3 12:21:47 2007 UTC (16 years, 8 months ago) by dpavlin
Original Path: M6502/Tape.pm
File size: 1271 byte(s)
command 'taperate' to change speed of which bytes are fed from tape
(still doesn't work)
1 package Tape;
2
3 # Dobrica Pavlinusic, <dpavlin@rot13.org> 08/03/07 11:11:56 CEST
4
5 use strict;
6 use warnings;
7
8 use base qw/Class::Accessor/;
9 __PACKAGE__->mk_accessors(qw(tape tape_pos tape_rate));
10
11 use File::Slurp;
12 use Carp qw/confess/;
13
14 =head1 NAME
15
16 Tape - implement tape reader/recorder
17
18 =cut
19
20 =head2 read_tape
21
22 $self->read_tape;
23
24 =cut
25
26 my $last_warn = '';
27
28 sub _warn {
29 my $msg = shift;
30 if ( $msg ne $last_warn ) {
31 warn "$msg\n";
32 $last_warn = $msg;
33 }
34 }
35
36 my $loop;
37
38 sub read_tape {
39 my $self = shift;
40 if ( ! $self->tape ) {
41 _warn "please load tape!";
42 return 0;
43 }
44 my $pos = $self->tape_pos;
45 my $tape = $self->tape;
46 if ( $pos > length( $tape ) ) {
47 _warn "end of tape [$pos]";
48 return -1;
49 }
50 my $byte = ord(substr($self->tape,$pos,1));
51
52 if ( ++$loop % $self->tape_rate == 0 ) {
53 warn sprintf("tape pos %d = %02x\n", $pos, $byte);
54 $pos++;
55 $self->tape_pos( $pos );
56 }
57 return $byte;
58 }
59
60 =head2 load_tape
61
62 $self->load_tape( '/path/to/file' );
63
64 =cut
65
66 sub load_tape {
67 my $self = shift;
68 my $path = shift || return;
69
70 my $tape = read_file( $path ) || confess "can't load $path: $!";
71
72 $self->tape_pos( 0 );
73 $self->tape( $tape );
74 $self->tape_rate( 512 );
75 warn "loaded tape $path ", -s $path, " bytes rate ", $self->tape_rate, "\n";
76 return 1;
77 }
78
79
80 1;

  ViewVC Help
Powered by ViewVC 1.1.26