home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / TPLZH019 / LZH.PAS < prev    next >
Pascal/Delphi Source File  |  1992-12-25  |  3KB  |  118 lines

  1. {$o+$A+}
  2. {
  3.  
  4.  
  5.    LZH.PAS - base unit for all Huffman engine components
  6.  
  7.    LZH.PAS based on:
  8.  
  9.    LZHUF.C English version 1.0 based on Japanese version 29-NOV-1988
  10.    Haruhiko OKUMURA:   LZSS coded
  11.    Haruyasu YOSHIZAKI: Adaptive Huffman Coding coded
  12.    Kenji RIKITAKE:     Edited and translated to English
  13.    Peter Sawatzki,
  14.    Wayne Sullivan:     Converted to Turbo Pascal 5.0
  15.    Joe Jared:          Assembler (12/16/92)
  16.    Andres Cvitkovich:  object-oriented interface
  17.  
  18.    <Your name here>: Other language interface.
  19.  
  20.  
  21. }
  22. {$i-,v-,s-,f+,r-}
  23. Unit LZH;
  24. Interface
  25. Const
  26.      EngineVer = '0.19ß';
  27. type
  28.     
  29.   IObuf = array[0..$2800-1] of byte; {These buffers are now FIXED!}
  30.  
  31.   LZHRec = Record       {Segment:0 aligned}
  32.          count          : LongInt;
  33.          textsize       : LongInt;
  34.          codesize       : LongInt;
  35.          inptr,inend,outptr,outend    : Word;
  36.          Ebytes         : Longint;
  37.          inbuf,outbuf        : IObuf;
  38.          {Buffersize and position are critical}
  39.          WorkSpace           : Array [0..$86ff] of byte;
  40.          {LZHASM work space} {Some space reserved}
  41.          End;
  42.  
  43.  {$L LZHASM}
  44.  {LZH_CUSTOM  : WORD  ; {Customized settings        
  45.  LZHERROR   : WORD  ; {
  46.  LZHMessage : String; { English response from
  47.  LZHVERSION : WORD  ; { Hibyte major, lobyte minor}
  48.  
  49.     
  50.  
  51. var
  52.    LZHERROR    : Word; {for future use}
  53.    StupidAlloc  : Boolean;
  54.    StupidPtr    : Pointer;
  55.    {$F+}
  56.    WriteFromBuffer,
  57.    ReadToBuffer: Procedure;
  58.    LZHMem: ^LZHRec;
  59.    LZHMemSeg       : WORD;
  60.    {$F+}                            
  61.    procedure Encode ;
  62.    procedure Decode;
  63.  
  64.    Procedure InitLZH;
  65.    Procedure DInitLZH;
  66. Implementation
  67. {$F+}
  68. procedure Decode; External;
  69. procedure Encode; External;
  70.  
  71.  
  72.  
  73.  
  74. {$R-}
  75. Procedure InitLZH;
  76. {
  77.  
  78. If need be, call this routine before any other allocations, or...
  79. Segment align all allocations.  This routine is setup to keep memory
  80. allocations segment aligned, and to be backwards compatible with all
  81. versions of Turbo Pascal, even though Borland isn't....
  82.  
  83. }
  84. Begin
  85.      
  86.      StupidAlloc := True;
  87.      GetMem (StupidPtr,8);
  88.      If Ofs(StupidPtr^) = 0 Then Begin
  89.         Freemem(StupidPtr,8);
  90.         StupidAlloc := False;
  91.         End;
  92.  
  93.  
  94.      GetMem (LZHMem,(Sizeof(LZhmem^)AND $FFF0) +16);
  95.      LZHMemSeg := Seg(LZhmem^);
  96.      LZhmem^.Inend := 0;  { This is to insure that Read is called.      }
  97.      LZhmem^.outend := 0; { If you don't fill the input, the engine will}
  98.      {If you wonder why it locks up at any point, this is probably the cause}
  99.      {If you changed this source, it's probably your fault.}
  100.  
  101.      {$IFDEF DEBUGLZH}
  102.      Writeln (Seg(LZhmem^),':', ofs(LZhmem^));
  103.      Writeln (Sizeof(LZhmem^));
  104.      halt;
  105.      {$ENDIF}
  106.  
  107.  
  108.  
  109. End;
  110. Procedure DInitLZH;
  111. Begin
  112.      FreeMem (LZHMem,(Sizeof(LZhmem^)AND $FFF0) +16);
  113.      if StupidAlloc then Freemem(StupidPtr,8);
  114.  
  115. End;
  116.  
  117. end.
  118.