From 075312027f4af9813ede622d173cd2cb8c86589f Mon Sep 17 00:00:00 2001 From: Link Date: Thu, 23 Oct 2025 08:56:36 -0300 Subject: [PATCH 1/8] Big endian fixes --- RSDKv4/Drawing.cpp | 11 +++++++++++ RSDKv4/Renderer.cpp | 18 +++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/RSDKv4/Drawing.cpp b/RSDKv4/Drawing.cpp index eaad86b54..3a3b0f5b7 100644 --- a/RSDKv4/Drawing.cpp +++ b/RSDKv4/Drawing.cpp @@ -1,4 +1,7 @@ #include "RetroEngine.hpp" +#if defined(__linux__) || defined(__FreeBSD__) +#include +#endif ushort blendLookupTable[0x20 * 0x100]; ushort subtractLookupTable[0x20 * 0x100]; @@ -907,10 +910,18 @@ void SetupViewport() #if RETRO_USING_OPENGL if (displaySettings.height > 720) { convertTo32Bit = true; +#if defined(__BYTE_ORDER__) && (__BYTE_ORDER == __BIG_ENDIAN) + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0); +#else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); +#endif } else if (convertTo32Bit) +#if defined(__BYTE_ORDER__) && (__BYTE_ORDER == __BIG_ENDIAN) + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0); +#else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); +#endif else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 0); diff --git a/RSDKv4/Renderer.cpp b/RSDKv4/Renderer.cpp index 0b58486b4..3f66f388a 100644 --- a/RSDKv4/Renderer.cpp +++ b/RSDKv4/Renderer.cpp @@ -2,6 +2,9 @@ #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" +#if defined(__linux__) || defined(__FreeBSD__) +#include +#endif float retroVertexList[40]; float screenBufferVertexList[40]; @@ -443,6 +446,7 @@ void RenderScene() if (!prevColors) glEnableClientState(GL_COLOR_ARRAY); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(DrawVertex), &state->vertPtr->r); + #endif prevColors = true; } @@ -688,7 +692,11 @@ int LoadTexture(const char *filePath, int format) } #if RETRO_USING_OPENGL +#if defined(__BYTE_ORDER__) && (__BYTE_ORDER == __BIG_ENDIAN) + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->width, texture->height, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels); +#else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->width, texture->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); +#endif glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D, 0); @@ -798,7 +806,11 @@ void ReplaceTexture(const char *filePath, int texID) } #if RETRO_USING_OPENGL +#if defined(__BYTE_ORDER__) && (__BYTE_ORDER == __BIG_ENDIAN) + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->width, texture->height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels); +#else glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->width, texture->height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); +#endif glBindTexture(GL_TEXTURE_2D, 0); #endif @@ -1069,7 +1081,11 @@ void TransferRetroBuffer() frameBufferPtr += GFX_LINESIZE; } +#if defined(__BYTE_ORDER__) && (__BYTE_ORDER == __BIG_ENDIAN) + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GFX_LINESIZE, SCREEN_YSIZE, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, Engine.texBuffer); +#else glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GFX_LINESIZE, SCREEN_YSIZE, GL_RGBA, GL_UNSIGNED_BYTE, Engine.texBuffer); +#endif } else { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GFX_LINESIZE, SCREEN_YSIZE, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, Engine.frameBuffer); @@ -1840,4 +1856,4 @@ void RenderMesh(MeshInfo *mesh, byte type, byte depthTest) renderStateCount++; } -} \ No newline at end of file +} From 96532691d53aadd2da34dc64d6bc9ab7935bb1e0 Mon Sep 17 00:00:00 2001 From: Link4Electronics Date: Thu, 23 Oct 2025 23:47:54 -0300 Subject: [PATCH 2/8] Fix sega logo, works on little and big-endian --- RSDKv4/NativeObjects/SegaSplash.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/RSDKv4/NativeObjects/SegaSplash.cpp b/RSDKv4/NativeObjects/SegaSplash.cpp index 406080acc..0c4468d68 100644 --- a/RSDKv4/NativeObjects/SegaSplash.cpp +++ b/RSDKv4/NativeObjects/SegaSplash.cpp @@ -8,15 +8,15 @@ void SegaSplash_Create(void *objPtr) self->textureID = LoadTexture("Data/Game/Menu/CWLogo.png", TEXFMT_RGBA8888); if (Engine.useHighResAssets) { if (Engine.language == RETRO_JP) - self->textureID = LoadTexture("Data/Game/Menu/SegaJP@2x.png", TEXFMT_RGBA5551); + self->textureID = LoadTexture("Data/Game/Menu/SegaJP@2x.png", TEXFMT_RGBA8888); else - self->textureID = LoadTexture("Data/Game/Menu/Sega@2x.png", TEXFMT_RGBA5551); + self->textureID = LoadTexture("Data/Game/Menu/Sega@2x.png", TEXFMT_RGBA8888); } else { if (Engine.language == RETRO_JP) - self->textureID = LoadTexture("Data/Game/Menu/SegaJP.png", TEXFMT_RGBA5551); + self->textureID = LoadTexture("Data/Game/Menu/SegaJP.png", TEXFMT_RGBA8888); else - self->textureID = LoadTexture("Data/Game/Menu/Sega.png", TEXFMT_RGBA5551); + self->textureID = LoadTexture("Data/Game/Menu/Sega.png", TEXFMT_RGBA8888); } // code has been here from TitleScreen_Create due to the possibility of opening the dev menu before this loads :( From 32be0fa11ffc3d86d4a231754144468e2d872378 Mon Sep 17 00:00:00 2001 From: Link4Electronics Date: Fri, 24 Oct 2025 07:26:43 -0300 Subject: [PATCH 3/8] Revert sega logo --- RSDKv4/NativeObjects/SegaSplash.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/RSDKv4/NativeObjects/SegaSplash.cpp b/RSDKv4/NativeObjects/SegaSplash.cpp index 0c4468d68..406080acc 100644 --- a/RSDKv4/NativeObjects/SegaSplash.cpp +++ b/RSDKv4/NativeObjects/SegaSplash.cpp @@ -8,15 +8,15 @@ void SegaSplash_Create(void *objPtr) self->textureID = LoadTexture("Data/Game/Menu/CWLogo.png", TEXFMT_RGBA8888); if (Engine.useHighResAssets) { if (Engine.language == RETRO_JP) - self->textureID = LoadTexture("Data/Game/Menu/SegaJP@2x.png", TEXFMT_RGBA8888); + self->textureID = LoadTexture("Data/Game/Menu/SegaJP@2x.png", TEXFMT_RGBA5551); else - self->textureID = LoadTexture("Data/Game/Menu/Sega@2x.png", TEXFMT_RGBA8888); + self->textureID = LoadTexture("Data/Game/Menu/Sega@2x.png", TEXFMT_RGBA5551); } else { if (Engine.language == RETRO_JP) - self->textureID = LoadTexture("Data/Game/Menu/SegaJP.png", TEXFMT_RGBA8888); + self->textureID = LoadTexture("Data/Game/Menu/SegaJP.png", TEXFMT_RGBA5551); else - self->textureID = LoadTexture("Data/Game/Menu/Sega.png", TEXFMT_RGBA8888); + self->textureID = LoadTexture("Data/Game/Menu/Sega.png", TEXFMT_RGBA5551); } // code has been here from TitleScreen_Create due to the possibility of opening the dev menu before this loads :( From 2556b57581feda5d395f356b1cb388ff9b09e815 Mon Sep 17 00:00:00 2001 From: Link4Electronics Date: Sat, 1 Nov 2025 05:20:49 -0300 Subject: [PATCH 4/8] Swap endianness for pixel and vertex data --- RSDKv4/Renderer.cpp | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/RSDKv4/Renderer.cpp b/RSDKv4/Renderer.cpp index 3f66f388a..8d11eaade 100644 --- a/RSDKv4/Renderer.cpp +++ b/RSDKv4/Renderer.cpp @@ -5,6 +5,7 @@ #if defined(__linux__) || defined(__FreeBSD__) #include #endif +#include float retroVertexList[40]; float screenBufferVertexList[40]; @@ -687,16 +688,14 @@ int LoadTexture(const char *filePath, int format) int g = data[id++]; int b = data[id++]; int a = data[id++]; - pixels[x + (y * width)] = (a << 24) | (b << 16) | (g << 8) | (r << 0); + int pixel = (a << 24) | (b << 16) | (g << 8) | (r << 0); + pixel = SDL_SwapLE32(pixel); + pixels[x + (y * width)] = pixel; } } #if RETRO_USING_OPENGL -#if defined(__BYTE_ORDER__) && (__BYTE_ORDER == __BIG_ENDIAN) - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->width, texture->height, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels); -#else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->width, texture->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); -#endif glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D, 0); @@ -801,16 +800,14 @@ void ReplaceTexture(const char *filePath, int texID) int g = data[id++]; int b = data[id++]; int a = data[id++]; - pixels[x + (y * width)] = (a << 24) | (b << 16) | (g << 8) | (r << 0); + int pixel = (a << 24) | (b << 16) | (g << 8) | (r << 0); + pixel = SDL_SwapLE32(pixel); + pixels[x + (y * width)] = pixel; } } #if RETRO_USING_OPENGL -#if defined(__BYTE_ORDER__) && (__BYTE_ORDER == __BIG_ENDIAN) - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->width, texture->height, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels); -#else glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->width, texture->height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); -#endif glBindTexture(GL_TEXTURE_2D, 0); #endif @@ -865,10 +862,10 @@ MeshInfo *LoadMesh(const char *filePath, byte textureID) for (int v = 0; v < mesh->vertexCount; ++v) { float buf = 0; FileRead(&buf, sizeof(float)); - mesh->vertices[v].texCoordX = buf; + mesh->vertices[v].texCoordX = SDL_SwapFloatLE(buf); FileRead(&buf, sizeof(float)); - mesh->vertices[v].texCoordY = buf; + mesh->vertices[v].texCoordY = SDL_SwapFloatLE(buf); mesh->vertices[v].r = 0xFF; mesh->vertices[v].g = 0xFF; @@ -901,22 +898,22 @@ MeshInfo *LoadMesh(const char *filePath, byte textureID) for (int v = 0; v < mesh->vertexCount; ++v) { float buf = 0; FileRead(&buf, sizeof(float)); - mesh->vertices[v].vertX = buf; + mesh->vertices[v].vertX = SDL_SwapFloatLE(buf); FileRead(&buf, sizeof(float)); - mesh->vertices[v].vertY = buf; + mesh->vertices[v].vertY = SDL_SwapFloatLE(buf); FileRead(&buf, sizeof(float)); - mesh->vertices[v].vertZ = buf; + mesh->vertices[v].vertZ = SDL_SwapFloatLE(buf); FileRead(&buf, sizeof(float)); - mesh->vertices[v].normalX = buf; + mesh->vertices[v].normalX = SDL_SwapFloatLE(buf); FileRead(&buf, sizeof(float)); - mesh->vertices[v].normalY = buf; + mesh->vertices[v].normalY = SDL_SwapFloatLE(buf); FileRead(&buf, sizeof(float)); - mesh->vertices[v].normalZ = buf; + mesh->vertices[v].normalZ = SDL_SwapFloatLE(buf); } } else { @@ -926,22 +923,22 @@ MeshInfo *LoadMesh(const char *filePath, byte textureID) for (int v = 0; v < mesh->vertexCount; ++v) { float buf = 0; FileRead(&buf, sizeof(float)); - mesh->frames[frameOff + v].vertX = buf; + mesh->frames[frameOff + v].vertX = SDL_SwapFloatLE(buf); FileRead(&buf, sizeof(float)); - mesh->frames[frameOff + v].vertY = buf; + mesh->frames[frameOff + v].vertY = SDL_SwapFloatLE(buf); FileRead(&buf, sizeof(float)); - mesh->frames[frameOff + v].vertZ = buf; + mesh->frames[frameOff + v].vertZ = SDL_SwapFloatLE(buf); FileRead(&buf, sizeof(float)); - mesh->frames[frameOff + v].normalX = buf; + mesh->frames[frameOff + v].normalX = SDL_SwapFloatLE(buf); FileRead(&buf, sizeof(float)); - mesh->frames[frameOff + v].normalY = buf; + mesh->frames[frameOff + v].normalY = SDL_SwapFloatLE(buf); FileRead(&buf, sizeof(float)); - mesh->frames[frameOff + v].normalZ = buf; + mesh->frames[frameOff + v].normalZ = SDL_SwapFloatLE(buf); } } } From 33839b0051662f7230744995d0615e75a9d21d77 Mon Sep 17 00:00:00 2001 From: Link4Electronics Date: Mon, 3 Nov 2025 21:01:51 -0300 Subject: [PATCH 5/8] Not really necessary Removed endian checks --- RSDKv4/Drawing.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/RSDKv4/Drawing.cpp b/RSDKv4/Drawing.cpp index 3a3b0f5b7..eaad86b54 100644 --- a/RSDKv4/Drawing.cpp +++ b/RSDKv4/Drawing.cpp @@ -1,7 +1,4 @@ #include "RetroEngine.hpp" -#if defined(__linux__) || defined(__FreeBSD__) -#include -#endif ushort blendLookupTable[0x20 * 0x100]; ushort subtractLookupTable[0x20 * 0x100]; @@ -910,18 +907,10 @@ void SetupViewport() #if RETRO_USING_OPENGL if (displaySettings.height > 720) { convertTo32Bit = true; -#if defined(__BYTE_ORDER__) && (__BYTE_ORDER == __BIG_ENDIAN) - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0); -#else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); -#endif } else if (convertTo32Bit) -#if defined(__BYTE_ORDER__) && (__BYTE_ORDER == __BIG_ENDIAN) - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0); -#else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); -#endif else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 0); From dd728f5f2d8448d279591fde55aba7dd1586ee2f Mon Sep 17 00:00:00 2001 From: Link4Electronics Date: Wed, 21 Jan 2026 00:25:54 -0300 Subject: [PATCH 6/8] Update Renderer.cpp --- RSDKv4/Renderer.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/RSDKv4/Renderer.cpp b/RSDKv4/Renderer.cpp index 8d11eaade..e51d2b9ee 100644 --- a/RSDKv4/Renderer.cpp +++ b/RSDKv4/Renderer.cpp @@ -2,9 +2,6 @@ #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" -#if defined(__linux__) || defined(__FreeBSD__) -#include -#endif #include float retroVertexList[40]; @@ -1078,11 +1075,7 @@ void TransferRetroBuffer() frameBufferPtr += GFX_LINESIZE; } -#if defined(__BYTE_ORDER__) && (__BYTE_ORDER == __BIG_ENDIAN) - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GFX_LINESIZE, SCREEN_YSIZE, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, Engine.texBuffer); -#else glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GFX_LINESIZE, SCREEN_YSIZE, GL_RGBA, GL_UNSIGNED_BYTE, Engine.texBuffer); -#endif } else { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, GFX_LINESIZE, SCREEN_YSIZE, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, Engine.frameBuffer); From 9f831d22ab452e68d97a36425e3e087c589156c2 Mon Sep 17 00:00:00 2001 From: Link4Electronics Date: Wed, 21 Jan 2026 00:27:03 -0300 Subject: [PATCH 7/8] Update Renderer.cpp just mesh fixed and remove spare line added. --- RSDKv4/Renderer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/RSDKv4/Renderer.cpp b/RSDKv4/Renderer.cpp index e51d2b9ee..9c8f8c6d5 100644 --- a/RSDKv4/Renderer.cpp +++ b/RSDKv4/Renderer.cpp @@ -444,7 +444,6 @@ void RenderScene() if (!prevColors) glEnableClientState(GL_COLOR_ARRAY); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(DrawVertex), &state->vertPtr->r); - #endif prevColors = true; } From f10d3a494bb4d1de9ea65f824450ae1abfbc6058 Mon Sep 17 00:00:00 2001 From: Link4Electronics Date: Wed, 21 Jan 2026 01:23:20 -0300 Subject: [PATCH 8/8] Update Renderer.cpp explaining the reason to why use it --- RSDKv4/Renderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RSDKv4/Renderer.cpp b/RSDKv4/Renderer.cpp index 9c8f8c6d5..963b6b73b 100644 --- a/RSDKv4/Renderer.cpp +++ b/RSDKv4/Renderer.cpp @@ -2,7 +2,7 @@ #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" -#include +#include // Used to correct vertex explosions in the main menu on big-endian devices. float retroVertexList[40]; float screenBufferVertexList[40];