Fixed compiler endianness detection. Unified to use common macros in endian.h
This commit is contained in:
parent
d5fd976ccf
commit
92b021171f
|
@ -47,10 +47,6 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
||||||
#define LSB_FIRST
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// GLOBALS
|
// GLOBALS
|
||||||
extern Config *g_config;
|
extern Config *g_config;
|
||||||
|
|
||||||
|
@ -286,7 +282,7 @@ int InitVideo(FCEUGI *gi)
|
||||||
}
|
}
|
||||||
nes_shm->video.pitch = nes_shm->video.ncol * 4;
|
nes_shm->video.pitch = nes_shm->video.ncol * 4;
|
||||||
|
|
||||||
#ifdef LSB_FIRST
|
#ifdef FCEU_BIG_ENDIAN
|
||||||
rmask = 0x00FF0000;
|
rmask = 0x00FF0000;
|
||||||
gmask = 0x0000FF00;
|
gmask = 0x0000FF00;
|
||||||
bmask = 0x000000FF;
|
bmask = 0x000000FF;
|
||||||
|
|
|
@ -51,10 +51,6 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
||||||
#define LSB_FIRST
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// GLOBALS
|
// GLOBALS
|
||||||
extern Config *g_config;
|
extern Config *g_config;
|
||||||
|
|
||||||
|
@ -201,7 +197,7 @@ int InitVideo(FCEUGI *gi)
|
||||||
// check to see if we are showing FPS
|
// check to see if we are showing FPS
|
||||||
FCEUI_SetShowFPS(show_fps);
|
FCEUI_SetShowFPS(show_fps);
|
||||||
|
|
||||||
#ifdef LSB_FIRST
|
#ifdef FCEU_BIG_ENDIAN
|
||||||
rmask = 0x00FF0000;
|
rmask = 0x00FF0000;
|
||||||
gmask = 0x0000FF00;
|
gmask = 0x0000FF00;
|
||||||
bmask = 0x000000FF;
|
bmask = 0x000000FF;
|
||||||
|
|
|
@ -152,7 +152,8 @@ static int SubWrite(EMUFILE* os, SFORMAT *sf)
|
||||||
os->fwrite(sf->desc,4);
|
os->fwrite(sf->desc,4);
|
||||||
write32le(sf->s&(~FCEUSTATE_FLAGS),os);
|
write32le(sf->s&(~FCEUSTATE_FLAGS),os);
|
||||||
|
|
||||||
#ifndef LSB_FIRST
|
#ifdef FCEU_BIG_ENDIAN
|
||||||
|
#pragma message("BSB!!!")
|
||||||
if(sf->s&RLSB)
|
if(sf->s&RLSB)
|
||||||
FlipByteOrder((uint8*)sf->v,sf->s&(~FCEUSTATE_FLAGS));
|
FlipByteOrder((uint8*)sf->v,sf->s&(~FCEUSTATE_FLAGS));
|
||||||
#endif
|
#endif
|
||||||
|
@ -163,7 +164,7 @@ static int SubWrite(EMUFILE* os, SFORMAT *sf)
|
||||||
os->fwrite((char*)sf->v,sf->s&(~FCEUSTATE_FLAGS));
|
os->fwrite((char*)sf->v,sf->s&(~FCEUSTATE_FLAGS));
|
||||||
|
|
||||||
//Now restore the original byte order.
|
//Now restore the original byte order.
|
||||||
#ifndef LSB_FIRST
|
#ifdef FCEU_BIG_ENDIAN
|
||||||
if(sf->s&RLSB)
|
if(sf->s&RLSB)
|
||||||
FlipByteOrder((uint8*)sf->v,sf->s&(~FCEUSTATE_FLAGS));
|
FlipByteOrder((uint8*)sf->v,sf->s&(~FCEUSTATE_FLAGS));
|
||||||
#endif
|
#endif
|
||||||
|
@ -231,7 +232,7 @@ static bool ReadStateChunk(EMUFILE* is, SFORMAT *sf, int size)
|
||||||
else
|
else
|
||||||
is->fread((char *)tmp->v,tmp->s&(~FCEUSTATE_FLAGS));
|
is->fread((char *)tmp->v,tmp->s&(~FCEUSTATE_FLAGS));
|
||||||
|
|
||||||
#ifndef LSB_FIRST
|
#ifdef FCEU_BIG_ENDIAN
|
||||||
if(tmp->s&RLSB)
|
if(tmp->s&RLSB)
|
||||||
FlipByteOrder((uint8*)tmp->v,tmp->s&(~FCEUSTATE_FLAGS));
|
FlipByteOrder((uint8*)tmp->v,tmp->s&(~FCEUSTATE_FLAGS));
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -28,8 +28,11 @@
|
||||||
#include "endian.h"
|
#include "endian.h"
|
||||||
#include "../emufile.h"
|
#include "../emufile.h"
|
||||||
|
|
||||||
//OMG ! configure this correctly
|
#ifdef FCEU_BIG_ENDIAN
|
||||||
|
#define LOCAL_BE
|
||||||
|
#else
|
||||||
#define LOCAL_LE
|
#define LOCAL_LE
|
||||||
|
#endif
|
||||||
|
|
||||||
/* little endian to local endianess convert macros */
|
/* little endian to local endianess convert macros */
|
||||||
#ifdef LOCAL_BE /* local arch is big endian */
|
#ifdef LOCAL_BE /* local arch is big endian */
|
||||||
|
@ -121,7 +124,7 @@ int read32le(uint32 *Bufo, FILE *fp)
|
||||||
uint32 buf;
|
uint32 buf;
|
||||||
if(fread(&buf,1,4,fp)<4)
|
if(fread(&buf,1,4,fp)<4)
|
||||||
return 0;
|
return 0;
|
||||||
#ifdef LSB_FIRST
|
#ifdef FCEU_LITTLE_ENDIAN
|
||||||
*(uint32*)Bufo=buf;
|
*(uint32*)Bufo=buf;
|
||||||
#else
|
#else
|
||||||
*(uint32*)Bufo=((buf&0xFF)<<24)|((buf&0xFF00)<<8)|((buf&0xFF0000)>>8)|((buf&0xFF000000)>>24);
|
*(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;
|
uint16 buf;
|
||||||
if(is->read((char*)&buf,2).gcount() != 2)
|
if(is->read((char*)&buf,2).gcount() != 2)
|
||||||
return 0;
|
return 0;
|
||||||
#ifdef LSB_FIRST
|
#ifdef FCEU_LITTLE_ENDIAN
|
||||||
*Bufo=buf;
|
*Bufo=buf;
|
||||||
#else
|
#else
|
||||||
*Bufo = FCEU_de16lsb((uint8*)&buf);
|
*Bufo = FCEU_de16lsb((uint8*)&buf);
|
||||||
|
@ -148,7 +151,7 @@ int read64le(uint64 *Bufo, std::istream *is)
|
||||||
uint64 buf;
|
uint64 buf;
|
||||||
if(is->read((char*)&buf,8).gcount() != 8)
|
if(is->read((char*)&buf,8).gcount() != 8)
|
||||||
return 0;
|
return 0;
|
||||||
#ifdef LSB_FIRST
|
#ifdef FCEU_LITTLE_ENDIAN
|
||||||
*Bufo=buf;
|
*Bufo=buf;
|
||||||
#else
|
#else
|
||||||
*Bufo = FCEU_de64lsb((uint8*)&buf);
|
*Bufo = FCEU_de64lsb((uint8*)&buf);
|
||||||
|
@ -162,7 +165,7 @@ int read32le(uint32 *Bufo, std::istream *is)
|
||||||
uint32 buf;
|
uint32 buf;
|
||||||
if(is->read((char*)&buf,4).gcount() != 4)
|
if(is->read((char*)&buf,4).gcount() != 4)
|
||||||
return 0;
|
return 0;
|
||||||
#ifdef LSB_FIRST
|
#ifdef FCEU_LITTLE_ENDIAN
|
||||||
*(uint32*)Bufo=buf;
|
*(uint32*)Bufo=buf;
|
||||||
#else
|
#else
|
||||||
*(uint32*)Bufo=((buf&0xFF)<<24)|((buf&0xFF00)<<8)|((buf&0xFF0000)>>8)|((buf&0xFF000000)>>24);
|
*(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
|
///reads a little endian 16bit value from the specified file
|
||||||
int read16le(char *d, FILE *fp)
|
int read16le(char *d, FILE *fp)
|
||||||
{
|
{
|
||||||
#ifdef LSB_FIRST
|
#ifdef FCEU_LITTLE_ENDIAN
|
||||||
return((fread(d,1,2,fp)<2)?0:2);
|
return((fread(d,1,2,fp)<2)?0:2);
|
||||||
#else
|
#else
|
||||||
int ret;
|
int ret;
|
||||||
|
|
|
@ -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
|
#endif //__FCEU_ENDIAN
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue