home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 2: Collection B / 17Bit_Collection_B.iso / files / 2224.dms / in.adf / source / DataDecr.s.pp / DataDecr.s
Encoding:
Text File  |  1990-09-13  |  5.7 KB  |  208 lines

  1. ***------------------------------------------------------------------------
  2. *** This is the ultimate Data-Decrunch-Routine
  3. *** for Crunch-Mania V1.4
  4. *** (c) 1991 by FRESH THRASH of CERBERUS, all rights reserved
  5. *** You may use this piece of code as long as you don't claim that
  6. *** you have written it. In any case the author (me) has to be
  7. *** mentioned someplace in your proggy.
  8. *** Note: Source- and Destinationaddresses have to be always even Addresses
  9. ***------------------------------------------------------------------------
  10. *** Here is the Format of the Header:
  11. *** Type  Offset  Contents                   Function
  12. *** LONG  0       "CrM!"                     to recongnize crunched files
  13. *** WORD  4       Minimum Security Distance  to savely decrunch data when
  14. ***                         Source and Dest is in the same
  15. ***                         Memoryblock
  16. *** LONG  6       Original Len               Datalen before packing
  17. *** LONG  10 ($a) Crunched Len               Datalen after packing without
  18. ***                         Header
  19. ***------------------------------------------------------------------------
  20. ** Jump here to decrunch some data with overlap check
  21. ** You need some Memory directly in front of the Destination Area
  22. ** which has to be as large as the MinSecDist
  23. ** Load the Regs with:
  24. ** a0: Adr of Source (with Header)    ** a1: Adr of Dest
  25. **---------------------------------------------------------------
  26. OverlapDecrunch:
  27.     movem.l    d0-d7/a0-a6,-(sp)
  28.     cmp.l    #"CrM!",(a0)+
  29.     bne.s    .NotCrunched
  30.     moveq    #0,d0
  31.     move.w    (a0)+,d0    ;MinSecDist
  32.     move.l    (a0)+,d1    ;DestLen
  33.     move.l    (a0)+,d2    ;SrcLen
  34.     lea    0(a0,d0.l),a2
  35.     cmp.l    a1,a2
  36.     ble.s    .NoCopy
  37.     move.l    a0,a2
  38.     move.l    a1,a0
  39.     sub.l    d0,a0        ;MinSecDist abziehen
  40.     move.l    a0,a3
  41.     move.l    d2,d7
  42.     lsr.l    #2,d7        ;Longs
  43. .CopyLoop:
  44.     move.l    (a2)+,(a3)+
  45.     subq.l    #1,d7
  46.     bne.s    .CopyLoop
  47.     move.l    (a2)+,(a3)+    ;in case of ...
  48. .NoCopy:
  49.     move.l    a0,a2
  50.     bsr.s    FastDecruncher
  51. .NotCrunched:
  52.     movem.l    (sp)+,d0-d7/a0-a6
  53.     rts
  54. **-----------------------------------------------------------
  55. ** Jump here to decrunch some data without any overlap checks
  56. ** The Regs have to loaded with:
  57. ** a0: Adr of Source (with Header)
  58. ** a1: Adr of Dest
  59. **-----------------------------------------------------------
  60. NormalDecrunch:
  61.     movem.l    d0-d7/a0-a6,-(sp)
  62.     cmp.l    #"CrM!",(a0)+
  63.     bne.s    .NotCrunched
  64.     tst.w    (a0)+        ;skip MinSecDist
  65.     move.l    (a0)+,d1    ;OrgLen
  66.     move.l    (a0)+,d2    ;CrLen
  67.     move.l    a0,a2
  68.     bsr.s    FastDecruncher
  69. .NotCrunched:
  70.     movem.l    (sp)+,d0-d7/a0-a6
  71.     rts
  72. **-------------------------------------------------------------------
  73. ** This is the pure Decrunch-Routine
  74. ** The Registers have to be loaded with the following values:
  75. ** a1: Adr of Destination (normal)    ** a2: Adr of Source (packed)
  76. ** d1: Len of Destination        ** d2: Len of Source
  77. **-------------------------------------------------------------------
  78. FastDecruncher:
  79.     move.l    a1,a5            ;Decrunched Anfang (hier Ende des Decrunchens)
  80.     add.l    d1,a1
  81.     add.l    d2,a2
  82.     move.w    -(a2),d0        ;Anz Bits in letztem Wort
  83.     move.l    -(a2),d6        ;1.LW
  84.     moveq    #16,d7            ;Anz Bits
  85.     sub.w    d0,d7            ;Anz Bits, die rotiert werden müssen
  86.     lsr.l    d7,d6            ;1.Bits an Anfang bringen
  87.     move.w    d0,d7            ;Anz Bits, die noch im Wort sind
  88.     moveq    #16,d3
  89.     moveq    #0,d4
  90. .DecrLoop:
  91.     cmp.l    a5,a1
  92.     ble.L    .DecrEnd            ;a1=a5: fertig (a1<a5: eigentlich Fehler)
  93.  
  94.     bsr.s    .BitTest
  95.     bcc.s    .InsertSeq        ;1.Bit 0: Sequenz
  96.     moveq    #0,d4
  97. ** einzelne Bytes einfügen **
  98. .InsertBytes:
  99.     moveq    #8,d1
  100.     bsr.w    .GetBits
  101.     move.b    d0,-(a1)
  102.     dbf    d4,.InsertBytes
  103.     bra.s    .DecrLoop
  104. *------------
  105. .SpecialInsert:
  106.     moveq    #14,d4
  107.     moveq    #5,d1
  108.     bsr.s    .BitTest
  109.     bcs.s    .IB1
  110.     moveq    #14,d1
  111. .IB1:    bsr.s    .GetBits
  112.     add.w    d0,d4
  113.     bra.s    .InsertBytes
  114. *------------
  115. .InsertSeq:
  116. ** Anzahl der gleichen Bits holen **
  117.     bsr.s    .BitTest
  118.     bcs.s    .AB1
  119.     moveq    #1,d1            ;Maske: 0 (1 AB)
  120.     moveq    #1,d4            ;normal: Summe 1
  121.     bra.s    .ABGet
  122. .AB1:
  123.     bsr.s    .BitTest
  124.     bcs.s    .AB2
  125.     moveq    #2,d1            ;Maske: 01 (2 ABs)
  126.     moveq    #3,d4            ;ab hier: Summe mindestens 3
  127.     bra.s    .ABGet
  128. .AB2:
  129.     bsr.s    .BitTest
  130.     bcs.s    .AB3
  131.     moveq    #4,d1            ;Maske: 011 (4 ABs)
  132.     moveq    #7,d4            ;hier: Summe 11
  133.     bra.s    .ABGet
  134. .AB3:
  135.     moveq    #8,d1            ;Maske: 111 (8 ABs)
  136.     moveq    #$17,d4            ;hier: Summe 11
  137. .ABGet:
  138.     bsr.s    .GetBits
  139.     add.w    d0,d4            ;d0: Länge der Sequenz - 1
  140.     cmp.w    #22,d4
  141.     beq.s    .SpecialInsert
  142.     blt.s    .Cont
  143.     subq.w    #1,d4
  144. .Cont:
  145. ** SequenzAnbstand holen **
  146.     bsr.s    .BitTest
  147.     bcs.s    .DB1
  148.     moveq    #9,d1            ;Maske: 0 (9 DBs)
  149.     moveq    #$20,d2
  150.     bra.s    .DBGet
  151. .DB1:
  152.     bsr.s    .BitTest
  153.     bcs.s    .DB2
  154.     moveq    #5,d1            ;Maske: 01 (5 DBs)
  155.     moveq    #0,d2
  156.     bra.s    .DBGet
  157. .DB2:
  158.     moveq    #14,d1            ;Maske: 11 (12 DBs)
  159.     move.w    #$220,d2
  160. .DBGet:
  161.     bsr.s    .GetBits
  162.     add.w    d2,d0
  163.     lea    0(a1,d0.w),a3        ;a3 auf Anf zu kopierender Seq setzten
  164. .InsSeqLoop:
  165.     move.b    -(a3),-(a1)        ;Byte kopieren
  166.     dbf    d4,.InsSeqLoop
  167.  
  168.     bra.w    .DecrLoop
  169. *------------
  170. .BitTest:
  171.     subq.w    #1,d7
  172.     bne.s    .BTNoLoop
  173.     moveq    #16,d7            ;hier kein add notwendig: d7 vorher 0
  174.     move.w    d6,d0
  175.     lsr.l    #1,d6            ;Bit rausschieben und Flags setzen
  176.     swap    d6            ;ror.l    #16,d6
  177.     move.w    -(a2),d6        ;nächstes Wort holen
  178.     swap    d6            ;rol.l    #16,d6
  179.     lsr.w    #1,d0            ;Bit rausschieben und Flags setzen
  180.     rts
  181. .BTNoLoop:
  182.     lsr.l    #1,d6            ;Bit rausschieben und Flags setzen
  183.     rts
  184. *----------
  185. .GetBits:                ;d1:AnzBits->d0:Bits
  186.     move.w    d6,d0            ;d6:Akt Wort
  187.     lsr.l    d1,d6            ;nächste Bits nach vorne bringen
  188.     sub.w    d1,d7            ;d7:Anz Bits, die noch im Wort sind
  189.     bgt.s    .GBNoLoop
  190. ;    add.w    #16,d7            ;BitCounter korrigieren
  191.     add.w    d3,d7            ;BitCounter korrigieren
  192.     ror.l    d7,d6            ;restliche Bits re rausschieben
  193.     move.w    -(a2),d6        ;nächstes Wort holen
  194.     rol.l    d7,d6            ;und zurückrotieren
  195. .GBNoLoop:
  196.     add.w    d1,d1            ;*2 (in Tab sind Ws)
  197.     and.w    .AndData-2(pc,d1.w),d0    ;unerwünschte Bits rausschmeißen
  198.     rts
  199. *----------
  200. .AndData:
  201.     dc.w    %1,%11,%111,%1111,%11111,%111111,%1111111
  202.     dc.w    %11111111,%111111111,%1111111111
  203.     dc.w    %11111111111,%111111111111
  204.     dc.w    %1111111111111,%11111111111111
  205. *-----------
  206. .DecrEnd:
  207.     rts        ;a5: Start of decrunched Data
  208.