/[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

Diff of /Tape.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

M6502/Tape.pm revision 114 by dpavlin, Fri Aug 3 20:01:51 2007 UTC Tape.pm revision 169 by dpavlin, Mon Aug 6 09:20:20 2007 UTC
# Line 6  use strict; Line 6  use strict;
6  use warnings;  use warnings;
7    
8  use base qw/Class::Accessor/;  use base qw/Class::Accessor/;
9  __PACKAGE__->mk_accessors(qw(tape tape_pos tape_rate));  __PACKAGE__->mk_accessors(qw(tape tape_path tape_pos trace));
10    
11  use File::Slurp;  use File::Slurp;
12  use Carp qw/confess/;  use Carp qw/confess/;
# Line 19  Tape - implement tape reader/recorder Line 19  Tape - implement tape reader/recorder
19    
20  =head2 read_tape  =head2 read_tape
21    
22    $self->read_tape;    my $byte = $self->read_tape;
23    
24  =cut  =cut
25    
# Line 33  sub _warn { Line 33  sub _warn {
33          }          }
34  }  }
35    
 my @tape_bits;  
   
36  sub read_tape {  sub read_tape {
37          my $self = shift;          my $self = shift;
38          if ( ! $self->tape ) {          if ( ! $self->tape ) {
# Line 48  sub read_tape { Line 46  sub read_tape {
46                  return -1;                  return -1;
47          }          }
48    
49          if ( ! @tape_bits ) {          my $byte = ord( substr($self->tape,$pos,1) );
50                  my $byte = ord( substr($self->tape,$pos,1) );          warn sprintf("tape pos %d = %02x\n", $pos, $byte); # if $self->trace;
                 warn sprintf("tape pos %d = %02x\n", $pos, $byte);  
51    
52                  $pos++;          $pos++;
53                  $self->tape_pos( $pos );          $self->tape_pos( $pos );
54    
55                  @tape_bits = split(//, unpack("B8",$byte) );          return $byte;
56          }  }
57          my $bit = shift @tape_bits ? 0xff : 0x00;  
58          warn "\t$bit\n";  =head2 write_tape
59          return $bit;  
60      $self->write_tape( $byte );
61    
62    =cut
63    
64    
65    sub write_tape {
66            my ( $self, $byte ) = @_;
67    
68            $self->append_to_file( 'tape.dmp', chr($byte) );
69    
70            return $byte;
71  }  }
72    
73  =head2 load_tape  =head2 load_tape
# Line 73  sub load_tape { Line 81  sub load_tape {
81          my $path = shift || return;          my $path = shift || return;
82    
83          my $tape = read_file( $path ) || confess "can't load $path: $!";          my $tape = read_file( $path ) || confess "can't load $path: $!";
84            $self->tape_path( $path );
85    
86          $self->tape_pos( 0 );          $self->tape_pos( 0 );
87          $self->tape( $tape );          $self->tape( $tape );
         $self->tape_rate( 512 );  
88          warn "loaded tape $path ", -s $path, " bytes rate ", $self->tape_rate, "\n";          warn "loaded tape $path ", -s $path, " bytes rate ", $self->tape_rate, "\n";
89          return 1;          return 1;
90  }  }
91    
92    =head tape_status
93    
94      print $self->tape_status;
95    
96    =cut
97    
98    sub tape_status {
99            my $self = shift;
100    
101            return "No tape in (simulated) drive" unless $self->tape;
102    
103            my $size = length( $self->tape );
104    
105            return sprintf(
106                    "tape file: %s with %d 0x%x bytes, current position: %d 0x%x",
107                    $self->tape_path, $size, $size, $self->pos, $self->pos,
108            );
109    }
110    
111    =head1 SEE ALSO
112    
113    L<VRac>
114    
115    =cut
116    
117  1;  1;

Legend:
Removed from v.114  
changed lines
  Added in v.169

  ViewVC Help
Powered by ViewVC 1.1.26