--- BasiliskII/src/Unix/video_blit.cpp 2001/07/01 14:38:03 1.4 +++ BasiliskII/src/Unix/video_blit.cpp 2004/01/12 15:29:25 1.12 @@ -1,7 +1,7 @@ /* * video_blit.cpp - Video/graphics emulation, blitters * - * Basilisk II (C) 1997-2001 Christian Bauer + * Basilisk II (C) 1997-2004 Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,6 +35,9 @@ struct VisualFormat { }; static VisualFormat visualFormat; +// This holds the pixels values of the palette colors for 8->16/32-bit expansion +uint32 ExpandMap[256]; + /* -------------------------------------------------------------------------- */ /* --- Raw Copy / No conversion required --- */ /* -------------------------------------------------------------------------- */ @@ -61,6 +64,10 @@ static void Blit_Copy_Raw(uint8 * dest, #define FB_BLIT_2(dst, src) \ (dst = (((src) >> 8) & 0x00ff00ff) | (((src) & 0x00ff00ff) << 8)) +#define FB_BLIT_4(dst, src) \ + (dst = (((src) >> 8) & UVAL64(0x00ff00ff00ff00ff)) | \ + (((src) & UVAL64(0x00ff00ff00ff00ff)) << 8)) + #define FB_DEPTH 15 #include "video_blit.h" @@ -78,6 +85,11 @@ static void Blit_Copy_Raw(uint8 * dest, #define FB_BLIT_2(dst, src) \ (dst = (((src) >> 10) & 0x001f001f) | ((src) & 0x03e003e0) | (((src) << 10) & 0x7c007c00)) +#define FB_BLIT_4(dst, src) \ + (dst = (((src) >> 10) & UVAL64(0x001f001f001f001f)) | \ + ( (src) & UVAL64(0x03e003e003e003e0)) | \ + (((src) << 10) & UVAL64(0x7c007c007c007c00))) + #define FB_DEPTH 15 #define FB_FUNC_NAME Blit_BGR555_NBO #include "video_blit.h" @@ -90,6 +102,12 @@ static void Blit_Copy_Raw(uint8 * dest, #define FB_BLIT_2(dst, src) \ (dst = (((src) >> 2) & 0x1f001f00) | (((src) >> 8) & 0x30003) | (((src) << 8) & 0xe000e000) | (((src) << 2) & 0x7c007c)) +#define FB_BLIT_4(dst, src) \ + (dst = (((src) >> 2) & UVAL64(0x1f001f001f001f00)) | \ + (((src) >> 8) & UVAL64(0x0003000300030003)) | \ + (((src) << 8) & UVAL64(0xe000e000e000e000)) | \ + (((src) << 2) & UVAL64(0x007c007c007c007c))) + #define FB_DEPTH 15 #define FB_FUNC_NAME Blit_BGR555_OBO #include "video_blit.h" @@ -104,6 +122,12 @@ static void Blit_Copy_Raw(uint8 * dest, #define FB_BLIT_2(dst, src) \ (dst = (((src) >> 2) & 0x1f001f) | (((src) >> 8) & 0xe000e0) | (((src) << 8) & 0x03000300) | (((src) << 2) & 0x7c007c00)) +#define FB_BLIT_4(dst, src) \ + (dst = (((src) >> 2) & UVAL64(0x001f001f001f001f)) | \ + (((src) >> 8) & UVAL64(0x00e000e000e000e0)) | \ + (((src) << 8) & UVAL64(0x0300030003000300)) | \ + (((src) << 2) & UVAL64(0x7c007c007c007c00))) + #define FB_DEPTH 15 #define FB_FUNC_NAME Blit_BGR555_NBO #include "video_blit.h" @@ -116,6 +140,11 @@ static void Blit_Copy_Raw(uint8 * dest, #define FB_BLIT_2(dst, src) \ (dst = (((src) << 6) & 0x1f001f00) | ((src) & 0xe003e003) | (((src) >> 6) & 0x7c007c)) +#define FB_BLIT_4(dst, src) \ + (dst = (((src) << 6) & UVAL64(0x1f001f001f001f00)) | \ + ( (src) & UVAL64(0xe003e003e003e003)) | \ + (((src) >> 6) & UVAL64(0x007c007c007c007c))) + #define FB_DEPTH 15 #define FB_FUNC_NAME Blit_BGR555_OBO #include "video_blit.h" @@ -136,6 +165,10 @@ static void Blit_Copy_Raw(uint8 * dest, #define FB_BLIT_2(dst, src) \ (dst = (((src) & 0x001f001f) | (((src) << 1) & 0xffc0ffc0))) +#define FB_BLIT_4(dst, src) \ + (dst = (((src) & UVAL64(0x001f001f001f001f)) | \ + (((src) << 1) & UVAL64(0xffc0ffc0ffc0ffc0)))) + #define FB_DEPTH 16 #define FB_FUNC_NAME Blit_RGB565_NBO #include "video_blit.h" @@ -148,6 +181,11 @@ static void Blit_Copy_Raw(uint8 * dest, #define FB_BLIT_2(dst, src) \ (dst = ((((src) >> 7) & 0x00ff00ff) | (((src) << 9) & 0xc000c000) | (((src) << 8) & 0x1f001f00))) +#define FB_BLIT_4(dst, src) \ + (dst = (((src) >> 7) & UVAL64(0x00ff00ff00ff00ff)) | \ + (((src) << 9) & UVAL64(0xc000c000c000c000)) | \ + (((src) << 8) & UVAL64(0x1f001f001f001f00))) + #define FB_DEPTH 16 #define FB_FUNC_NAME Blit_RGB565_OBO #include "video_blit.h" @@ -159,28 +197,13 @@ static void Blit_Copy_Raw(uint8 * dest, #define FB_BLIT_1(dst, src) \ (dst = (((src) >> 8) & 0x001f) | (((src) << 9) & 0xfe00) | (((src) >> 7) & 0x01c0)) -// gb-- Disabled because I don't see any improvement -#if 0 && defined(__i386__) && defined(X86_ASSEMBLY) - -#define FB_BLIT_2(dst, src) \ - __asm__ ( "movl %0,%%ebx\n\t" \ - "movl %0,%%ebp\n\t" \ - "andl $0x1f001f00,%%ebx\n\t" \ - "andl $0x007f007f,%0\n\t" \ - "andl $0xe000e000,%%ebp\n\t" \ - "shrl $8,%%ebx\n\t" \ - "shrl $7,%%ebp\n\t" \ - "shll $9,%0\n\t" \ - "orl %%ebx,%%ebp\n\t" \ - "orl %%ebp,%0\n\t" \ - : "=r" (dst) : "0" (src) : "ebx", "ebp", "cc" ) - -#else - #define FB_BLIT_2(dst, src) \ (dst = (((src) >> 8) & 0x001f001f) | (((src) << 9) & 0xfe00fe00) | (((src) >> 7) & 0x01c001c0)) -#endif +#define FB_BLIT_4(dst, src) \ + (dst = (((src) >> 8) & UVAL64(0x001f001f001f001f)) | \ + (((src) << 9) & UVAL64(0xfe00fe00fe00fe00)) | \ + (((src) >> 7) & UVAL64(0x01c001c001c001c0))) #define FB_DEPTH 16 #define FB_FUNC_NAME Blit_RGB565_NBO @@ -194,6 +217,11 @@ static void Blit_Copy_Raw(uint8 * dest, #define FB_BLIT_2(dst, src) \ (dst = (((src) & 0x1f001f00) | (((src) << 1) & 0xe0fee0fe) | (((src) >> 15) & 0x10001))) +#define FB_BLIT_4(dst, src) \ + (dst = (((src) & UVAL64(0x1f001f001f001f00)) | \ + (((src) << 1) & UVAL64(0xe0fee0fee0fee0fe)) | \ + (((src) >> 15) & UVAL64(0x0001000100010001)))) + #define FB_DEPTH 16 #define FB_FUNC_NAME Blit_RGB565_OBO #include "video_blit.h" @@ -213,6 +241,12 @@ static void Blit_Copy_Raw(uint8 * dest, #define FB_BLIT_2(dst, src) \ (dst = (((src) >> 24) & 0xff) | (((src) >> 8) & 0xff00) | (((src) & 0xff00) << 8) | (((src) & 0xff) << 24)) +#define FB_BLIT_4(dst, src) \ + (dst = (((src) >> 24) & UVAL64(0x000000ff000000ff)) | \ + (((src) >> 8) & UVAL64(0x0000ff000000ff00)) | \ + (((src) & UVAL64(0x0000ff000000ff00)) << 8) | \ + (((src) & UVAL64(0x000000ff000000ff)) << 24)) + #define FB_DEPTH 24 #include "video_blit.h" @@ -227,6 +261,11 @@ static void Blit_Copy_Raw(uint8 * dest, #define FB_BLIT_2(dst, src) \ (dst = (((src) >> 16) & 0xff) | ((src) & 0xff00) | (((src) & 0xff) << 16)) +#define FB_BLIT_4(dst, src) \ + (dst = (((src) >> 16) & UVAL64(0x000000ff000000ff)) | \ + ( (src) & UVAL64(0x0000ff000000ff00)) | \ + (((src) & UVAL64(0x000000ff000000ff)) << 16)) + #define FB_FUNC_NAME Blit_BGR888_NBO #define FB_DEPTH 24 #include "video_blit.h" @@ -238,6 +277,11 @@ static void Blit_Copy_Raw(uint8 * dest, #define FB_BLIT_2(dst, src) \ (dst = (((src) >> 16) & 0xff) | ((src) & 0xff0000) | (((src) & 0xff) << 16)) +#define FB_BLIT_4(dst, src) \ + (dst = (((src) >> 16) & UVAL64(0x000000ff000000ff)) | \ + ( (src) & UVAL64(0x00ff000000ff0000)) | \ + (((src) & UVAL64(0x000000ff000000ff)) << 16)) + #define FB_FUNC_NAME Blit_BGR888_OBO #define FB_DEPTH 24 #include "video_blit.h" @@ -255,10 +299,105 @@ static void Blit_Copy_Raw(uint8 * dest, #define FB_BLIT_2(dst, src) \ (dst = ((src) & 0xff00ff) | (((src) & 0xff00) << 16)) +#define FB_BLIT_4(dst, src) \ + (dst = ((src) & UVAL64(0x00ff00ff00ff00ff)) | (((src) & UVAL64(0x0000ff000000ff00)) << 16)) + #define FB_DEPTH 24 #include "video_blit.h" /* -------------------------------------------------------------------------- */ +/* --- 2/4-bit indexed to 8-bit mode conversion --- */ +/* -------------------------------------------------------------------------- */ + +static void Blit_Expand_2_To_8(uint8 * dest, const uint8 * p, uint32 length) +{ + uint8 *q = (uint8 *)dest; + for (uint32 i=0; i> 6; + *q++ = (c >> 4) & 3; + *q++ = (c >> 2) & 3; + *q++ = c & 3; + } +} + +static void Blit_Expand_4_To_8(uint8 * dest, const uint8 * p, uint32 length) +{ + uint8 *q = (uint8 *)dest; + for (uint32 i=0; i> 4; + *q++ = c & 0x0f; + } +} + +/* -------------------------------------------------------------------------- */ +/* --- 2/4/8-bit indexed to 16-bit mode color expansion --- */ +/* -------------------------------------------------------------------------- */ + +static void Blit_Expand_2_To_16(uint8 * dest, const uint8 * p, uint32 length) +{ + uint16 *q = (uint16 *)dest; + for (uint32 i=0; i> 6]; + *q++ = ExpandMap[c >> 4]; + *q++ = ExpandMap[c >> 2]; + *q++ = ExpandMap[c]; + } +} + +static void Blit_Expand_4_To_16(uint8 * dest, const uint8 * p, uint32 length) +{ + uint16 *q = (uint16 *)dest; + for (uint32 i=0; i> 4]; + *q++ = ExpandMap[c]; + } +} + +static void Blit_Expand_8_To_16(uint8 * dest, const uint8 * p, uint32 length) +{ + uint16 *q = (uint16 *)dest; + for (uint32 i=0; i> 6]; + *q++ = ExpandMap[c >> 4]; + *q++ = ExpandMap[c >> 2]; + *q++ = ExpandMap[c]; + } +} + +static void Blit_Expand_4_To_32(uint8 * dest, const uint8 * p, uint32 length) +{ + uint32 *q = (uint32 *)dest; + for (uint32 i=0; i> 4]; + *q++ = ExpandMap[c]; + } +} + +static void Blit_Expand_8_To_32(uint8 * dest, const uint8 * p, uint32 length) +{ + uint32 *q = (uint32 *)dest; + for (uint32 i=0; i In that case, VOSF is not necessary -bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order, video_depth mac_depth) +bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order, int mac_depth) { #if REAL_ADDRESSING || DIRECT_ADDRESSING - if (mac_depth == VDEPTH_1BIT) { + if (mac_depth == 1) { // 1-bit mode uses a 1-bit X image, so there's no need for special blitting routines Screen_blit = Blit_Copy_Raw; @@ -319,7 +458,7 @@ bool Screen_blitter_init(XVisualInfo * v visualFormat.Rmask = visual_info->red_mask; visualFormat.Gmask = visual_info->green_mask; visualFormat.Bmask = visual_info->blue_mask; - + // Compute RGB shift values visualFormat.Rshift = 0; for (uint32 Rmask = visualFormat.Rmask; Rmask && ((Rmask & 1) != 1); Rmask >>= 1) @@ -330,9 +469,43 @@ bool Screen_blitter_init(XVisualInfo * v visualFormat.Bshift = 0; for (uint32 Bmask = visualFormat.Bmask; Bmask && ((Bmask & 1) != 1); Bmask >>= 1) ++visualFormat.Bshift; + + bool blitter_found = false; + + // 2/4/8-bit mode on 8/16/32-bit screen? + if (visualFormat.depth == 8) { + if (mac_depth == 2) { + Screen_blit = Blit_Expand_2_To_8; + blitter_found = true; + } else if (mac_depth == 4) { + Screen_blit = Blit_Expand_4_To_8; + blitter_found = true; + } + } else if (visualFormat.depth == 15 || visualFormat.depth == 16) { + if (mac_depth == 2) { + Screen_blit = Blit_Expand_2_To_16; + blitter_found = true; + } else if (mac_depth == 4) { + Screen_blit = Blit_Expand_4_To_16; + blitter_found = true; + } else if (mac_depth == 8) { + Screen_blit = Blit_Expand_8_To_16; + blitter_found = true; + } + } else if (visualFormat.depth == 24 || visualFormat.depth == 32) { + if (mac_depth == 2) { + Screen_blit = Blit_Expand_2_To_32; + blitter_found = true; + } else if (mac_depth == 4) { + Screen_blit = Blit_Expand_4_To_32; + blitter_found = true; + } else if (mac_depth == 8) { + Screen_blit = Blit_Expand_8_To_32; + blitter_found = true; + } + } // Search for an adequate blit function - bool blitter_found = false; const int blitters_count = sizeof(Screen_blitters)/sizeof(Screen_blitters[0]); for (int i = 0; !blitter_found && (i < blitters_count); i++) { if ( (visualFormat.depth == Screen_blitters[i].depth)