From e2936e40b209c051b2f7cc85f02590eb1676884e Mon Sep 17 00:00:00 2001 From: gecko_reverse Date: Sun, 6 Apr 2008 15:47:35 +0000 Subject: [PATCH] applied endian fixes in GPU thanks to Phazz --- desmume/ChangeLog | 1 + desmume/src/GPU.c | 55 ++++++++++++++++++++++++++++++++++++++--------- desmume/src/GPU.h | 35 +++++++++++++++++++++++++++--- 3 files changed, 78 insertions(+), 13 deletions(-) diff --git a/desmume/ChangeLog b/desmume/ChangeLog index 718d6b598..df46f66f5 100644 --- a/desmume/ChangeLog +++ b/desmume/ChangeLog @@ -19,6 +19,7 @@ - Fixed possible segfault in ROMReader on ia64 and amd64. [evilynux] - Fixed a crash bug with 2D background corrupting memory [shash] - Flag check optimization [carlo_bramini] + - Applied some endian fixes in GPU (thanks to Phazz) [Jeff B] gtk-glade: - Added DeSmuME version in about dialog. [evilynux] - Updated website url in about dialog. [evilynux] diff --git a/desmume/src/GPU.c b/desmume/src/GPU.c index 543bad4df..ca807514f 100644 --- a/desmume/src/GPU.c +++ b/desmume/src/GPU.c @@ -1272,7 +1272,7 @@ INLINE void render_sprite_BMP (GPU * gpu, u16 l, u8 * dst, u16 * src, u8 * prioT int i; u16 color; for(i = 0; i < lg; i++, ++sprX, x+=xdir) { - color = src[x]; + color = LE_TO_LOCAL_16(src[x]); // alpha bit = invisible if ((color&0x8000)&&(prio<=prioTab[sprX])) @@ -1301,7 +1301,7 @@ INLINE void render_sprite_256 ( GPU * gpu, u16 l, u8 * dst, u8 * src, u16 * pal, for(i = 0; i < lg; i++, ++sprX, x+=xdir) { palette_entry = src[(x&0x7) + ((x&0xFFF8)<<3)]; - color = pal[palette_entry]; + color = LE_TO_LOCAL_16(pal[palette_entry]); // palette entry = 0 means backdrop if ((palette_entry>0)&&(prio<=prioTab[sprX])) @@ -1337,7 +1337,7 @@ INLINE void render_sprite_16 ( GPU * gpu, u16 l, u8 * dst, u8 * src, u16 * pal, palette = src[(x1&0x3) + ((x1&0xFFFC)<<3)]; if (x & 1) palette_entry = palette >> 4; else palette_entry = palette & 0xF; - color = pal[palette_entry]; + color = LE_TO_LOCAL_16(pal[palette_entry]); // palette entry = 0 means backdrop if ((palette_entry>0)&&(prio<=prioTab[sprX])) @@ -1436,13 +1436,26 @@ void sprite1D(GPU * gpu, u16 l, u8 * dst, u8 * prioTab) u8 block = gpu->sprBoundary; u16 i; - for(i = 0; i> 1) | *(((u16*)spriteInfo)+1) << 15; + *(((u16*)spriteInfo)+2) = (*(((u16*)spriteInfo)+2) >> 2) | *(((u16*)spriteInfo)+2) << 14; +#endif + + for(i = 0; i> 15 + ,*(((u16*)(spriteInfo+1))+2) = (*(((u16*)(spriteInfo+1))+2) << 2) | *(((u16*)(spriteInfo+1))+2) >> 14 + ,*(((u16*)spriteInfo)+1) = (*(((u16*)spriteInfo)+1) >> 1) | *(((u16*)spriteInfo)+1) << 15 + ,*(((u16*)spriteInfo)+2) = (*(((u16*)spriteInfo)+2) >> 2) | *(((u16*)spriteInfo)+2) << 14 +#endif + ) /* check all sprites */ { size sprSize; s32 sprX, sprY, x, y, lg; int xdir; u8 prio, * src; - u16 i,j; + u16 i; // Check if sprite is disabled before everything if (spriteInfo->RotScale == 2) @@ -1671,6 +1684,11 @@ void sprite1D(GPU * gpu, u16 l, u8 * dst, u8 * prioTab) render_sprite_16 (gpu, l, dst, src, pal, prioTab, prio, lg, sprX, x, xdir, spriteInfo->Mode == 1); } } + +#ifdef WORDS_BIGENDIAN + *(((u16*)spriteInfo)+1) = (*(((u16*)spriteInfo)+1) << 1) | *(((u16*)spriteInfo)+1) >> 15; + *(((u16*)spriteInfo)+2) = (*(((u16*)spriteInfo)+2) << 2) | *(((u16*)spriteInfo)+2) >> 14; +#endif } void sprite2D(GPU * gpu, u16 l, u8 * dst, u8 * prioTab) @@ -1679,7 +1697,19 @@ void sprite2D(GPU * gpu, u16 l, u8 * dst, u8 * prioTab) _OAM_ * spriteInfo = (_OAM_*)(gpu->oam + (nbShow-1));// + 127; u16 i; - for(i = 0; i> 1) | *(((u16*)spriteInfo)+1) << 15; + *(((u16*)spriteInfo)+2) = (*(((u16*)spriteInfo)+2) >> 2) | *(((u16*)spriteInfo)+2) << 14; +#endif + + for(i = 0; i> 15 + ,*(((u16*)(spriteInfo+1))+2) = (*(((u16*)(spriteInfo+1))+2) << 2) | *(((u16*)(spriteInfo+1))+2) >> 14 + ,*(((u16*)spriteInfo)+1) = (*(((u16*)spriteInfo)+1) >> 1) | *(((u16*)spriteInfo)+1) << 15 + ,*(((u16*)spriteInfo)+2) = (*(((u16*)spriteInfo)+2) >> 2) | *(((u16*)spriteInfo)+2) << 14 +#endif + ) /* check all sprites */ { size sprSize; s32 sprX, sprY, x, y, lg; @@ -1915,6 +1945,11 @@ void sprite2D(GPU * gpu, u16 l, u8 * dst, u8 * prioTab) prioTab, prio, lg, sprX, x, xdir, spriteInfo->Mode == 1); } } + +#ifdef WORDS_BIGENDIAN + *(((u16*)spriteInfo)+1) = (*(((u16*)spriteInfo)+1) << 1) | *(((u16*)spriteInfo)+1) >> 15; + *(((u16*)spriteInfo)+2) = (*(((u16*)spriteInfo)+2) << 2) | *(((u16*)spriteInfo)+2) >> 14; +#endif } /*****************************************************************************/ @@ -2415,7 +2450,7 @@ void GPU_ligne(NDS_Screen * screen, u16 l) #ifndef BRIGHT_TABLES u8 base ; u8 r,g,b; // get components, 5bit each - dstColor.val = T1ReadWord(dst, i16 << 1); + dstColor.val = *((u16 *) (dst + (i16 << 1))); r = dstColor.bits.red; g = dstColor.bits.green; b = dstColor.bits.blue; @@ -2428,7 +2463,7 @@ void GPU_ligne(NDS_Screen * screen, u16 l) dstColor.val = T1ReadWord(dst, i16 << 1); dstColor.bitx.bgr = colors[dstColor.bitx.bgr]; #endif - T2WriteWord (dst, i16 << 1, dstColor.val); + *((u16 *) (dst + (i16 << 1))) = dstColor.val; } break; } @@ -2464,7 +2499,7 @@ void GPU_ligne(NDS_Screen * screen, u16 l) { #ifndef BRIGHT_TABLES u8 r,g,b; - dstColor.val = T1ReadWord(dst, i16 << 1); + dstColor.val = *((u16 *) (dst + (i16 << 1))); r = dstColor.bits.red; g = dstColor.bits.green; b = dstColor.bits.blue; @@ -2476,7 +2511,7 @@ void GPU_ligne(NDS_Screen * screen, u16 l) dstColor.val = T1ReadWord(dst, i16 << 1); dstColor.bitx.bgr = colors[dstColor.bitx.bgr]; #endif - T2WriteWord (dst, i16 << 1, dstColor.val); + *((u16 *) (dst + (i16 << 1))) = dstColor.val; } break; } diff --git a/desmume/src/GPU.h b/desmume/src/GPU.h index 1d355fe05..ac89d9543 100644 --- a/desmume/src/GPU.h +++ b/desmume/src/GPU.h @@ -466,10 +466,17 @@ typedef union */ struct _COLOR { // abgr x555 - unsigned red:5; - unsigned green:5; +#ifdef WORDS_BIGENDIAN + unsigned alpha:1; // sometimes it is unused (pad) unsigned blue:5; - unsigned alpha:1; // sometimes it is unused (pad) + unsigned green:5; + unsigned red:5; +#else + unsigned red:5; + unsigned green:5; + unsigned blue:5; + unsigned alpha:1; // sometimes it is unused (pad) +#endif }; struct _COLORx { // abgr x555 unsigned bgr:15; @@ -521,6 +528,27 @@ ref: http://www.bottledlight.com/ds/index.php/Video/Sprites typedef struct { +#ifdef WORDS_BIGENDIAN +// attr0 +/* 0*/ unsigned Y:8; +/*14*/ unsigned Shape:2; // (00: Square, 01: Wide, 10: Tall, 11: Illegal) +/*13*/ unsigned Depth:1; // (0: 16, 1: 256) +/*12*/ unsigned Mosaic:1; // (1: Enabled) +/*10*/ unsigned Mode:2; // (00: Normal, 01: Transparent, 10: Object window, 11: Bitmap) +/* 8*/ unsigned RotScale:2; // (00: Normal, 01: Rot/scale, 10: Disabled, 11: Double-size rot/scale) +// attr1 +/* 0*/ signed X:9; +/*14*/ unsigned Size:2; +/*13*/ unsigned VFlip:1; +/*12*/ unsigned HFlip:1; +/* 9*/ unsigned RotScalIndex:3; // Rot/scale matrix index +// attr2 +/* 0*/ unsigned TileIndex:10; +/*12*/ unsigned PaletteIndex:4; +/*10*/ unsigned Priority:2; +// attr3 +unsigned attr3:16; +#else // attr0 /* 0*/ unsigned Y:8; /* 8*/ unsigned RotScale:2; // (00: Normal, 01: Rot/scale, 10: Disabled, 11: Double-size rot/scale) @@ -540,6 +568,7 @@ typedef struct /*12*/ unsigned PaletteIndex:4; // attr3 unsigned attr3:16; +#endif } _OAM_; typedef struct