#*------------------------------------------------------------------------------ #* PRO-PACK Unpack Source Code (Compact Version) - PowerPC, Method 2 #* #* Copyright (c) 1991,92 Rob Northen Computing, U.K. All Rights Reserved. #* #* File: RNC_2C.S #* Adapted for PowerPC of the NGameCube #* Date: 08.06.03 #* Destop - CZN #*------------------------------------------------------------------------------ #*------------------------------------------------------------------------------ #* Equates #*------------------------------------------------------------------------------ .set input,r3 .set output,r4 .set temp,r5 .set len,r6 .set pos,r7 .set bitbuf,r8 .set carry,r9 #*------------------------------------------------------------------------------ #* Macros #*------------------------------------------------------------------------------ .macro getbit add bitbuf,bitbuf srwi carry,bitbuf,8 andi. bitbuf,0xFF .endm .macro reload lbz bitbuf,0(input) addi input,1 add bitbuf,bitbuf add bitbuf,carry srwi carry,bitbuf,8 andi. bitbuf,0xFF .ENDM .macro getraw lbz r10,0(input) addi input,1 stb r10,0(output) addi output,1 .ENDM .macro getrawREP getrawREP2\@: lbz r10,0(input) stb r10,0(output) lbz r10,1(input) stb r10,1(output) lbz r10,2(input) stb r10,2(output) lbz r10,3(input) stb r10,3(output) addi input,4 addi output,4 subic. pos,1 bge getrawREP2\@ .ENDM .macro la lis \1,\2@h ori \1,\1,\2@l .endm .macro lw lis \1,\2@ha lwz \1,\2@l(\1) .endm .section .text #*------------------------------------------------------------------------------ #* Unpack Routine (Compact Version) - PowerPC, Method 2 #* #* on entry, #* r3 = start address of packed file #* r4 = start address to write unpacked file #* (note: r3 cannot be equal to r4) #*------------------------------------------------------------------------------ .global Unpack Unpack: addi input,18 li carry,1 reload getbit b GetBits2 #*------------------------------------------------------------------------------ Fetch0: reload b Back0 Fetch1: reload b Back1 Fetch2: reload b Back2 Fetch3: reload b Back3 Fetch4: reload b Back4 Fetch5: reload b Back5 Fetch6: reload b Back6 Fetch7: reload b Back7 Raw: li len,3 x4Bits: add bitbuf,bitbuf srwi carry,bitbuf,8 andi. bitbuf,0xFF beq Fetch0 Back0: add pos,pos add pos,carry subic. len,1 bge x4Bits addi pos,2 getrawREP b GetBits2 #*------------------------------------------------------------------------------ GetLen: getbit beq Fetch1 Back1: add len,len add len,carry getbit beq Fetch2 Back2: cmpwi carry,0 beq Copy #clear subi len,1 getbit beq Fetch3 Back3: add len,len add len,carry cmpwi len,9 beq Raw #*------------------------------------------------------------------------------ Copy: getbit beq Fetch4 Back4: cmpwi carry,0 beq ByteDisp2 #clear getbit beq Fetch5 Back5: add pos,pos add pos,carry getbit beq Fetch6 Back6: cmpwi carry,0 bne BigDisp #set cmpwi pos,0 #tst.w pos bne ByteDisp addi pos,1 Another: getbit beq Fetch7 Back7: add pos,pos add pos,carry ByteDisp: rlwinm pos,pos,8,16,23 #rol.w #8,pos ByteDisp2: lbz temp,0(input) #move.b (input)+,pos addi input,1 or pos,temp mr temp,output #move.l output,temp sub temp,pos #sub.w pos,temp subi temp,1 #subq.w 1,temp andi. carry,len,1 srwi len,1 #lsr.w 1,len # cmpwi carry,0 beq ByteDisp3 #clear lbz r10,0(temp) #move.b (temp)+,(output)+ stb r10,0(output) addi temp,1 addi output,1 ByteDisp3: subi len,1 cmpwi pos,0 #tst.w pos bne ByteDisp5 lbz pos,0(temp) #move.b (temp),pos ByteDisp4: stb pos,0(output) #move.b pos,(output)+ stb pos,1(output) #move.b pos,(output)+ addi output,2 subic. len,1 bge ByteDisp4 b GetBits2 ByteDisp5: lbz r10,0(temp) stb r10,0(output) lbz r10,1(temp) stb r10,1(output) addi temp,2 addi output,2 subic. len,1 bge ByteDisp5 b GetBits2 #*------------------------------------------------------------------------------ GetBits: reload cmpwi carry,0 bne String #set xByte: getraw GetBits2: getbit cmpwi carry,0 bne Chkz #set getraw getbit cmpwi carry,0 beq xByte #clear Chkz: cmpwi bitbuf,0 beq GetBits #*------------------------------------------------------------------------------ String: li len,2 li pos,0 getbit beq Fetch8 Back8: cmpwi carry,0 #clear bcc GetLen beq GetLen Smalls: getbit beq Fetch9 Back9: cmpwi carry,0 beq ByteDisp2 #clear addi len,1 getbit beq Fetch10 Back10: cmpwi carry,0 beq Copy #clear lbz len,0(input) addi input,1 cmpwi len,0 beq OverNout addi len,8 b Copy BigDisp: getbit beq Fetch11 Back11: add pos,pos add pos,carry ori pos,4 getbit beq Fetch12 Back12: cmpwi carry,0 bne ByteDisp #set b Another Fetch8: reload b Back8 Fetch9: reload b Back9 Fetch10: reload b Back10 Fetch11: reload b Back11 Fetch12: reload b Back12 OverNout: getbit bne Check4end reload Check4end: cmpwi carry,0 bne GetBits2 #set blr