home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1997 #2 / amigaacscoverdisc / games / alienbreed3d2 / source_4000 / unfib.s < prev    next >
Text File  |  1997-01-31  |  2KB  |  82 lines

  1. ;This routine will take a sample file that has been
  2. ;compacted using the delta fibonacci compaction method
  3. ;pointed to by d0 of length d1, and returns a pointer
  4. ;to the decompressed file in d0 with the new length
  5. ;in d1.  The original memory will be deallocated and
  6. ;new memory for the uncompacted SFX will be requested.
  7.  
  8. ;The first long word will be "CSFX"
  9. ;the second long word holds the length of the
  10. ;uncompressed sample.
  11.  
  12.     include    "utils:devpac/system.gs"
  13.  
  14. UnPackSample:
  15.     add.l    #4,d0        ;Skip "CSFX"
  16.     move.l    d1,.CompressedSampleSize
  17.     move.l    d0,a0
  18.     move.l    4.w,a6
  19.     move.l    (a0)+,d0    ;file size
  20.     move.l    d0,.SampleSize
  21.     move.l    a0,.CompressedSamplePosition
  22.     move.l    #MEMF_CHIP,d1
  23.     jsr    _LVOAllocMem(a6)
  24.     move.l    d0,.SamplePosition
  25.     move.l    .CompressedSamplePosition,a0
  26.     move.l    d0,a1
  27.     move.l    .SampleSize,d0
  28.     sub.w    #2,d0
  29.     move.b    (a0)+,d1    ;first byte (actual value)
  30.     move.b    d1,(a1)+
  31.     lea    .FibList(pc),a2
  32. .DecompLoop:
  33.     move.b    (a0)+,d2
  34.     and.w    #$00ff,d2
  35.     move.w    d2,d3
  36.     lsr.w    #4,d2
  37.     and.w    #$000f,d3
  38.     move.b    (a2,d2.w),d4    ;first fib value
  39.     add.b    d4,d1
  40.     move.b    d1,(a1)+    ;store sample value
  41.     dbra    d0,.NotFinishedYet
  42.     bra.s    .SampleFinished
  43. .NotFinishedYet:
  44.     move.b    (a2,d3.w),d4    ;second fib value
  45.     add.b    d4,d1
  46.     move.b    d1,(a1)+    ;store sample value
  47.     dbra    d0,.DecompLoop    
  48. .SampleFinished:
  49.     move.l    .CompressedSamplePosition,a1
  50.     move.l    .CompressedSampleSize,d0
  51.     move.l    4.w,a6
  52.     jsr    _LVOFreeMem(a6)
  53.     ;Now check the sample and clip it if it ever gets
  54.     ;too big
  55.     
  56.     move.l    .SamplePosition,a0
  57.     move.l    .SampleSize,d0
  58.     sub.w    #1,d0
  59. .ClipLoop:
  60.     move.b    (a0),d1
  61.     cmp.b    #64,d1
  62.     blt.s    .NotTooBig
  63.     move.b    #63,d1
  64. .NotTooBig:
  65.     cmp.b    #-64,d1
  66.     bge.s    .NotTooSmall
  67.     move.b    #-64,d1
  68. .NotTooSmall:
  69.     move.b    d1,(a0)+
  70.     dbra    d0,.ClipLoop
  71.     
  72.     move.l    .SamplePosition,d0
  73.     move.l    .SampleSize,d1
  74.     
  75.     rts
  76.     
  77. .CompressedSamplePosition:    dc.l    0
  78. .CompressedSampleSize:        dc.l    0
  79. .SamplePosition:        dc.l    0
  80. .SampleSize:            dc.l    0
  81. .FibList:    dc.b    -34,-21,-13,-8,-5,-3,-2,-1,0,1,2,3,5,8,13,21
  82.