From 92d1a7324891ed87be419f8492c940ef7846d046 Mon Sep 17 00:00:00 2001 From: Jan Racek Date: Sun, 29 Mar 2026 11:05:16 +0200 Subject: [PATCH] fixup --- src/splashpack.cpp | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/splashpack.cpp b/src/splashpack.cpp index ce95cea..b3c5be3 100644 --- a/src/splashpack.cpp +++ b/src/splashpack.cpp @@ -192,16 +192,39 @@ void SplashPackLoader::LoadSplashpack(uint8_t *data, SplashpackSceneSetup &setup for (uint16_t i = 0; i < header->textureAtlasCount; i++) { psxsplash::SPLASHPACKTextureAtlas *atlas = reinterpret_cast(cursor); uint8_t *offsetData = data + atlas->polygonsOffset; - uint16_t *castedData = reinterpret_cast(offsetData); - psxsplash::Renderer::GetInstance().VramUpload(castedData, atlas->x, atlas->y, atlas->width, atlas->height); + // Ensure 4-byte alignment for DMA transfer. If the exporter + // produced an unaligned offset, copy to an aligned temporary. + uint32_t pixelBytes = (uint32_t)atlas->width * atlas->height * 2; + if (reinterpret_cast(offsetData) & 3) { + uint8_t* aligned = new uint8_t[(pixelBytes + 3) & ~3]; + __builtin_memcpy(aligned, offsetData, pixelBytes); + psxsplash::Renderer::GetInstance().VramUpload( + reinterpret_cast(aligned), atlas->x, atlas->y, atlas->width, atlas->height); + delete[] aligned; + } else { + psxsplash::Renderer::GetInstance().VramUpload( + reinterpret_cast(offsetData), atlas->x, atlas->y, atlas->width, atlas->height); + } cursor += sizeof(psxsplash::SPLASHPACKTextureAtlas); } for (uint16_t i = 0; i < header->clutCount; i++) { psxsplash::SPLASHPACKClut *clut = reinterpret_cast(cursor); uint8_t *clutOffset = data + clut->clutOffset; - psxsplash::Renderer::GetInstance().VramUpload((uint16_t *)clutOffset, clut->clutPackingX * 16, - clut->clutPackingY, clut->length, 1); + // Same alignment guard for CLUT data. + uint32_t clutBytes = (uint32_t)clut->length * 2; + if (reinterpret_cast(clutOffset) & 3) { + uint8_t* aligned = new uint8_t[(clutBytes + 3) & ~3]; + __builtin_memcpy(aligned, clutOffset, clutBytes); + psxsplash::Renderer::GetInstance().VramUpload( + reinterpret_cast(aligned), clut->clutPackingX * 16, + clut->clutPackingY, clut->length, 1); + delete[] aligned; + } else { + psxsplash::Renderer::GetInstance().VramUpload( + reinterpret_cast(clutOffset), clut->clutPackingX * 16, + clut->clutPackingY, clut->length, 1); + } cursor += sizeof(psxsplash::SPLASHPACKClut); } @@ -345,4 +368,4 @@ void SplashPackLoader::LoadSplashpack(uint8_t *data, SplashpackSceneSetup &setup } -} // namespace psxsplash +} // namespace psxsplash \ No newline at end of file