diff --git a/src/drivers/Qt/sdl-video.cpp b/src/drivers/Qt/sdl-video.cpp index 73bbd8bc..d8b72a0d 100644 --- a/src/drivers/Qt/sdl-video.cpp +++ b/src/drivers/Qt/sdl-video.cpp @@ -47,10 +47,6 @@ #include #include -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define LSB_FIRST -#endif - // GLOBALS extern Config *g_config; @@ -286,7 +282,7 @@ int InitVideo(FCEUGI *gi) } nes_shm->video.pitch = nes_shm->video.ncol * 4; -#ifdef LSB_FIRST +#ifdef FCEU_BIG_ENDIAN rmask = 0x00FF0000; gmask = 0x0000FF00; bmask = 0x000000FF; diff --git a/src/drivers/sdl/sdl-video.cpp b/src/drivers/sdl/sdl-video.cpp index 0edbfb4c..a7bf3324 100644 --- a/src/drivers/sdl/sdl-video.cpp +++ b/src/drivers/sdl/sdl-video.cpp @@ -51,10 +51,6 @@ #include #include -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define LSB_FIRST -#endif - // GLOBALS extern Config *g_config; @@ -201,7 +197,7 @@ int InitVideo(FCEUGI *gi) // check to see if we are showing FPS FCEUI_SetShowFPS(show_fps); -#ifdef LSB_FIRST +#ifdef FCEU_BIG_ENDIAN rmask = 0x00FF0000; gmask = 0x0000FF00; bmask = 0x000000FF; diff --git a/src/state.cpp b/src/state.cpp index 27eff791..5284678c 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -152,7 +152,8 @@ static int SubWrite(EMUFILE* os, SFORMAT *sf) os->fwrite(sf->desc,4); write32le(sf->s&(~FCEUSTATE_FLAGS),os); -#ifndef LSB_FIRST +#ifdef FCEU_BIG_ENDIAN +#pragma message("BSB!!!") if(sf->s&RLSB) FlipByteOrder((uint8*)sf->v,sf->s&(~FCEUSTATE_FLAGS)); #endif @@ -163,7 +164,7 @@ static int SubWrite(EMUFILE* os, SFORMAT *sf) os->fwrite((char*)sf->v,sf->s&(~FCEUSTATE_FLAGS)); //Now restore the original byte order. -#ifndef LSB_FIRST +#ifdef FCEU_BIG_ENDIAN if(sf->s&RLSB) FlipByteOrder((uint8*)sf->v,sf->s&(~FCEUSTATE_FLAGS)); #endif @@ -231,7 +232,7 @@ static bool ReadStateChunk(EMUFILE* is, SFORMAT *sf, int size) else is->fread((char *)tmp->v,tmp->s&(~FCEUSTATE_FLAGS)); -#ifndef LSB_FIRST +#ifdef FCEU_BIG_ENDIAN if(tmp->s&RLSB) FlipByteOrder((uint8*)tmp->v,tmp->s&(~FCEUSTATE_FLAGS)); #endif diff --git a/src/utils/endian.cpp b/src/utils/endian.cpp index 56704d41..477f84b0 100644 --- a/src/utils/endian.cpp +++ b/src/utils/endian.cpp @@ -28,8 +28,11 @@ #include "endian.h" #include "../emufile.h" -//OMG ! configure this correctly +#ifdef FCEU_BIG_ENDIAN +#define LOCAL_BE +#else #define LOCAL_LE +#endif /* little endian to local endianess convert macros */ #ifdef LOCAL_BE /* local arch is big endian */ @@ -121,7 +124,7 @@ int read32le(uint32 *Bufo, FILE *fp) uint32 buf; if(fread(&buf,1,4,fp)<4) return 0; -#ifdef LSB_FIRST +#ifdef FCEU_LITTLE_ENDIAN *(uint32*)Bufo=buf; #else *(uint32*)Bufo=((buf&0xFF)<<24)|((buf&0xFF00)<<8)|((buf&0xFF0000)>>8)|((buf&0xFF000000)>>24); @@ -134,7 +137,7 @@ int read16le(uint16 *Bufo, std::istream *is) uint16 buf; if(is->read((char*)&buf,2).gcount() != 2) return 0; -#ifdef LSB_FIRST +#ifdef FCEU_LITTLE_ENDIAN *Bufo=buf; #else *Bufo = FCEU_de16lsb((uint8*)&buf); @@ -148,7 +151,7 @@ int read64le(uint64 *Bufo, std::istream *is) uint64 buf; if(is->read((char*)&buf,8).gcount() != 8) return 0; -#ifdef LSB_FIRST +#ifdef FCEU_LITTLE_ENDIAN *Bufo=buf; #else *Bufo = FCEU_de64lsb((uint8*)&buf); @@ -162,7 +165,7 @@ int read32le(uint32 *Bufo, std::istream *is) uint32 buf; if(is->read((char*)&buf,4).gcount() != 4) return 0; -#ifdef LSB_FIRST +#ifdef FCEU_LITTLE_ENDIAN *(uint32*)Bufo=buf; #else *(uint32*)Bufo=((buf&0xFF)<<24)|((buf&0xFF00)<<8)|((buf&0xFF0000)>>8)|((buf&0xFF000000)>>24); @@ -173,7 +176,7 @@ int read32le(uint32 *Bufo, std::istream *is) ///reads a little endian 16bit value from the specified file int read16le(char *d, FILE *fp) { -#ifdef LSB_FIRST +#ifdef FCEU_LITTLE_ENDIAN return((fread(d,1,2,fp)<2)?0:2); #else int ret; diff --git a/src/utils/endian.h b/src/utils/endian.h index 5bdbcde1..3cbbe42b 100644 --- a/src/utils/endian.h +++ b/src/utils/endian.h @@ -107,5 +107,13 @@ int writele(T *Bufo, EMUFILE*os) } } +#ifdef __BIG_ENDIAN__ +# define FCEU_BIG_ENDIAN +#elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +# define FCEU_BIG_ENDIAN +#else +# define FCEU_LITTLE_ENDIAN +#endif + #endif //__FCEU_ENDIAN