fix a typo..
[AROS-Contrib.git] / Demo / Galaxy / opti_cvrt.S
blob3e72da6e6860532b63acd677c0045ff923dce607
1 /***************************************
2 *        
3 * $RCSfile$ 
4 * ( $Revision$ $Date$ )
5 * $Author$ / Optimum
7 * http://optimum.citeweb.net/index.html 
8 *                                       
9 ****************************************/
12 # *  conversions functions between graphic modes
13 # *
14 # *  (trifouilli extrait de l'optilib en version pre-beta)
15 # *
18         
20         
21 .text
23 .global SOpti_cvrt_RGB_888_RGB_565
24 .global SOpti_cvrt_BGR_888_RGB_565
28 .global SOpti_cvrt_ABGR_8888_RGB_565
29 .global SOpti_cvrt_bRGBA_8888_RGB_565
30 .global SOpti_cvrt_mRGBA_8888_RGB_565
31 .global SOpti_cvrt_lABGR_8888_RGB_565
33 .global SOpti_cvrt_ARGB_8888_RGB_565
34 .global SOpti_cvrt_bBGRA_8888_RGB_565
35 .global SOpti_cvrt_mBGRA_8888_RGB_565
36 .global SOpti_cvrt_lARGB_8888_RGB_565
37         
38 .global SOpti_cvrt_RGB_565_ARGB_8888
39 .global SOpti_cvrt_RGB_565_bBGRA_8888
40 .global SOpti_cvrt_RGB_565_mBGRA_8888
41 .global SOpti_cvrt_RGB_565_lARGB_8888   
43 .global SOpti_cvrt_PAL_8_RGB_565
44 .global SOpti_cvrt_PAL_8_RGBA_8888
46         .type    SOpti_cvrt_RGB_888_RGB_565,@function
47         .type    SOpti_cvrt_BGR_888_RGB_565,@function
48         
49         .type    SOpti_cvrt_ABGR_8888_RGB_565,@function
50         .type    SOpti_cvrt_bRGBA_8888_RGB_565,@function
51         .type    SOpti_cvrt_mRGBA_8888_RGB_565,@function
52         .type    SOpti_cvrt_lABGR_8888_RGB_565,@function
53         
54         .type    SOpti_cvrt_ARGB_8888_RGB_565,@function
55         .type    SOpti_cvrt_bBGRA_8888_RGB_565,@function
56         .type    SOpti_cvrt_mBGRA_8888_RGB_565,@function
57         .type    SOpti_cvrt_lARGB_8888_RGB_565,@function
58         
59         .type    SOpti_cvrt_RGB_565_ARGB_8888,@function
60         .type    SOpti_cvrt_RGB_565_bBGRA_8888,@function
61         .type    SOpti_cvrt_RGB_565_mBGRA_8888,@function
62         .type    SOpti_cvrt_RGB_565_lARGB_8888,@function
63         
64         .type    SOpti_cvrt_PAL_8_RGB_565,@function
65         .type    SOpti_cvrt_PAL_8_RGBA_888,@function
67 SOpti_cvrt_RGB_888_RGB_565:     
69         pushl   %ebp
70         movl    %esp,%ebp
72         pushl   %esi
73         pushl   %edi
74         pushl   %ebx
75         
76         movl    8(%ebp),%esi       // load src and dst ptr,
77         movl   12(%ebp),%edi 
78         movl   16(%ebp),%ecx        // and number of pixels
80                  
81         subl    $2,%edi         //        will be re-added in the loop (for pairability)
82         
83 .align 16, 0x90                 //      align loop start for efficiency; fill with nops(90)
85         movb    (%esi),%ah
86         movb    2(%esi),%bl
87         
88         movb    1(%esi),%al
89         shrb    $3,%bl
90         
91         shrb    $3,%ah
92         addl    $3,%esi
94         andb    $0xfc,%al
95         addl    $2,%edi
96         
97         shll    $3,%eax
98         
99         orb     %bl,%al
101         movw    %ax,(%edi)      
102         nop
103         
104         decl    %ecx            
105         jnz     1b              
106         
107         popl    %ebx
108         popl    %edi
109         popl    %esi
110                 
111         leave
112         ret
114 SOpti_cvrt_BGR_888_RGB_565:     
116         pushl   %ebp
117         movl    %esp,%ebp
119         pushl   %esi
120         pushl   %edi
121         pushl   %ebx
122         
123         movl    8(%ebp),%esi       // load src and dst ptr,
124         movl   12(%ebp),%edi 
125         movl   16(%ebp),%ecx        // and number of pixels
127                  
128         subl    $2,%edi         //        will be re-added in the loop (for pairability)
129         
130 .align 16, 0x90                 //      align loop start for efficiency; fill with nops(90)
132         movb    2(%esi),%ah
133         movb    (%esi),%bl
134         
135         movb    1(%esi),%al
136         shrb    $3,%bl
137         
138         shrb    $3,%ah
139         addl    $3,%esi
141         andb    $0xfc,%al
142         addl    $2,%edi
143         
144         shll    $3,%eax
145         
146         orb     %bl,%al
148         movw    %ax,(%edi)      
149         nop
150         
151         decl    %ecx            
152         jnz     1b              
153         
154         popl    %ebx
155         popl    %edi
156         popl    %esi
157                 
158         leave
159         ret
161         
162 SOpti_cvrt_ABGR_8888_RGB_565:
163 SOpti_cvrt_bRGBA_8888_RGB_565:
164 SOpti_cvrt_mRGBA_8888_RGB_565:
165 SOpti_cvrt_lABGR_8888_RGB_565:  
166         pushl   %ebp
167         movl    %esp,%ebp
168         pushl   %esi
169         pushl   %edi
170         pushl   %ebx
171         movl    8(%ebp),%esi       //# \0load src and dst ptr,
172         movl   12(%ebp),%edi 
173         movl   16(%ebp),%ecx       //# and number of pixels
175                  
176         subl    $2,%edi         //        will be re-added in the loop (for pairability)
177         
178 .align 16, 0x90                 //      align loop start for efficiency;fill with nops(90)
180         movl    (%esi),%eax     # 
181         addl    $4,%esi         # 
183         movb    %al,%dl         //       R
184         andl    $0x00ffff00,%eax//        keep only BG
185         
186         shll    $8,%eax         //        ABGR => BGR0  ( BG00 in fact)
187         andb    $0xf8,%dl       //        zeroe 3 low bits of R
188         
189         bswapl  %eax            //      Rearange BGR0 into 0RGB (00GB)
191         
192         shrb    $2,%ah          //       shift G (8bits ->6bits)
193         addl    $2,%edi         //        next dest. pixel
195         shrl    $3,%eax         //       shift B (8bits -> 5bits) and put GB on position
197         orb     %dl,%ah         //        mix R with GB
198         
199         movw    %ax,(%edi)      
200         nop
201         
202         decl    %ecx            
203         jnz     1b              
204         
205         popl    %ebx
206         popl    %edi
207         popl    %esi    
208         leave
209         ret
211 SOpti_cvrt_ARGB_8888_RGB_565:   
212 SOpti_cvrt_bBGRA_8888_RGB_565:  
213 SOpti_cvrt_mBGRA_8888_RGB_565:  
214 SOpti_cvrt_lARGB_8888_RGB_565:
215         pushl   %ebp
216         movl    %esp,%ebp
217         pushl   %esi
218         pushl   %edi
219         pushl   %ebx
220         
221         movl    8(%ebp),%esi       // load src and dst ptr,
222         movl   12(%ebp),%edi 
223         movl   16(%ebp),%ecx        // and number of pixels
225                  
226         subl    $2,%edi         //        will be re-added in the loop (for pairability)
227         
228 .align 16, 0x90                 //      align loop start for efficiency; fill with nops(90)
230         movl    (%esi),%eax     
231         addl    $4,%esi         
233         movl    %eax,%edx       //       
234         andl    $0x0000ffff,%eax//        keep only GB
235         
236         shrl    $16,%edx        //       R into dl
238         shrb    $2,%ah          //       shift G (8bits ->6bits)
239         addl    $2,%edi         //        next dest. pixel
241         shrl    $3,%eax         //       shift B (8bits -> 5bits) and put GB on position
242         andb    $0xf8,%dl       //        zeroe 3 low bits of R
243         
244         orb     %dl,%ah         //        mix R with GB
245         
246         movw    %ax,(%edi)      
247         nop
248         
249         decl    %ecx            
250         jnz     1b              
251         
252         popl    %ebx
253         popl    %edi
254         popl    %esi
255                 
256         leave
257         ret
259         
263 SOpti_cvrt_RGB_565_ARGB_8888:
264 SOpti_cvrt_RGB_565_bBGRA_8888:
265 SOpti_cvrt_RGB_565_mBGRA_8888:
266 SOpti_cvrt_RGB_565_lARGB_8888:  
267         pushl   %ebp
268         movl    %esp,%ebp
269         pushl   %esi
270         pushl   %edi
271         pushl   %ebx
272                 
273         movl    8(%ebp),%esi        // load src and dst ptr,
274         movl   12(%ebp),%edi 
275         movl   16(%ebp),%ecx        // and number of pixels
277 .align 16, 0x90
279         movw    (%esi,%ecx,2),%ax       
280         movl    %eax,%ebx       
281         
282         shll    $3,%eax         //     shift  B and ~G
283         andl    $0xf800,%ebx    //      isolate R
284         
285         shll    $8,%ebx         //      set R in position
286         andl    $0xffff,%eax    //      clear upper word for future R
287         
288         shlb    $2,%ah          //      shift G
289         
290         orl     %eax,%ebx       //      mix 0R GB
292         movl    %ebx,(%edi,%ecx,4)      
293         nop                     
294         
295         
296         decl    %ecx            
297         jnz     1b              
298         
299         popl    %ebx
300         popl    %edi
301         popl    %esi
302         leave
303         ret
308 SOpti_cvrt_PAL_8_RGB_565:
309         pushl   %ebp
310         movl    %esp,%ebp
311         pushl   %esi
312         pushl   %edi
313         pushl   %ebx
314                 
315         movl    8(%ebp),%esi        # load src and dst ptr,
316         movl    12(%ebp),%edi 
317         movl    16(%ebp),%ecx       # number of pixels
318         movl    20(%ebp),%ebx       # palette
319         
320         addl    %ecx,%esi               # partir de la fin pour partir du debut (hem)
321         movl    %ecx,%eax
322         shll    $1,%eax
323         addl    %eax,%edi
324         shrl    $2,%ecx                 # 4 pixels par tour
325         negl    %ecx
326 .align 16,0x90
327 1:      
328         movl    (%esi,%ecx,4),%edx
329         xorl    %eax,%eax
330         
331         pushl   %esi
332         movb    %dh,%al
333         
334         movw    (%ebx,%eax,2),%si
335         movb    %dl,%al
337         shll    $16,%esi
338         andl    $0xffff0000,%edx
340         movw    (%ebx,%eax,2),%si
341         nop
343         shrl    $16,%edx
344         movl    %esi,(%edi,%ecx,8)      ###
346         movb    %dh,%al
347         andl    $0xff,%edx
349         movw    (%ebx,%eax,2),%ax
350         popl    %esi
352         shll    $16,%eax
353         nop
354         
355         movw    (%ebx,%edx,2),%ax
356         nop
358         movl    %eax,4(%edi,%ecx,8)
359         nop
360         
361         incl    %ecx            
362         js      1b              
363         
364         popl    %ebx
365         popl    %edi
366         popl    %esi
367         leave
368         ret
372 SOpti_cvrt_PAL_8_RGBA_8888:
373         pushl   %ebp
374         movl    %esp,%ebp
375         pushl   %esi
376         pushl   %edi
377         pushl   %ebx
378                 
379         movl    8(%ebp),%esi        # load src and dst ptr,
380         movl    12(%ebp),%edi 
381         movl    16(%ebp),%ecx       # number of pixels
382         movl    20(%ebp),%ebx       # palette
383         
384         addl    %ecx,%esi               # partir de la fin pour partir du debut (hem)
385         movl    %ecx,%eax
386         shll    $2,%eax
387         addl    %eax,%edi
388         negl    %ecx
389         xorl    %edx,%edx
390         
391 .align 16,0x90
392 1:      
393         movb    (%esi,%ecx),%dl
394         nop
395         
396         movl    (%ebx,%edx,4),%eax
397         incl    %ecx            
399         movl    %eax,(%edi,%ecx,4)
400         js      1b              
401         
402         popl    %ebx
403         popl    %edi
404         popl    %esi
405         leave
406         ret