TheForceEngine icon indicating copy to clipboard operation
TheForceEngine copied to clipboard

Big endian fixes

Open BSzili opened this issue 2 years ago • 6 comments

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.

BSzili avatar Jul 02 '23 19:07 BSzili

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?

mlauss2 avatar Jul 05 '23 06:07 mlauss2

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 avatar Jul 05 '23 16:07 BSzili

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.

BSzili avatar Jul 05 '23 17:07 BSzili

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?

mlauss2 avatar Aug 03 '23 08:08 mlauss2

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 avatar Aug 03 '23 12:08 BSzili

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

BSzili avatar Aug 16 '23 07:08 BSzili