update DI disc code
[libogc.git] / libogc / depackrnc.S
blob18b70e3b65c24ece8f3588e250ef63449d668ac2
1 #include <asm.h>
3 /**********************************/
4 /* register map                                   */
5 /*                                                                */
6 /* r0   = tmp                                     */
7 /* r3   = in                    = r2      */
8 /* r4   = out                   = r4      */
9 /* r5   = A                             = r5      */
10 /* r6   = X                             = r6      */
11 /* r7   = Y                             = r7      */
12 /* r8   = carry flag    = r3      */
13 /* r10  = tmp                   = r8      */
14 /* r11  = store data    = r9      */
15 /* r29  = copy in(r3)   = r0      */
16 /* r30  = copy out(r4)  = r1      */
17 /*                                                                */
18 /**********************************/
20 #define LOAD                            \
21         lbzu            r5,1(r29);      \
22         slwi            r5,r5,1;        \
23         insrwi          r5,r8,1,31;     \
24         extrwi          r8,r5,1,23;     \
25         clrlwi.         r5,r5,24
27 #define GETBIT                          \
28         slwi            r5,r5,1;        \
29         extrwi          r8,r5,1,23;     \
30         clrlwi.         r5,r5,24        
32 #define COPYRAW                         \
33         lbzu            r11,1(r29);     \
34         stbu            r11,1(r30)
36         //r3 is input, r4 is output
37         .globl depackrnc2
38 depackrnc2:
39         mflr    r0
40         stw             r0,4(sp)
41         stwu    sp,-64(sp)
42         stw             r3,8(sp)
43         stw             r4,12(sp)
44         stw             r29,48(sp)
45         mr              r29,r3
46         stw             r30,52(sp)
47         mr              r30,r4
49         li              r8,1
50         addi    r30,r30,-1
51         addi    r29,r29,17
52         
53         LOAD
54         GETBIT
55         b               _xloop
57 _fetch3:
58         LOAD
59         b               _back3
60 _fetch4:
61         LOAD
62         b               _back4
63 _fetch5:
64         LOAD
65         b               _back5
66 _fetch6:
67         LOAD
68         b               _back6
69 _fetch7:
70         LOAD
71         b               _back7
73 _raw:
74         li              r7,4
75 _x4bits:
76         GETBIT
77         beq             _fetch7
78 _back7:
79         slwi    r6,r6,1                         //ROL(X)
80         insrwi  r6,r8,1,31
81         extrwi  r8,r6,1,23
82         clrlwi  r6,r6,24
84         subic.  r7,r7,1
85         bne             _x4bits
86         addi    r7,r6,3
88         slwi    r7,r7,1                         //ROL(Y)
89         insrwi  r7,r8,1,31
90         extrwi  r8,r7,1,23
91         clrlwi  r7,r7,24
92 _rawlpb:
93         COPYRAW
94         COPYRAW
96         subic.  r7,r7,1
97         bne             _rawlpb
98         b               _xloop
100 _fetch0:
101         LOAD
102         rlwinm. r0,r8,0,31,31
103         bne             _smalls
104 _getlen:
105         GETBIT
106         beq             _fetch3
107 _back3:
108         slwi    r7,r7,1                         //ROL(Y)
109         insrwi  r7,r8,1,31
110         extrwi  r8,r7,1,23
111         clrlwi  r7,r7,24
112         
113         GETBIT
114         beq             _fetch4
115 _back4:
116         rlwinm. r0,r8,0,31,31
117         beq             _copy
118         
119         GETBIT
120         beq             _fetch5
121 _back5:
122         subic   r7,r7,1
123         slwi    r7,r7,1                         //ROL(Y)
124         insrwi  r7,r8,1,31
125         extrwi  r8,r7,1,23
126         clrlwi  r7,r7,24
128         cmpwi   r7,9
129         beq             _raw
130         
131 _copy:
132         GETBIT
133         beq             _fetch6
134 _back6:
135         rlwinm. r0,r8,0,31,31
136         beq             _bytedisp
138         GETBIT
139         bne             _skip0
140         
141         LOAD
142 _skip0:
143         slwi    r6,r6,1                         //ROL(X)
144         insrwi  r6,r8,1,31
145         extrwi  r8,r6,1,23
146         clrlwi  r6,r6,24
148         slwi    r5,r5,1                         //ROL(A)
149         insrwi  r5,r8,1,31
150         extrwi  r8,r5,1,23
151         clrlwi. r5,r5,24
152         bne             _skip1
153         
154         LOAD
155 _skip1:
156         rlwinm. r0,r8,0,31,31
157         bne             _bigdisp
158         cmpwi   r6,0
159         bne             _bytedisp
160         addic   r6,r6,1
161         
162 _another:
163         GETBIT
164         bne             _dispx
165         
166         LOAD
167 _dispx:
168         slwi    r6,r6,1                         //ROL(X)
169         insrwi  r6,r8,1,31
170         extrwi  r8,r6,1,23
171         clrlwi  r6,r6,24
173 _bytedisp:
174         lbzu    r8,1(r29)
175         andi.   r10,r30,0xff
176         sub             r8,r10,r8
177         srwi    r10,r30,8
178         sub             r10,r10,r6
179         slwi    r10,r10,8
180         add             r8,r8,r10
181         subic   r8,r8,1
182 _bytelp:
183         lbzu    r11,1(r8)
184         stbu    r11,1(r30)
186         subic.  r7,r7,1
187         bne             _bytelp
188         b               _xloop
190 _getbits:
191         LOAD
192         rlwinm. r0,r8,0,31,31
193         bne             _string
194 _xbyte:
195         COPYRAW
196 _xloop:
197         GETBIT
198         rlwinm. r0,r8,0,31,31
199         bne             _chkz
200         
201         COPYRAW
203         GETBIT
204         rlwinm. r0,r8,0,31,31
205         beq             _xbyte
207         li              r8,1
208 _chkz:
209         rlwinm. r0,r5,0,24,31
210         beq             _getbits
212 _string:
213         li              r6,0
214         li              r7,2
215         GETBIT
216         beq             _fetch0
217         rlwinm. r0,r8,0,31,31
218         beq             _getlen
219 _smalls:
220         GETBIT
221         beq             _fetch1
222 _back1:
223         rlwinm. r0,r8,0,31,31
224         beq             _bytedisp
226         addic   r7,r7,1
228         GETBIT
229         beq             _fetch2
230 _back2:
231         rlwinm. r0,r8,0,31,31
232         beq             _copy
233         lbzu    r7,1(r29)
234         cmpwi   r7,0
235         beq             _overnout
236         addic   r7,r7,8
237         b               _copy
239 _bigdisp:
240         GETBIT
241         bne             _skip2
242         LOAD
243 _skip2:
244         slwi    r6,r6,1                         //ROL(X)
245         insrwi  r6,r8,1,31
246         extrwi  r8,r6,1,23
247         clrlwi  r6,r6,24
248         ori             r6,r6,4
250         GETBIT
251         bne             _skip3
252         LOAD
253 _skip3:
254         rlwinm. r0,r8,0,31,31
255         bne             _bytedisp
256         b               _another
258 _fetch1:
259         LOAD
260         b               _back1
261 _fetch2:
262         LOAD
263         b               _back2
264 _overnout:
265         GETBIT
266         bne             _check4end
267         LOAD
268 _check4end:
269         rlwinm. r0,r8,0,31,31
270         bne             _xloop
272         lwz             r29,48(sp)
273         lwz             r30,52(sp)
274         lwz             r4,12(sp)
275         lwz             r3,8(sp)
276         lwz             r0,68(sp)
277         addi    sp,sp,64
278         mtlr    r0
279         blr