summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ca64d41)
raw | patch | inline | side by side (parent: ca64d41)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Tue, 6 Apr 2021 09:54:14 +0000 (12:54 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Tue, 6 Apr 2021 09:54:14 +0000 (12:54 +0300) |
src/common/endianness.h | [new file with mode: 0644] | patch | blob |
src/common/streams.c | patch | blob | history | |
src/gl/render.c | patch | blob | history | |
src/misc.h | patch | blob | history | |
src/miscc.c | patch | blob | history | |
src/my.c | patch | blob | history | |
src/openal/sound.c | patch | blob | history | |
src/sdlmixer/sound.c | patch | blob | history | |
src/soft/vga.c | patch | blob | history |
diff --git a/src/common/endianness.h b/src/common/endianness.h
--- /dev/null
+++ b/src/common/endianness.h
@@ -0,0 +1,47 @@
+#ifndef COMMON_ENDIANNESS_H_INCLUDED
+#define COMMON_ENDIANNESS_H_INCLUDED
+
+#include <stdint.h>
+
+#define SWAP_VAR(a, b) do { unsigned char t = a; a = b; b = t; } while(0)
+
+static inline int16_t short2swap (int16_t x) {
+ union {
+ uint8_t a[2];
+ int16_t x;
+ } y;
+ y.x = x;
+ SWAP_VAR(y.a[0], y.a[1]);
+ return y.x;
+}
+
+static inline int32_t int2swap (int32_t x) {
+ union {
+ uint8_t a[4];
+ int32_t x;
+ } y;
+ y.x = x;
+ SWAP_VAR(y.a[0], y.a[3]);
+ SWAP_VAR(y.a[1], y.a[2]);
+ return y.x;
+}
+
+#undef SWAP_VAR
+
+static inline int16_t short2host (int16_t x) {
+#if __BIG_ENDIAN__
+ return short2swap(x);
+#else
+ return x;
+#endif
+}
+
+static inline int32_t int2host (int32_t x) {
+#if __BIG_ENDIAN__
+ return int2swap(x);
+#else
+ return x;
+#endif
+}
+
+#endif /* COMMON_ENDIANNESS_H_INCLUDED */
\ No newline at end of file
diff --git a/src/common/streams.c b/src/common/streams.c
index 615274cb98d63e738df275307fb3bd642e7666bd..46e756b18b66acf0d36f93022f696ef8327639f0 100644 (file)
--- a/src/common/streams.c
+++ b/src/common/streams.c
-#include "streams.h"
+#include "common/streams.h"
+#include "common/endianness.h"
#include <stddef.h>
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
-#include "misc.h" // endianness conversion
-
void stream_read (void *data, size_t size, size_t n, Reader *r) {
r->read(r, data, size, n);
}
void stream_read (void *data, size_t size, size_t n, Reader *r) {
r->read(r, data, size, n);
}
diff --git a/src/gl/render.c b/src/gl/render.c
index 948a7b5cc8d3abb22ffd6484fde0957fa3c0d201..e29dd232c40cfd39ff164ab81e1483e17d710948 100644 (file)
--- a/src/gl/render.c
+++ b/src/gl/render.c
#include "switch.h" // sw_secrets
#include "cp866.h"
#include "switch.h" // sw_secrets
#include "cp866.h"
+#include "common/endianness.h"
#ifdef __APPLE__
# include <OpenGL/gl.h>
#ifdef __APPLE__
# include <OpenGL/gl.h>
diff --git a/src/misc.h b/src/misc.h
index 20ec63016cfc56393d034b73a17bd70116ef5529..b863460c2c70b6ab63170f5afe27665df1f22e98 100644 (file)
--- a/src/misc.h
+++ b/src/misc.h
void Z_splash (obj_t *p, int n);
void Z_calc_time(dword t, word *h, word *m, word *s);
void Z_splash (obj_t *p, int n);
void Z_calc_time(dword t, word *h, word *m, word *s);
-int16_t short2host (int16_t x);
-int32_t int2host (int32_t x);
-
#endif /* MISC_H_INCLUDED */
#endif /* MISC_H_INCLUDED */
diff --git a/src/miscc.c b/src/miscc.c
index b2bbbaf585fc6b082e8350228a3cee7b2405acb0..184e369b7ea7f8637d3f3831e30b381f544250d4 100644 (file)
--- a/src/miscc.c
+++ b/src/miscc.c
t = t / 60;
*h = t;
}
t = t / 60;
*h = t;
}
-
-#define SWAP_VAR(a, b) do { unsigned char t = a; a = b; b = t; } while(0)
-
-static int16_t short2swap (int16_t x) {
- union {
- uint8_t a[2];
- int16_t x;
- } y;
- y.x = x;
- SWAP_VAR(y.a[0], y.a[1]);
- return y.x;
-}
-
-static int32_t int2swap (int32_t x) {
- union {
- uint8_t a[4];
- int32_t x;
- } y;
- y.x = x;
- SWAP_VAR(y.a[0], y.a[3]);
- SWAP_VAR(y.a[1], y.a[2]);
- return y.x;
-}
-
-#undef SWAP_VAR
-
-int16_t short2host (int16_t x) {
-#if __BIG_ENDIAN__
- return short2swap(x);
-#else
- return x;
-#endif
-}
-
-int32_t int2host (int32_t x) {
-#if __BIG_ENDIAN__
- return int2swap(x);
-#else
- return x;
-#endif
-}
diff --git a/src/my.c b/src/my.c
index b3eb964f476a95f2cfba3e0e71b1995812468999..a7adf3c5c0087bb1294034f5e8d3ddda274846f4 100644 (file)
--- a/src/my.c
+++ b/src/my.c
#include "glob.h"
#include "error.h"
#include "glob.h"
#include "error.h"
-#include "misc.h"
+#include "common/endianness.h"
+
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
diff --git a/src/openal/sound.c b/src/openal/sound.c
index 8d0b342c4ff656dee368401530f64946d9e4d98a..7bb60a0933b0145b63a7d4a70054e06f4db5af75 100644 (file)
--- a/src/openal/sound.c
+++ b/src/openal/sound.c
#include "files.h" // F_findres F_getreslen
#include "memory.h" // M_lock M_unlock
#include "files.h" // F_findres F_getreslen
#include "memory.h" // M_lock M_unlock
-#include "misc.h" // int2host
#include "error.h" // logo
#include "error.h" // logo
+#include "common/endianness.h"
+
#ifdef __APPLE__
# include <OpenAL/al.h>
# include <OpenAL/alc.h>
#ifdef __APPLE__
# include <OpenAL/al.h>
# include <OpenAL/alc.h>
diff --git a/src/sdlmixer/sound.c b/src/sdlmixer/sound.c
index ec27e45f373387512c6e2422220d4c5866ee63a6..a5da8c5aecc272b00b3b69297881e90cf02b8b06 100644 (file)
--- a/src/sdlmixer/sound.c
+++ b/src/sdlmixer/sound.c
#include "glob.h"
#include "sound.h"
#include "music.h"
#include "glob.h"
#include "sound.h"
#include "music.h"
-#include "misc.h" // int2host
#include "memory.h" // M_lock M_unlock
#include "files.h" // F_findres
#include "error.h"
#include "memory.h" // M_lock M_unlock
#include "files.h" // F_findres
#include "error.h"
+#include "common/endianness.h"
+
#include "SDL.h"
#include "SDL_mixer.h"
#include <assert.h>
#include "SDL.h"
#include "SDL_mixer.h"
#include <assert.h>
diff --git a/src/soft/vga.c b/src/soft/vga.c
index 63b5f65b7f104ef2204b2058a6dfb6c6fe9266fa..5f9078533aea39957dfa1c9ae8acaaabbb7010da 100644 (file)
--- a/src/soft/vga.c
+++ b/src/soft/vga.c
#include "files.h"
#include "system.h"
#include "files.h"
#include "system.h"
+#include "common/endianness.h"
+
#include <string.h>
#include <assert.h>
#include <string.h>
#include <assert.h>