From 5660bc3ebf75ee00d616b7e951b3c4d1bdd274b2 Mon Sep 17 00:00:00 2001 From: "grepwood@sucs.org" Date: Fri, 5 Nov 2021 00:39:36 +0100 Subject: [PATCH] Big endian port is here! --- CMakeLists.txt | 2 +- SpaceCadetPinball/GroupData.cpp | 13 +++++++ SpaceCadetPinball/GroupData.h | 1 + SpaceCadetPinball/TBall.cpp | 1 - SpaceCadetPinball/gdrv.h | 7 ++++ SpaceCadetPinball/loader.cpp | 9 ++++- SpaceCadetPinball/partman.cpp | 68 ++++++++++++++++++++++++++++++++- 7 files changed, 97 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d729de1..a48194a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(SpaceCadetPinball) set(CMAKE_CXX_STANDARD 11) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/bin) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/bin-${CMAKE_HOST_SYSTEM_PROCESSOR}) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMakeModules") diff --git a/SpaceCadetPinball/GroupData.cpp b/SpaceCadetPinball/GroupData.cpp index 5ef2542..54a3d7d 100644 --- a/SpaceCadetPinball/GroupData.cpp +++ b/SpaceCadetPinball/GroupData.cpp @@ -9,6 +9,14 @@ #include "pinball.h" #include "zdrv.h" +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# if defined(__GNUC__) && defined(linux) +# include +# define scp_bswap64(x) __bswap_64(x) +# define scp_bswap32(x) __bswap_32(x) +# define scp_bswap16(x) __bswap_16(x) +# endif //__GNUC__ && linux +#endif EntryData::~EntryData() { @@ -291,6 +299,11 @@ void DatFile::Finalize() // Load 3DPB font into dat to simplify pipeline auto rcData = reinterpret_cast(ImFontAtlas::DecompressCompressedBase85Data( EmbeddedData::PB_MSGFT_bin_compressed_data_base85)); +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + rcData->GapWidth = scp_bswap16(rcData->GapWidth); + rcData->Unknown1 = scp_bswap16(rcData->Unknown1); + rcData->Height = scp_bswap16(rcData->Height); +#endif //__BIG_ENDIAN__ AddMsgFont(rcData, "pbmsg_ft"); IM_FREE(rcData); diff --git a/SpaceCadetPinball/GroupData.h b/SpaceCadetPinball/GroupData.h index 63d670d..340f70f 100644 --- a/SpaceCadetPinball/GroupData.h +++ b/SpaceCadetPinball/GroupData.h @@ -39,6 +39,7 @@ enum class FieldTypes : int16_t // Sprite depth map, 16bpp, unsigned Bitmap16bit = 12, + Debug = 13, }; struct EntryData diff --git a/SpaceCadetPinball/TBall.cpp b/SpaceCadetPinball/TBall.cpp index 25dd48f..db27e43 100644 --- a/SpaceCadetPinball/TBall.cpp +++ b/SpaceCadetPinball/TBall.cpp @@ -37,7 +37,6 @@ TBall::TBall(TPinballTable* table) : TPinballComponent(table, -1, false) if (pb::FullTiltMode) ballGroupName[4] = '0' + fullscrn::GetResolution(); auto groupIndex = loader::query_handle(ballGroupName); - Offset = *loader::query_float_attribute(groupIndex, 0, 500); auto visualCount = loader::query_visual_states(groupIndex); auto index = 0; diff --git a/SpaceCadetPinball/gdrv.h b/SpaceCadetPinball/gdrv.h index e0da784..218d851 100644 --- a/SpaceCadetPinball/gdrv.h +++ b/SpaceCadetPinball/gdrv.h @@ -11,10 +11,17 @@ enum class BitmapTypes : uint8_t struct Rgba { +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + uint8_t Alpha; + uint8_t Red; + uint8_t Green; + uint8_t Blue; +#else uint8_t Blue; uint8_t Green; uint8_t Red; uint8_t Alpha; +#endif }; union ColorRgba diff --git a/SpaceCadetPinball/loader.cpp b/SpaceCadetPinball/loader.cpp index 4b68880..bfd06a1 100644 --- a/SpaceCadetPinball/loader.cpp +++ b/SpaceCadetPinball/loader.cpp @@ -6,6 +6,14 @@ #include "Sound.h" #include "zdrv.h" +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# if defined(__GNUC__) && defined(linux) +# include +# define scp_bswap64(x) __bswap_64(x) +# define scp_bswap32(x) __bswap_32(x) +# define scp_bswap16(x) __bswap_16(x) +# endif //__GNUC__ && linux +#endif errorMsg loader::loader_errors[] = { @@ -85,7 +93,6 @@ void loader::loadfrom(DatFile* datFile) { loader_table = datFile; sound_record_table = loader_table; - for (auto groupIndex = 0; groupIndex < static_cast(datFile->Groups.size()); ++groupIndex) { auto value = reinterpret_cast(datFile->field(groupIndex, FieldTypes::ShortValue)); diff --git a/SpaceCadetPinball/partman.cpp b/SpaceCadetPinball/partman.cpp index 5c89df9..3348c92 100644 --- a/SpaceCadetPinball/partman.cpp +++ b/SpaceCadetPinball/partman.cpp @@ -5,6 +5,15 @@ #include "GroupData.h" #include "zdrv.h" +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# if defined(__GNUC__) && defined(linux) +# include +# define scp_bswap64(x) __bswap_64(x) +# define scp_bswap32(x) __bswap_32(x) +# define scp_bswap16(x) __bswap_16(x) +# endif //__GNUC__ && linux +#endif + short partman::_field_size[] = { 2, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0 @@ -21,6 +30,12 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode) return nullptr; fread(&header, 1, sizeof header, fileHandle); +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + header.FileSize = scp_bswap32(header.FileSize); + header.NumberOfGroups = scp_bswap16(header.NumberOfGroups); + header.SizeOfBody = scp_bswap32(header.SizeOfBody); + header.Unknown = scp_bswap16(header.Unknown); +#endif if (strcmp("PARTOUT(4.0)RESOURCE", header.FileSignature) != 0) { fclose(fileHandle); @@ -65,12 +80,26 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode) entryData->EntryType = entryType; int fixedSize = _field_size[static_cast(entryType)]; - size_t fieldSize = fixedSize >= 0 ? fixedSize : LRead(fileHandle); + size_t fieldSize; + if(fixedSize >= 0) fieldSize = fixedSize; + else { + fieldSize = LRead(fileHandle); +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + fieldSize = scp_bswap32(fieldSize); +#endif //__BIG_ENDIAN + } entryData->FieldSize = static_cast(fieldSize); if (entryType == FieldTypes::Bitmap8bit) { fread(&bmpHeader, 1, sizeof(dat8BitBmpHeader), fileHandle); +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + bmpHeader.Width = scp_bswap16(bmpHeader.Width); + bmpHeader.Height = scp_bswap16(bmpHeader.Height); + bmpHeader.XPosition = scp_bswap16(bmpHeader.XPosition); + bmpHeader.YPosition = scp_bswap16(bmpHeader.YPosition); + bmpHeader.Size = scp_bswap32(bmpHeader.Size); +#endif //__BIG_ENDIAN__ assertm(bmpHeader.Size + sizeof(dat8BitBmpHeader) == fieldSize, "partman: Wrong bitmap field size"); assertm(bmpHeader.Resolution <= 2, "partman: bitmap resolution out of bounds"); @@ -90,6 +119,14 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode) } fread(&zMapHeader, 1, sizeof(dat16BitBmpHeader), fileHandle); +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + zMapHeader.Width = scp_bswap16(zMapHeader.Width); + zMapHeader.Height = scp_bswap16(zMapHeader.Height); + zMapHeader.Stride = scp_bswap16(zMapHeader.Stride); + zMapHeader.Unknown0 = scp_bswap32(zMapHeader.Unknown0); + zMapHeader.Unknown1_0 = scp_bswap16(zMapHeader.Unknown1_0); + zMapHeader.Unknown1_1 = scp_bswap16(zMapHeader.Unknown1_1); +#endif //__BIG_ENDIAN__ auto length = fieldSize - sizeof(dat16BitBmpHeader); auto zMap = new zmap_header_type(zMapHeader.Width, zMapHeader.Height, zMapHeader.Stride); @@ -97,6 +134,12 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode) if (zMapHeader.Stride * zMapHeader.Height * 2u == length) { fread(zMap->ZPtr1, 1, length, fileHandle); +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + int16_t * temporaryPointer = (int16_t *)zMap->ZPtr1; + for(size_t temporaryCounter = 0; temporaryCounter < length/2; ++temporaryCounter) { + temporaryPointer[temporaryCounter] = scp_bswap16(temporaryPointer[temporaryCounter]); + } +#endif } else { @@ -115,6 +158,29 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode) break; } fread(entryBuffer, 1, fieldSize, fileHandle); +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + if(entryType == FieldTypes::ShortValue) { + *((int16_t*)entryBuffer) = scp_bswap16(*((int16_t*)entryBuffer)); + } + if(entryType == FieldTypes::Palette) { + int32_t * temporaryPointer = (int32_t *)entryBuffer; + for(int16_t pixelCounter = 0; pixelCounter < 256; ++pixelCounter) { + temporaryPointer[pixelCounter] = scp_bswap32(temporaryPointer[pixelCounter]); + } + } + if(entryType == FieldTypes::ShortArray) { + int16_t * temporaryPointer = (int16_t *)entryBuffer; + for(size_t temporaryCounter = 0; temporaryCounter < fieldSize/2; ++temporaryCounter) { + temporaryPointer[temporaryCounter] = scp_bswap16(temporaryPointer[temporaryCounter]); + } + } + if(entryType == FieldTypes::FloatArray) { + int32_t * temporaryPointer = (int32_t *)entryBuffer; + for(size_t temporaryCounter = 0; temporaryCounter < fieldSize/4; ++temporaryCounter) { + temporaryPointer[temporaryCounter] = scp_bswap32(temporaryPointer[temporaryCounter]); + } + } +#endif } groupData->AddEntry(entryData);