ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/video_blit.cpp
Revision: 1.4
Committed: 2001-07-01T14:38:03Z (23 years, 5 months ago) by cebix
Branch: MAIN
Changes since 1.3: +48 -39 lines
Log Message:
- sony.cpp/disk.cpp/cdrom.cpp use vector<> of drive_info objects instead of
  linked list
- color depth switching updates slot ROM
- video_x.cpp always supports 1-bit window modes
- timer_create()/clock_gettime() are pulled from librt if present

File Contents

# User Rev Content
1 gbeauche 1.1 /*
2     * video_blit.cpp - Video/graphics emulation, blitters
3     *
4     * Basilisk II (C) 1997-2001 Christian Bauer
5     *
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.1
24     #include <stdio.h>
25     #include <stdlib.h>
26     #include <X11/Xlib.h>
27     #include <X11/Xutil.h>
28    
29     #ifdef ENABLE_VOSF
30     // Format of the target visual
31     struct VisualFormat {
32     int depth; // Screen depth
33     uint32 Rmask, Gmask, Bmask; // RGB mask values
34     uint32 Rshift, Gshift, Bshift; // RGB shift values
35     };
36     static VisualFormat visualFormat;
37    
38     /* -------------------------------------------------------------------------- */
39     /* --- Raw Copy / No conversion required --- */
40     /* -------------------------------------------------------------------------- */
41    
42     static void Blit_Copy_Raw(uint8 * dest, const uint8 * source, uint32 length)
43     {
44     // This function is likely to be inlined and/or highly optimized
45     memcpy(dest, source, length);
46     }
47    
48     /* -------------------------------------------------------------------------- */
49     /* --- RGB 555 --- */
50     /* -------------------------------------------------------------------------- */
51    
52     #ifdef WORDS_BIGENDIAN
53     # define FB_FUNC_NAME Blit_RGB555_OBO
54     #else
55     # define FB_FUNC_NAME Blit_RGB555_NBO
56     #endif
57    
58     #define FB_BLIT_1(dst, src) \
59     (dst = (((src) >> 8) & 0xff) | (((src) & 0xff) << 8))
60    
61     #define FB_BLIT_2(dst, src) \
62     (dst = (((src) >> 8) & 0x00ff00ff) | (((src) & 0x00ff00ff) << 8))
63    
64     #define FB_DEPTH 15
65     #include "video_blit.h"
66    
67     /* -------------------------------------------------------------------------- */
68     /* --- BGR 555 --- */
69     /* -------------------------------------------------------------------------- */
70    
71 gbeauche 1.2 #ifdef WORDS_BIGENDIAN
72    
73     // Native byte order
74    
75     #define FB_BLIT_1(dst, src) \
76     (dst = (((src) >> 10) & 0x001f) | ((src) & 0x03e0) | (((src) << 10) & 0x7c00))
77    
78     #define FB_BLIT_2(dst, src) \
79     (dst = (((src) >> 10) & 0x001f001f) | ((src) & 0x03e003e0) | (((src) << 10) & 0x7c007c00))
80    
81     #define FB_DEPTH 15
82     #define FB_FUNC_NAME Blit_BGR555_NBO
83     #include "video_blit.h"
84    
85     // Opposite byte order (untested)
86    
87     #define FB_BLIT_1(dst, src) \
88     (dst = (((src) >> 2) & 0x1f00) | (((src) >> 8) & 3) | (((src) << 8) & 0xe000) | (((src) << 2) & 0x7c))
89    
90     #define FB_BLIT_2(dst, src) \
91     (dst = (((src) >> 2) & 0x1f001f00) | (((src) >> 8) & 0x30003) | (((src) << 8) & 0xe000e000) | (((src) << 2) & 0x7c007c))
92    
93     #define FB_DEPTH 15
94     #define FB_FUNC_NAME Blit_BGR555_OBO
95     #include "video_blit.h"
96    
97     #else
98    
99     // Native byte order (untested)
100    
101     #define FB_BLIT_1(dst, src) \
102     (dst = (((src) >> 2) & 0x1f) | (((src) >> 8) & 0xe0) | (((src) << 8) & 0x0300) | (((src) << 2) & 0x7c00))
103    
104     #define FB_BLIT_2(dst, src) \
105     (dst = (((src) >> 2) & 0x1f001f) | (((src) >> 8) & 0xe000e0) | (((src) << 8) & 0x03000300) | (((src) << 2) & 0x7c007c00))
106    
107     #define FB_DEPTH 15
108     #define FB_FUNC_NAME Blit_BGR555_NBO
109     #include "video_blit.h"
110    
111     // Opposite byte order (untested)
112    
113     #define FB_BLIT_1(dst, src) \
114     (dst = (((src) << 6) & 0x1f00) | ((src) & 0xe003) | (((src) >> 6) & 0x7c))
115    
116     #define FB_BLIT_2(dst, src) \
117     (dst = (((src) << 6) & 0x1f001f00) | ((src) & 0xe003e003) | (((src) >> 6) & 0x7c007c))
118    
119     #define FB_DEPTH 15
120     #define FB_FUNC_NAME Blit_BGR555_OBO
121     #include "video_blit.h"
122    
123     #endif
124 gbeauche 1.1
125     /* -------------------------------------------------------------------------- */
126     /* --- RGB 565 --- */
127     /* -------------------------------------------------------------------------- */
128    
129     #ifdef WORDS_BIGENDIAN
130    
131     // Native byte order
132    
133     #define FB_BLIT_1(dst, src) \
134     (dst = (((src) & 0x1f) | (((src) << 1) & 0xffc0)))
135    
136     #define FB_BLIT_2(dst, src) \
137     (dst = (((src) & 0x001f001f) | (((src) << 1) & 0xffc0ffc0)))
138    
139     #define FB_DEPTH 16
140     #define FB_FUNC_NAME Blit_RGB565_NBO
141     #include "video_blit.h"
142    
143     // Opposite byte order
144    
145     #define FB_BLIT_1(dst, src) \
146     (dst = ((((src) >> 7) & 0xff) | (((src) << 9) & 0xc000) | (((src) << 8) & 0x1f00)))
147    
148     #define FB_BLIT_2(dst, src) \
149     (dst = ((((src) >> 7) & 0x00ff00ff) | (((src) << 9) & 0xc000c000) | (((src) << 8) & 0x1f001f00)))
150    
151     #define FB_DEPTH 16
152     #define FB_FUNC_NAME Blit_RGB565_OBO
153     #include "video_blit.h"
154    
155     #else
156    
157     // Native byte order
158    
159     #define FB_BLIT_1(dst, src) \
160     (dst = (((src) >> 8) & 0x001f) | (((src) << 9) & 0xfe00) | (((src) >> 7) & 0x01c0))
161    
162     // gb-- Disabled because I don't see any improvement
163     #if 0 && defined(__i386__) && defined(X86_ASSEMBLY)
164    
165     #define FB_BLIT_2(dst, src) \
166     __asm__ ( "movl %0,%%ebx\n\t" \
167     "movl %0,%%ebp\n\t" \
168     "andl $0x1f001f00,%%ebx\n\t" \
169     "andl $0x007f007f,%0\n\t" \
170     "andl $0xe000e000,%%ebp\n\t" \
171     "shrl $8,%%ebx\n\t" \
172     "shrl $7,%%ebp\n\t" \
173     "shll $9,%0\n\t" \
174     "orl %%ebx,%%ebp\n\t" \
175     "orl %%ebp,%0\n\t" \
176     : "=r" (dst) : "0" (src) : "ebx", "ebp", "cc" )
177    
178     #else
179    
180     #define FB_BLIT_2(dst, src) \
181     (dst = (((src) >> 8) & 0x001f001f) | (((src) << 9) & 0xfe00fe00) | (((src) >> 7) & 0x01c001c0))
182    
183     #endif
184    
185     #define FB_DEPTH 16
186     #define FB_FUNC_NAME Blit_RGB565_NBO
187     #include "video_blit.h"
188    
189     // Opposite byte order (untested)
190    
191     #define FB_BLIT_1(dst, src) \
192     (dst = (((src) & 0x1f00) | (((src) << 1) & 0xe0fe) | (((src) >> 15) & 1)))
193    
194     #define FB_BLIT_2(dst, src) \
195     (dst = (((src) & 0x1f001f00) | (((src) << 1) & 0xe0fee0fe) | (((src) >> 15) & 0x10001)))
196    
197     #define FB_DEPTH 16
198     #define FB_FUNC_NAME Blit_RGB565_OBO
199     #include "video_blit.h"
200    
201     #endif
202    
203     /* -------------------------------------------------------------------------- */
204     /* --- RGB 888 --- */
205     /* -------------------------------------------------------------------------- */
206    
207     #ifdef WORDS_BIGENDIAN
208     # define FB_FUNC_NAME Blit_RGB888_OBO
209     #else
210     # define FB_FUNC_NAME Blit_RGB888_NBO
211     #endif
212    
213     #define FB_BLIT_2(dst, src) \
214     (dst = (((src) >> 24) & 0xff) | (((src) >> 8) & 0xff00) | (((src) & 0xff00) << 8) | (((src) & 0xff) << 24))
215    
216     #define FB_DEPTH 24
217     #include "video_blit.h"
218    
219     /* -------------------------------------------------------------------------- */
220     /* --- BGR 888 --- */
221     /* -------------------------------------------------------------------------- */
222    
223 gbeauche 1.2 // Native byte order [BE] (untested)
224 gbeauche 1.1
225     #ifdef WORDS_BIGENDIAN
226    
227     #define FB_BLIT_2(dst, src) \
228     (dst = (((src) >> 16) & 0xff) | ((src) & 0xff00) | (((src) & 0xff) << 16))
229    
230     #define FB_FUNC_NAME Blit_BGR888_NBO
231     #define FB_DEPTH 24
232     #include "video_blit.h"
233    
234     #else
235    
236 gbeauche 1.2 // Opposite byte order [LE] (untested)
237    
238 gbeauche 1.1 #define FB_BLIT_2(dst, src) \
239     (dst = (((src) >> 16) & 0xff) | ((src) & 0xff0000) | (((src) & 0xff) << 16))
240    
241     #define FB_FUNC_NAME Blit_BGR888_OBO
242     #define FB_DEPTH 24
243     #include "video_blit.h"
244    
245     #endif
246    
247 gbeauche 1.2 // Opposite byte order [BE] (untested) / Native byte order [LE] (untested)
248 gbeauche 1.1
249     #ifdef WORDS_BIGENDIAN
250     # define FB_FUNC_NAME Blit_BGR888_OBO
251     #else
252     # define FB_FUNC_NAME Blit_BGR888_NBO
253     #endif
254    
255     #define FB_BLIT_2(dst, src) \
256     (dst = ((src) & 0xff00ff) | (((src) & 0xff00) << 16))
257    
258     #define FB_DEPTH 24
259     #include "video_blit.h"
260    
261     /* -------------------------------------------------------------------------- */
262     /* --- Blitters to the host frame buffer, or XImage buffer --- */
263     /* -------------------------------------------------------------------------- */
264    
265     // Function used to update the hosst frame buffer (DGA), or an XImage buffer (WIN)
266     // --> Shall be initialized only through the Screen_blitter_init() function
267     typedef void (*Screen_blit_func)(uint8 * dest, const uint8 * source, uint32 length);
268     Screen_blit_func Screen_blit = 0;
269    
270     // Structure used to match the adequate framebuffer update function
271     struct Screen_blit_func_info {
272     int depth; // Screen depth
273     uint32 Rmask; // Red mask
274     uint32 Gmask; // Green mask
275     uint32 Bmask; // Blue mask
276     Screen_blit_func handler_nbo; // Update function (native byte order)
277     Screen_blit_func handler_obo; // Update function (opposite byte order)
278     };
279    
280     // Table of visual formats supported and their respective handler
281     static Screen_blit_func_info Screen_blitters[] = {
282     #ifdef WORDS_BIGENDIAN
283     { 1, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw , Blit_Copy_Raw }, // NT
284     { 8, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw , Blit_Copy_Raw }, // OK (NBO)
285     { 15, 0x007c00, 0x0003e0, 0x00001f, Blit_Copy_Raw , Blit_RGB555_OBO }, // OK (OBO)
286 gbeauche 1.2 { 15, 0x00001f, 0x0003e0, 0x007c00, Blit_BGR555_NBO , Blit_BGR555_OBO }, // NT
287 gbeauche 1.1 { 16, 0x00f800, 0x0007e0, 0x00001f, Blit_RGB565_NBO , Blit_RGB565_OBO }, // OK (OBO)
288     { 24, 0xff0000, 0x00ff00, 0x0000ff, Blit_Copy_Raw , Blit_RGB888_OBO }, // OK (OBO)
289     { 24, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO , Blit_BGR888_OBO }, // NT
290 gbeauche 1.2 { 32, 0xff0000, 0x00ff00, 0x0000ff, Blit_Copy_Raw , Blit_RGB888_OBO }, // OK
291     { 32, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO , Blit_BGR888_OBO } // OK
292 gbeauche 1.1 #else
293     { 1, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw , Blit_Copy_Raw }, // NT
294     { 8, 0x000000, 0x000000, 0x000000, Blit_Copy_Raw , Blit_Copy_Raw }, // OK (NBO)
295     { 15, 0x007c00, 0x0003e0, 0x00001f, Blit_RGB555_NBO , Blit_Copy_Raw }, // OK (NBO)
296 gbeauche 1.2 { 15, 0x00001f, 0x0003e0, 0x007c00, Blit_BGR555_NBO , Blit_BGR555_OBO }, // NT
297 gbeauche 1.1 { 16, 0x00f800, 0x0007e0, 0x00001f, Blit_RGB565_NBO , Blit_RGB565_OBO }, // OK (NBO)
298     { 24, 0xff0000, 0x00ff00, 0x0000ff, Blit_RGB888_NBO , Blit_Copy_Raw }, // OK (NBO)
299     { 24, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO , Blit_BGR888_OBO }, // NT
300     { 32, 0xff0000, 0x00ff00, 0x0000ff, Blit_RGB888_NBO , Blit_Copy_Raw }, // OK (NBO)
301     { 32, 0x0000ff, 0x00ff00, 0xff0000, Blit_BGR888_NBO , Blit_BGR888_OBO } // NT
302     #endif
303     };
304    
305     // Initialize the framebuffer update function
306     // Returns FALSE, if the function was to be reduced to a simple memcpy()
307     // --> In that case, VOSF is not necessary
308 cebix 1.4 bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order, video_depth mac_depth)
309 gbeauche 1.1 {
310 gbeauche 1.3 #if REAL_ADDRESSING || DIRECT_ADDRESSING
311 cebix 1.4 if (mac_depth == VDEPTH_1BIT) {
312    
313     // 1-bit mode uses a 1-bit X image, so there's no need for special blitting routines
314     Screen_blit = Blit_Copy_Raw;
315    
316     } else {
317    
318     visualFormat.depth = visual_info->depth;
319     visualFormat.Rmask = visual_info->red_mask;
320     visualFormat.Gmask = visual_info->green_mask;
321     visualFormat.Bmask = visual_info->blue_mask;
322 gbeauche 1.1
323 cebix 1.4 // Compute RGB shift values
324     visualFormat.Rshift = 0;
325     for (uint32 Rmask = visualFormat.Rmask; Rmask && ((Rmask & 1) != 1); Rmask >>= 1)
326     ++visualFormat.Rshift;
327     visualFormat.Gshift = 0;
328     for (uint32 Gmask = visualFormat.Gmask; Gmask && ((Gmask & 1) != 1); Gmask >>= 1)
329     ++visualFormat.Gshift;
330     visualFormat.Bshift = 0;
331     for (uint32 Bmask = visualFormat.Bmask; Bmask && ((Bmask & 1) != 1); Bmask >>= 1)
332     ++visualFormat.Bshift;
333 gbeauche 1.1
334 cebix 1.4 // Search for an adequate blit function
335     bool blitter_found = false;
336     const int blitters_count = sizeof(Screen_blitters)/sizeof(Screen_blitters[0]);
337     for (int i = 0; !blitter_found && (i < blitters_count); i++) {
338     if ( (visualFormat.depth == Screen_blitters[i].depth)
339     && (visualFormat.Rmask == Screen_blitters[i].Rmask)
340     && (visualFormat.Gmask == Screen_blitters[i].Gmask)
341     && (visualFormat.Bmask == Screen_blitters[i].Bmask)
342     )
343     {
344     blitter_found = true;
345     Screen_blit = native_byte_order
346     ? Screen_blitters[i].handler_nbo
347     : Screen_blitters[i].handler_obo
348     ;
349     }
350 gbeauche 1.1 }
351    
352 cebix 1.4 // No appropriate blitter found, dump RGB mask values and abort()
353     if (!blitter_found) {
354     fprintf(stderr, "### No appropriate blitter found\n");
355     fprintf(stderr, "\tR/G/B mask values : 0x%06x, 0x%06x, 0x%06x (depth = %d)\n",
356     visualFormat.Rmask, visualFormat.Gmask, visualFormat.Bmask, visualFormat.depth);
357     fprintf(stderr, "\tR/G/B shift values : %d/%d/%d\n",
358     visualFormat.Rshift, visualFormat.Gshift, visualFormat.Bshift);
359     abort();
360     }
361 gbeauche 1.1 }
362 gbeauche 1.3 #else
363     // The UAE memory handlers will blit correctly
364     // --> no need for specialised blitters here
365     Screen_blit = Blit_Copy_Raw;
366     #endif
367 gbeauche 1.1
368     // If the blitter simply reduces to a copy, we don't need VOSF in DGA mode
369     // --> In that case, we return FALSE
370     return (Screen_blit != Blit_Copy_Raw);
371     }
372     #endif /* ENABLE_VOSF */