home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / packery / xpk_source / libraries / fast / decompress.a < prev    next >
Text File  |  1996-10-19  |  3KB  |  121 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.     XDEF    decompress
  16.  
  17. ;                                ;Register Map
  18. ;                                ;============
  19. ;  a0    Points to next source      byte.
  20. ;  a1    Points to next destination byte.
  21. ;  a2    Temporary.
  22. ;  a3    Unused.
  23. ;  a4    Pointer for the input word stream.
  24. ;  a5    Unused.
  25. ;  a6    Stackframe linkage register. Don't touch!
  26. ;  a7    Stack pointer.
  27.  
  28. ;  d0    Length of the compressed.
  29. ;  d1    control Word
  30. ;  d2    Counter for halfunrolled decompress_16_items_loop.
  31. ;  d3    Temporary used to calculate copy item length.
  32. ;  d4    Temporary used to calculate copy item offset.
  33. ;  d5    Unused.
  34. ;  d6    Unused.
  35. ;  d7    Unused.
  36.  
  37. ;;;---------------------------------------------------------------------------
  38.  
  39. decompress:
  40.     movem.l    a0-a2/a4-a5/d1-d5,-(sp)
  41.  
  42.     move.l    d0,a4
  43.     add.l    a0,a4        ;a4:=behind the end of input block
  44.  
  45.     moveq.l    #0,d4        ;d4:=0
  46.  
  47. ;;;---------------------------------------------------------------------------
  48.  
  49. DOCOPY MACRO
  50.     move.w    -(a4),d4    ;Grab the copy item description
  51.     moveq    #$0F,d3
  52.     and.b    d4,d3        ;extract length.
  53.     add.b    d3,d3        ;adjust length to length*2
  54.     lsr.w    #4,d4        ;extract offset
  55.  
  56.     move.l    a1,a2        ;Subtract the offset yielding the
  57.     suba.l    d4,a2        ;address from which we copy.
  58.     jmp    MOVE\@(PC,d3.w)    ;jump to the right place
  59. MOVE\@    move.b    (a2)+,(a1)+    ;0
  60.     move.b    (a2)+,(a1)+    ;1
  61.     move.b    (a2)+,(a1)+    ;2
  62.     move.b    (a2)+,(a1)+    ;3
  63.     move.b    (a2)+,(a1)+    ;4
  64.     move.b    (a2)+,(a1)+    ;5
  65.     move.b    (a2)+,(a1)+    ;6
  66.     move.b    (a2)+,(a1)+    ;7
  67.     move.b    (a2)+,(a1)+    ;8
  68.     move.b    (a2)+,(a1)+    ;9
  69.     move.b    (a2)+,(a1)+    ;10
  70.     move.b    (a2)+,(a1)+    ;11
  71.     move.b    (a2)+,(a1)+    ;12
  72.     move.b    (a2)+,(a1)+    ;13
  73.     move.b    (a2)+,(a1)+    ;14
  74.     move.b    (a2)+,(a1)+    ;15
  75.     move.b    (a2)+,(a1)+
  76.     move.b    (a2)+,(a1)+
  77.     ENDM
  78.  
  79. DOLITERAL MACRO
  80.     move.b    (a0)+,(a1)+    ;Literal item means copy a byte.
  81.     ENDM
  82.  
  83.     ;This loop processes one 16-item item group per iteration.
  84.     ;This loop terminates when we definitely have decompressed all
  85.     ;16-item blocks.  It may overwrite 15+17 innocent bytes AFTER the
  86.     ;end of outbuf.
  87.  
  88.     move.w    #$8000,d1
  89.     add.w    d1,d1
  90.  
  91. oloop:    move.w    -(a4),d1
  92.     addx.w    d1,d1
  93.     bcs.s    Copy0
  94.  
  95. Lit0:    DOLITERAL
  96.     add.w    d1,d1
  97.     bcc.W    Lit1
  98. Copy1:    DOCOPY
  99.     add.w    d1,d1
  100.     bcc.s    Lit0
  101.     bne.s    Copy0
  102.     cmp.l    a4,a0
  103.     bcc.s    finish
  104.     move.w    -(a4),d1
  105.     addx.w    d1,d1
  106.     bcc.s    Lit0
  107.  
  108. Copy0:    DOCOPY
  109.     add.w    d1,d1
  110.     bcs.s    Copy1
  111. Lit1:    DOLITERAL
  112.     add.w    d1,d1
  113.     bcc.W    Lit0
  114.     bne.s    Copy0
  115.     cmp.l    a4,a0
  116.     bcs.W    oloop
  117.     
  118. finish:    movem.l    (sp)+,a0-a2/a4-a5/d1-d5
  119.     rts
  120.     END
  121.