ICE depacker by Gordon Gibson - Sinister Developments..

I suppose you may remember my days in the ST scene as EGB or Skywalker
(Good old days...).

Anyway, enough bollox... I have included below some goodies for you. 

1st is the ICE_DEPACK routine coded in GPU RISC for speed. There are 2 
routines, the 1st one just loads the GPU and runs it, the 2nd one is the
depack  code. after the depack code the mike.inc is listed, this is just
some register equates and macros, these may need changed for Devpac
(So if you trust me that it works, the assembled version will be easier
to get working...).

I have also included a UUENCODED block at the end, which is the GPU depack
code as an assembled binary file. All you need to do is incbin this instead
of reassembling the GPU source, just put it in between the
Start_Ice_Depack:: and End_Ice_Depack:: labels.

**********************************************************************
**  call_depack - loads depack code into GPU and runs it            **
**  d0 = source  d1 = destination                                   **
**********************************************************************
ice_depack:
        move.l  #0,G_CTRL      ;F02114  ; Make sure the GPU is stopped
        move.l  #0,G_FLAGS     ;F02100  ; and in the right mode
        move.l  #$70007,G_END  ;F0210C  ;

        move.l  #Ice_Depack,a0          ; Get the address of the GPU code
        move.l  #G_RAM+$800,a1 ;F03800  ; Get destination address
        move.l  a1,a6                   ; Gpu Base

        swap    d0
        swap    d1

        move.l  #End_Ice_Depack,d7      ; and calculate length of GPU code
        sub.l   #Start_Ice_Depack,d7
        asr.l   #2,d7                   ; divide by 4 since we're copying
long
loop1:
        move.l  (a0)+,(a1)+             ; actually copy the code...
        dbra    d7,loop1

        move.l  d0,8(a6)                ; in gpu code
        move.l  d1,16(a6)               ; in gpu code
        move.l  #0,orig_length(a6)      ; in gpu code

        move.l  #G_RAM+$800,G_PC ;F02110; GPU Program counter gets $00f03000

        move.l  #$1,G_CTRL     ;F02114  ; Set the GPU going

wait1:  cmp.l   #0,orig_length(a6)
        beq.s   wait1
.exit:  rts

orig_length     .EQU    608

**********************************************************************
**  Ice Depack code - GPU                                           **
**                                                                  **
**********************************************************************

        .gpu

        include "mike.inc"

        .phrase

Ice_Depack::
        .org     $f03800

Start_Ice_Depack::
        movei   #MyStack,S_P
Source_add::
        movei   #$12345678,A_0
        nop
Dest_add::
        movei   #$12345678,A_1
        load    (A_0),D_0       ; bsr.s getinfo
        addq    #4,A_0          ;
        movei   #'ICE!',Junk    ; cmpi.l #'ICE!',d0
        nop
        cmp     Junk,D_0        ;
        movei   #Unpacked,Junk  ; bne not_packed
        jump    NE,(Junk)       ;
        nop

; get packed length
        load    (A_0),D_0       ; bsr.s getinfo
        addq    #4,A_0          ;

        move    D_0,A_5         ; lea.l -8(a0,d0.l),a5
        add     A_0,A_5         ;
        subq    #8,A_5          ;

        load    (A_0),Orig_Len  ; bsr.s getinfo
        nop
        move    Orig_Len,D_0
        addq    #4,A_0
        move    A_1,A_4
        move    A_1,A_6
        add     D_0,A_6
;
; Set up a few things
;
        movei   #$ff,mask1
        movei   #$ffff0000,mask2
        movei   #Get_D0_Bits,D0_BITS
        subq    #1,A_5          ;
        loadb   (A_5),D_7       ; move.b -(a5),d7
        rorq    #8,D_7          ; Make into 32bit!!

        JSR     Normal_Bytes    ; bsr normal_bytes

Normal_Bytes::
        Get1Bit frig1
frig1::
        BCC     Test_If_End     ; bcc.s test_if_end
        moveq   #0,D_1          ; moveq.l #0,d1
        Get1Bit frig2           ; bsr.s   get_1_bit
frig2::
        BCC     Copy_Direkt
        movei   #Direct_Tab+20,A_1   ;  lea.l   direkt_tab+20(pc),a1
        moveq   #4,D_3
Nextgb::
        subq    #4,A_1          ; move.l  -(a1),d0
        load    (A_1),D_0       ;
        move    D_0,D_4         ;
        and     mask1,D_0       ;

        JSR_D0_Bits             ; bsr.s   get_d0_bits
        move    D_4,D_0
        and     mask2,D_0
        SWAP    D_0
        cmp     D_0,D_1

        jr      NE,No_More
        nop
        DBF     D_3,Nextgb


No_More::
        move    A_1,r14         ; add.l   20(a1),d1
        load    (r14+(20/4)),Junk
        add     Junk,D_1

Copy_Direkt::
        subq    #1,A_5          ; move.b  -(a5),-(a6)
        subq    #1,A_6          ;
        loadb   (A_5),Junk      ;

        subq    #1,D_1          ; dbf     d1,copy_direkt  ; noch ein Byte
        jr      PL,Copy_Direkt  ;
        storeb  Junk,(A_6)      ;

Test_If_End::
        cmp     A_4,A_6         ; cmpa.l  a4,a6
        BHI     Strings
; Bomb out!!
Unpacked::
        movei   #Orig_Length,Junk
        store   Orig_Len,(Junk)
        nop
        nop
        movei   #0,R30
        movei   #$00f02114,R31
        store   R30,(R31)

        nop
        nop
;
        nop
        nop
        nop
        nop
        nop
        nop

        .phrase
Get_D0_Bits::
        moveq   #0,D_1
Hole_Bit_Loop:
        add     D_7,D_7
        jr      NE,On_D0
        nop
        subqt   #1,A_5
        loadb   (A_5),D_7
        addc    D_7,D_7
        rorq    #9,D_7          ; Dont ask!
        shlq    #1,D_7          ; !!!!!!!!!
On_D0:  addc    D_1,D_1
        subq    #1,D_0
        jr      PL,Hole_Bit_Loop
        nop
        D0_RTS

Strings::
        nop
        movei   #Length_Tab,A_1
        moveq   #3,D_2
Get_Length_Bit::
        Get1Bit frig3
frig3::
        jr      CC,No_Length_Bit
        nop
        DBF     D_2,Get_Length_Bit
No_Length_Bit::

        moveq   #1,Junk
        xor     D_4,D_4
        add     D_2,Junk
        move    D_4,D_1
        shlq    #2,Junk
        add     A_1,Junk

        load    (Junk),D_0
        rorq    #8,D_0
        jr      MI,No_Uber
        nop
Get_Uber::
        rorq    #24,D_0
        JSR_D0_Bits
No_Uber::
        moveq   #6,Junk
        add     D_2,Junk
        shlq    #2,Junk
        add     A_1,Junk
        load    (Junk),D_4

        add     D_1,D_4
        BEQ     Get_Offset_2
        movei   #More_Offset,A_1
        moveq   #1,D_2
getoffs::
        Get1Bit frig4
frig4::
        BCC     .Crap
        DBF     D_2,getoffs
.Crap:
        movei   #Depack_Bytes,D_6
        xor     D_1,D_1
        move    D_2,Junk
        addq    #1,Junk
        shlq    #2,Junk

        add     A_1,Junk

        load    (Junk),D_0

        JSR_D0_Bits

        shlq    #2,D_2
        move    A_1,Junk
        addq    #24,D_2
        add     D_2,Junk

        load    (Junk),D_5
        add     D_5,D_1
        jump    PL,(D_6)
        nop
        sub     D_4,D_1
        jump    (D_6)
        nop
Get_Offset_2:
        xor     D_1,D_1
        moveq   #5,D_0
        movei   #-1,D_2
        Get1Bit frig5
frig5::
        jr      CC,Less_40
        nop
        moveq   #8,D_0
        movei   #$3f,D_2
Less_40::
        JSR_D0_Bits
        add     D_2,D_1

Depack_Bytes::
;
; All interleaved as well!!
;
        move    A_6,A_1
        addq    #1,D_1
        add     D_4,A_1
        subq    #1,A_6
        add     D_1,A_1
        movei   #Normal_Bytes,D_6
        loadb   (A_1),Junk
        storeb  Junk,(A_6)


Dep_B:: subq    #1,A_1
        subq    #1,A_6
        loadb   (A_1),Junk


        subq    #1,D_4          ;
        jr      PL,Dep_B        ; This is a DBF with some nice code 
optimisation!
        storeb  Junk,(A_6)      ;


        jump    (D_6)
        nop

        .phrase

Orig_Length::   dc.l    0
Direct_Tab::    dc.l    $7fff000e,$00ff0007
                dc.l    $00070002,$00030001
                dc.l    $00030001
                dc.l    270-1,15-1,8-1,5-1,2-1
        .phrase
Length_Tab::    dc.l    9,1,0,-1,-1
                dc.l    8,4,2,1,0
        .phrase
More_Offset::   dc.l    $0000000b,$00000004,$00000007,$00000000
                dc.l    $00000000,$0000011f,$ffffffff,$0000001f
        .phrase
                dcb.l   20,0
MyStack::       dc.l    0


End_Ice_Depack::
**********************************************************************
**  The End                                                         **
**                                                                  **
**********************************************************************

GPU_EQUATES:        
        A_0             .equr   R1
        A_1             .equr   R2
        A_2             .equr   R3
        A_3             .equr   R4
        A_4             .equr   R5
        A_5             .equr   R6
        A_6             .equr   R7
        A_7             .equr   R8
        D_0             .equr   R9
        D_1             .equr   R10
        D_2             .equr   R11
        D_3             .equr   R12
        D_4             .equr   R13
        D_5             .equr   R14
        D_6             .equr   R15
        D_7             .equr   R16
        Junk            .equr   R19
        Orig_Len        .equr   R20
        Return          .equr   R21
        D0_BITS         .equr   R22
        S_P             .equr   R23
        mask1           .equr   R24
        mask2           .equr   R25

        .MACRO  Get1Bit frig

        move    D_7,Junk
        add     D_7,D_7
        jr      NE,\frig
        nop
        subqt   #1,A_5
        loadb   (A_5),D_7
        add     Junk,Junk       ; recreate carry flag
        addc    D_7,D_7         ; add with it
        rorq    #9,D_7          ; and then frig city!!
        shlq    #1,D_7          ; !!!!!!!!!!!!!!!!!!!!
        .ENDM


;*******************
;       JSR Macro
;       Trashes R19
;*******************
        .MACRO  JSR     dest
        subqt   #4,S_P          ; adjust the stack pointer
        nop
        move    PC,Junk         ; determine current program address
        addq    #16,Junk        ; new address for after this macro
        nop
        store   Junk,(S_P)      ; push return address onto stack
        movei   #\dest,Junk     ; load up subroutine address
        jump    (Junk)          ; jump to subroutine
        nop                     ; jump doesn't occur until this instr
        .ENDM

;*******************
;       RTS Macro
;       Trashes R19
;*******************
        .MACRO  RTS
        load    (S_P),Junk      ; load up return address
        jump    (Junk)          ; jump back to return address
        addqt   #4,S_P          ; adjust the stack pointer
        .ENDM
;*****************************
;       Macro to call D0 Bits
;*****************************
        .MACRO  JSR_D0_Bits
        move    PC,Return
        jump    (D0_BITS)
        addq    #6,Return       ; Determine Return Address
        .ENDM

        .MACRO  D0_RTS
        jump    (Return)
        .ENDM
;*******************
;       BCC Macro
;       Trashes R19
;*******************
        .MACRO  BCC     dest
        movei   #\dest,Junk
        jump    CC,(Junk)
        nop
        .ENDM

;*******************
;       BMI Macro
;       Trashes R19
;*******************
        .MACRO  BMI     dest
        movei   #\dest,Junk
        jump    MI,(Junk)
        nop
        .ENDM

;*******************
;       BPL Macro
;       Trashes R19
;*******************
        .MACRO  BPL     dest
        movei   #\dest,Junk
        jump    PL,(Junk)
        nop
        .ENDM

;*******************
;       BHI Macro
;       Trashes R19
;*******************
        .MACRO  BHI     dest
        movei   #\dest,Junk
        jump    HI,(Junk)
        nop
        .ENDM
;*******************
;       BEQ Macro
;       Trashes R19
;*******************
        .MACRO  BEQ     dest
        movei   #\dest,Junk
        jump    EQ,(Junk)
        nop
        .ENDM

;*******************
;       DBF Macro
;       Trashes R19
;*******************
        .MACRO  DBF     reggie,dest
        movei   #\dest,Junk
        subq    #1,\reggie
        jump    PL,(Junk)
        nop
        .ENDM

;*******************
;       SWAP Macro
;*******************
        .MACRO  SWAP    reggie
        rorq    #16,\reggie
        .ENDM


section 1/1   file ice_dpak.bin   [ Wincode v2.6.1 ]

begin 644 ice_dpak.bin
MF!<S*`#PF`%6>!(TY`"8`E9X$C2D*0B!F!-%(4E#Y`!Z:9@3,/P`\-)AY`"D
M*0B!B28`)AD&I#3D`(J)"(&(18A'`2>8&`#_``"8&0``__^8%C$H`/`8)IS0
M=1`<E^0`S!,*$^0`OO.8$S!R`/#28.0`BA,"$-3AY``<)IS0`G,&$'4P8_"8
M$S#P`/#29.0`C`J*$P(0U.'D`!PFG-`"<P80=3!C\)@3,.0`\-)DY`"8`C)X
M`/",C!B"I$F)+2<)S!72P`C5B:DG*78)>2K4X>0`F!,PN`#P&"S2=.0`B$ZL
MLP)J&"88)YS3&"K7=+3S>*>8$S%$`/#29>0`F!,R8`#POG3D`.0`F!X`````
MF!\A%`#PO_[D`.0`Y`#D`.0`Y`#D`.0```","@(0U,'D`!PFG-`&$'4P8_`%
M2A@IUK3D`-*@Y`"8`C*0`/",:XH3`A#4X>0`'":<T`)S!A!U,&/PU.3D`)@3
M,4X`\!@KTG3D`(PS+:T!<XFJ8],`4Z9I=0G4N.0`=PG,%=+`"-6,TP%S8],`
M4Z9M`4V8$S($`/#28N0`F`(RN`#PC"N*$P(0U.'D`!PFG-`"<P80=3!C\)@3
M,=8`\-)DY`"8$S&L`/`8*])TY`"8#S(V`/`M2HES"#-CTP!3IFG,%=+`"-5C
MRXA3"PL!<Z9N`<K1].0`$:K1X.0`+4J,J9@+_____XH3`A#4X>0`'":<T`)S
M!A!U,&/PU*3D`(T)F`L`/P``S!72P`C5`6J(X@@J`:(8)P%"F`\P<@#PG%.T
M\Q@B&"><4Q@MUW2T\]'@Y```````````````?_\`#@#_``<`!P`"``,``0`#
M``$```$-````#@````<````$`````0`````````)`````0````#_________
M_P````@````$`````@````$`````````"P````0````'``````````````$?
M_____P```!\`````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
&````````
`
end
sum -r/size 60043/816

section 1/1   file ice_dpak.bin   [ Wincode v2.6.1 ]
