From: Michael Gernoth Date: Sun, 13 Jan 2008 11:05:53 +0000 (+0100) Subject: automatically detect byteorder of X server X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/micropolis/commitdiff_plain/99c730ea57a9022357cce87208b5a02c6612c286 automatically detect byteorder of X server --- diff --git a/src/sim/g_smmaps.c b/src/sim/g_smmaps.c index d2646a6..b29199b 100644 --- a/src/sim/g_smmaps.c +++ b/src/sim/g_smmaps.c @@ -84,63 +84,67 @@ int DynamicData[32]; if (tile >= TILE_COUNT) tile -= TILE_COUNT; -#if defined(MSDOS) || defined(OSF1) || defined(IS_INTEL) - -#define ROW1_8(n) \ +#define LE_ROW1_8(n) \ l = mem[n]; \ image[0] = l; \ image[1] = l >>8; \ image[2] = l >>16; \ image += lineBytes; -#define ROW1_16(n) \ +#define LE_ROW1_16(n) \ memcpy((char *)image, ((char *)mem) + (n * 4 * 2), (3 * 2)); \ image += lineBytes; -#define ROW1_24(n) \ +#define LE_ROW1_24(n) \ memcpy((char *)image, ((char *)mem) + (n * 4 * 3), (3 * 3)); \ image += lineBytes; -#define ROW1_32(n) \ +#define LE_ROW1_32(n) \ memcpy((char *)image, ((char *)mem) + (n * 4 * 4), (3 * 4)); \ image += lineBytes; -#else - -#define ROW1_8(n) \ +#define BE_ROW1_8(n) \ l = mem[n]; \ image[0] = l >>24; \ image[1] = l >>16; \ image[2] = l >>8; \ image += lineBytes; -#define ROW1_16(n) \ +#define BE_ROW1_16(n) \ l = mem[n]; /* XXX: WRONG. handle depth */ \ image[0] = l >>24; \ image[1] = l >>16; \ image[2] = l >>8; \ image += lineBytes; -#define ROW1_24(n) \ +#define BE_ROW1_24(n) \ l = mem[n]; /* XXX: WRONG. handle depth */ \ image[0] = l >>24; \ image[1] = l >>16; \ image[2] = l >>8; \ image += lineBytes; -#define ROW1_32(n) \ +#define BE_ROW1_32(n) \ l = mem[n]; /* XXX: WRONG. handle depth */ \ image[0] = l >>24; \ image[1] = l >>16; \ image[2] = l >>8; \ image += lineBytes; -#endif +#define LE_ROW3_8 LE_ROW1_8(0) LE_ROW1_8(1) LE_ROW1_8(2) +#define LE_ROW3_16 LE_ROW1_16(0) LE_ROW1_16(1) LE_ROW1_16(2) +#define LE_ROW3_24 LE_ROW1_24(0) LE_ROW1_24(1) LE_ROW1_24(2) +#define LE_ROW3_32 LE_ROW1_32(0) LE_ROW1_32(1) LE_ROW1_32(2) + +#define BE_ROW3_8 BE_ROW1_8(0) BE_ROW1_8(1) BE_ROW1_8(2) +#define BE_ROW3_16 BE_ROW1_16(0) BE_ROW1_16(1) BE_ROW1_16(2) +#define BE_ROW3_24 BE_ROW1_24(0) BE_ROW1_24(1) BE_ROW1_24(2) +#define BE_ROW3_32 BE_ROW1_32(0) BE_ROW1_32(1) BE_ROW1_32(2) -#define ROW3_8 ROW1_8(0) ROW1_8(1) ROW1_8(2) -#define ROW3_16 ROW1_16(0) ROW1_16(1) ROW1_16(2) -#define ROW3_24 ROW1_24(0) ROW1_24(1) ROW1_24(2) -#define ROW3_32 ROW1_32(0) ROW1_32(1) ROW1_32(2) +#define ROW3_8 if (view->x->big_endian) { BE_ROW3_8 } else { LE_ROW3_8 } +#define ROW3_16 if (view->x->big_endian) { BE_ROW3_16 } else { LE_ROW3_16 } +#define ROW3_24 if (view->x->big_endian) { BE_ROW3_24 } else { LE_ROW3_24 } +#define ROW3_32 if (view->x->big_endian) { BE_ROW3_32 } else { LE_ROW3_32 } #define ROW3 \ switch (view->x->depth) { \ diff --git a/src/sim/headers/view.h b/src/sim/headers/view.h index 39931a5..aabdafe 100644 --- a/src/sim/headers/view.h +++ b/src/sim/headers/view.h @@ -113,6 +113,7 @@ typedef struct XDisplay { Pixmap vert_stipple; Pixmap horiz_stipple; Pixmap diag_stipple; + int big_endian; } XDisplay; diff --git a/src/sim/w_x.c b/src/sim/w_x.c index a00d551..76e9ff6 100644 --- a/src/sim/w_x.c +++ b/src/sim/w_x.c @@ -584,6 +584,8 @@ InitNewView(SimView *view, char *title, int class, int w, int h) view->type = X_Mem_View; } + view->x->big_endian = (ImageByteOrder(view->x->dpy) == MSBFirst); + GetPixmaps(view->x); view->pixels = view->x->pixels;