--- Tape.pm 2008/04/12 13:54:53 191 +++ Tape.pm 2008/04/12 16:18:09 193 @@ -37,29 +37,23 @@ my $c_1 = 0; my $mask = 1; -my $bits = ''; - sub read_tape { my $self = shift; - if ( ! $self->tape ) { - _warn "please load tape!"; - return 0; - } + my $pos = $self->tape_pos; my $tape = $self->tape; - if ( $pos > length( $tape ) ) { - _warn "end of tape [$pos]"; - return -1; + + if ( ! $tape ) { + _warn "please load tape!"; + return 0; } if ( $c_0 ) { $c_0--; - $bits .= "."; return 0; } if ( $c_1 ) { $c_1--; - $bits .= "X"; return 255; } @@ -68,14 +62,20 @@ $pos++; $self->tape_pos( $pos ); $mask = 1; + } - warn "# $bits\n"; - $bits = ''; - }; + my $byte = 0; + my $tape_len = length( $tape ); + + if ( $pos <= $tape_len ) { + $byte = ord( substr($self->tape,$pos,1) ); + warn sprintf("## tape pos %d/%d %.02f%% 0x%04x = %02x\n", $pos, $tape_len, ($pos * 100) / $tape_len, $pos, $byte); + } elsif ( $pos == $tape_len ) { + _warn "end of tape [$pos]"; + } - my $byte = ord( substr($self->tape,$pos,1) ); my $bit = $byte & $mask; - warn sprintf("tape pos %d 0x%04x mask %02x and %02x = %d\n", $pos, $pos, $mask, $byte, $bit); # if $self->trace; + #warn sprintf("## tape pos %d 0x%04x mask %02x and %02x = %d\n", $pos, $pos, $mask, $byte, $bit); # if $self->trace; ( $c_0, $c_1 ) = ( 0x17, 0x17 ); ( $c_0, $c_1 ) = ( 0x30, 0x30 ) if $bit;