From: kub Date: Sat, 5 Dec 2020 14:20:15 +0000 (+0100) Subject: rendering, fix bgr555 output mode X-Git-Tag: v2.00~649 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16b11d91719baf28607cf5c00ac8e7d1821e50b1;p=picodrive.git rendering, fix bgr555 output mode NB not done for ARM asm since no target uses bgr555 --- diff --git a/pico/32x/draw.c b/pico/32x/draw.c index 8f933a08..c38f60d6 100644 --- a/pico/32x/draw.c +++ b/pico/32x/draw.c @@ -8,6 +8,15 @@ */ #include "../pico_int.h" +// BGR555 to native conversion +#if defined(USE_BGR555) +#define PXCONV(t) (t) +#define PXPRIO 0x8000 // prio in MSB +#else // RGB565 +#define PXCONV(t) ((((t)&m1) << 11) | (((t)&m2) << 1) | (((t)&m3) >> 10)) +#define PXPRIO 0x0020 // prio in LS green bit +#endif + int (*PicoScan32xBegin)(unsigned int num); int (*PicoScan32xEnd)(unsigned int num); int Pico32xDrawMode; @@ -21,33 +30,21 @@ static void convert_pal555(int invert_prio) unsigned int *pd = (void *)Pico32xMem->pal_native; unsigned int m1 = 0x001f001f; unsigned int m2 = 0x03e003e0; - unsigned int m3 = 0xfc00fc00; + unsigned int m3 = 0xfc00fc00; // includes prio bit unsigned int inv = 0; int i; if (invert_prio) - inv = 0x00200020; + inv = 0x80008000; - // place prio to LS green bit for (i = 0x100/2; i > 0; i--, ps++, pd++) { - unsigned int t = *ps; -#if defined(USE_BGR555) - *pd = t ^ inv; -#else - *pd = (((t & m1) << 11) | ((t & m2) << 1) | ((t & m3) >> 10)) ^ inv; -#endif + unsigned int t = *ps ^ inv; + *pd = PXCONV(t); } Pico32x.dirty_pal = 0; } -// 555 conversion for direct color mode -#if defined(USE_BGR555) -#define DC555(t) t -#else -#define DC555(t) ((t&m1) << 11) | ((t&m2) << 1) | ((t&m3) >> 10) -#endif - // direct color mode #define do_line_dc(pd, p32x, pmd, inv, pmd_draw_code) \ { \ @@ -60,12 +57,12 @@ static void convert_pal555(int invert_prio) while (i > 0) { \ for (; i > 0 && (*pmd & 0x3f) == mdbg; pd++, pmd++, i--) { \ t = *p32x++; \ - *pd = DC555(t); \ + *pd = PXCONV(t); \ } \ for (; i > 0 && (*pmd & 0x3f) != mdbg; pd++, pmd++, i--) { \ - t = *p32x++; \ - if ((t ^ inv) & 0x8000) \ - *pd = DC555(t); \ + t = *p32x++ ^ inv; \ + if (t & 0x8000) \ + *pd = PXCONV(t); \ else \ pmd_draw_code; \ } \ @@ -84,7 +81,7 @@ static void convert_pal555(int invert_prio) } \ for (; i > 0 && (*pmd & 0x3f) != mdbg; pd++, pmd++, i--) { \ t = pal[*(unsigned char *)((uintptr_t)(p32x++) ^ 1)]; \ - if (t & 0x20) \ + if (t & PXPRIO) \ *pd = t; \ else \ pmd_draw_code; \ @@ -100,7 +97,7 @@ static void convert_pal555(int invert_prio) for (i = 320; i > 0; p32x++) { \ t = pal[*p32x & 0xff]; \ for (len = (*p32x >> 8) + 1; len > 0 && i > 0; len--, i--, pd++, pmd++) { \ - if ((*pmd & 0x3f) == mdbg || (t & 0x20)) \ + if ((*pmd & 0x3f) == mdbg || (t & PXPRIO)) \ *pd = t; \ else \ pmd_draw_code; \ diff --git a/pico/draw.c b/pico/draw.c index 1aab2bcb..e8a4723b 100644 --- a/pico/draw.c +++ b/pico/draw.c @@ -65,6 +65,16 @@ unsigned int VdpSATCache[128]; // VDP sprite cache (1st 32 sprite attr bits) // NB don't change any defines without checking their usage in ASM +#if defined(USE_BGR555) +#define PXCONV(t) ((t & 0x000e000e)<< 1) | ((t & 0x00e000e0)<<2) | ((t & 0x0e000e00)<<3) +#define PXMASKL 0x04210421 // 0x0c630c63, LSB for all colours +#define PXMASKH 0x39ce39ce // 0x3def3def, all but MSB for all colours +#else // RGB565 +#define PXCONV(t) ((t & 0x000e000e)<<12) | ((t & 0x00e000e0)<<3) | ((t & 0x0e000e00)>>7) +#define PXMASKL 0x08610861 // 0x18e318e3 +#define PXMASKH 0x738e738e // 0x7bef7bef +#endif + #define LF_PLANE (1 << 0) // must be = 1 #define LF_SH (1 << 1) // must be = 2 //#define LF_FORCE (1 << 2) @@ -1542,14 +1552,10 @@ void PicoDoHighPal555_8bit(int sh, int line, struct PicoEState *est) // additional palettes stored after in-frame changes for (i = 0; i < cnt * 0x40 / 2; i++) { t = spal[i]; -#ifdef USE_BGR555 - t = ((t & 0x000e000e)<< 1) | ((t & 0x00e000e0)<<3) | ((t & 0x0e000e00)<<4); -#else - t = ((t & 0x000e000e)<<12) | ((t & 0x00e000e0)<<3) | ((t & 0x0e000e00)>>7); -#endif // treat it like it was 4-bit per channel, since in s/h mode it somewhat is that. // otherwise intensity difference between this and s/h will be wrong - t |= (t >> 4) & 0x08610861; // 0x18e318e3 + t = PXCONV(t); + t |= (t >> 4) & PXMASKL; dpal[i] = dpal[0xc0/2 + i] = t; } @@ -1558,11 +1564,11 @@ void PicoDoHighPal555_8bit(int sh, int line, struct PicoEState *est) { // shadowed pixels for (i = 0; i < 0x40 / 2; i++) - dpal[0x80/2 + i] = (dpal[i] >> 1) & 0x738e738e; + dpal[0x80/2 + i] = (dpal[i] >> 1) & PXMASKH; // hilighted pixels for (i = 0; i < 0x40 / 2; i++) { - t = ((dpal[i] >> 1) & 0x738e738e) + 0x738e738e; // 0x7bef7bef; - t |= (t >> 4) & 0x08610861; + t = ((dpal[i] >> 1) & PXMASKH) + PXMASKH; + t |= (t >> 4) & PXMASKL; dpal[0x40/2 + i] = t; } // shadowed pixels in color 14 always appear normal (hw bug?) @@ -1586,14 +1592,10 @@ void PicoDoHighPal555(int sh, int line, struct PicoEState *est) for (i = 0; i < 0x40 / 2; i++) { t = spal[i]; -#ifdef USE_BGR555 - t = ((t & 0x0e000e00)<< 3) | ((t & 0x00e000e0)<<2) | ((t & 0x000e000e)<<1); -#else - t = ((t & 0x000e000e)<<12) | ((t & 0x00e000e0)<<3) | ((t & 0x0e000e00)>>7); -#endif // treat it like it was 4-bit per channel, since in s/h mode it somewhat is that. // otherwise intensity difference between this and s/h will be wrong - t |= (t >> 4) & 0x08610861; // 0x18e318e3 + t = PXCONV(t); + t |= (t >> 4) & PXMASKL; dpal[i] = dpal[0xc0/2 + i] = t; } @@ -1602,11 +1604,11 @@ void PicoDoHighPal555(int sh, int line, struct PicoEState *est) { // shadowed pixels for (i = 0; i < 0x40 / 2; i++) - dpal[0x80/2 + i] = (dpal[i] >> 1) & 0x738e738e; + dpal[0x80/2 + i] = (dpal[i] >> 1) & PXMASKH; // hilighted pixels for (i = 0; i < 0x40 / 2; i++) { - t = ((dpal[i] >> 1) & 0x738e738e) + 0x738e738e; // 0x7bef7bef; - t |= (t >> 4) & 0x08610861; + t = ((dpal[i] >> 1) & PXMASKH) + PXMASKH; + t |= (t >> 4) & PXMASKL; dpal[0x40/2 + i] = t; } // shadowed pixels in color 14 always appear normal (hw bug?) diff --git a/pico/draw_arm.S b/pico/draw_arm.S index d455197d..37441222 100644 --- a/pico/draw_arm.S +++ b/pico/draw_arm.S @@ -7,6 +7,8 @@ * See COPYING file in the top-level directory. * * this is highly specialized, be careful if changing related C code! + * + * NB only does RGB565 output, BGR555 isn't supported */ #include "pico_int_offs.h" diff --git a/pico/mode4.c b/pico/mode4.c index 6e921c89..8de41aed 100644 --- a/pico/mode4.c +++ b/pico/mode4.c @@ -339,11 +339,11 @@ void PicoDoHighPal555M4(void) t = *spal; #ifdef USE_BGR555 t = ((t & 0x00030003)<< 3) | ((t & 0x000c000c)<<6) | ((t & 0x00300030)<<9); + t |= (t >> 2) | ((t >> 4) & 0x04210421); #else t = ((t & 0x00030003)<<14) | ((t & 0x000c000c)<<7) | ((t & 0x00300030)>>1); + t |= (t >> 2) | ((t >> 4) & 0x08610861); #endif - t |= t >> 2; - t |= (t >> 4) & 0x08610861; *dpal = t; } Pico.est.HighPal[0xe0] = 0;