1
0
Fork 0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-12-18 18:37:55 +01:00

Big endian port is here!

This commit is contained in:
grepwood@sucs.org 2021-11-05 00:39:36 +01:00
parent 5947727f80
commit 5660bc3ebf
7 changed files with 97 additions and 4 deletions

View file

@ -4,7 +4,7 @@ project(SpaceCadetPinball)
set(CMAKE_CXX_STANDARD 11) 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") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMakeModules")

View file

@ -9,6 +9,14 @@
#include "pinball.h" #include "pinball.h"
#include "zdrv.h" #include "zdrv.h"
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# if defined(__GNUC__) && defined(linux)
# include <byteswap.h>
# 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() EntryData::~EntryData()
{ {
@ -291,6 +299,11 @@ void DatFile::Finalize()
// Load 3DPB font into dat to simplify pipeline // Load 3DPB font into dat to simplify pipeline
auto rcData = reinterpret_cast<MsgFont*>(ImFontAtlas::DecompressCompressedBase85Data( auto rcData = reinterpret_cast<MsgFont*>(ImFontAtlas::DecompressCompressedBase85Data(
EmbeddedData::PB_MSGFT_bin_compressed_data_base85)); 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"); AddMsgFont(rcData, "pbmsg_ft");
IM_FREE(rcData); IM_FREE(rcData);

View file

@ -39,6 +39,7 @@ enum class FieldTypes : int16_t
// Sprite depth map, 16bpp, unsigned // Sprite depth map, 16bpp, unsigned
Bitmap16bit = 12, Bitmap16bit = 12,
Debug = 13,
}; };
struct EntryData struct EntryData

View file

@ -37,7 +37,6 @@ TBall::TBall(TPinballTable* table) : TPinballComponent(table, -1, false)
if (pb::FullTiltMode) if (pb::FullTiltMode)
ballGroupName[4] = '0' + fullscrn::GetResolution(); ballGroupName[4] = '0' + fullscrn::GetResolution();
auto groupIndex = loader::query_handle(ballGroupName); auto groupIndex = loader::query_handle(ballGroupName);
Offset = *loader::query_float_attribute(groupIndex, 0, 500); Offset = *loader::query_float_attribute(groupIndex, 0, 500);
auto visualCount = loader::query_visual_states(groupIndex); auto visualCount = loader::query_visual_states(groupIndex);
auto index = 0; auto index = 0;

View file

@ -11,10 +11,17 @@ enum class BitmapTypes : uint8_t
struct Rgba 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 Blue;
uint8_t Green; uint8_t Green;
uint8_t Red; uint8_t Red;
uint8_t Alpha; uint8_t Alpha;
#endif
}; };
union ColorRgba union ColorRgba

View file

@ -6,6 +6,14 @@
#include "Sound.h" #include "Sound.h"
#include "zdrv.h" #include "zdrv.h"
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# if defined(__GNUC__) && defined(linux)
# include <byteswap.h>
# 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 loader::loader_errors[] =
{ {
@ -85,7 +93,6 @@ void loader::loadfrom(DatFile* datFile)
{ {
loader_table = datFile; loader_table = datFile;
sound_record_table = loader_table; sound_record_table = loader_table;
for (auto groupIndex = 0; groupIndex < static_cast<int>(datFile->Groups.size()); ++groupIndex) for (auto groupIndex = 0; groupIndex < static_cast<int>(datFile->Groups.size()); ++groupIndex)
{ {
auto value = reinterpret_cast<int16_t*>(datFile->field(groupIndex, FieldTypes::ShortValue)); auto value = reinterpret_cast<int16_t*>(datFile->field(groupIndex, FieldTypes::ShortValue));

View file

@ -5,6 +5,15 @@
#include "GroupData.h" #include "GroupData.h"
#include "zdrv.h" #include "zdrv.h"
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# if defined(__GNUC__) && defined(linux)
# include <byteswap.h>
# 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[] = short partman::_field_size[] =
{ {
2, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0 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; return nullptr;
fread(&header, 1, sizeof header, fileHandle); 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) if (strcmp("PARTOUT(4.0)RESOURCE", header.FileSignature) != 0)
{ {
fclose(fileHandle); fclose(fileHandle);
@ -65,12 +80,26 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode)
entryData->EntryType = entryType; entryData->EntryType = entryType;
int fixedSize = _field_size[static_cast<int>(entryType)]; int fixedSize = _field_size[static_cast<int>(entryType)];
size_t fieldSize = fixedSize >= 0 ? fixedSize : LRead<uint32_t>(fileHandle); size_t fieldSize;
if(fixedSize >= 0) fieldSize = fixedSize;
else {
fieldSize = LRead<uint32_t>(fileHandle);
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
fieldSize = scp_bswap32(fieldSize);
#endif //__BIG_ENDIAN
}
entryData->FieldSize = static_cast<int>(fieldSize); entryData->FieldSize = static_cast<int>(fieldSize);
if (entryType == FieldTypes::Bitmap8bit) if (entryType == FieldTypes::Bitmap8bit)
{ {
fread(&bmpHeader, 1, sizeof(dat8BitBmpHeader), fileHandle); 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.Size + sizeof(dat8BitBmpHeader) == fieldSize, "partman: Wrong bitmap field size");
assertm(bmpHeader.Resolution <= 2, "partman: bitmap resolution out of bounds"); 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); 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 length = fieldSize - sizeof(dat16BitBmpHeader);
auto zMap = new zmap_header_type(zMapHeader.Width, zMapHeader.Height, zMapHeader.Stride); 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) if (zMapHeader.Stride * zMapHeader.Height * 2u == length)
{ {
fread(zMap->ZPtr1, 1, length, fileHandle); 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 else
{ {
@ -115,6 +158,29 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode)
break; break;
} }
fread(entryBuffer, 1, fieldSize, fileHandle); 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); groupData->AddEntry(entryData);