/[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 193 by dpavlin, Sat Apr 12 16:18:09 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 ) {  
43            my $pos = $self->tape_pos;
44            my $tape = $self->tape;
45    
46            if ( ! $tape ) {
47                  _warn "please load tape!";                  _warn "please load tape!";
48                  return 0;                  return 0;
49          }          }
50          my $pos = $self->tape_pos;  
51          my $tape = $self->tape;          if ( $c_0 ) {
52          if ( $pos > length( $tape ) ) {                  $c_0--;
53                    return 0;
54            }
55            if ( $c_1 ) {
56                    $c_1--;
57                    return 255;
58            }
59    
60            $mask = $mask << 1;
61            if ( $mask > 0x80 ) {
62                    $pos++;
63                    $self->tape_pos( $pos );
64                    $mask = 1;
65            }
66    
67            my $byte = 0;
68            my $tape_len = length( $tape );
69    
70            if ( $pos <= $tape_len ) {
71                    $byte = ord( substr($self->tape,$pos,1) );
72                    warn sprintf("## tape pos %d/%d %.02f%% 0x%04x = %02x\n", $pos, $tape_len, ($pos * 100) / $tape_len, $pos, $byte);
73            } elsif ( $pos  == $tape_len ) {
74                  _warn "end of tape [$pos]";                  _warn "end of tape [$pos]";
                 return -1;  
75          }          }
76    
77          my $byte = ord( substr($self->tape,$pos,1) );          my $bit = $byte & $mask;
78          warn sprintf("tape pos %d = %02x\n", $pos, $byte); # if $self->trace;          #warn sprintf("## tape pos %d 0x%04x mask %02x and %02x = %d\n", $pos, $pos, $mask, $byte, $bit); # if $self->trace;
79    
80          $pos++;          ( $c_0, $c_1 ) = ( 0x17, 0x17 );
81          $self->tape_pos( $pos );          ( $c_0, $c_1 ) = ( 0x30, 0x30 ) if $bit;
82    
83          return $byte;          return 0;
84  }  }
85    
86  =head2 write_tape  =head2 write_tape
# Line 65  sub read_tape { Line 93  sub read_tape {
93  sub write_tape {  sub write_tape {
94          my ( $self, $byte ) = @_;          my ( $self, $byte ) = @_;
95    
96          $self->append_to_file( 'tape.dmp', chr($byte) );          $self->append_to_file( 'tape.dmp', $byte );
97    
98          return $byte;          return $byte;
99  }  }
# Line 85  sub load_tape { Line 113  sub load_tape {
113    
114          $self->tape_pos( 0 );          $self->tape_pos( 0 );
115          $self->tape( $tape );          $self->tape( $tape );
116          warn "loaded tape $path ", -s $path, " bytes rate ", $self->tape_rate, "\n";          warn "loaded tape $path ", -s $path, " bytes\n";
117          return 1;          return 1;
118  }  }
119    
120  =head tape_status  =head2 tape_status
121    
122    print $self->tape_status;    print $self->tape_status;
123    

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

  ViewVC Help
Powered by ViewVC 1.1.26