home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga Shareware Floppies / ma32.dms / ma32.adf / xfd-lib / sources / Chryseis.s
Text File  |  1994-03-27  |  5KB  |  291 lines

  1. *******************************************************
  2. **   XFD external decruncher for Chryseis Cruncher   **
  3. **        written and © 1994 by Georg Hörmann        **
  4. *******************************************************
  5.  
  6.         OUTPUT    "LIBS:xfd/Chryseis"
  7.  
  8.         SECTION    Chryseis,CODE
  9.  
  10.         INCDIR    "dh0:Include_Asm"    ;change this as you need it
  11.         INCLUDE    "dh0:xfd/xfdmaster.i"
  12.  
  13. ; xfdForeman structure MUST be first thing in all external decrunchers
  14.  
  15. F_Chryseis    moveq    #-1,d0        ;security
  16.         rts
  17.         dc.l    XFDF_ID        ;id
  18.         dc.w    1        ;version
  19.         dc.w    0
  20.         dc.l    0,0        ;private
  21.         dc.l    S_Chryseis09    ;first slave
  22.  
  23. **************************************************
  24.  
  25. ; xfdSlave structure: this one doesn't support segment decrunching
  26.  
  27. S_Chryseis09    dc.l    0        ;no more slaves
  28.         dc.w    1        ;version
  29.         dc.w    33        ;master version
  30.         dc.l    N_Chryseis09    ;name
  31.         dc.w    XFDPFF_RELOC    ;flags
  32.         dc.w    0
  33.         dc.l    RB_Chryseis09    ;recog buffer
  34.         dc.l    DB_Chryseis09    ;decrunch buffer
  35.         dc.l    0        ;recog segment
  36.         dc.l    0        ;decrunch segment
  37.  
  38. N_Chryseis09    dc.b    'Chryseis Cruncher 0.9',0
  39.         even
  40.  
  41. ;-------------------------------------------------
  42.  
  43. ; Recog buffer function: receives buffer + length in a0/d0
  44.  
  45. RB_Chryseis09    cmp.l    #$4bc+32,d0    ;min. file length for header and data
  46.         ble.s    .Exit
  47.         cmp.w    #$abcd,$2a(a0)    ;some more verification
  48.         bne.s    .Exit
  49.         cmp.w    #$03f6,$4ba(a0)
  50.         bne.s    .Exit
  51.  
  52.         cmp.l    #$208f205f,$42(a0)
  53.         bne.s    .Exit
  54.         cmp.l    #$4eba01c8,$46(a0)
  55.         bne.s    .Exit
  56.         cmp.l    #$49fa025c,$214(a0)
  57.         bne.s    .Exit
  58.         moveq    #1,d0
  59.         rts
  60.  
  61. .Exit        moveq    #0,d0
  62.         rts
  63.  
  64. ;-------------------------------------------------
  65.  
  66. ;Decrunch buffer function: receives bufferinfo in a0
  67.  
  68. DB_Chryseis09    movem.l    d2-d7/a2-a6,-(a7)
  69.         move.l    a0,a5
  70.         move.l    xfdbi_SourceBuffer(a5),a2
  71.  
  72. ; first of all, we calculate the length of the decrunched file
  73.  
  74.         moveq    #20,d2        ;3f3,0,x,0,x-1
  75.         lea    $4bc(a2),a0
  76.         move.l    (a0),d0
  77.         move.l    d0,d3        ;amount hunks
  78.         lsl.l    #2,d0
  79.         add.l    d0,d2        ;hunklens
  80.         lea    12(a0,d0.l),a0
  81.         
  82. .CountAgain    addq.l    #8,d2        ;3ex,x
  83.         move.w    (a0)+,d0
  84.         move.w    (a0)+,d1
  85.         cmp.w    #$3eb,d1
  86.         bne.s    .CountNoBSS
  87.         addq.w    #4,a0
  88.         bra.s    .CountReloc
  89.  
  90. .CountNoBSS    and.w    #$0fff,d0
  91.         beq.s    .CountUncr
  92.  
  93.         move.l    (a0),d0
  94.         add.l    d0,a0
  95.         move.l    (a0)+,d0
  96.         lsr.l    #8,d0
  97.         add.l    d0,d2        ;uncr hunklen
  98.         bra.s    .CountReloc
  99.  
  100. .CountUncr    move.l    (a0)+,d0
  101.         add.l    d0,d2
  102.         add.l    d0,a0
  103.  
  104. .CountReloc    addq.l    #4,d2        ;end|reloc
  105.         cmp.l    #$3f2,(a0)+
  106.         beq.s    .CountEnd
  107.  
  108. .CountNextRel    addq.l    #4,d2
  109.         move.l    (a0)+,d0
  110.         beq.s    .CountReloc
  111.         addq.l    #1,d0
  112.         lsl.l    #2,d0
  113.         add.l    d0,d2
  114.         add.l    d0,a0
  115.         bra.s    .CountNextRel
  116.  
  117. .CountEnd    subq.l    #1,d3
  118.         bne.s    .CountAgain
  119.  
  120. ; now we have the desired length and allocate the buffer
  121.  
  122.         move.l    d2,d0
  123.         move.l    d0,xfdbi_TargetBufSaveLen(a5)
  124.         move.l    d0,xfdbi_TargetBufLen(a5)
  125.  
  126.         move.l    xfdbi_TargetBufMemType(a5),d1
  127.         move.l    4.w,a6
  128.         jsr    -198(a6)
  129.         move.w    #XFDERR_NOMEMORY,xfdbi_Error(a5)
  130.         move.l    d0,xfdbi_TargetBuffer(a5)
  131.         beq    .Exit
  132.  
  133. ; let's fill the buffer
  134.  
  135.         move.l    d0,a3
  136.         move.l    #$3f3,(a3)+
  137.         clr.l    (a3)+
  138.         lea    $4bc(a2),a2
  139.         move.l    (a2),d0
  140.         move.l    d0,d3
  141.         addq.w    #3-1,d0
  142. .CopyHeader    move.l    (a2)+,(a3)+
  143.         dbf    d0,.CopyHeader
  144.  
  145. .CopyAgain    move.w    (a2)+,d0
  146.         move.w    (a2)+,d1
  147.         clr.w    (a3)+
  148.         move.w    d1,(a3)+
  149.         cmp.w    #$3eb,d1
  150.         bne.s    .NoBSS
  151.         move.l    (a2)+,d0
  152.         lsr.l    #2,d0
  153.         move.l    d0,(a3)+
  154.         bra.s    .CopyReloc
  155.  
  156. .NoBSS        and.w    #$0fff,d0
  157.         beq.s    .CopyUncr
  158.         move.l    (a2),d1
  159.         add.l    d1,a2
  160.         move.l    (a2)+,d1
  161.         lsr.l    #8,d1
  162.         lsr.l    #2,d1
  163.         move.l    d1,(a3)+
  164.         move.l    a2,a0
  165.         move.l    a3,a1
  166.         lsl.l    #2,d1
  167.         add.l    d1,a3
  168.         lsl.w    #2,d0
  169.         move.l    a2,-(a7)
  170.         lea    .EffTable-4(pc),a2
  171.         add.w    d0,a2
  172.         bsr    D_Chryseis
  173.         move.l    (a7)+,a2
  174.         bra.s    .CopyReloc
  175.  
  176. .CopyUncr    move.l    (a2)+,d0
  177.         lsr.l    #2,d0
  178.         move.l    d0,(a3)+
  179. .CopyUncr1    move.l    (a2)+,(a3)+
  180.         subq.l    #1,d0
  181.         bne.s    .CopyUncr1
  182.  
  183. .CopyReloc    move.l    (a2)+,d0
  184.         move.l    d0,(a3)+
  185.         cmp.w    #$3f2,d0
  186.         beq.s    .CopyEnd
  187.  
  188. .CopyNextRel    move.l    (a2)+,d0
  189.         move.l    d0,(a3)+
  190.         beq.s    .CopyReloc
  191.         addq.l    #1,d0
  192. .CopyEntries    move.l    (a2)+,(a3)+
  193.         subq.l    #1,d0
  194.         bne.s    .CopyEntries
  195.         bra.s    .CopyNextRel
  196.  
  197. .CopyEnd    subq.l    #1,d3
  198.         bne.s    .CopyAgain
  199.  
  200. ; successful exit
  201.  
  202.         moveq    #1,d0
  203. .Exit        movem.l    (a7)+,d2-d7/a2-a6
  204.         rts
  205.  
  206. .EffTable    dc.b    9,9,9,9
  207.         dc.b    9,10,10,10
  208.         dc.b    9,10,11,11
  209.         dc.b    9,10,12,12
  210.         dc.b    9,10,12,13
  211.  
  212. **************************************************
  213.  
  214. D_Chryseis    movem.l    d2-d5/a2/a3,-(a7)
  215.         moveq    #-1,d4
  216.         moveq    #1,d5
  217.         move.l    a1,a3
  218.         move.l    -(a0),d1
  219.         tst.b    d1
  220.         beq.s    .Decr1
  221.         bsr.s    .Decr5
  222.         subq.b    #1,d1
  223.         lsr.l    d1,d5
  224. .Decr1        lsr.l    #8,d1
  225.         add.l    d1,a1
  226. .Decr2        bsr.s    .Decr5
  227.         bcs.s    .Decr11
  228.         moveq    #0,d2
  229. .Decr3        moveq    #1,d0
  230.         bsr.s    .Decr8
  231.         add.w    d1,d2
  232.         subq.w    #3,d1
  233.         beq.s    .Decr3
  234. .Decr4        moveq    #7,d0
  235.         bsr.s    .Decr8
  236.         move.b    d1,-(a1)
  237.         cmp.l    a3,a1        ; modified for
  238.         dbeq    d2,.Decr4    ; perfect error
  239.         cmp.w    d4,d2        ; detection
  240.         beq.s    .Decr11
  241.         bra.s    .Decr17
  242.  
  243. .Decr5        lsr.l    #1,d5
  244.         beq.s    .Decr6
  245.         rts
  246. .Decr6        move.l    -(a0),d5
  247.         roxr.l    #1,d5
  248.         rts
  249.  
  250. .Decr7        subq.w    #1,d0
  251. .Decr8        moveq    #0,d1
  252. .Decr9        lsr.l    #1,d5
  253.         bne.s    .Decr10
  254.         move.l    -(a0),d5
  255.         roxr.l    #1,d5
  256. .Decr10        roxl.l    #1,d1
  257.         dbra    d0,.Decr9
  258.         rts
  259.  
  260. .Decr11        moveq    #1,d0
  261.         bsr.s    .Decr8
  262.         moveq    #0,d0
  263.         move.b    (a2,d1.w),d0
  264.         move.w    d1,d2
  265.         subq.w    #3,d1
  266.         bne.s    .Decr14
  267.         bsr.s    .Decr5
  268.         bcs.s    .Decr12
  269.         moveq    #7,d0
  270. .Decr12        bsr.s    .Decr7
  271.         move.w    d1,d3
  272. .Decr13        moveq    #2,d0
  273.         bsr.s    .Decr8
  274.         add.w    d1,d2
  275.         subq.w    #7,d1
  276.         beq.s    .Decr13
  277.         bra.s    .Decr15
  278.  
  279. .Decr14        bsr.s    .Decr7
  280.         move.w    d1,d3
  281. .Decr15        addq.w    #1,d2
  282. .Decr16        move.b    (a1,d3.w),-(a1)
  283.         cmp.l    a3,a1        ; modified
  284.         dbeq    d2,.Decr16    ; for perfect
  285.         cmp.w    d4,d2        ; error detection
  286.         beq.s    .Decr2
  287. .Decr17        movem.l    (a7)+,d2-d5/a2/a3
  288.         rts
  289.  
  290.         END
  291.