home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / packery / xpkilzr / source / bitio.h next >
Text File  |  1977-12-31  |  7KB  |  128 lines

  1.  
  2. /**
  3.   *  Este fichero ha sido diseqado para manejar de forma estandar
  4.   * las entradas salidas que son necesarias de forma binaria
  5.   *  Se ha intentado optimizar al maximo para aumentar la velocidad
  6.   * sin preocuparse si el origen o destino es memoria o un fichero
  7.   *
  8.   **/
  9.  
  10.  
  11. /*  compress InputByte  , OutputBits , OutputBit                    */
  12. /*  expand   OutputByte , InputBits  , InputBit                     */
  13.  
  14. /*    START of COMPRESS                                             */
  15.  
  16. /*          UBYTE   endoffile                                       */
  17. /*          CHARS   *inpb                                           */
  18. /*          CHARS   *endinp                                         */
  19. /*          CHARS   *outb                                           */
  20. /*          CHARS   *endout                                         */
  21. /*          ULONG   ioaux                                           */
  22.  
  23. #define InitOutput()    {                                         \
  24.                         outb      = (CHARS *)xpar->OutBuf;        \
  25.                         *outb     = 0;                            \
  26.                         outmask   = 0x80;                         \
  27.                         endout    = (CHARS *)                     \
  28.                       ((long)xpar->OutBuf+(long)xpar->OutBufLen); \
  29.                         }
  30.  
  31. #define InitInput()     {                                         \
  32.                         inpb      = (CHARS *)xpar->InBuf;         \
  33.                         inpmask   = 0x80;                         \
  34.                         endinp    = (CHARS *)                     \
  35.                       ((long)xpar->InBuf+(long)xpar->InLen);      \
  36.                         }
  37.  
  38.  
  39. #define OutputBit( bit )  {                                       \
  40.                           if ( bit )                              \
  41.                             *outb |= outmask;                     \
  42.                           outmask >>= 1;                          \
  43.                           if ( !outmask  )                        \
  44.                             {                                     \
  45.                             if( ++outb >= endout )                \
  46.                               return( XPKERR_EXPANSION );         \
  47.                             *outb   = 0;                          \
  48.                             outmask = 0x80;                       \
  49.                             }                                     \
  50.                           }
  51.  
  52. #define OutputBits( code, count ) {                               \
  53.                           ioaux = 1L << ( count - 1 );            \
  54.                           while ( ioaux != 0)                     \
  55.                             {                                     \
  56.                             if ( code & ioaux )                   \
  57.                               *outb |= outmask;                   \
  58.                             outmask >>= 1;                        \
  59.                             if ( !outmask  )                      \
  60.                               {                                   \
  61.                               if( ++outb >= endout )              \
  62.                                 return( XPKERR_EXPANSION );       \
  63.                               *outb   = 0;                        \
  64.                               outmask = 0x80;                     \
  65.                               }                                   \
  66.                             ioaux >>= 1;                          \
  67.                             }                                     \
  68.                           } 
  69.  
  70. #define InputByte(  )     {                                       \
  71.                           if(inpb++ >=endinp )                    \
  72.                             endoffile = 1;                        \
  73.                           }
  74.  
  75. #define EndOfFile()       ( endoffile )
  76.  
  77. /*  START OF EXPAND               */
  78.  
  79. /*  Definir UBYTE   inpmask                                         */
  80. /*          UBYTE   endoffile                                       */
  81. /*          CHARS   *inpb                                           */
  82. /*          CHARS   *endinp                                         */
  83. /*          CHARS   *outb                                           */
  84. /*          CHARS   *endout                                         */
  85. /*          ULONG   ioaux                                           */
  86.  
  87. #define InputBit( code )  {                                       \
  88.                           if( inpmask == 0x80 )                   \
  89.                             if( inpb >= endinp)                   \
  90.                               endoffile=1;                        \
  91.                           code = (*inpb) & inpmask;               \
  92.                           inpmask >>= 1;                          \
  93.                           if ( !inpmask )                         \
  94.                             {                                     \
  95.                             inpmask = 0x80;                       \
  96.                             inpb++;                               \
  97.                             }                                     \
  98.                           }
  99.  
  100. #define InputBits( code , bit_count ) {                           \
  101.                           ioaux = 1L <<  (bit_count -1);          \
  102.                           code = 0;                               \
  103.                           while( ioaux )                          \
  104.                             {                                     \
  105.                             if( inpmask == 0x80 )                 \
  106.                               if( inpb >= endinp )                \
  107.                                 endoffile=1;                      \
  108.                             if( (*inpb) & inpmask )               \
  109.                               code |= ioaux;                      \
  110.                             ioaux >>=1;                           \
  111.                             inpmask >>= 1;                        \
  112.                             if ( !inpmask  )                      \
  113.                               {                                   \
  114.                               inpmask = 0x80;                     \ 
  115.                               inpb++;                             \
  116.                               }                                   \
  117.                             }                                     \
  118.                           }
  119.  
  120.  
  121. #define OutputByte( car ) {                                       \
  122.                           *outb = car;                            \
  123.                           if( ++outb >= endout )                  \
  124.                             return( XPKERR_SMALLBUF );            \
  125.                           }
  126.  
  127. /*************************** End of BITIO.C **************************/
  128.