home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga Shareware Floppies / ma54.dms / ma54.adf / xpkFAST_V1_03 / decompress.s < prev    next >
Text File  |  1993-08-21  |  3KB  |  117 lines

  1. ;;;
  2. ;;;                Remarks
  3. ;;;                =======
  4. ;;;
  5. ;;;   * This code relies on XPK_MARGIN being >= 32 !!!
  6. ;;;     If only one Bit in the last ControlWord is used, the remaining 15
  7. ;;;     will be filled with 0.  This will result in 15 LiteralItems on
  8. ;;;     decompression.  In Addition to this there is NO CHECK, if a match
  9. ;;;     matches more than the input.  This can result in a match which is
  10. ;;;     17 Bytes to long giving a maximum total of 32 Bytes garbled after
  11. ;;;     the outputblock after decompresion.
  12. ;;;       (XPK_MARGIN is 256 in xpkmaster.library V2.0)
  13. ;;;
  14.  
  15.     CODE
  16.  
  17.     XDEF    decompress
  18.  
  19. ;                                ;Register Map
  20. ;                                ;============
  21. ;  a0    Points to next source      byte.
  22. ;  a1    Points to next destination byte.
  23. ;  a2    Temporary.
  24. ;  a3    Unused.
  25. ;  a4    Pointer for the input word stream.
  26. ;  a5    Unused.
  27. ;  a6    Stackframe linkage register. Don't touch!
  28. ;  a7    Stack pointer.
  29.  
  30. ;  d0    Length of the compressed.
  31. ;  d1    control Word
  32. ;  d2    Counter for halfunrolled decompress_16_items_loop.
  33. ;  d3    Temporary used to calculate copy item length.
  34. ;  d4    Temporary used to calculate copy item offset.
  35. ;  d5    Unused.
  36. ;  d6    Unused.
  37. ;  d7    Unused.
  38.  
  39. ;;;---------------------------------------------------------------------------
  40.  
  41. DECOMPRESSREGS    reg    a0-a2/a4-a5/d1-d5
  42. decompress:
  43.     movem.l    DECOMPRESSREGS,-(sp)
  44.  
  45.     move.l    d0,a4
  46.     add.l    a0,a4        ;a4:=behind the end of input block
  47.  
  48.     moveq.l    #0,d4        ;d4:=0
  49.  
  50. ;;;---------------------------------------------------------------------------
  51.  
  52. DOCOPY MACRO
  53.     move.w    -(a4),d4    ;Grab the copy item description
  54.     moveq    #$0F,d3
  55.     and.b    d4,d3        ;extract length.
  56.     add.b    d3,d3        ;adjust length to length*2
  57.     lsr.w    #4,d4        ;extract offset
  58.  
  59.     move.l    a1,a2        ;Subtract the offset yielding the
  60.     suba.l    d4,a2        ;address from which we copy.
  61.     jmp    MOVE\@(PC,d3.w)    ;jump to the right place
  62. MOVE\@    move.b    (a2)+,(a1)+    ;0
  63.     move.b    (a2)+,(a1)+    ;1
  64.     move.b    (a2)+,(a1)+    ;2
  65.     move.b    (a2)+,(a1)+    ;3
  66.     move.b    (a2)+,(a1)+    ;4
  67.     move.b    (a2)+,(a1)+    ;5
  68.     move.b    (a2)+,(a1)+    ;6
  69.     move.b    (a2)+,(a1)+    ;7
  70.     move.b    (a2)+,(a1)+    ;8
  71.     move.b    (a2)+,(a1)+    ;9
  72.     move.b    (a2)+,(a1)+    ;10
  73.     move.b    (a2)+,(a1)+    ;11
  74.     move.b    (a2)+,(a1)+    ;12
  75.     move.b    (a2)+,(a1)+    ;13
  76.     move.b    (a2)+,(a1)+    ;14
  77.     move.b    (a2)+,(a1)+    ;15
  78.     move.b    (a2)+,(a1)+
  79.     move.b    (a2)+,(a1)+
  80.     ENDM
  81.  
  82. DOLITERAL MACRO
  83.     move.b    (a0)+,(a1)+    ;Literal item means copy a byte.
  84.     ENDM
  85.  
  86.     ;This loop processes one 16-item item group per iteration.
  87.     ;This loop terminates when we definitely have decompressed all
  88.     ;16-item blocks.  It may overwrite 15+17 innocent bytes AFTER the
  89.     ;end of outbuf.
  90.  
  91. oloop:    move.w    -(a4),d1
  92.     moveq    #7,d2
  93. iloop:
  94.     add.w    d1,d1
  95.     bcs.s    Copy0
  96. Lit0:    DOLITERAL
  97.     add.w    d1,d1
  98.     bcs.s    Copy1
  99. Lit1:    DOLITERAL
  100.     dbra    d2,iloop
  101.     cmp.l    a4,a0
  102.     bcs.s    oloop
  103.     bra.s    finish
  104.  
  105. Copy0:    DOCOPY
  106.     add.w    d1,d1
  107.     bcc.s    Lit1
  108. Copy1:    DOCOPY
  109.     dbra    d2,iloop
  110.     cmp.l    a4,a0
  111.     bcs    oloop
  112.     
  113. finish:    movem.l    (sp)+,DECOMPRESSREGS
  114.     rts
  115.  
  116.     END
  117.