Use SDL byte-swapping macros

This commit is contained in:
kichikuou
2021-01-17 21:35:27 +09:00
parent 29c85aad36
commit 4e2d81cf47
6 changed files with 12 additions and 35 deletions
-3
View File
@@ -46,9 +46,6 @@ elseif (ANDROID)
find_library(ndk_zlib z) find_library(ndk_zlib z)
find_library(ndk_log log) find_library(ndk_log log)
else() else()
include(TestBigEndian)
TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
if (NOT DEFINED ENABLE_MODULES) if (NOT DEFINED ENABLE_MODULES)
set(ENABLE_MODULES 1) set(ENABLE_MODULES 1)
endif() endif()
-2
View File
@@ -3,8 +3,6 @@
#cmakedefine CMAKE_SYSTEM_NAME "@CMAKE_SYSTEM_NAME@" #cmakedefine CMAKE_SYSTEM_NAME "@CMAKE_SYSTEM_NAME@"
#cmakedefine WORDS_BIGENDIAN @WORDS_BIGENDIAN@
#cmakedefine CACHE_TOTALSIZE @CACHE_TOTALSIZE@ #cmakedefine CACHE_TOTALSIZE @CACHE_TOTALSIZE@
#cmakedefine ENABLE_CDROM_ANDROID @ENABLE_CDROM_ANDROID@ #cmakedefine ENABLE_CDROM_ANDROID @ENABLE_CDROM_ANDROID@
+1 -5
View File
@@ -166,11 +166,7 @@ void commandLL() {
num = dfile->size / sizeof(WORD); num = dfile->size / sizeof(WORD);
} }
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
#ifdef WORDS_BIGENDIAN var[i] = SDL_SwapLE16(data[i]);
*var = swap16(*data); var++; data++;
#else
*var = *data; var++; data++;
#endif
} }
break; break;
-6
View File
@@ -87,12 +87,6 @@ typedef _Bool ___boolean;
# define N_(String) (String) # define N_(String) (String)
#endif #endif
#define swap16(a) ( (((a) & 0xff) << 8) | ((unsigned short)(a) >> 8) )
#define swap32(a) ( ((a) << 24) | \
(((a) << 8) & 0x00ff0000) | \
(((a) >> 8) & 0x0000ff00) | \
((unsigned int)(a) >>24) )
#ifndef __EMSCRIPTEN__ #ifndef __EMSCRIPTEN__
#define EMSCRIPTEN_KEEPALIVE #define EMSCRIPTEN_KEEPALIVE
#endif #endif
+9 -17
View File
@@ -80,9 +80,9 @@ int save_delete_file(int index) {
int save_save_var_with_file(char *fname_utf8, int *start, int cnt) { int save_save_var_with_file(char *fname_utf8, int *start, int cnt) {
int status = 0, size, i; int status = 0, size, i;
FILE *fp; FILE *fp;
WORD *tmp, *_tmp; WORD *tmp;
tmp = _tmp = (WORD *)malloc(cnt * sizeof(WORD)); tmp = (WORD *)malloc(cnt * sizeof(WORD));
if (tmp == NULL) { if (tmp == NULL) {
WARNING("Out of memory\n"); WARNING("Out of memory\n");
@@ -90,18 +90,14 @@ int save_save_var_with_file(char *fname_utf8, int *start, int cnt) {
} }
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {
#ifdef WORDS_BIGENDIAN tmp[i] = SDL_SwapLE16((WORD)start[i]);
*tmp = swap16((WORD)*start); start++; tmp++;
#else
*tmp = (WORD)*start; start++; tmp++;
#endif
} }
if (NULL == (fp = fc_open(fname_utf8, 'w'))) { if (NULL == (fp = fc_open(fname_utf8, 'w'))) {
status = SAVE_SAVEERR; goto errexit; status = SAVE_SAVEERR; goto errexit;
} }
size = fwrite(_tmp, sizeof(WORD), cnt, fp); size = fwrite(tmp, sizeof(WORD), cnt, fp);
if (size != cnt) { if (size != cnt) {
status = SAVE_OTHERERR; status = SAVE_OTHERERR;
@@ -112,7 +108,7 @@ int save_save_var_with_file(char *fname_utf8, int *start, int cnt) {
fclose(fp); fclose(fp);
scheduleSync(); scheduleSync();
errexit: errexit:
free(_tmp); free(tmp);
return status; return status;
} }
@@ -121,9 +117,9 @@ int save_save_var_with_file(char *fname_utf8, int *start, int cnt) {
int save_load_var_with_file(char *fname_utf8, int *start, int cnt) { int save_load_var_with_file(char *fname_utf8, int *start, int cnt) {
int status = 0, size, i; int status = 0, size, i;
FILE *fp; FILE *fp;
WORD *tmp, *_tmp; WORD *tmp;
tmp = _tmp = (WORD *)malloc(cnt * sizeof(WORD)); tmp = (WORD *)malloc(cnt * sizeof(WORD));
if (tmp == NULL) { if (tmp == NULL) {
WARNING("Out of memory\n"); WARNING("Out of memory\n");
@@ -143,16 +139,12 @@ int save_load_var_with_file(char *fname_utf8, int *start, int cnt) {
} }
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {
#ifdef WORDS_BIGENDIAN start[i] = SDL_SwapLE16(tmp[i]);
*start = swap16(*tmp); start++; tmp++;
#else
*start = *tmp; start++; tmp++;
#endif
} }
fclose(fp); fclose(fp);
errexit: errexit:
free(_tmp); free(tmp);
return status; return status;
} }
+2 -2
View File
@@ -248,7 +248,7 @@ void sdl_copyAreaSP16_shadow(int sx, int sy, int w, int h, int dx, int dy, int l
SDL_LockSurface(s); SDL_LockSurface(s);
#ifndef WORDS_BIGENDIAN #if SDL_BYTEORDER == SDL_LTL_ENDIAN
p_ds = s->pixels + 3; p_ds = s->pixels + 3;
#else #else
p_ds = s->pixels; p_ds = s->pixels;
@@ -347,7 +347,7 @@ void sdl_getPixel(int x, int y, Palette *cell) {
} }
break; break;
case 3: case 3:
#ifndef WORDS_BIGENDIAN #if SDL_BYTEORDER == SDL_LTL_ENDIAN
cl = (p[2]<<16)+(p[1]<<8) + p[0]; cl = (p[2]<<16)+(p[1]<<8) + p[0];
#else #else
cl = (p[0]<<16)+(p[1]<<8) + p[2]; cl = (p[0]<<16)+(p[1]<<8) + p[2];