all repos — mgba @ 24da1097ba1199b1665be78e93288c3f3401e2fe

mGBA Game Boy Advance Emulator

All: Generic big-endian changes
Jeffrey Pfau jeffrey@endrift.com
Mon, 19 Oct 2015 23:49:35 -0700
commit

24da1097ba1199b1665be78e93288c3f3401e2fe

parent

ea204bbfed6c468861a62ecd36114e974966848d

2 files changed, 11 insertions(+), 3 deletions(-)

jump to
M src/util/common.hsrc/util/common.h

@@ -73,6 +73,15 @@ uint32_t _addr = (ADDR); \

void* _ptr = (ARR); \ __asm__("sthbrx %0, %1, %2" : : "r"(SRC), "b"(_ptr), "r"(_addr)); \ } +#elif defined __BIG_ENDIAN__ +#if defined(__llvm__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) +#define LOAD_32LE(DEST, ADDR, ARR) DEST = __builtin_bswap32(((uint32_t*) ARR)[(ADDR) >> 2]) +#define LOAD_16LE(DEST, ADDR, ARR) DEST = __builtin_bswap16(((uint16_t*) ARR)[(ADDR) >> 1]) +#define STORE_32LE(SRC, ADDR, ARR) ((uint32_t*) ARR)[(ADDR) >> 2] = __builtin_bswap32(SRC) +#define STORE_16LE(SRC, ADDR, ARR) ((uint16_t*) ARR)[(ADDR) >> 1] = __builtin_bswap16(SRC) +#else +#error Big endian build not supported on this platform. +#endif #else #define LOAD_32LE(DEST, ADDR, ARR) DEST = ((uint32_t*) ARR)[(ADDR) >> 2] #define LOAD_16LE(DEST, ADDR, ARR) DEST = ((uint16_t*) ARR)[(ADDR) >> 1]
M src/util/png-io.csrc/util/png-io.c

@@ -65,7 +65,7 @@ unsigned i;

for (i = 0; i < height; ++i) { unsigned x; for (x = 0; x < width; ++x) { -#if defined(__POWERPC__) || defined(__PPC__) +#ifdef __BIG_ENDIAN__ row[x * 3] = pixelData[stride * i * 4 + x * 4 + 3]; row[x * 3 + 1] = pixelData[stride * i * 4 + x * 4 + 2]; row[x * 3 + 2] = pixelData[stride * i * 4 + x * 4 + 1];

@@ -173,8 +173,7 @@ for (i = 0; i < pngHeight; ++i) {

png_read_row(png, row, 0); unsigned x; for (x = 0; x < pngWidth; ++x) { - -#if defined(__POWERPC__) || defined(__PPC__) +#if __BIG_ENDIAN__ pixelData[stride * i * 4 + x * 4 + 3] = row[x * 3]; pixelData[stride * i * 4 + x * 4 + 2] = row[x * 3 + 1]; pixelData[stride * i * 4 + x * 4 + 1] = row[x * 3 + 2];