Fixed compiler endianness detection. Unified to use common macros in endian.h

This commit is contained in:
harry 2023-02-19 20:07:50 -05:00
parent d5fd976ccf
commit 92b021171f
5 changed files with 23 additions and 19 deletions

View File

@ -47,10 +47,6 @@
#include <cstring>
#include <cstdlib>
#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;

View File

@ -51,10 +51,6 @@
#include <cstring>
#include <cstdlib>
#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;

View File

@ -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

View File

@ -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;

View File

@ -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