Don't rely on LSB_FIRST

This commit is contained in:
twinaphex
2015-07-23 22:18:46 +02:00
parent 46ac3a807b
commit 5cfa9e8ac9
9 changed files with 62 additions and 60 deletions

View File

@@ -41,13 +41,13 @@ ifeq ($(platform), unix)
TARGET := $(TARGET_NAME)_libretro.so
fpic := -fPIC
SHARED := -shared -Wl,--version-script=src/drivers/libretro/link.T -Wl,-no-undefined
ENDIANNESS_DEFINES = -DLSB_FIRST -DLOCAL_LE=1
ENDIANNESS_DEFINES = -DLOCAL_LE=1
else ifeq ($(platform), linux-portable)
TARGET := $(TARGET_NAME)_libretro.so
fpic := -fPIC -nostdlib
SHARED := -shared -Wl,--version-script=src/drivers/libretro/link.T
ENDIANNESS_DEFINES = -DLSB_FIRST -DLOCAL_LE=1
ENDIANNESS_DEFINES = -DLOCAL_LE=1
LIBM :=
# OS X
else ifeq ($(platform), osx)
@@ -55,7 +55,7 @@ else ifeq ($(platform), osx)
fpic := -fPIC
SHARED := -dynamiclib
ifneq ($(arch),ppc)
ENDIANNESS_DEFINES = -DLSB_FIRST -DLOCAL_LE=1
ENDIANNESS_DEFINES = -DLOCAL_LE=1
endif
CFLAGS += -DHAVE_ASPRINTF
OSXVER = `sw_vers -productVersion | cut -d. -f 2`
@@ -73,7 +73,7 @@ else ifeq ($(platform), ios)
TARGET := $(TARGET_NAME)_libretro_ios.dylib
fpic := -fPIC
SHARED := -dynamiclib
ENDIANNESS_DEFINES = -DLSB_FIRST -DLOCAL_LE=1
ENDIANNESS_DEFINES = -DLOCAL_LE=1
CFLAGS += -DHAVE_ASPRINTF -DIOS
ifeq ($(IOSSDK),)
IOSSDK := $(shell xcodebuild -version -sdk iphoneos Path)
@@ -103,7 +103,7 @@ else ifeq ($(platform), qnx)
TARGET := $(TARGET_NAME)_libretro_qnx.so
fpic := -fPIC
SHARED := -shared -Wl,--version-script=src/drivers/libretro/link.T -Wl,-no-undefined
ENDIANNESS_DEFINES = -DLSB_FIRST -DLOCAL_LE=1
ENDIANNESS_DEFINES = -DLOCAL_LE=1
CC = qcc -Vgcc_ntoarmv7le
AR = qcc -Vgcc_ntoarmv7le
PLATFORM_DEFINES := -D__BLACKBERRY_QNX__ -marm -mcpu=cortex-a9 -mfpu=neon -mfloat-abi=softfp
@@ -132,7 +132,7 @@ else ifeq ($(platform), psp1)
CC = psp-gcc$(EXE_EXT)
CXX = psp-g++$(EXE_EXT)
AR = psp-ar$(EXE_EXT)
PLATFORM_DEFINES := -DPSP -G0 -DLSB_FIRST -DHAVE_ASPRINTF
PLATFORM_DEFINES := -DPSP -G0 -DHAVE_ASPRINTF
PLATFORM_DEFINES += -march=allegrex -mfp32 -mgp32 -mlong32 -mabi=eabi
PLATFORM_DEFINES += -fomit-frame-pointer -fstrict-aliasing
PLATFORM_DEFINES += -falign-functions=32 -falign-loops -falign-labels -falign-jumps
@@ -145,7 +145,7 @@ else ifeq ($(platform), ctr)
CC = $(DEVKITARM)/bin/arm-none-eabi-gcc$(EXE_EXT)
CXX = $(DEVKITARM)/bin/arm-none-eabi-g++$(EXE_EXT)
AR = $(DEVKITARM)/bin/arm-none-eabi-ar$(EXE_EXT)
PLATFORM_DEFINES := -DARM11 -D_3DS -DLSB_FIRST -DHAVE_ASPRINTF
PLATFORM_DEFINES := -DARM11 -D_3DS -DHAVE_ASPRINTF
CFLAGS += -march=armv6k -mtune=mpcore -mfloat-abi=hard
CFLAGS += -Wall -mword-relocations
CFLAGS += -fomit-frame-pointer -fstrict-aliasing -ffast-math
@@ -195,7 +195,7 @@ else ifeq ($(platform), wii)
else ifneq (,$(findstring armv,$(platform)))
TARGET := $(TARGET_NAME)_libretro.so
SHARED := -shared -Wl,--version-script=src/drivers/libretro/link.T -Wl,-no-undefined
ENDIANNESS_DEFINES = -DLSB_FIRST -DLOCAL_LE=1
ENDIANNESS_DEFINES = -DLOCAL_LE=1
fpic := -fPIC
ifneq (,$(findstring cortexa5,$(platform)))
PLATFORM_DEFINES += -marm -mcpu=cortex-a5
@@ -220,7 +220,7 @@ else
TARGET := $(TARGET_NAME)_libretro.dll
CC = gcc
SHARED := -shared -static-libgcc -static-libstdc++ -s -Wl,--version-script=src/drivers/libretro/link.T
ENDIANNESS_DEFINES = -DLSB_FIRST -DLOCAL_LE=1
ENDIANNESS_DEFINES = -DLOCAL_LE=1
endif

View File

@@ -66,10 +66,10 @@ int read32le(uint32 *Bufo, FILE *fp)
uint32 buf;
if (fread(&buf, 1, 4, fp) < 4)
return 0;
#ifdef LSB_FIRST
*(uint32*)Bufo = buf;
#else
#ifdef MSB_FIRST
*(uint32*)Bufo = ((buf & 0xFF) << 24) | ((buf & 0xFF00) << 8) | ((buf & 0xFF0000) >> 8) | ((buf & 0xFF000000) >> 24);
#else
*(uint32*)Bufo = buf;
#endif
return 1;
}
@@ -89,23 +89,23 @@ int read32le_mem(uint32 *Bufo, memstream_t *mem)
uint32 buf;
if(memstream_read(mem, &buf, 4)<4)
return 0;
#ifdef LSB_FIRST
*(uint32*)Bufo=buf;
#else
#ifdef MSB_FIRST
*(uint32*)Bufo=((buf&0xFF)<<24)|((buf&0xFF00)<<8)|((buf&0xFF0000)>>8)|((buf&0xFF000000)>>24);
#else
*(uint32*)Bufo=buf;
#endif
return 1;
}
int read16le(char *d, FILE *fp)
{
#ifdef LSB_FIRST
return((fread(d, 1, 2, fp) < 2) ? 0 : 2);
#else
#ifdef MSB_FIRST
int ret;
ret = fread(d + 1, 1, 1, fp);
ret += fread(d, 1, 1, fp);
return ret < 2 ? 0 : 2;
#else
return((fread(d, 1, 2, fp) < 2) ? 0 : 2);
#endif
}

View File

@@ -106,14 +106,14 @@ static int SubWrite(memstream_t *mem, SFORMAT *sf)
memstream_write(mem, sf->desc, 4);
write32le_mem(sf->s&(~RLSB), mem);
#ifndef LSB_FIRST
#ifdef MSB_FIRST
if(sf->s&RLSB)
FlipByteOrder(sf->v,sf->s&(~RLSB));
#endif
memstream_write(mem, (uint8 *)sf->v, sf->s&(~RLSB));
/* Now restore the original byte order. */
#ifndef LSB_FIRST
#ifdef MSB_FIRST
if(sf->s&RLSB)
FlipByteOrder(sf->v,sf->s&(~RLSB));
#endif
@@ -180,7 +180,7 @@ static int ReadStateChunk(memstream_t *mem, SFORMAT *sf, int size)
{
memstream_read(mem, (uint8 *)tmp->v, tmp->s&(~RLSB));
#ifndef LSB_FIRST
#ifdef MSB_FIRST
if(tmp->s&RLSB)
FlipByteOrder(tmp->v,tmp->s&(~RLSB));
#endif

View File

@@ -23,7 +23,7 @@ include ../../../../Makefile.common
LOCAL_SRC_FILES = $(SOURCES_C)
LOCAL_CFLAGS += -DWANT_GRIFFIN -DINLINE=inline -DSOUND_QUALITY=0 -DPSS_STYLE=1 -DLSB_FIRST -D__LIBRETRO__ -DHAVE_ASPRINTF -DFCEU_VERSION_NUMERIC=9813 -DFRONTEND_SUPPORTS_RGB565
LOCAL_CFLAGS += -DWANT_GRIFFIN -DINLINE=inline -DSOUND_QUALITY=0 -DPSS_STYLE=1 -D__LIBRETRO__ -DHAVE_ASPRINTF -DFCEU_VERSION_NUMERIC=9813 -DFRONTEND_SUPPORTS_RGB565
LOCAL_C_INCLUDES = $(LOCAL_PATH)/$(CORE_DIR)
include $(BUILD_SHARED_LIBRARY)

View File

@@ -22,7 +22,7 @@
Optimization="0"
OptimizeForProcessor="2"
AdditionalIncludeDirectories="&quot;$(SolutionDir)\msvc-2003-xbox1&quot;;&quot;$(SolutionDir)\..\&quot;;&quot;$(SolutionDir)\..\..\..\&quot;"
PreprocessorDefinitions="_DEBUG;_XBOX;_LIB;__LIBRETRO__;LSB_FIRST;LOCAL_LE;INLINE=_inline;SOUND_QUALITY=0;PSS_STYLE=2;ZLIB;PATH_MAX=1024;_XBOX1;FCEU_VERSION_NUMERIC=9813;FRONTEND_SUPPORTS_RGB565;WANT_GRIFFIN;HAVE_EXTERNAL_ZLIB"
PreprocessorDefinitions="_DEBUG;_XBOX;_LIB;__LIBRETRO__;LOCAL_LE;INLINE=_inline;SOUND_QUALITY=0;PSS_STYLE=2;ZLIB;PATH_MAX=1024;_XBOX1;FCEU_VERSION_NUMERIC=9813;FRONTEND_SUPPORTS_RGB565;WANT_GRIFFIN;HAVE_EXTERNAL_ZLIB"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
@@ -56,7 +56,7 @@
OmitFramePointers="TRUE"
OptimizeForProcessor="2"
AdditionalIncludeDirectories="&quot;$(SolutionDir)\msvc-2003-xbox1&quot;;&quot;$(SolutionDir)\..\&quot;;&quot;$(SolutionDir)\..\..\..\&quot;"
PreprocessorDefinitions="NDEBUG;_XBOX;PROFILE;_LIB;__LIBRETRO__;LSB_FIRST;LOCAL_LE;INLINE=_inline;SOUND_QUALITY=0;PSS_STYLE=2;ZLIB;PATH_MAX=1024;_XBOX1;FCEU_VERSION_NUMERIC=9813;FRONTEND_SUPPORTS_RGB565;WANT_GRIFFIN;HAVE_EXTERNAL_ZLIB"
PreprocessorDefinitions="NDEBUG;_XBOX;PROFILE;_LIB;__LIBRETRO__;LOCAL_LE;INLINE=_inline;SOUND_QUALITY=0;PSS_STYLE=2;ZLIB;PATH_MAX=1024;_XBOX1;FCEU_VERSION_NUMERIC=9813;FRONTEND_SUPPORTS_RGB565;WANT_GRIFFIN;HAVE_EXTERNAL_ZLIB"
StringPooling="TRUE"
RuntimeLibrary="0"
BufferSecurityCheck="TRUE"
@@ -91,7 +91,7 @@
OmitFramePointers="TRUE"
OptimizeForProcessor="2"
AdditionalIncludeDirectories="&quot;$(SolutionDir)\msvc-2003-xbox1&quot;;&quot;$(SolutionDir)\..\&quot;;&quot;$(SolutionDir)\..\..\..\&quot;"
PreprocessorDefinitions="NDEBUG;_XBOX;PROFILE;FASTCAP;_LIB;__LIBRETRO__;LSB_FIRST;LOCAL_LE;INLINE=_inline;SOUND_QUALITY=0;PSS_STYLE=2;ZLIB;PATH_MAX=1024;_XBOX1;FCEU_VERSION_NUMERIC=9813;FRONTEND_SUPPORTS_RGB565;WANT_GRIFFIN;HAVE_EXTERNAL_ZLIB"
PreprocessorDefinitions="NDEBUG;_XBOX;PROFILE;FASTCAP;_LIB;__LIBRETRO__;LOCAL_LE;INLINE=_inline;SOUND_QUALITY=0;PSS_STYLE=2;ZLIB;PATH_MAX=1024;_XBOX1;FCEU_VERSION_NUMERIC=9813;FRONTEND_SUPPORTS_RGB565;WANT_GRIFFIN;HAVE_EXTERNAL_ZLIB"
StringPooling="TRUE"
RuntimeLibrary="0"
BufferSecurityCheck="TRUE"
@@ -127,7 +127,7 @@
OmitFramePointers="TRUE"
OptimizeForProcessor="2"
AdditionalIncludeDirectories="&quot;$(SolutionDir)\msvc-2003-xbox1&quot;;&quot;$(SolutionDir)\..\&quot;;&quot;$(SolutionDir)\..\..\..\&quot;"
PreprocessorDefinitions="NDEBUG;_XBOX;_LIB;__LIBRETRO__;LSB_FIRST;LOCAL_LE;INLINE=_inline;SOUND_QUALITY=0;PSS_STYLE=2;ZLIB;PATH_MAX=1024;_XBOX1;FCEU_VERSION_NUMERIC=9813;FRONTEND_SUPPORTS_RGB565;WANT_GRIFFIN;HAVE_EXTERNAL_ZLIB"
PreprocessorDefinitions="NDEBUG;_XBOX;_LIB;__LIBRETRO__;LOCAL_LE;INLINE=_inline;SOUND_QUALITY=0;PSS_STYLE=2;ZLIB;PATH_MAX=1024;_XBOX1;FCEU_VERSION_NUMERIC=9813;FRONTEND_SUPPORTS_RGB565;WANT_GRIFFIN;HAVE_EXTERNAL_ZLIB"
StringPooling="TRUE"
RuntimeLibrary="0"
BufferSecurityCheck="TRUE"
@@ -163,7 +163,7 @@
OmitFramePointers="TRUE"
OptimizeForProcessor="2"
AdditionalIncludeDirectories="&quot;$(SolutionDir)\msvc-2003-xbox1&quot;;&quot;$(SolutionDir)\..\&quot;;&quot;$(SolutionDir)\..\..\..\&quot;"
PreprocessorDefinitions="NDEBUG;_XBOX;LTCG;_LIB;__LIBRETRO__;LSB_FIRST;LOCAL_LE;INLINE=_inline;SOUND_QUALITY=0;PSS_STYLE=2;ZLIB;PATH_MAX=1024;_XBOX1;FCEU_VERSION_NUMERIC=9813;FRONTEND_SUPPORTS_RGB565;WANT_GRIFFIN;HAVE_EXTERNAL_ZLIB"
PreprocessorDefinitions="NDEBUG;_XBOX;LTCG;_LIB;__LIBRETRO__;LOCAL_LE;INLINE=_inline;SOUND_QUALITY=0;PSS_STYLE=2;ZLIB;PATH_MAX=1024;_XBOX1;FCEU_VERSION_NUMERIC=9813;FRONTEND_SUPPORTS_RGB565;WANT_GRIFFIN;HAVE_EXTERNAL_ZLIB"
StringPooling="TRUE"
RuntimeLibrary="0"
BufferSecurityCheck="TRUE"

View File

@@ -63,22 +63,22 @@ int read32le(uint32 *Bufo, FILE *fp) {
uint32 buf;
if (fread(&buf, 1, 4, fp) < 4)
return 0;
#ifdef LSB_FIRST
*(uint32*)Bufo = buf;
#else
#ifdef MSB_FIRST
*(uint32*)Bufo = ((buf & 0xFF) << 24) | ((buf & 0xFF00) << 8) | ((buf & 0xFF0000) >> 8) | ((buf & 0xFF000000) >> 24);
#else
*(uint32*)Bufo = buf;
#endif
return 1;
}
int read16le(char *d, FILE *fp) {
#ifdef LSB_FIRST
return((fread(d, 1, 2, fp) < 2) ? 0 : 2);
#else
#ifdef MSB_FIRST
int ret;
ret = fread(d + 1, 1, 1, fp);
ret += fread(d, 1, 1, fp);
return ret < 2 ? 0 : 2;
#else
return((fread(d, 1, 2, fp) < 2) ? 0 : 2);
#endif
}

View File

@@ -413,10 +413,11 @@ int FCEU_read16le(uint16 *val, FCEUFILE *fp) {
return(1);
}
int FCEU_read32le(uint32 *Bufo, FCEUFILE *fp) {
int FCEU_read32le(uint32 *Bufo, FCEUFILE *fp)
{
if (fp->type >= 1) {
uint8 t[4];
#ifndef LSB_FIRST
#ifdef MSB_FIRST
uint8 x[4];
#endif
if (fp->type >= 2) {
@@ -429,7 +430,7 @@ int FCEU_read32le(uint32 *Bufo, FCEUFILE *fp) {
wz->location += 4;
} else if (fp->type == 1)
gzread(fp->fp, &t, 4);
#ifndef LSB_FIRST
#ifdef MSB_FIRST
x[0] = t[3];
x[1] = t[2];
x[2] = t[1];

View File

@@ -1002,27 +1002,7 @@ static void CopySprites(uint8 *target) {
uint32 t = *(uint32*)(sprlinebuf + n);
if (t != 0x80808080) {
#ifdef LSB_FIRST
if (!(t & 0x80)) {
if (!(t & 0x40) || (P[n] & 0x40)) // Normal sprite || behind bg sprite
P[n] = sprlinebuf[n];
}
if (!(t & 0x8000)) {
if (!(t & 0x4000) || (P[n + 1] & 0x40)) // Normal sprite || behind bg sprite
P[n + 1] = (sprlinebuf + 1)[n];
}
if (!(t & 0x800000)) {
if (!(t & 0x400000) || (P[n + 2] & 0x40)) // Normal sprite || behind bg sprite
P[n + 2] = (sprlinebuf + 2)[n];
}
if (!(t & 0x80000000)) {
if (!(t & 0x40000000) || (P[n + 3] & 0x40)) // Normal sprite || behind bg sprite
P[n + 3] = (sprlinebuf + 3)[n];
}
#else
#ifdef MSB_FIRST
if (!(t & 0x80000000)) {
if (!(t & 0x40000000) || (P[n] & 64)) // Normal sprite || behind bg sprite
P[n] = sprlinebuf[n];
@@ -1042,6 +1022,27 @@ static void CopySprites(uint8 *target) {
if (!(t & 0x40) || (P[n + 3] & 64)) // Normal sprite || behind bg sprite
P[n + 3] = (sprlinebuf + 3)[n];
}
#else
if (!(t & 0x80)) {
if (!(t & 0x40) || (P[n] & 0x40)) // Normal sprite || behind bg sprite
P[n] = sprlinebuf[n];
}
if (!(t & 0x8000)) {
if (!(t & 0x4000) || (P[n + 1] & 0x40)) // Normal sprite || behind bg sprite
P[n + 1] = (sprlinebuf + 1)[n];
}
if (!(t & 0x800000)) {
if (!(t & 0x400000) || (P[n + 2] & 0x40)) // Normal sprite || behind bg sprite
P[n + 2] = (sprlinebuf + 2)[n];
}
if (!(t & 0x80000000)) {
if (!(t & 0x40000000) || (P[n + 3] & 0x40)) // Normal sprite || behind bg sprite
P[n + 3] = (sprlinebuf + 3)[n];
}
#endif
}
n += 4;

View File

@@ -108,14 +108,14 @@ static int SubWrite(MEM_TYPE *st, SFORMAT *sf) {
fwrite(sf->desc, 1, 4, st);
write32le(sf->s & (~RLSB), st);
#ifndef LSB_FIRST
#ifdef MSB_FIRST
if (sf->s & RLSB)
FlipByteOrder(sf->v, sf->s & (~RLSB));
#endif
fwrite((uint8*)sf->v, 1, sf->s & (~RLSB), st);
/* Now restore the original byte order. */
#ifndef LSB_FIRST
#ifdef MSB_FIRST
if (sf->s & RLSB)
FlipByteOrder(sf->v, sf->s & (~RLSB));
#endif
@@ -173,7 +173,7 @@ static int ReadStateChunk(MEM_TYPE *st, SFORMAT *sf, int size) {
if ((tmp = CheckS(sf, tsize, toa))) {
fread((uint8*)tmp->v, 1, tmp->s & (~RLSB), st);
#ifndef LSB_FIRST
#ifdef MSB_FIRST
if (tmp->s & RLSB)
FlipByteOrder(tmp->v, tmp->s & (~RLSB));
#endif