Skip to content

Commit ca49707

Browse files
committed
Fixed the libc HSSImpl on big endian CPUs
Tested and coded on my iMac G5 running Arch POWER
1 parent 0aedada commit ca49707

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ option(BUILD_WITH_RES "Build with the resource file (Windows Compiler Only)" ON)
2222

2323
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -MD")
2424

25+
include(TestBigEndian)
26+
TEST_BIG_ENDIAN(BIG_ENDIAN)
27+
if (BIG_ENDIAN)
28+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBIG_ENDIAN")
29+
endif()
30+
2531
if(
2632
NOT IMPL STREQUAL "DJGPP"
2733
AND

src/impl/highScore/libc.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ unsigned int hssImpl_get() {
5959
}
6060

6161
void hssImpl_set(const unsigned int highScore) {
62+
#ifdef BIG_ENDIAN
63+
unsigned char i;
64+
unsigned char hsByte[4];
65+
#endif
66+
6267
if (fileStatus == FILE_BROKEN) {
6368
fprintf(stderr, HSSIMPL_STRING_FILE_NOTVALID);
6469
return;
@@ -73,12 +78,24 @@ void hssImpl_set(const unsigned int highScore) {
7378
return;
7479
}
7580
fprintf(file, HSSIMPL_SIGNATURE);
81+
#ifdef BIG_ENDIAN
82+
for (i = 0; i < 4; i++) {
83+
hsByte[i] = highScore >> i * 8;
84+
fwrite(
85+
&hsByte[i],
86+
1,
87+
sizeof(unsigned char),
88+
file
89+
);
90+
}
91+
#else
7692
fwrite(
7793
&highScore,
7894
1,
7995
sizeof(unsigned int),
8096
file
8197
);
98+
#endif
8299
fflush(file);
83100
}
84101
return;

0 commit comments

Comments
 (0)