ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/video_blit.cpp
Revision: 1.14
Committed: 2004-11-14T21:41:46Z (19 years, 10 months ago) by gbeauche
Branch: MAIN
Changes since 1.13: +1 -0 lines
Log Message:
Implement RGB555 mode on 16-bit displays (Windows)

File Contents

# User Rev Content
1 gbeauche 1.1 /*
2     * video_blit.cpp - Video/graphics emulation, blitters
3     *
4 cebix 1.12 * Basilisk II (C) 1997-2004 Christian Bauer
5 gbeauche 1.1 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19     */
20    
21     #include "sysdeps.h"
22 cebix 1.4 #include "video.h"
23 gbeauche 1.13 #include "video_blit.h"
24 gbeauche 1.1
25     #include <stdio.h>
26     #include <stdlib.h>
27    
28     // Format of the target visual
29     static VisualFormat visualFormat;
30    
31 cebix 1.5 // This holds the pixels values of the palette colors for 8->16/32-bit expansion
32     uint32 ExpandMap[256];
33    
34 gbeauche 1.13 // Mark video_blit.h for specialization
35     #define DEFINE_VIDEO_BLITTERS 1
36    
37 gbeauche 1.1 /* -------------------------------------------------------------------------- */
38     /* --- Raw Copy / No conversion required --- */
39     /* -------------------------------------------------------------------------- */
40    
41     static void Blit_Copy_Raw(uint8 * dest, const uint8 * source, uint32 length)
42     {
43     // This function is likely to be inlined and/or highly optimized
44     memcpy(dest, source, length);
45     }
46    
47     /* -------------------------------------------------------------------------- */
48     /* --- RGB 555 --- */
49     /* -------------------------------------------------------------------------- */
50    
51     #ifdef WORDS_BIGENDIAN
52     # define FB_FUNC_NAME Blit_RGB555_OBO
53     #else
54     # define FB_FUNC_NAME Blit_RGB555_NBO
55     #endif
56    
57     #define FB_BLIT_1(dst, src) \
58     (dst = (((src) >> 8) & 0xff) | (((src) & 0xff) << 8))
59    
60     #define FB_BLIT_2(dst, src) \
61     (dst = (((src) >> 8) & 0x00ff00ff) | (((src) & 0x00ff00ff) << 8))
62    
63 gbeauche 1.9 #define FB_BLIT_4(dst, src) \
64     (dst = (((src) >> 8) & UVAL64(0x00ff00ff00ff00ff)) | \
65     (((src) & UVAL64(0x00ff00ff00ff00ff)) << 8))
66    
67 gbeauche 1.1 #define FB_DEPTH 15
68     #include "video_blit.h"
69    
70     /* -------------------------------------------------------------------------- */
71     /* --- BGR 555 --- */
72     /* -------------------------------------------------------------------------- */
73    
74 gbeauche 1.2 #ifdef WORDS_BIGENDIAN
75    
76     // Native byte order
77    
78     #define FB_BLIT_1(dst, src) \
79     (dst = (((src) >> 10) & 0x001f) | ((src) & 0x03e0) | (((src) << 10) & 0x7c00))
80    
81     #define FB_BLIT_2(dst, src) \
82     (dst = (((src) >> 10) & 0x001f001f) | ((src) & 0x03e003e0) | (((src) << 10) & 0x7c007c00))
83    
84 gbeauche 1.9 #define FB_BLIT_4(dst, src) \
85     (dst = (((src) >> 10) & UVAL64(0x001f001f001f001f)) | \
86     ( (src) & UVAL64(0x03e003e003e003e0)) | \
87     (((src) << 10) & UVAL64(0x7c007c007c007c00)))
88    
89 gbeauche 1.2 #define FB_DEPTH 15
90     #define FB_FUNC_NAME Blit_BGR555_NBO
91     #include "video_blit.h"
92    
93     // Opposite byte order (untested)
94    
95     #define FB_BLIT_1(dst, src) \
96     (dst = (((src) >> 2) & 0x1f00) | (((src) >> 8) & 3) | (((src) << 8) & 0xe000) | (((src) << 2) & 0x7c))
97    
98     #define FB_BLIT_2(dst, src) \
99     (dst = (((src) >> 2) & 0x1f001f00) | (((src) >> 8) & 0x30003) | (((src) << 8) & 0xe000e000) | (((src) << 2) & 0x7c007c))
100    
101 gbeauche 1.9 #define FB_BLIT_4(dst, src) \
102     (dst = (((src) >> 2) & UVAL64(0x1f001f001f001f00)) | \
103     (((src) >> 8) & UVAL64(0x0003000300030003)) | \
104     (((src) << 8) & UVAL64(0xe000e000e000e000)) | \
105     (((src) << 2) & UVAL64(0x007c007c007c007c)))
106    
107 gbeauche 1.2 #define FB_DEPTH 15
108     #define FB_FUNC_NAME Blit_BGR555_OBO
109     #include "video_blit.h"
110    
111     #else
112    
113     // Native byte order (untested)
114    
115     #define FB_BLIT_1(dst, src) \
116     (dst = (((src) >> 2) & 0x1f) | (((src) >> 8) & 0xe0) | (((src) << 8) & 0x0300) | (((src) << 2) & 0x7c00))
117    
118     #define FB_BLIT_2(dst, src) \
119     (dst = (((src) >> 2) & 0x1f001f) | (((src) >> 8) & 0xe000e0) | (((src) << 8) & 0x03000300) | (((src) << 2) & 0x7c007c00))
120    
121 gbeauche 1.9 #define FB_BLIT_4(dst, src) \
122     (dst = (((src) >> 2) & UVAL64(0x001f001f001f001f)) | \
123     (((src) >> 8) & UVAL64(0x00e000e000e000e0)) | \
124     (((src) << 8) & UVAL64(0x0300030003000300)) | \
125     (((src) << 2) & UVAL64(0x7c007c007c007c00)))
126    
127 gbeauche 1.2 #define FB_DEPTH 15
128     #define FB_FUNC_NAME Blit_BGR555_NBO
129     #include "video_blit.h"
130    
131     // Opposite byte order (untested)
132    
133     #define FB_BLIT_1(dst, src) \
134     (dst = (((src) << 6) & 0x1f00) | ((src) & 0xe003) | (((src) >> 6) & 0x7c))
135    
136     #define FB_BLIT_2(dst, src) \
137     (dst = (((src) << 6) & 0x1f001f00) | ((src) & 0xe003e003) | (((src) >> 6) & 0x7c007c))
138    
139 gbeauche 1.9 #define FB_BLIT_4(dst, src) \
140     (dst = (((src) << 6) & UVAL64(0x1f001f001f001f00)) | \
141     ( (src) & UVAL64(0xe003e003e003e003)) | \
142     (((src) >> 6) & UVAL64(0x007c007c007c007c)))
143    
144 gbeauche 1.2 #define FB_DEPTH 15
145     #define FB_FUNC_NAME Blit_BGR555_OBO
146     #include "video_blit.h"
147    
148     #endif
149 gbeauche 1.1
150     /* -------------------------------------------------------------------------- */
151     /* --- RGB 565 --- */
152     /* -------------------------------------------------------------------------- */
153    
154     #ifdef WORDS_BIGENDIAN
155    
156     // Native byte order
157    
158     #define FB_BLIT_1(dst, src) \
159     (dst = (((src) & 0x1f) | (((src) << 1) & 0xffc0)))
160    
161     #define FB_BLIT_2(dst, src) \
162     (dst = (((src) & 0x001f001f) | (((src) << 1) & 0xffc0ffc0)))
163    
164 gbeauche 1.9 #define FB_BLIT_4(dst, src) \
165     (dst = (((src) & UVAL64(0x001f001f001f001f)) | \
166     (((src) << 1) & UVAL64(0xffc0ffc0ffc0ffc0))))
167    
168 gbeauche 1.1 #define FB_DEPTH 16
169     #define FB_FUNC_NAME Blit_RGB565_NBO
170     #include "video_blit.h"
171    
172     // Opposite byte order
173    
174     #define FB_BLIT_1(dst, src) \
175     (dst = ((((src) >> 7) & 0xff) | (((src) << 9) & 0xc000) | (((src) << 8) & 0x1f00)))
176    
177     #define FB_BLIT_2(dst, src) \
178     (dst = ((((src) >> 7) & 0x00ff00ff) | (((src) << 9) & 0xc000c000) | (((src) << 8) & 0x1f001f00)))
179    
180 gbeauche 1.9 #define FB_BLIT_4(dst, src) \
181     (dst = (((src) >> 7) & UVAL64(0x00ff00ff00ff00ff)) | \
182     (((src) << 9) & UVAL64(0xc000c000c000c000)) | \
183     (((src) << 8) & UVAL64(0x1f001f001f001f00)))
184    
185 gbeauche 1.1 #define FB_DEPTH 16
186     #define FB_FUNC_NAME Blit_RGB565_OBO
187     #include "video_blit.h"
188    
189     #else
190    
191     // Native byte order
192    
193     #define FB_BLIT_1(dst, src) \
194     (dst = (((src) >> 8) & 0x001f) | (((src) << 9) & 0xfe00) | (((src) >> 7) & 0x01c0))
195    
196     #define FB_BLIT_2(dst, src) \
197     (dst = (((src) >> 8) & 0x001f001f) | (((src) << 9) & 0xfe00fe00) | (((src) >> 7) & 0x01c001c0))
198    
199 gbeauche 1.9 #define FB_BLIT_4(dst, src) \
200     (dst = (((src) >> 8) & UVAL64(0x001f001f001f001f)) | \
201     (((src) << 9) & UVAL64(0xfe00fe00fe00fe00)) | \
202     (((src) >> 7) & UVAL64(0x01c001c001c001c0)))
203 gbeauche 1.1
204     #define FB_DEPTH 16
205     #define FB_FUNC_NAME Blit_RGB565_NBO
206     #include "video_blit.h"
207    
208     // Opposite byte order (untested)
209    
210     #define FB_BLIT_1(dst, src) \
211     (dst = (((src) & 0x1f00) | (((src) << 1) & 0xe0fe) | (((src) >> 15) & 1)))
212    
213     #define FB_BLIT_2(dst, src) \
214     (dst = (((src) & 0x1f001f00) | (((src) << 1) & 0xe0fee0fe) | (((src) >> 15) & 0x10001)))
215    
216 gbeauche 1.9 #define FB_BLIT_4(dst, src) \
217     (dst = (((src) & UVAL64(0x1f001f001f001f00)) | \
218     (((src) << 1) & UVAL64(0xe0fee0fee0fee0fe)) | \
219     (((src) >> 15) & UVAL64(0x0001000100010001))))
220    
221 gbeauche 1.1 #define FB_DEPTH 16
222     #define FB_FUNC_NAME Blit_RGB565_OBO
223     #include "video_blit.h"
224    
225     #endif
226    
227     /* -------------------------------------------------------------------------- */
228     /* --- RGB 888 --- */
229     /* -------------------------------------------------------------------------- */
230    
231     #ifdef WORDS_BIGENDIAN
232     # define FB_FUNC_NAME Blit_RGB888_OBO
233     #else
234     # define FB_FUNC_NAME Blit_RGB888_NBO
235     #endif
236    
237     #define FB_BLIT_2(dst, src) \
238     (dst = (((src) >> 24) & 0xff) | (((src) >> 8) & 0xff00) | (((src) & 0xff00) << 8) | (((src) & 0xff) << 24))
239    
240 gbeauche 1.9 #define FB_BLIT_4(dst, src) \
241     (dst = (((src) >> 24) & UVAL64(0x000000ff000000ff)) | \
242     (((src) >> 8) & UVAL64(0x0000ff000000ff00)) | \
243     (((src) & UVAL64(0x0000ff000000ff00)) << 8) | \
244     (((src) & UVAL64(0x000000ff000000ff)) << 24))
245    
246 gbeauche 1.1 #define FB_DEPTH 24
247     #include "video_blit.h"
248    
249     /* -------------------------------------------------------------------------- */
250     /* --- BGR 888 --- */
251     /* -------------------------------------------------------------------------- */
252    
253 gbeauche 1.2 // Native byte order [BE] (untested)
254 gbeauche 1.1
255     #ifdef WORDS_BIGENDIAN
256    
257     #define FB_BLIT_2(dst, src) \
258     (dst = (((src) >> 16) & 0xff) | ((src) & 0xff00) | (((src) & 0xff) << 16))
259    
260 gbeauche 1.9 #define FB_BLIT_4(dst, src) \
261     (dst = (((src) >> 16) & UVAL64(0x000000ff000000ff)) | \
262     ( (src) & UVAL64(0x0000ff000000ff00)) | \
263     (((src) & UVAL64(0x000000ff000000ff)) << 16))
264    
265 gbeauche 1.1 #define FB_FUNC_NAME Blit_BGR888_NBO
266     #define FB_DEPTH 24
267     #include "video_blit.h"
268    
269     #else
270    
271 gbeauche 1.2 // Opposite byte order [LE] (untested)
272    
273 gbeauche 1.1 #define FB_BLIT_2(dst, src) \
274     (dst = (((src) >> 16) & 0xff) | ((src) & 0xff0000) | (((src) & 0xff) << 16))
275    
276 gbeauche 1.9 #define FB_BLIT_4(dst, src) \
277     (dst = (((src) >> 16) & UVAL64(0x000000ff000000ff)) | \
278     ( (src) & UVAL64(0x00ff000000ff0000)) | \
279     (((src) & UVAL64(0x000000ff000000ff)) << 16))
280    
281 gbeauche 1.1 #define FB_FUNC_NAME Blit_BGR888_OBO
282     #define FB_DEPTH 24
283     #include "video_blit.h"
284    
285     #endif
286    
287 gbeauche 1.2 // Opposite byte order [BE] (untested) / Native byte order [LE] (untested)
288 gbeauche 1.1
289     #ifdef WORDS_BIGENDIAN
290     # define FB_FUNC_NAME Blit_BGR888_OBO
291     #else
292     # define FB_FUNC_NAME Blit_BGR888_NBO
293     #endif
294    
295     #define FB_BLIT_2(dst, src) \
296     (dst = ((src) & 0xff00ff) | (((src) & 0xff00) << 16))
297 gbeauche 1.9
298     #define FB_BLIT_4(dst, src) \
299     (dst = ((src) & UVAL64(0x00ff00ff00ff00ff)) | (((src) & UVAL64(0x0000ff000000ff00)) << 16))
300 gbeauche 1.1
301     #define FB_DEPTH 24
302     #include "video_blit.h"
303    
304     /* -------------------------------------------------------------------------- */
305 gbeauche 1.13 /* --- 1/2/4-bit indexed to 8-bit mode conversion --- */
306 cebix 1.7 /* -------------------------------------------------------------------------- */
307    
308 gbeauche 1.13 static void Blit_Expand_1_To_8(uint8 * dest, const uint8 * p, uint32 length)
309     {
310     uint8 *q = (uint8 *)dest;
311     for (uint32 i=0; i<length; i++) {
312     uint8 c = *p++;
313     *q++ = c >> 7;
314     *q++ = (c >> 6) & 1;
315     *q++ = (c >> 5) & 1;
316     *q++ = (c >> 4) & 1;
317     *q++ = (c >> 3) & 1;
318     *q++ = (c >> 2) & 1;
319     *q++ = (c >> 1) & 1;
320     *q++ = c & 1;
321     }
322     }
323    
324 cebix 1.7 static void Blit_Expand_2_To_8(uint8 * dest, const uint8 * p, uint32 length)
325     {
326     uint8 *q = (uint8 *)dest;
327 cebix 1.8 for (uint32 i=0; i<length; i++) {
328 cebix 1.7 uint8 c = *p++;
329     *q++ = c >> 6;
330     *q++ = (c >> 4) & 3;
331     *q++ = (c >> 2) & 3;
332     *q++ = c & 3;
333     }
334     }
335    
336     static void Blit_Expand_4_To_8(uint8 * dest, const uint8 * p, uint32 length)
337     {
338     uint8 *q = (uint8 *)dest;
339 cebix 1.8 for (uint32 i=0; i<length; i++) {
340 cebix 1.7 uint8 c = *p++;
341     *q++ = c >> 4;
342     *q++ = c & 0x0f;
343     }
344     }
345    
346     /* -------------------------------------------------------------------------- */
347 cebix 1.6 /* --- 2/4/8-bit indexed to 16-bit mode color expansion --- */
348 cebix 1.5 /* -------------------------------------------------------------------------- */
349    
350 cebix 1.6 static void Blit_Expand_2_To_16(uint8 * dest, const uint8 * p, uint32 length)
351     {
352     uint16 *q = (uint16 *)dest;
353 cebix 1.8 for (uint32 i=0; i<length; i++) {
354 cebix 1.6 uint8 c = *p++;
355     *q++ = ExpandMap[c >> 6];
356     *q++ = ExpandMap[c >> 4];
357     *q++ = ExpandMap[c >> 2];
358     *q++ = ExpandMap[c];
359     }
360     }
361    
362     static void Blit_Expand_4_To_16(uint8 * dest, const uint8 * p, uint32 length)
363     {
364     uint16 *q = (uint16 *)dest;
365 cebix 1.8 for (uint32 i=0; i<length; i++) {
366 cebix 1.6 uint8 c = *p++;
367     *q++ = ExpandMap[c >> 4];
368     *q++ = ExpandMap[c];
369     }
370     }
371    
372 cebix 1.5 static void Blit_Expand_8_To_16(uint8 * dest, const uint8 * p, uint32 length)
373     {
374     uint16 *q = (uint16 *)dest;
375 cebix 1.8 for (uint32 i=0; i<length; i++)
376 cebix 1.5 *q++ = ExpandMap[*p++];
377     }
378    
379     /* -------------------------------------------------------------------------- */
380 cebix 1.6 /* --- 2/4/8-bit indexed to 32-bit mode color expansion --- */
381 cebix 1.5 /* -------------------------------------------------------------------------- */
382    
383 cebix 1.6 static void Blit_Expand_2_To_32(uint8 * dest, const uint8 * p, uint32 length)
384     {
385     uint32 *q = (uint32 *)dest;
386 cebix 1.8 for (uint32 i=0; i<length; i++) {
387 cebix 1.6 uint8 c = *p++;
388     *q++ = ExpandMap[c >> 6];
389     *q++ = ExpandMap[c >> 4];
390     *q++ = ExpandMap[c >> 2];
391     *q++ = ExpandMap[c];
392     }
393     }
394    
395     static void Blit_Expand_4_To_32(uint8 * dest, const uint8 * p, uint32 length)
396     {
397     uint32 *q = (uint32 *)dest;
398 cebix 1.8 for (uint32 i=0; i<length; i++) {
399 cebix 1.6 uint8 c = *p++;
400     *q++ = ExpandMap[c >> 4];
401     *q++ = ExpandMap[c];
402     }
403     }
404    
405 cebix 1.5 static void Blit_Expand_8_To_32(uint8 * dest, const uint8 * p, uint32 length)
406     {
407     uint32 *q = (uint32 *)dest;
408 cebix 1.8 for (uint32 i=0; i<length; i++)
409 cebix 1.5 *q++ = ExpandMap[*p++];
410     }
411    
412     /* -------------------------------------------------------------------------- */
413 gbeauche 1.1 /* --- Blitters to the host frame buffer, or XImage buffer --- */
414     /* -------------------------------------------------------------------------- */
415    
416     // Function used to update the hosst frame buffer (DGA), or an XImage buffer (WIN)
417     // --> Shall be initialized only through the Screen_blitter_init() function
418     typedef void (*Screen_blit_func)(uint8 * dest, const uint8 * source, uint32 length);
419     Screen_blit_func Screen_blit = 0;
420    
421     // Structure used to match the adequate framebuffer update function
422     struct Screen_blit_func_info {
423     int depth; // Screen depth
424     uint32 Rmask; // Red mask
425     uint32 Gmask; // Green mask
426     uint32 Bmask; // Blue mask
427     Screen_blit_func handler_nbo; // Update function (native byte order)
428     Screen_blit_func handler_obo; // Update function (opposite byte order)
429     };
430    
431     // Table of visual formats supported and their respective handler
432     static Screen_blit_func_info Screen_blitters[] = {
433     #ifdef WORDS_BIGENDIAN
434     { 1, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw , Blit_Copy_Raw }, // NT
435     { 8, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw , Blit_Copy_Raw }, // OK (NBO)
436     { 15, 0x007c00, 0x0003e0, 0x00001f, Blit_Copy_Raw , Blit_RGB555_OBO }, // OK (OBO)
437 gbeauche 1.2 { 15, 0x00001f, 0x0003e0, 0x007c00, Blit_BGR555_NBO , Blit_BGR555_OBO }, // NT
438 gbeauche 1.1 { 16, 0x00f800, 0x0007e0, 0x00001f, Blit_RGB565_NBO , Blit_RGB565_OBO }, // OK (OBO)
439     { 24, 0xff0000, 0x00ff00, 0x0000ff, Blit_Copy_Raw , Blit_RGB888_OBO }, // OK (OBO)
440     { 24, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO , Blit_BGR888_OBO }, // NT
441 gbeauche 1.2 { 32, 0xff0000, 0x00ff00, 0x0000ff, Blit_Copy_Raw , Blit_RGB888_OBO }, // OK
442     { 32, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO , Blit_BGR888_OBO } // OK
443 gbeauche 1.1 #else
444     { 1, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw , Blit_Copy_Raw }, // NT
445     { 8, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw , Blit_Copy_Raw }, // OK (NBO)
446     { 15, 0x007c00, 0x0003e0, 0x00001f, Blit_RGB555_NBO , Blit_Copy_Raw }, // OK (NBO)
447 gbeauche 1.2 { 15, 0x00001f, 0x0003e0, 0x007c00, Blit_BGR555_NBO , Blit_BGR555_OBO }, // NT
448 gbeauche 1.14 { 16, 0x007c00, 0x0003e0, 0x00001f, Blit_RGB555_NBO , Blit_Copy_Raw }, // OK (NBO)
449 gbeauche 1.1 { 16, 0x00f800, 0x0007e0, 0x00001f, Blit_RGB565_NBO , Blit_RGB565_OBO }, // OK (NBO)
450     { 24, 0xff0000, 0x00ff00, 0x0000ff, Blit_RGB888_NBO , Blit_Copy_Raw }, // OK (NBO)
451     { 24, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO , Blit_BGR888_OBO }, // NT
452     { 32, 0xff0000, 0x00ff00, 0x0000ff, Blit_RGB888_NBO , Blit_Copy_Raw }, // OK (NBO)
453     { 32, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO , Blit_BGR888_OBO } // NT
454     #endif
455     };
456    
457     // Initialize the framebuffer update function
458     // Returns FALSE, if the function was to be reduced to a simple memcpy()
459     // --> In that case, VOSF is not necessary
460 gbeauche 1.13 bool Screen_blitter_init(VisualFormat const & visual_format, bool native_byte_order, int mac_depth)
461 gbeauche 1.1 {
462 gbeauche 1.13 #if USE_SDL_VIDEO
463     const bool use_sdl_video = true;
464     #else
465     const bool use_sdl_video = false;
466     #endif
467 gbeauche 1.3 #if REAL_ADDRESSING || DIRECT_ADDRESSING
468 gbeauche 1.13 if (!use_sdl_video && mac_depth == 1) {
469 cebix 1.4
470     // 1-bit mode uses a 1-bit X image, so there's no need for special blitting routines
471     Screen_blit = Blit_Copy_Raw;
472    
473     } else {
474    
475     // Compute RGB shift values
476 gbeauche 1.13 visualFormat = visual_format;
477 cebix 1.4 visualFormat.Rshift = 0;
478     for (uint32 Rmask = visualFormat.Rmask; Rmask && ((Rmask & 1) != 1); Rmask >>= 1)
479     ++visualFormat.Rshift;
480     visualFormat.Gshift = 0;
481     for (uint32 Gmask = visualFormat.Gmask; Gmask && ((Gmask & 1) != 1); Gmask >>= 1)
482     ++visualFormat.Gshift;
483     visualFormat.Bshift = 0;
484     for (uint32 Bmask = visualFormat.Bmask; Bmask && ((Bmask & 1) != 1); Bmask >>= 1)
485     ++visualFormat.Bshift;
486 cebix 1.5
487 gbeauche 1.13 // 1/2/4/8-bit mode on 8/16/32-bit screen?
488     Screen_blit = NULL;
489     switch (visualFormat.depth) {
490     case 8:
491     switch (mac_depth) {
492     case 1: Screen_blit = Blit_Expand_1_To_8; break;
493     case 2: Screen_blit = Blit_Expand_2_To_8; break;
494     case 4: Screen_blit = Blit_Expand_4_To_8; break;
495 cebix 1.7 }
496 gbeauche 1.13 break;
497     case 15:
498     case 16:
499     switch (mac_depth) {
500     case 2: Screen_blit = Blit_Expand_2_To_16; break;
501     case 4: Screen_blit = Blit_Expand_4_To_16; break;
502     case 8: Screen_blit = Blit_Expand_8_To_16; break;
503 cebix 1.7 }
504 gbeauche 1.13 break;
505     case 24:
506     case 32:
507     switch (mac_depth) {
508     case 2: Screen_blit = Blit_Expand_2_To_32; break;
509     case 4: Screen_blit = Blit_Expand_4_To_32; break;
510     case 8: Screen_blit = Blit_Expand_8_To_32; break;
511 cebix 1.5 }
512 gbeauche 1.13 break;
513 cebix 1.5 }
514 gbeauche 1.13 bool blitter_found = (Screen_blit != NULL);
515 gbeauche 1.1
516 cebix 1.4 // Search for an adequate blit function
517     const int blitters_count = sizeof(Screen_blitters)/sizeof(Screen_blitters[0]);
518     for (int i = 0; !blitter_found && (i < blitters_count); i++) {
519     if ( (visualFormat.depth == Screen_blitters[i].depth)
520     && (visualFormat.Rmask == Screen_blitters[i].Rmask)
521     && (visualFormat.Gmask == Screen_blitters[i].Gmask)
522     && (visualFormat.Bmask == Screen_blitters[i].Bmask)
523     )
524     {
525     blitter_found = true;
526     Screen_blit = native_byte_order
527     ? Screen_blitters[i].handler_nbo
528     : Screen_blitters[i].handler_obo
529     ;
530     }
531 gbeauche 1.1 }
532    
533 cebix 1.4 // No appropriate blitter found, dump RGB mask values and abort()
534     if (!blitter_found) {
535     fprintf(stderr, "### No appropriate blitter found\n");
536     fprintf(stderr, "\tR/G/B mask values : 0x%06x, 0x%06x, 0x%06x (depth = %d)\n",
537     visualFormat.Rmask, visualFormat.Gmask, visualFormat.Bmask, visualFormat.depth);
538     fprintf(stderr, "\tR/G/B shift values : %d/%d/%d\n",
539     visualFormat.Rshift, visualFormat.Gshift, visualFormat.Bshift);
540     abort();
541     }
542 gbeauche 1.1 }
543 gbeauche 1.3 #else
544     // The UAE memory handlers will blit correctly
545     // --> no need for specialised blitters here
546     Screen_blit = Blit_Copy_Raw;
547     #endif
548 gbeauche 1.1
549     // If the blitter simply reduces to a copy, we don't need VOSF in DGA mode
550     // --> In that case, we return FALSE
551     return (Screen_blit != Blit_Copy_Raw);
552     }