From ffe97735d2c5683cb3ebc91299c047c417d2322d Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Wed, 11 Sep 2019 17:33:14 +0200 Subject: [PATCH] Fix PCSX on big-endian systems The __BIGENDIAN__ macro was never defined anywhere, and the __BIG_ENDIAN__ macro isn't set anymore by recent versions of GCC. Replace them by checking __BYTE_ORDER__ against __ORDER_BIG_ENDIAN__. Signed-off-by: Paul Cercueil --- libpcsxcore/misc.c | 2 +- libpcsxcore/psxmem.h | 2 +- libpcsxcore/r3000a.h | 4 ++-- plugins/dfxvideo/draw.c | 8 ++++---- plugins/dfxvideo/gpu.h | 12 +++--------- plugins/dfxvideo/gpulib_if.c | 12 +++--------- 6 files changed, 14 insertions(+), 26 deletions(-) diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c index 94fac61e..f820868d 100644 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -61,7 +61,7 @@ void mmssdd( char *b, char *p ) #if defined(__arm__) unsigned char *u = (void *)b; int block = (u[3] << 24) | (u[2] << 16) | (u[1] << 8) | u[0]; -#elif defined(__BIGENDIAN__) +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ int block = (b[0] & 0xff) | ((b[1] & 0xff) << 8) | ((b[2] & 0xff) << 16) | (b[3] << 24); #else int block = *((int*)b); diff --git a/libpcsxcore/psxmem.h b/libpcsxcore/psxmem.h index a69b4a38..a7c6dd16 100644 --- a/libpcsxcore/psxmem.h +++ b/libpcsxcore/psxmem.h @@ -26,7 +26,7 @@ extern "C" { #include "psxcommon.h" -#if defined(__BIGENDIAN__) +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define _SWAP16(b) ((((unsigned char *)&(b))[0] & 0xff) | (((unsigned char *)&(b))[1] & 0xff) << 8) #define _SWAP32(b) ((((unsigned char *)&(b))[0] & 0xff) | ((((unsigned char *)&(b))[1] & 0xff) << 8) | ((((unsigned char *)&(b))[2] & 0xff) << 16) | (((unsigned char *)&(b))[3] << 24)) diff --git a/libpcsxcore/r3000a.h b/libpcsxcore/r3000a.h index 0e21f518..aabddec4 100644 --- a/libpcsxcore/r3000a.h +++ b/libpcsxcore/r3000a.h @@ -51,7 +51,7 @@ extern R3000Acpu psxInt; extern R3000Acpu psxRec; typedef union { -#if defined(__BIGENDIAN__) +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ struct { u8 h3, h2, h, l; } b; struct { s8 h3, h2, h, l; } sb; struct { u16 h, l; } w; @@ -222,7 +222,7 @@ void new_dyna_freeze(void *f, int mode); } \ } -#if defined(__BIGENDIAN__) +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define _i32(x) *(s32 *)&x #define _u32(x) x diff --git a/plugins/dfxvideo/draw.c b/plugins/dfxvideo/draw.c index ad3f3a19..e68f1a19 100644 --- a/plugins/dfxvideo/draw.c +++ b/plugins/dfxvideo/draw.c @@ -1053,7 +1053,7 @@ void CreateDisplay(void) //backup YUV mode //hmm, should I bother check guid == 55595659-0000-0010-8000-00aa00389b71? //and check byte order? fo[j].byte_order == LSBFirst -#ifdef __BIG_ENDIAN__ +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ if ( fo[j].type == XvYUV && fo[j].bits_per_pixel == 16 && fo[j].format == XvPacked && strncmp("YUYV", fo[j].component_order, 5) == 0 ) #else if ( fo[j].type == XvYUV && fo[j].bits_per_pixel == 16 && fo[j].format == XvPacked && strncmp("UYVY", fo[j].component_order, 5) == 0 ) @@ -1473,7 +1473,7 @@ void BlitToYUV(unsigned char * surf,int32_t x,int32_t y) U = min(abs(R * -1214 + G * -2384 + B * 3598 + 4096 + 1048576) >> 13, 240); V = min(abs(R * 3598 + G * -3013 + B * -585 + 4096 + 1048576) >> 13, 240); -#ifdef __BIG_ENDIAN__ +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ destpix[row] = Y << 24 | U << 16 | Y << 8 | V; #else destpix[row] = Y << 24 | V << 16 | Y << 8 | U; @@ -1500,7 +1500,7 @@ void BlitToYUV(unsigned char * surf,int32_t x,int32_t y) U = min(abs(R * -1214 + G * -2384 + B * 3598 + 4096 + 1048576) >> 13, 240); V = min(abs(R * 3598 + G * -3013 + B * -585 + 4096 + 1048576) >> 13, 240); -#ifdef __BIG_ENDIAN__ +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ destpix[row] = Y << 24 | U << 16 | Y << 8 | V; #else destpix[row] = Y << 24 | V << 16 | Y << 8 | U; @@ -1534,7 +1534,7 @@ void RGB2YUV(uint32_t *s, int width, int height, uint32_t *d) Y2 = min(abs(R * 2104 + G * 4130 + B * 802 + 4096 + 131072) >> 13, 235); -#ifdef __BIG_ENDIAN__ +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ *d = V | Y2 << 8 | U << 16 | Y1 << 24; #else *d = U | Y1 << 8 | V << 16 | Y2 << 24; diff --git a/plugins/dfxvideo/gpu.h b/plugins/dfxvideo/gpu.h index 9ee5f3e6..25fcc3ce 100644 --- a/plugins/dfxvideo/gpu.h +++ b/plugins/dfxvideo/gpu.h @@ -72,7 +72,7 @@ #define SWAP16(x) ({ uint16_t y=(x); (((y)>>8 & 0xff) | ((y)<<8 & 0xff00)); }) #define SWAP32(x) ({ uint32_t y=(x); (((y)>>24 & 0xfful) | ((y)>>8 & 0xff00ul) | ((y)<<8 & 0xff0000ul) | ((y)<<24 & 0xff000000ul)); }) -#ifdef __BIG_ENDIAN__ +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ // big endian config #define HOST2LE32(x) SWAP32(x) @@ -251,18 +251,12 @@ extern int32_t drawH; #define KEY_BADTEXTURES 128 #define KEY_CHECKTHISOUT 256 -#if !defined(__BIG_ENDIAN__) || defined(__x86_64__) || defined(__i386__) -#ifndef __LITTLE_ENDIAN__ -#define __LITTLE_ENDIAN__ -#endif -#endif - -#ifdef __LITTLE_ENDIAN__ +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define RED(x) (x & 0xff) #define BLUE(x) ((x>>16) & 0xff) #define GREEN(x) ((x>>8) & 0xff) #define COLOR(x) (x & 0xffffff) -#elif defined __BIG_ENDIAN__ +#else #define RED(x) ((x>>24) & 0xff) #define BLUE(x) ((x>>8) & 0xff) #define GREEN(x) ((x>>16) & 0xff) diff --git a/plugins/dfxvideo/gpulib_if.c b/plugins/dfxvideo/gpulib_if.c index b2cca195..c1466ed8 100644 --- a/plugins/dfxvideo/gpulib_if.c +++ b/plugins/dfxvideo/gpulib_if.c @@ -56,7 +56,7 @@ #define SWAP16(x) ({ uint16_t y=(x); (((y)>>8 & 0xff) | ((y)<<8 & 0xff00)); }) #define SWAP32(x) ({ uint32_t y=(x); (((y)>>24 & 0xfful) | ((y)>>8 & 0xff00ul) | ((y)<<8 & 0xff0000ul) | ((y)<<24 & 0xff000000ul)); }) -#ifdef __BIG_ENDIAN__ +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ // big endian config #define HOST2LE32(x) SWAP32(x) @@ -235,18 +235,12 @@ extern int32_t drawH; #define KEY_BADTEXTURES 128 #define KEY_CHECKTHISOUT 256 -#if !defined(__BIG_ENDIAN__) || defined(__x86_64__) || defined(__i386__) -#ifndef __LITTLE_ENDIAN__ -#define __LITTLE_ENDIAN__ -#endif -#endif - -#ifdef __LITTLE_ENDIAN__ +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define RED(x) (x & 0xff) #define BLUE(x) ((x>>16) & 0xff) #define GREEN(x) ((x>>8) & 0xff) #define COLOR(x) (x & 0xffffff) -#elif defined __BIG_ENDIAN__ +#else #define RED(x) ((x>>24) & 0xff) #define BLUE(x) ((x>>8) & 0xff) #define GREEN(x) ((x>>16) & 0xff) -- 2.39.5