home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.tar / ftp.whtech.com / Geneve / 9640news / CAT01 / RCHVRMT.ARK < prev    next >
Text File  |  2006-10-19  |  15KB  |  323 lines

  1. ?
  2.                                                                  07-Nov-1987
  3.                                                           by:   Alan L. Beard
  4.                                                            BIX:  abeard
  5.                                                     Compuserve:  71370,2723
  6.  
  7.                         TI-99/GENEVE Archiver Format
  8.                         ----------------------------
  9.  
  10.   1  General
  11.  
  12.        This is a text file describing the archiver format popularized by Barry
  13.        Traver.  It is furthur extended by Huffman encoding techniques, into
  14.        a squeezing archiver.
  15.  
  16.        An archiver is a program, which reads a collection of (usually related)
  17.        other programs, and combines them into a single file called an archive.
  18.        Sometime later, the programs can be recovered from this single file in
  19.        the original file formats.
  20.  
  21.        The advantage of an archiver is that only a single file need be posted
  22.        on a network instead of multiple files.  A user need only be concerned
  23.        that the single file was downloaded, and be assured that this single
  24.        file contains all necessary elements to run a program (e.g. source,
  25.        objects, executables, documentation files, readme files, etc.).
  26.  
  27.        A second advantage of an archiver is that the archiver can be made
  28.        "smart", i.e. it can take advantage of repitition of characters in
  29.        files to "squeeze" or "crunch" the files into an archive, making
  30.        the resulting archive usually some 30 to 60% smaller than the original
  31.        files contained.  This is done without loss of information.  The
  32.        "squeezed" archive is shorter to upload/download, saving the user 30
  33.        to 60% on his downloading fees.  Also, moderators on networks and
  34.        bulletin board systems encourage file compression as immediately 30
  35.        to 60% more mass storage becomes available, with no increase in costs!
  36.  
  37.        A squeezing archiver also makes sense to a user interested in
  38.        archiving a number of infrequently used files (such as the source
  39.        for a program after it has been compiled).
  40.  
  41.        As a matter of fact, the only disadvantage to archiving is that
  42.        the archive/dearchiving process tends to be time-consuming (2 to
  43.        15 minutes to unpack an archive).  But, since this is done offline,
  44.        on an essentially free (your) system, this usually isn't very
  45.        significant.
  46.  
  47.  
  48. 2 The TRAVER Algorithm/Format
  49.  
  50.        Barry Traver introduced the most popular archiver for the TI-99
  51.        and Geneve.  It is written in Extended BASIC, is quite a professional
  52.        program, and demonstrates the capabilities of Extended BASIC.  A
  53.        single assembly language subroutine was used, which allowed sector
  54.        reads and writes by accessing a Device Service Routine (DSR) in
  55.        the TI Disk controller card.
  56.  
  57.        The TRAVER archiver is FAIRWARE, for those people who subscribe
  58.        to the TRAVelER, the program is free.
  59.  
  60.        Barry picked a simple approach to the archiving algorithm, one
  61.        that shows an indepth knowledge of the internal TI-99 disk file
  62.        structure, and uses that structure to the archiver's advantage.
  63.        Files are packed in a archive very close to the same way they
  64.        are on the TI-99 disk.  The archive itself consists of a fixed/
  65.        display/128 file (probably since BASIC can't open a fixed/display/
  66.        256 byte file).
  67.  
  68.   2.1 File Packing Algorithm
  69.  
  70.        The basic algorithm for the archiver works something like this:
  71.  
  72.          a. The file descriptor index record is read which points to
  73.             all of the one sector file header records.
  74.  
  75.          b. The user is prompted for which files on the disk are to
  76.             be compressed.
  77.  
  78.          c. Each desired file header record is read, the unused bytes
  79.             are stripped (including the reserved expansion bytes, and
  80.             the data chain pointer blocks) leaving a "mini" file descriptor
  81.             record which consists of the following:
  82.  
  83.                   o 10 character file name
  84.                   o File Status Flags
  85.                   o Maximum Number Records/Sector or AU
  86.                   o Total Number of Sectors Used
  87.                   o End of File Offset
  88.                   o Logical Record Length
  89.                   o Number of Fixed Records or Number Sectors Used
  90.  
  91.             These 18 byte mini file headers are packed fourteen to two
  92.             128 byte records (for a total of 252 bytes).  The remaining
  93.             unused four bytes per sector contain either zeroes (meaning
  94.             this is NOT the last header sector) or the characters END!
  95.             (meaning this is the last header sector).
  96.  
  97.          d. Following the header section of the archive is the data
  98.             section.  Each 256 byte sector of the file is packed as
  99.             two 128 byte records.
  100.  
  101.   2.2  File Unpacking Algorithm
  102.  
  103.        The file unpacking algorithm is quite straightforward.  The user
  104.        is solicited for the file or the files to be "unpacked".  These
  105.        are read from the archive file headers, and:
  106.  
  107.           a. The data section for each file is located using the
  108.              "total number of sectors used" field in the mini-file
  109.              descriptor records.
  110.  
  111.           b. The file is read from the archive, and written to the disk
  112.              as a DISPLAY/FIXED/128 file.
  113.  
  114.           c. After the file has been successfully written to the disk,
  115.              the disk is searched for the file header and the file
  116.              header is overwritten by the information contained in
  117.              mini-file descriptor.
  118.  
  119.  
  120.   3  The BEARD Huffman Squeezing FORMAT
  121.  
  122.      An extension to the TRAVER archiver format was released by myself
  123.      in September 1987.  This extension provides capability for squeezing
  124.      the archive using HUFFMAN encoding techniques originally developed
  125.      by R.Greenlaw under CP/M.  This CP/M method was ported from CP/M
  126.      to the IBM PC, and then to the Amiga, and finally to the TI-99.
  127.      Software sources were obtained in the public domain from BYTE
  128.      INFORMATION EXCHANGE.
  129.  
  130.      Thanks should be offered at this point for the inputs provided
  131.      by Dr. Jerry Coffey, who helped me work out the final bugs in
  132.      the squeezing archiver, especially for helping me make it backwards
  133.      compatible to the Traver Archive.
  134.  
  135.      The program is written in FORTRAN, so to use it you need to either
  136.      own a copy of FORTRAN, or get a copy of the public domain module
  137.      99STAND.ARC (for version 2.0) or FORTSA (for version 3.1 and above).
  138.  
  139.      The program maintains backwards compatibility to the TRAVER format,
  140.      it can unpacked either squeezed or unsqueezed archives, or a combination
  141.      of them.  The basic format of the archive is the same, a header
  142.      section consisting of "Traver-like" mini file headers, followed by
  143.      a data section of squeezed and (possibly) unsqueezed data files.
  144.  
  145.  
  146.   3.1 File Analysis
  147.  
  148.      Before a file can be squeezed, it must be analyzed.  This is performed
  149.      automatically by the squeezing archiver as a first pass on the file.
  150.  
  151.      The analysis portion basically consists of reading every sector in
  152.      the file to be compressed, and counting the occurances of each of
  153.      the possible 256 data byte values.  Once all of the file has been
  154.      read, and all of the occurance counts have been collected, then
  155.      a sort and binary tree is created containing the optimal Huffman
  156.      codes for the file.
  157.  
  158.   3.1 File Squeezing Algorithm
  159.  
  160.      Once the file has been analyzed, and a binary tree created, then
  161.      the squeezing part of the archiver is executed.  This portion
  162.      first writes a prolouge to the data file consisting of the
  163.      archival type, the sector length of the original file, the
  164.      number of binary tree nodes, and the binary tree, followed
  165.      by variable length bit strings representing the Huffman encoded
  166.      data.
  167.  
  168.      Following the squeeze operation, the reduction in the file size
  169.      is tested.  If the resulting file is larger than the original
  170.      file, then the file is "re-packed", using the normal unsqueezed
  171.      TRAVER format.
  172.  
  173.      If a reduction is detected in the file size, then the file header
  174.      is modified.  First, the file status flag is OR'd with a '20'X,
  175.      indicating an archived file.  The Total Number of Sectors used
  176.      field is changed to the Total Number of 128 byte records used.
  177.  
  178.      The actual data file contains the following information:
  179.  
  180.         o One word representing the archiving method.  This is currently
  181.           set to a 1, since this is the first squeezing method to be
  182.           implemented.  Future methods should set this to a different
  183.           unique number representing the different squeezing technique.
  184.  
  185.         o One word representing the original value for the Total
  186.           Number of Sectors.  Note that this was changed in the
  187.           mini-file header to be the number of 128 byte records.
  188.  
  189.         o One word representing the number of nodes in the binary
  190.           huffman tree (this word starts the particular encoding
  191.           scheme, whereas the first two words must be understood
  192.           by all archivers).
  193.  
  194.         o The nodes of the binary tree, first the left child, and then
  195.           the right child, repeated for the NUMNODES.
  196.  
  197.         o The squeezed archive data, terminated by a special "end-of-file"
  198.           character.
  199.  
  200.   3.2  File Unsqueezing Algorithm
  201.  
  202.       The file unsqueezing algorithm is similar to the "non-squeezing"
  203.       file unpacking algorithm.  The only key is to recognize that this
  204.       is a squeezed file (by the special file status bit OR'd '20'X),
  205.       and to recognize that the total sectors used is actually the
  206.       total records used if this is a squeezed file.
  207.  
  208.       If this is not a squeezed file, than the unpacking algorithm is
  209.       identical to the TRAVER format.
  210.  
  211.       One small difference can occur between an unpacked file (via the
  212.       Traver method) and a squeezed file (via the Beard method).  The
  213.       final sector of a file is usually only partially used, and the
  214.       squeezing archiver takes advantage of this fact to only save the
  215.       in use partial amount of the final sector.  The archiver "zero-
  216.       fills" the remainder of the sector.  The inconsistency is that
  217.       the final sector can be different (in its unused portion) than
  218.       the original file.  This should not cause any problems in using
  219.       the file (unless some tricks have been played with the DSR), but
  220.       would show as a difference on a sector by sector compare.
  221.  
  222.   4 Improvements
  223.  
  224.      Many improvements to the implemented squeezing archiver are possible
  225.      and encouraged.  The following is a list of possible improvement
  226.      areas:
  227.  
  228.        a. The TI-99 disk format is quite wasteful in that it does not
  229.           split a record (either fixed or variable) over a sector
  230.           boundry.  Therefore, a DISPLAY/FIXED/129 file will have 127
  231.           bytes/sector of unused space!  Variable files are similar, if
  232.           the next record to be stored cannot fit in the current sector,
  233.           then the record is terminated and the next record is started.
  234.           Since the squeezing archive is actually a stream of bits, this
  235.           unused space could easily be skipped in the archive.
  236.  
  237.        b. The bit manipulation routines in this program are in FORTRAN,
  238.           therefore are slower than what is achievable with Assembly.
  239.           A good deal of the lower level stuff could be streamlined.
  240.  
  241.        c. It would be useful if the archiver would recognize that a
  242.           file could not be squeezed at the "analysis" stage rather
  243.           than after it has been squeezed and written.
  244.  
  245.        d. Different, and better squeezing algorithms are available.
  246.           It might be possible to borrow from the IBM PC archiver,
  247.           and do the analysis in various formats, and pick the
  248.           compression method that yielded the best result.
  249.  
  250.        e. There is currently no support for hard disks, or reading/
  251.           writing sectors to/from a RAM disk.  (the reason being
  252.           that I don't have a hard disk, and I haven't figured out
  253.           the RAM disk yet).
  254.  
  255.   5. Archive FORMAT Recap
  256.  
  257.      a. Archive consists of two sections packed into a 128 byte fixed
  258.         length record file:
  259.  
  260.                o Header Section
  261.                o Data Section
  262.  
  263.      b. The header section consists of "mini-file headers" packed 14
  264.         to a record.  Each "mini-file header" is a stripped version of
  265.         a standard TI-99 file header, and contains the following:
  266.  
  267.            byte nos          Contents
  268.  
  269.             0-9         10 Character (MAX) file name.  Unused characters
  270.                         are space characters.
  271.  
  272.             10          File Status Flags:
  273.                                           Bit No   ON=1         OFF=0
  274.                            >00 Dis/Fix      0   Program File   Data File
  275.                            >01 Program      1   Internal       Display
  276.                            >02 Int/Fix      2   Reserved
  277.                            >80 Dis/Var      3   Write Prot     No Write Prot
  278.                            >82 Int/Var      4   Reserved
  279.                                            *5   Squeezed       Unsqueezed
  280.                          *Non-standard      6   Reserved
  281.                             meaning         7   Variable Len   Fixed Len
  282.  
  283.             11          Maximum Number of Records/Sector or AU
  284.  
  285.             12-13       Total Number of Sectors Used (unsqueezed archive) or
  286.                         Total Number of 128 byte Records Used (squeezed archive)
  287.  
  288.  
  289.             14          End of File Offset
  290.  
  291.             15          Logical Record Length
  292.  
  293.             16-17       Number of Fixed Length Records or Number of Sectors
  294.                         Used by Variable Length Records
  295.  
  296.         The last 128 byte header record contains the characters "END!" in
  297.         the last four bytes.  Unused header record slots (to fill out a
  298.         128 byte record) contain zeroes.
  299.  
  300.   c. The data section follows the header section, and contains a number
  301.      of data files pointed to by the header section.  There is no special
  302.      seperation between the data sections in the data section itself, it
  303.      is merely a collection of 128 byte records.
  304.  
  305.      The unsqueezed data section contains an even number of 128 byte
  306.      records for each sector in the input file.
  307.  
  308.      The squeezed data section has a more complex format, but still
  309.      consists of 128 byte records.  Actually, the data section can
  310.      be thought of as a continuous "stream" of data, organized as
  311.      follows:
  312.  
  313.         word 0 - Set to a "1", to indicate the compression method.
  314.         word 1 - The original value for the Total Number of Sectors
  315.         word 2 - The number of nodes in the binary tree
  316.         words 3 to numnodes*2+2 - The binary tree
  317.         remaining - Variable bit data for the Huffman Encoding.
  318.  
  319.  
  320. Download complete.  Turn off Capture File.
  321.  
  322.  
  323.