/[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 190 by dpavlin, Sat Sep 29 12:03:56 2007 UTC revision 191 by dpavlin, Sat Apr 12 13:54:53 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    my $bits = '';
41    
42  sub read_tape {  sub read_tape {
43          my $self = shift;          my $self = shift;
44          if ( ! $self->tape ) {          if ( ! $self->tape ) {
# Line 46  sub read_tape { Line 52  sub read_tape {
52                  return -1;                  return -1;
53          }          }
54    
55            if ( $c_0 ) {
56                    $c_0--;
57                    $bits .= ".";
58                    return 0;
59            }
60            if ( $c_1 ) {
61                    $c_1--;
62                    $bits .= "X";
63                    return 255;
64            }
65    
66            $mask = $mask << 1;
67            if ( $mask > 0x80 ) {
68                    $pos++;
69                    $self->tape_pos( $pos );
70                    $mask = 1;
71    
72                    warn "# $bits\n";
73                    $bits = '';
74            };
75    
76          my $byte = ord( substr($self->tape,$pos,1) );          my $byte = ord( substr($self->tape,$pos,1) );
77          warn sprintf("tape pos %d = %02x\n", $pos, $byte); # if $self->trace;          my $bit = $byte & $mask;
78            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  }  }

Legend:
Removed from v.190  
changed lines
  Added in v.191

  ViewVC Help
Powered by ViewVC 1.1.26