B: seq = c9to8( input, inpos, inseq, nbytes, output );
C: int c9to8(const char *input, int inpos, int inseq, int nbytes, int *output);
C9TO8 packs a sequence of 9-bit bytes into a stream of 8 bit values. It does this by stripping the high order bit of each byte and concatenating the 8-bit values together. Input data like this is likely to have come from the TP.RD9 function.
Each 9 bytes of 8-bit data contains 72 bits of information that is packed into a double machine word as shown in the diagram below:
Input Character stream: ---------+---------+---------+--------- 0aaaaaaaa 0bbbbbbbb 0cccccccc 0dddddddd ---------+---------+---------+--------- 0eeeeeeee 0ffffffff 0gggggggg 0hhhhhhhh ---------+---------+---------+--------- 0iiiiiiii ---------+
Output Double Word: ---------+---------+---------+--------- aaaaaaaab bbbbbbbcc ccccccddd dddddeeee ---------+---------+---------+--------- eeeefffff fffgggggg gghhhhhhh hiiiiiiii ---------+---------+---------+---------
The example below shows a typical way to use C9TO8 in unpacking data from tape:
bseq = 0; /* initial position in input byte sequence */ for( word=0; nb && word < IO_BLKSIZE; word += wordinc ) { howmany = min( nb, blksz-byteno ); howmany = min( howmany, (IO_BLKSIZE-word)/2*9-bseq ); wordinc = (howmany+bseq)/9*2; bseq = c9to8(buffer,byteno,bseq,howmany,llinkbuf+word ); if( (byteno+=howmany)>=blksz && fill_tar_buffer()==0 ) error("Premature EOF on input restoring file %s.*n", hname ); nb -= howmany; }
Copyright © 1996, Thinkage Ltd.