aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authortwinaphex2014-12-15 00:59:52 +0100
committertwinaphex2014-12-15 00:59:52 +0100
commit6b8c7d2376bb04578dec209eeafc037c33a32d45 (patch)
tree01e95a3b8e66ea12004d20a667f3f3eff45b5107 /source
parentb27c451831082179cc9bc3c1b3424ebb0f66dd74 (diff)
downloadsnesemu-6b8c7d2376bb04578dec209eeafc037c33a32d45.tar.gz
snesemu-6b8c7d2376bb04578dec209eeafc037c33a32d45.tar.bz2
snesemu-6b8c7d2376bb04578dec209eeafc037c33a32d45.zip
Use MSB_FIRST instead of LSB_FIRST
Diffstat (limited to 'source')
-rw-r--r--source/65c816.h6
-rw-r--r--source/blargg_endian.h96
-rw-r--r--source/gfx.c68
-rw-r--r--source/gfx.h6
-rw-r--r--source/globals.c12
-rw-r--r--source/memmap.c6
-rw-r--r--source/port.h3
-rw-r--r--source/spc700.h6
-rw-r--r--source/srtc.c16
9 files changed, 88 insertions, 131 deletions
diff --git a/source/65c816.h b/source/65c816.h
index 505d185..406341a 100644
--- a/source/65c816.h
+++ b/source/65c816.h
@@ -146,15 +146,15 @@
typedef union
{
-#ifdef LSB_FIRST
+#ifdef MSB_FIRST
struct
{
- uint8_t l, h;
+ uint8_t h, l;
} B;
#else
struct
{
- uint8_t h, l;
+ uint8_t l, h;
} B;
#endif
uint16_t W;
diff --git a/source/blargg_endian.h b/source/blargg_endian.h
index 8322fb1..177a081 100644
--- a/source/blargg_endian.h
+++ b/source/blargg_endian.h
@@ -65,75 +65,41 @@
#define BLARGG_CPU_RISC 1
#endif
-/* BLARGG_BIG_ENDIAN, BLARGG_LITTLE_ENDIAN: Determined automatically, otherwise only */
-/* one may be #defined to 1. Only needed if something actually depends on byte order. */
-#if !defined (BLARGG_BIG_ENDIAN) && !defined (BLARGG_LITTLE_ENDIAN)
-#ifdef __GLIBC__
- /* GCC handles this for us */
- #include <endian.h>
- #if __BYTE_ORDER == __LITTLE_ENDIAN
- #define BLARGG_LITTLE_ENDIAN 1
- #elif __BYTE_ORDER == __BIG_ENDIAN
- #define BLARGG_BIG_ENDIAN 1
- #endif
-#else
-
-#if defined (LSB_FIRST) || defined (__LITTLE_ENDIAN__) || BLARGG_CPU_X86 || \
- defined(ANDROID_X86) || defined(ANDROID_MIPS) || \
- defined(__BLACKBERRY_QNX__) || (defined (LITTLE_ENDIAN) && LITTLE_ENDIAN+0 != 1234)
- #define BLARGG_LITTLE_ENDIAN 1
-#endif
+#if BLARGG_NONPORTABLE
+ /* Optimized implementation if byte order is known */
-#if defined (MSB_FIRST) || defined (__BIG_ENDIAN__) || defined (WORDS_BIGENDIAN) || \
- defined (__sparc__) || BLARGG_CPU_POWERPC || \
- (defined (BIG_ENDIAN) && BIG_ENDIAN+0 != 4321)
- #define BLARGG_BIG_ENDIAN 1
-#elif !defined(__mips__) || !defined(ANDROID_MIPS)
- /* No endian specified; assume little-endian, since it's most common */
- #define BLARGG_LITTLE_ENDIAN 1
-#endif
+#ifdef MSB_FIRST
+#if BLARGG_CPU_POWERPC
+ /* PowerPC has special byte-reversed instructions */
+#if defined (__SNC__)
+#define GET_LE16( addr ) (__builtin_lhbrx(addr, 0))
+#define GET_LE32( addr ) (__builtin_lwbrx(addr, 0))
+#define SET_LE16( addr, in ) (__builtin_sthbrx(in, addr, 0))
+#define SET_LE32( addr, in ) (__builtin_stwbrx(in, addr, 0))
+#elif defined (_XBOX360)
+#include <PPCIntrinsics.h>
+#define GET_LE16( addr ) (__loadshortbytereverse(0, addr))
+#define GET_LE32( addr ) (__loadwordbytereverse(0, addr))
+#define SET_LE16( addr, in ) (__storeshortbytereverse(in, 0, addr))
+#define SET_LE32( addr, in ) (__storewordbytereverse(in, 0, addr))
+#elif defined (__MWERKS__)
+#define GET_LE16( addr ) (__lhbrx( addr, 0 ))
+#define GET_LE32( addr ) (__lwbrx( addr, 0 ))
+#define SET_LE16( addr, in ) (__sthbrx( in, addr, 0 ))
+#define SET_LE32( addr, in ) (__stwbrx( in, addr, 0 ))
+#elif defined (__GNUC__)
+#define GET_LE16( addr ) ({unsigned ppc_lhbrx_; asm( "lhbrx %0,0,%1" : "=r" (ppc_lhbrx_) : "r" (addr), "0" (ppc_lhbrx_) ); ppc_lhbrx_;})
+#define GET_LE32( addr ) ({unsigned ppc_lwbrx_; asm( "lwbrx %0,0,%1" : "=r" (ppc_lwbrx_) : "r" (addr), "0" (ppc_lwbrx_) ); ppc_lwbrx_;})
+#define SET_LE16( addr, in ) ({asm( "sthbrx %0,0,%1" : : "r" (in), "r" (addr) );})
+#define SET_LE32( addr, in ) ({asm( "stwbrx %0,0,%1" : : "r" (in), "r" (addr) );})
#endif
#endif
-
-#if BLARGG_LITTLE_ENDIAN && BLARGG_BIG_ENDIAN
- #undef BLARGG_LITTLE_ENDIAN
- #undef BLARGG_BIG_ENDIAN
+#else
+#define GET_LE16( addr ) (*(uint16_t*) (addr))
+#define GET_LE32( addr ) (*(uint32_t*) (addr))
+#define SET_LE16( addr, data ) (void) (*(uint16_t*) (addr) = (data))
+#define SET_LE32( addr, data ) (void) (*(uint32_t*) (addr) = (data))
#endif
-
-#if BLARGG_NONPORTABLE
- /* Optimized implementation if byte order is known */
- #if BLARGG_LITTLE_ENDIAN
- #define GET_LE16( addr ) (*(uint16_t*) (addr))
- #define GET_LE32( addr ) (*(uint32_t*) (addr))
- #define SET_LE16( addr, data ) (void) (*(uint16_t*) (addr) = (data))
- #define SET_LE32( addr, data ) (void) (*(uint32_t*) (addr) = (data))
- #elif BLARGG_BIG_ENDIAN
- #if BLARGG_CPU_POWERPC
- /* PowerPC has special byte-reversed instructions */
- #if defined (__SNC__)
- #define GET_LE16( addr ) (__builtin_lhbrx(addr, 0))
- #define GET_LE32( addr ) (__builtin_lwbrx(addr, 0))
- #define SET_LE16( addr, in ) (__builtin_sthbrx(in, addr, 0))
- #define SET_LE32( addr, in ) (__builtin_stwbrx(in, addr, 0))
- #elif defined (_XBOX360)
- #include <PPCIntrinsics.h>
- #define GET_LE16( addr ) (__loadshortbytereverse(0, addr))
- #define GET_LE32( addr ) (__loadwordbytereverse(0, addr))
- #define SET_LE16( addr, in ) (__storeshortbytereverse(in, 0, addr))
- #define SET_LE32( addr, in ) (__storewordbytereverse(in, 0, addr))
- #elif defined (__MWERKS__)
- #define GET_LE16( addr ) (__lhbrx( addr, 0 ))
- #define GET_LE32( addr ) (__lwbrx( addr, 0 ))
- #define SET_LE16( addr, in ) (__sthbrx( in, addr, 0 ))
- #define SET_LE32( addr, in ) (__stwbrx( in, addr, 0 ))
- #elif defined (__GNUC__)
- #define GET_LE16( addr ) ({unsigned ppc_lhbrx_; asm( "lhbrx %0,0,%1" : "=r" (ppc_lhbrx_) : "r" (addr), "0" (ppc_lhbrx_) ); ppc_lhbrx_;})
- #define GET_LE32( addr ) ({unsigned ppc_lwbrx_; asm( "lwbrx %0,0,%1" : "=r" (ppc_lwbrx_) : "r" (addr), "0" (ppc_lwbrx_) ); ppc_lwbrx_;})
- #define SET_LE16( addr, in ) ({asm( "sthbrx %0,0,%1" : : "r" (in), "r" (addr) );})
- #define SET_LE32( addr, in ) ({asm( "stwbrx %0,0,%1" : : "r" (in), "r" (addr) );})
- #endif
- #endif
- #endif
#else
static INLINE unsigned get_le16( void const* p )
{
diff --git a/source/gfx.c b/source/gfx.c
index 6c86ba5..2cd7584 100644
--- a/source/gfx.c
+++ b/source/gfx.c
@@ -268,24 +268,7 @@ bool S9xInitGFX()
register uint32_t h = 0;
register uint32_t l = 0;
-#if defined(LSB_FIRST)
- if (i & 8)
- h |= PixelOdd;
- if (i & 4)
- h |= PixelOdd << 8;
- if (i & 2)
- h |= PixelOdd << 16;
- if (i & 1)
- h |= PixelOdd << 24;
- if (i & 8)
- l |= PixelOdd;
- if (i & 4)
- l |= PixelOdd << 8;
- if (i & 2)
- l |= PixelOdd << 16;
- if (i & 1)
- l |= PixelOdd << 24;
-#else
+#if defined(MSB_FIRST)
if (i & 8)
h |= (PixelOdd << 24);
if (i & 4)
@@ -302,30 +285,30 @@ bool S9xInitGFX()
l |= (PixelOdd << 8);
if (i & 1)
l |= PixelOdd;
-#endif
-
- odd_high[bitshift][i] = h;
- odd_low[bitshift][i] = l;
- h = l = 0;
-
-#if defined(LSB_FIRST)
+#else
if (i & 8)
- h |= PixelEven;
+ h |= PixelOdd;
if (i & 4)
- h |= PixelEven << 8;
+ h |= PixelOdd << 8;
if (i & 2)
- h |= PixelEven << 16;
+ h |= PixelOdd << 16;
if (i & 1)
- h |= PixelEven << 24;
+ h |= PixelOdd << 24;
if (i & 8)
- l |= PixelEven;
+ l |= PixelOdd;
if (i & 4)
- l |= PixelEven << 8;
+ l |= PixelOdd << 8;
if (i & 2)
- l |= PixelEven << 16;
+ l |= PixelOdd << 16;
if (i & 1)
- l |= PixelEven << 24;
-#else
+ l |= PixelOdd << 24;
+#endif
+
+ odd_high[bitshift][i] = h;
+ odd_low[bitshift][i] = l;
+ h = l = 0;
+
+#if defined(MSB_FIRST)
if (i & 8)
h |= (PixelEven << 24);
if (i & 4)
@@ -342,6 +325,23 @@ bool S9xInitGFX()
l |= (PixelEven << 8);
if (i & 1)
l |= PixelEven;
+#else
+ if (i & 8)
+ h |= PixelEven;
+ if (i & 4)
+ h |= PixelEven << 8;
+ if (i & 2)
+ h |= PixelEven << 16;
+ if (i & 1)
+ h |= PixelEven << 24;
+ if (i & 8)
+ l |= PixelEven;
+ if (i & 4)
+ l |= PixelEven << 8;
+ if (i & 2)
+ l |= PixelEven << 16;
+ if (i & 1)
+ l |= PixelEven << 24;
#endif
even_high[bitshift][i] = h;
diff --git a/source/gfx.h b/source/gfx.h
index 98e22ae..c13620a 100644
--- a/source/gfx.h
+++ b/source/gfx.h
@@ -239,15 +239,9 @@ extern uint8_t mul_brightness [16][32];
#define READ_2BYTES(s) (*(uint16_t *) (s))
#define WRITE_2BYTES(s, d) *(uint16_t *) (s) = (d)
#else
-#ifdef LSB_FIRST
#define READ_2BYTES(s) (*(uint8_t *) (s) | (*((uint8_t *) (s) + 1) << 8))
#define WRITE_2BYTES(s, d) *(uint8_t *) (s) = (d), \
*((uint8_t *) (s) + 1) = (d) >> 8
-#else // else MSB_FISRT
-#define READ_2BYTES(s) (*(uint8_t *) (s) | (*((uint8_t *) (s) + 1) << 8))
-#define WRITE_2BYTES(s, d) *(uint8_t *) (s) = (d), \
- *((uint8_t *) (s) + 1) = (d) >> 8
-#endif // LSB_FIRST
#endif // i386
#define SUB_SCREEN_DEPTH 0
diff --git a/source/globals.c b/source/globals.c
index 0625df8..d7fa677 100644
--- a/source/globals.c
+++ b/source/globals.c
@@ -271,19 +271,19 @@ int NoiseFreq [32] =
uint32_t HeadMask [4] =
{
-#ifdef LSB_FIRST
- 0xffffffff, 0xffffff00, 0xffff0000, 0xff000000
-#else
+#ifdef MSB_FIRST
0xffffffff, 0x00ffffff, 0x0000ffff, 0x000000ff
+#else
+ 0xffffffff, 0xffffff00, 0xffff0000, 0xff000000
#endif
};
uint32_t TailMask [5] =
{
-#ifdef LSB_FIRST
- 0x00000000, 0x000000ff, 0x0000ffff, 0x00ffffff, 0xffffffff
-#else
+#ifdef MSB_FIRST
0x00000000, 0xff000000, 0xffff0000, 0xffffff00, 0xffffffff
+#else
+ 0x00000000, 0x000000ff, 0x0000ffff, 0x00ffffff, 0xffffffff
#endif
};
diff --git a/source/memmap.c b/source/memmap.c
index 951c5bb..12d65ff 100644
--- a/source/memmap.c
+++ b/source/memmap.c
@@ -815,12 +815,12 @@ again:
#ifdef DETECT_NASTY_FX_INTERLEAVE
//MK: Damn. YI trips a BRK currently. Maybe even on a real cart.
-#ifdef LSB_FIRST
+#ifdef MSB_FIRST
if (strncmp((char*) &ROM [0x7fc0], "YOSHI'S ISLAND", 14) == 0
- && (*(uint16_t*)&ROM[0x7FDE]) == 57611 && ROM[0x10002] == 0xA9)
+ && (ROM[0x7FDE] + (ROM[0x7FDF] << 8)) == 57611 && ROM[0x10002] == 0xA9)
#else
if (strncmp((char*) &ROM [0x7fc0], "YOSHI'S ISLAND", 14) == 0
- && (ROM[0x7FDE] + (ROM[0x7FDF] << 8)) == 57611 && ROM[0x10002] == 0xA9)
+ && (*(uint16_t*)&ROM[0x7FDE]) == 57611 && ROM[0x10002] == 0xA9)
#endif
{
Interleaved = true;
diff --git a/source/port.h b/source/port.h
index 264425f..9dd2229 100644
--- a/source/port.h
+++ b/source/port.h
@@ -202,16 +202,13 @@ void MixSound(void);
#if defined(__i386__) || defined(__i486__) || defined(__i586__) || \
defined(__WIN32__) || defined(__alpha__)
-#define LSB_FIRST
#define FAST_LSB_WORD_ACCESS
#elif defined(__MIPSEL__)
-#define LSB_FIRST
// On little-endian MIPS, a 16-bit word can be read directly from an address
// only if it's aligned.
#define FAST_ALIGNED_LSB_WORD_ACCESS
#else
//#define MSB_FIRST
-#define LSB_FIRST
//#define FAST_LSB_WORD_ACCESS
#endif
diff --git a/source/spc700.h b/source/spc700.h
index 9ddb72f..5c0bb14 100644
--- a/source/spc700.h
+++ b/source/spc700.h
@@ -135,15 +135,15 @@
typedef union
{
-#ifdef LSB_FIRST
+#ifdef MSB_FIRST
struct
{
- uint8_t A, Y;
+ uint8_t Y, A;
} B;
#else
struct
{
- uint8_t Y, A;
+ uint8_t A, Y;
} B;
#endif
uint16_t W;
diff --git a/source/srtc.c b/source/srtc.c
index 5073d35..2d63e96 100644
--- a/source/srtc.c
+++ b/source/srtc.c
@@ -518,10 +518,7 @@ void S9xSRTCPreSaveState()
Memory.SRAM [s + 3 + MAX_RTC_INDEX] = rtc.index;
Memory.SRAM [s + 4 + MAX_RTC_INDEX] = rtc.mode;
-#ifdef LSB_FIRST
- // memmove converted: Different mallocs [Neb]
- memcpy(&Memory.SRAM [s + 5 + MAX_RTC_INDEX], &rtc.system_timestamp, 8);
-#else
+#ifdef MSB_FIRST
SRAM [s + 5 + MAX_RTC_INDEX] = (uint8_t)(rtc.system_timestamp >> 0);
SRAM [s + 6 + MAX_RTC_INDEX] = (uint8_t)(rtc.system_timestamp >> 8);
SRAM [s + 7 + MAX_RTC_INDEX] = (uint8_t)(rtc.system_timestamp >> 16);
@@ -530,6 +527,9 @@ void S9xSRTCPreSaveState()
SRAM [s + 10 + MAX_RTC_INDEX] = (uint8_t)(rtc.system_timestamp >> 40);
SRAM [s + 11 + MAX_RTC_INDEX] = (uint8_t)(rtc.system_timestamp >> 48);
SRAM [s + 12 + MAX_RTC_INDEX] = (uint8_t)(rtc.system_timestamp >> 56);
+#else
+ // memmove converted: Different mallocs [Neb]
+ memcpy(&Memory.SRAM [s + 5 + MAX_RTC_INDEX], &rtc.system_timestamp, 8);
#endif
}
}
@@ -550,10 +550,7 @@ void S9xSRTCPostLoadState()
rtc.index = Memory.SRAM [s + 3 + MAX_RTC_INDEX];
rtc.mode = Memory.SRAM [s + 4 + MAX_RTC_INDEX];
-#ifdef LSB_FIRST
- // memmove converted: Different mallocs [Neb]
- memcpy(&rtc.system_timestamp, &Memory.SRAM [s + 5 + MAX_RTC_INDEX], 8);
-#else
+#ifdef MSB_FIRST
rtc.system_timestamp |= (SRAM [s + 5 + MAX_RTC_INDEX] << 0);
rtc.system_timestamp |= (SRAM [s + 6 + MAX_RTC_INDEX] << 8);
rtc.system_timestamp |= (SRAM [s + 7 + MAX_RTC_INDEX] << 16);
@@ -562,6 +559,9 @@ void S9xSRTCPostLoadState()
rtc.system_timestamp |= (SRAM [s + 10 + MAX_RTC_INDEX] << 40);
rtc.system_timestamp |= (SRAM [s + 11 + MAX_RTC_INDEX] << 48);
rtc.system_timestamp |= (SRAM [s + 12 + MAX_RTC_INDEX] << 56);
+#else
+ // memmove converted: Different mallocs [Neb]
+ memcpy(&rtc.system_timestamp, &Memory.SRAM [s + 5 + MAX_RTC_INDEX], 8);
#endif
S9xUpdateSrtcTime();
}