From 5660bc3ebf75ee00d616b7e951b3c4d1bdd274b2 Mon Sep 17 00:00:00 2001 From: "grepwood@sucs.org" Date: Fri, 5 Nov 2021 00:39:36 +0100 Subject: [PATCH 1/6] 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 d729de1c9..a48194a06 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 5ef254281..54a3d7ddf 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 63d670d18..340f70fba 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 25dd48fec..db27e43b6 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 e0da784b9..218d85171 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 4b68880dc..bfd06a1e0 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 5c89df986..3348c92b2 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); From 641551a065912bb1d77c5f0533775ef5f22e549f Mon Sep 17 00:00:00 2001 From: "grepwood@sucs.org" Date: Sun, 7 Nov 2021 03:08:02 +0100 Subject: [PATCH 2/6] Reverting pointless addition of BE logic to loader.cpp --- SpaceCadetPinball/loader.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/SpaceCadetPinball/loader.cpp b/SpaceCadetPinball/loader.cpp index bfd06a1e0..7f3e9dab9 100644 --- a/SpaceCadetPinball/loader.cpp +++ b/SpaceCadetPinball/loader.cpp @@ -6,15 +6,6 @@ #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[] = { errorMsg{0, "Bad Handle"}, @@ -93,6 +84,7 @@ 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)); From dcde9b3d5a6299fcc47d7ae1372bf2439034683c Mon Sep 17 00:00:00 2001 From: "grepwood@sucs.org" Date: Sun, 7 Nov 2021 03:08:33 +0100 Subject: [PATCH 3/6] Reducing diff --- SpaceCadetPinball/loader.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/SpaceCadetPinball/loader.cpp b/SpaceCadetPinball/loader.cpp index 7f3e9dab9..4b68880dc 100644 --- a/SpaceCadetPinball/loader.cpp +++ b/SpaceCadetPinball/loader.cpp @@ -6,6 +6,7 @@ #include "Sound.h" #include "zdrv.h" + errorMsg loader::loader_errors[] = { errorMsg{0, "Bad Handle"}, From b81b1a04965b255ce2c36b23ffe9f16ea23f4a7a Mon Sep 17 00:00:00 2001 From: "grepwood@sucs.org" Date: Sun, 7 Nov 2021 03:09:37 +0100 Subject: [PATCH 4/6] Reducing diff --- SpaceCadetPinball/TBall.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/SpaceCadetPinball/TBall.cpp b/SpaceCadetPinball/TBall.cpp index db27e43b6..25dd48fec 100644 --- a/SpaceCadetPinball/TBall.cpp +++ b/SpaceCadetPinball/TBall.cpp @@ -37,6 +37,7 @@ 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; From 12faca37d7e82401e8733e3461e9202aaead392a Mon Sep 17 00:00:00 2001 From: "grepwood@sucs.org" Date: Sun, 7 Nov 2021 03:15:17 +0100 Subject: [PATCH 5/6] Not needed, debugging finished --- SpaceCadetPinball/GroupData.h | 1 - 1 file changed, 1 deletion(-) diff --git a/SpaceCadetPinball/GroupData.h b/SpaceCadetPinball/GroupData.h index 340f70fba..63d670d18 100644 --- a/SpaceCadetPinball/GroupData.h +++ b/SpaceCadetPinball/GroupData.h @@ -39,7 +39,6 @@ enum class FieldTypes : int16_t // Sprite depth map, 16bpp, unsigned Bitmap16bit = 12, - Debug = 13, }; struct EntryData From 86cf13d57d93b02eeda0b1788411d14d6e19a2a9 Mon Sep 17 00:00:00 2001 From: "grepwood@sucs.org" Date: Sun, 7 Nov 2021 03:17:47 +0100 Subject: [PATCH 6/6] Removed unused swap types --- SpaceCadetPinball/GroupData.cpp | 1 - SpaceCadetPinball/partman.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/SpaceCadetPinball/GroupData.cpp b/SpaceCadetPinball/GroupData.cpp index 54a3d7ddf..fbdf6b47e 100644 --- a/SpaceCadetPinball/GroupData.cpp +++ b/SpaceCadetPinball/GroupData.cpp @@ -12,7 +12,6 @@ #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 diff --git a/SpaceCadetPinball/partman.cpp b/SpaceCadetPinball/partman.cpp index 3348c92b2..d0a631edb 100644 --- a/SpaceCadetPinball/partman.cpp +++ b/SpaceCadetPinball/partman.cpp @@ -8,7 +8,6 @@ #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