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

revision 169 by dpavlin, Mon Aug 6 09:20:20 2007 UTC revision 192 by dpavlin, Sat Apr 12 14:20:01 2008 UTC
# Line 33  sub _warn { Line 33  sub _warn {
33          }          }
34  }  }
35    
36    my $c_0 = 0;
37    my $c_1 = 0;
38    my $mask = 1;
39    
40  sub read_tape {  sub read_tape {
41          my $self = shift;          my $self = shift;
42          if ( ! $self->tape ) {          if ( ! $self->tape ) {
# Line 46  sub read_tape { Line 50  sub read_tape {
50                  return -1;                  return -1;
51          }          }
52    
53            if ( $c_0 ) {
54                    $c_0--;
55                    return 0;
56            }
57            if ( $c_1 ) {
58                    $c_1--;
59                    return 255;
60            }
61    
62            $mask = $mask << 1;
63            if ( $mask > 0x80 ) {
64                    $pos++;
65                    $self->tape_pos( $pos );
66                    $mask = 1;
67            };
68    
69          my $byte = ord( substr($self->tape,$pos,1) );          my $byte = ord( substr($self->tape,$pos,1) );
70          warn sprintf("tape pos %d = %02x\n", $pos, $byte); # if $self->trace;          my $bit = $byte & $mask;
71    #       warn sprintf("## tape pos %d 0x%04x mask %02x and %02x = %d\n", $pos, $pos, $mask, $byte, $bit); # if $self->trace;
72    
73          $pos++;          ( $c_0, $c_1 ) = ( 0x17, 0x17 );
74          $self->tape_pos( $pos );          ( $c_0, $c_1 ) = ( 0x30, 0x30 ) if $bit;
75    
76          return $byte;          return 0;
77  }  }
78    
79  =head2 write_tape  =head2 write_tape
# Line 65  sub read_tape { Line 86  sub read_tape {
86  sub write_tape {  sub write_tape {
87          my ( $self, $byte ) = @_;          my ( $self, $byte ) = @_;
88    
89          $self->append_to_file( 'tape.dmp', chr($byte) );          $self->append_to_file( 'tape.dmp', $byte );
90    
91          return $byte;          return $byte;
92  }  }
# Line 85  sub load_tape { Line 106  sub load_tape {
106    
107          $self->tape_pos( 0 );          $self->tape_pos( 0 );
108          $self->tape( $tape );          $self->tape( $tape );
109          warn "loaded tape $path ", -s $path, " bytes rate ", $self->tape_rate, "\n";          warn "loaded tape $path ", -s $path, " bytes\n";
110          return 1;          return 1;
111  }  }
112    
113  =head tape_status  =head2 tape_status
114    
115    print $self->tape_status;    print $self->tape_status;
116    

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

  ViewVC Help
Powered by ViewVC 1.1.26