Added some code to print out ASCIi characters in each word.
This commit is contained in:
+19
-6
@@ -12,12 +12,12 @@ use Fcntl qw(:flock SEEK_SET);
|
|||||||
### return -1 on EOF
|
### return -1 on EOF
|
||||||
sub read_word {
|
sub read_word {
|
||||||
my $F = shift;
|
my $F = shift;
|
||||||
|
|
||||||
# Convert four bytes into one 18-bit word
|
# Convert four bytes into one 18-bit word
|
||||||
return -1 if ( read( $F, my $four, 4 ) != 4 ); # Not enough bytes read
|
return -1 if ( read( $F, my $four, 4 ) != 4 ); # Not enough bytes read
|
||||||
my ( $b1, $b2, $b3, $b4 ) = unpack( "CCCC", $four );
|
my ( $b1, $b2, $b3, $b4 ) = unpack( "CCCC", $four );
|
||||||
return (($b1 & 0xff) |
|
return (
|
||||||
(($b2 & 0xff) << 8 ) |
|
( $b1 & 0xff ) | ( ( $b2 & 0xff ) << 8 ) | ( ( $b3 & 0xff ) << 16 ) |
|
||||||
(($b3 & 0xff) << 16) |
|
|
||||||
( ( $b4 & 0xff ) << 24 ) );
|
( ( $b4 & 0xff ) << 24 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,19 +31,32 @@ use constant WORDSPERBLK => 64; # 64 words per block
|
|||||||
use constant BYTESPERWORD => 4; # We encode each word into 4 bytes
|
use constant BYTESPERWORD => 4; # We encode each word into 4 bytes
|
||||||
|
|
||||||
# Skip the first surface
|
# Skip the first surface
|
||||||
seek($IN, NUMBLOCKS*WORDSPERBLK*BYTESPERWORD, SEEK_SET) ||
|
seek( $IN, NUMBLOCKS * WORDSPERBLK * BYTESPERWORD, SEEK_SET )
|
||||||
die("Cannot seek: $!\n");
|
|| die("Cannot seek: $!\n");
|
||||||
|
|
||||||
foreach my $blocknum ( 0 .. NUMBLOCKS * 2 - 1 ) {
|
foreach my $blocknum ( 0 .. NUMBLOCKS * 2 - 1 ) {
|
||||||
printf( "Block %d (%06o)\n", $blocknum, $blocknum );
|
printf( "Block %d (%06o)\n", $blocknum, $blocknum );
|
||||||
foreach my $line ( 0 .. 7 ) {
|
foreach my $line ( 0 .. 7 ) {
|
||||||
|
|
||||||
# Print out the words in octal
|
# Print out the words in octal
|
||||||
|
my @buf;
|
||||||
foreach my $offset ( 0 .. 7 ) {
|
foreach my $offset ( 0 .. 7 ) {
|
||||||
|
|
||||||
# Get a word
|
# Get a word
|
||||||
my $word = read_word($IN);
|
my $word = read_word($IN);
|
||||||
exit(0) if ( $word == -1 );
|
exit(0) if ( $word == -1 );
|
||||||
printf("%06o ", $word);
|
$buf[$offset] = $word;
|
||||||
|
}
|
||||||
|
foreach my $offset ( 0 .. 7 ) {
|
||||||
|
printf( "%06o ", $buf[$offset] );
|
||||||
|
}
|
||||||
|
print(" ");
|
||||||
|
foreach my $offset ( 0 .. 7 ) {
|
||||||
|
my $c1 = ( $buf[$offset] >> 9 ) & 0777;
|
||||||
|
$c1 = ( ( $c1 >= 32 ) && ( $c1 <= 126 ) ) ? chr($c1) : ' ';
|
||||||
|
my $c2 = $buf[$offset] & 0777;
|
||||||
|
$c2 = ( ( $c2 >= 32 ) && ( $c2 <= 126 ) ) ? chr($c2) : ' ';
|
||||||
|
print("$c1$c2");
|
||||||
}
|
}
|
||||||
print("\n");
|
print("\n");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user