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 fixes #282

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Big endian fixes #282

wants to merge 3 commits into from

Conversation

BSzili
Copy link

@BSzili BSzili commented Jul 2, 2023

I started working on porting TFE to big endian systems. I focused mostly on loading the original game data, editor-only features were not tested. This should allow TFE to run on various alternate systems, like PS3, XB360, Wii, WiiU, Amiga and its derivatives.
To avoid reinventing the wheel I wrapped SDL_endian.h in a header (TFE_System/endian.h), so it can be replaced with custom implementations if necessary.

@mlauss2
Copy link
Contributor

mlauss2 commented Jul 5, 2023

Great idea! What do you think about calling the functions "readLE32()" or similar (or le32_to_cpu() like Linux kernel uses), to indicate to the casual code reader that the attempt is to read 32-bit little-endian formatted data into host cpu endianness?

@BSzili
Copy link
Author

BSzili commented Jul 5, 2023

The name readLE32 implies some kind of I/O for me, also these functions are used for saving too, e.g. for DARKPILO.CFG. I didn't put much tought into the naming convention though, just copied what they are called in SDL2, so le32_to_cpu and co are fine by me. I'll look up how they are named in the linux kernel and replace them here.

@BSzili
Copy link
Author

BSzili commented Jul 5, 2023

I renamed the functions and rebased the PR. The float variants had no Linux kernel equivalents, so I took some liberties there. Let me know what you think.

for (s32 i = 0; i < 140; i++)
{
saveData->ammo[i] = TFE_Endian::le32_to_cpu(saveData->ammo[i]);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's written to file, shouldn't these all be "cpu_to_le32()" ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, I'll add the reverse to the header for some syntactic sugar.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just looked closer at this function: it's used for the darkpilo.cfg file which is created by TFE, therefore you don't need any endianness conversion.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I added byteswaps here so that people can continue where they left off in the dos version. It's also easy to copy this file along with the rest of the game data which can lead to confusion if it doesn't just work.

@mlauss2
Copy link
Contributor

mlauss2 commented Aug 3, 2023

I compared the disassembly in a few places and at least on x86 all your changes are simply optimized away by the compiler, so good job :)
What system did you test this on? Are the saves of BE and LE compatible?

@BSzili
Copy link
Author

BSzili commented Aug 3, 2023

I'm working on a custom Amiga port, TFE's own formats are currently not endian swapped, but I can add it there as well.

@BSzili
Copy link
Author

BSzili commented Aug 16, 2023

Just rebased this to the latest head. Let me know if there's anything else I should change/add before it can be merged.

@mlauss2 mlauss2 mentioned this pull request Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants