home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / System / XFD / Developer / Sources / ASM / TPWM.a < prev    next >
Encoding:
Text File  |  2001-09-16  |  4.1 KB  |  194 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Program.    TPWM.asm
  3. ;  :Contents.   Decruncher for XFDMaster.Library
  4. ;  :Author.     WEPL
  5. ;  :History.    V 0.9 29-Oct-94
  6. ;        V 1.0 19-Nov-94 angepaßt auf orginal includes
  7. ;                msdos-tpwm support added
  8. ;        1.1    12.01.96 memory protection read/write
  9. ;                 memory freeing after error
  10. ;        1.2    08.03.00 problems with "moon of chromos" files fixed
  11. ;                 x86-support removed
  12. ;  :Copyright.  Public Domain
  13. ;  :Language.   68000 Assembler
  14. ;  :Translator. Barfly 1.130
  15. ;---------------------------------------------------------------------------*
  16. ;##########################################################################
  17.  
  18.     INCDIR    Includes:
  19.     INCLUDE    lvo/exec.i
  20.     INCLUDE    libraries/xfdmaster.i
  21.     
  22.     OUTPUT    libs:xfd/TPWM
  23.  
  24. ;##########################################################################
  25. ;----------------------------------------
  26. ; XFD-Library-Header
  27.  
  28.         moveq    #-1,d0
  29.         rts    
  30.  
  31.         dc.l    XFDF_ID        ;id
  32.         dc.w    XFDF_VERSION    ;version
  33.         dc.w    0
  34.         dc.l    0,0        ;private
  35.         dc.l    _xfdSlave1    ;first slave
  36.  
  37. ;----------------------------------------
  38. ; version string
  39.  
  40.         dc.b    '$VER: TPWM 1.2 '
  41.     DOSCMD    "WDate >T:date"
  42.     INCBIN    T:date
  43.         dc.b    ' by WEPL for xfdmaster.library',0
  44.     CNOP 0,4
  45.  
  46. ;----------------------------------------
  47. ; xfdSlave-structure
  48.  
  49. _xfdSlave1    dc.l    0        ; next slave
  50.         dc.w    1        ; structure version
  51.         dc.w    33        ; req xfdmaster version
  52.         dc.l    _name1        ; cruncher name
  53.         dc.w    XFDPFF_DATA    ; cruncher flags
  54.         dc.w    0        ; max length of special info (passwd)
  55.         dc.l    _check1        ; check routine
  56.         dc.l    _decrunch1    ; decrunch routine
  57.         dc.l    0        ; segment recog routine
  58.         dc.l    0        ; segment decrunch routine
  59.  
  60. ;----------------------------------------
  61. ; name of packer
  62.  
  63. _name1        dc.b    'TPWM Cruncher',0
  64.     EVEN
  65.  
  66. ;----------------------------------------
  67. ; code to check crunched
  68. ; Übergabe :    D0 = ULONG data size
  69. ;        A0 = APTR  data
  70. ; Rückgabe :    D0 = BOOL  success
  71.  
  72. _check1        moveq    #12,d1        ;minimum 12 bytes
  73.         cmp.l    d1,d0
  74.         blo    .no
  75.         cmp.l    #"TPWM",(a0)
  76.         beq    .yes
  77. .no        moveq    #0,d0
  78.         rts
  79.  
  80. .yes        moveq    #-1,d0
  81.         rts
  82.  
  83. ;----------------------------------------
  84. ; code to decrunch the file
  85. ; Übergabe :    A0 = APTR xfdBufferInfo
  86. ; Rückgabe :    D0 = BOOL success
  87.  
  88. _decrunch1    movem.l    a4-a6,-(a7)
  89.         move.l    a0,a5                ;A5 = xfdbi
  90.         move.l    (xfdbi_SourceBuffer,a5),a4    ;A4 = source
  91.         move.l    (4,a4),d0
  92.         move.l    d0,(xfdbi_TargetBufLen,a5)
  93.         move.l    d0,(xfdbi_TargetBufSaveLen,a5)
  94.         move.l    (xfdbi_TargetBufMemType,a5),d1
  95.         move.l    (4).w,a6
  96.         jsr    (_LVOAllocMem,a6)
  97.         move.l    d0,(xfdbi_TargetBuffer,a5)
  98.         bne    .memok
  99.         moveq    #XFDERR_NOMEMORY,d1
  100.         bra    .quit
  101.         
  102. .memok        move.l    d0,a1
  103.         move.l    a4,a0
  104.         move.l    (xfdbi_SourceBufLen,a5),d0
  105.         move.l    (xfdbi_TargetBufLen,a5),d1
  106.         bsr    _TPWM
  107.         bne    .decok
  108.         move.l    (xfdbi_TargetBufLen,a5),d0
  109.         move.l    (xfdbi_TargetBuffer,a5),a1
  110.         jsr    (_LVOFreeMem,a6)
  111.         moveq    #0,d0
  112.         moveq    #XFDERR_CORRUPTEDDATA,d1
  113.         bra    .quit
  114.         
  115. .decok        moveq    #-1,d0
  116.         moveq    #0,d1
  117.  
  118. .quit        move.w    d1,(xfdbi_Error,a5)
  119.         movem.l    (a7)+,a4-a6
  120.         rts
  121.  
  122. ;----------------------------------------
  123. ;    Battle Isle
  124. ;    History Line
  125. ;    Turrican 3
  126. ;    Moon of Chromos
  127. ;
  128. ; Format :    $0    dc.b    "TPWM"
  129. ;        $4    ULONG    size unpacked (MSDOS: little endian)
  130. ;        $8        Daten...
  131. ;
  132. ; Übergabe :    D0 = ULONG size of source buffer
  133. ;        D1 = ULONG size of dest buffer
  134. ;        A0 = APTR source
  135. ;        A1 = APTR destination
  136. ; Rückgabe :    D0 = BOOL success
  137.  
  138. _TPWM        movem.l    d2-d7/a2-a4,-(a7)
  139.         lea    (a0,d0.l),a3        ;A3 = end of source
  140.         lea    (a1,d1.l),a4        ;A4 = end of destination
  141.         addq.l    #8,a0
  142.  
  143. ChkSrc    MACRO
  144.         cmp.l    a0,a3
  145.         beq    .fail
  146.     ENDM
  147. ChkDestOK    MACRO
  148.         cmp.l    a1,a4
  149.         beq    .ok
  150.     ENDM
  151.         
  152. .370    ChkDestOK
  153.     ChkSrc
  154.         MOVE.B    (A0)+,D0
  155.         MOVEQ    #7,D5
  156. .376        ADD.B    D0,D0
  157.         BCS.B    .394
  158.     cmp.l    a1,a4
  159.     beq    .ok            ;last unused bits are cleared
  160.     ChkSrc
  161.         MOVE.B    (A0)+,(A1)+
  162. .38A        DBRA    D5,.376
  163.         BRA.B    .370
  164.  
  165. .394    ChkSrc
  166.         MOVE.B    (A0)+,D7
  167.         MOVEQ    #0,D2
  168.         MOVE.B    D7,D2
  169.         LSL.W    #4,D2
  170. .3A2    ChkSrc
  171.         MOVE.B    (A0)+,D2
  172.         ANDI.W    #$000F,D7
  173.         ADDQ.W    #2,D7
  174.         MOVEA.L    A1,A2
  175.         SUBA.W    D2,A2
  176. .3B0
  177.     cmp.l    a1,a4
  178.     beq    .ok            ;required for Moon of Chromos
  179.         MOVE.B    (A2)+,(A1)+
  180.         DBRA    D7,.3B0
  181.         BRA.B    .38A
  182.  
  183. .ok        moveq    #-1,d0
  184. .end        movem.l    (a7)+,d2-d7/a2-a4
  185.         RTS
  186.  
  187. .fail        moveq    #0,d0
  188.         bra    .end
  189.  
  190. ;##########################################################################
  191.  
  192.     END
  193.  
  194.