Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Big endian port is here! #83

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
12 changes: 12 additions & 0 deletions SpaceCadetPinball/GroupData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
#include "pinball.h"
#include "zdrv.h"

#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# if defined(__GNUC__) && defined(linux)
# include <byteswap.h>
# define scp_bswap32(x) __bswap_32(x)
# define scp_bswap16(x) __bswap_16(x)
# endif //__GNUC__ && linux
#endif

EntryData::~EntryData()
{
Expand Down Expand Up @@ -291,6 +298,11 @@ void DatFile::Finalize()
// Load 3DPB font into dat to simplify pipeline
auto rcData = reinterpret_cast<MsgFont*>(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);

Expand Down
7 changes: 7 additions & 0 deletions SpaceCadetPinball/gdrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 66 additions & 1 deletion SpaceCadetPinball/partman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
#include "GroupData.h"
#include "zdrv.h"

#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# if defined(__GNUC__) && defined(linux)
# include <byteswap.h>
# 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
Expand All @@ -21,6 +29,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);
Expand Down Expand Up @@ -65,12 +79,26 @@ DatFile* partman::load_records(LPCSTR lpFileName, bool fullTiltMode)
entryData->EntryType = 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);

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");

Expand All @@ -90,13 +118,27 @@ 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);
zMap->Resolution = zMapResolution;
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
{
Expand All @@ -115,6 +157,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);
Expand Down