1
0
mirror of https://github.com/DoctorWkt/pdp7-unix.git synced 2026-01-24 19:33:02 +00:00
Warren Toomey 451a58fc58 I've added code to detect binary PDP-7 files to a7out. This is needed
for doing the seek() and tell() syscalls which are next to do.
2016-03-04 13:03:42 +10:00

27 lines
734 B
Perl
Executable File

#!/usr/bin/perl
#
# Dump a binary PDP-7 file where a word is encoded as three bytes,
# with sixbits are stored big-endian in each of the three byte.
#
use strict;
use warnings;
die("Usage: $0 binaryfile\n") if (@ARGV==0);
open(my $IN, "<", $ARGV[0]) || die("Can't open $ARGV[0]: $!\n");
while (1) {
# Convert three bytes into one 18-bit word
my $result= read($IN, my $three, 3);
last if ($result != 3); # Not enough bytes read
my ($b1, $b2, $b3)= unpack("CCC", $three);
my $word= (($b1 & 077) << 12) | ($b2 << 6) | $b3;
my $c1= ($word >> 9) & 0777;
$c1= ($c1 < 0200) ? chr($c1) : " ";
my $c2= $word & 0777;
$c2= ($c2 < 0200) ? chr($c2) : " ";
printf("%06o %s%s\n", $word, $c1, $c2)
}
close($IN);
exit(0);