annotate src/dmlib.h @ 2395:e149fc273f2b

Remove the __USE_MINGW_ANSI_STDIO hack.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 09 Jan 2020 21:14:18 +0200
parents 147d40b708ea
children bcd33c77c605
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * DMLib
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * -- Main header file
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * Programmed and designed by Matti 'ccr' Hamalainen
2361
c801995cbb13 Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 2353
diff changeset
5 * (C) Copyright 2011-2020 Tecnic Software productions (TNSP)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #ifndef DMLIB_H
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #define DMLIB_H
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
288
e2f286781180 Use more glanular header includes from SDL, enables us to succesfully link
Matti Hamalainen <ccr@tnsp.org>
parents: 265
diff changeset
10 #include <SDL_config.h>
e2f286781180 Use more glanular header includes from SDL, enables us to succesfully link
Matti Hamalainen <ccr@tnsp.org>
parents: 265
diff changeset
11 #include <SDL_endian.h>
e2f286781180 Use more glanular header includes from SDL, enables us to succesfully link
Matti Hamalainen <ccr@tnsp.org>
parents: 265
diff changeset
12 #include <SDL_types.h>
e2f286781180 Use more glanular header includes from SDL, enables us to succesfully link
Matti Hamalainen <ccr@tnsp.org>
parents: 265
diff changeset
13 #include <SDL_mutex.h>
781
e15e0469499a Add initial code for simulating audio playback while in no-sound situation.
Matti Hamalainen <ccr@tnsp.org>
parents: 770
diff changeset
14 #include <SDL_thread.h>
288
e2f286781180 Use more glanular header includes from SDL, enables us to succesfully link
Matti Hamalainen <ccr@tnsp.org>
parents: 265
diff changeset
15 #include <SDL_video.h>
1557
5e5f75b45f8d Initial port to SDL2. Many things will not work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1554
diff changeset
16 #include <SDL_render.h>
1554
7ed25973dbcb Add some missing includes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1453
diff changeset
17 #include <stdio.h>
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 #include <stdarg.h>
1554
7ed25973dbcb Add some missing includes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1453
diff changeset
19 #include <stdlib.h>
7ed25973dbcb Add some missing includes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1453
diff changeset
20 #include <ctype.h>
2392
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
21 #include <inttypes.h>
1554
7ed25973dbcb Add some missing includes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1453
diff changeset
22
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 #ifdef DM_USE_ASSERTS
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
25 # include <assert.h>
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 #else
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
27 # define assert(NEXPR) // stub
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
1046
7e54b2d08ce7 Add special debug error message function/macro that can be
Matti Hamalainen <ccr@tnsp.org>
parents: 980
diff changeset
30
1143
e7c3de96b6fd Check if we are compiling for Windows and if we are compiling under MINGW.
Matti Hamalainen <ccr@tnsp.org>
parents: 1106
diff changeset
31 // Check for arch bitness
e7c3de96b6fd Check if we are compiling for Windows and if we are compiling under MINGW.
Matti Hamalainen <ccr@tnsp.org>
parents: 1106
diff changeset
32 #if defined(__WIN64) || defined(_WIN64) || defined(_WIN32) || defined(__WIN32)
2394
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
33 # define DM_PLAT_WINDOWS 1
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
34 #else
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
35 # define DM_PLAT_UNIX 1
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
36 #endif
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
37
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
38 // Check for arch bitness
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
39 #if !defined(DM_ARCH) && (defined(__WIN64) || defined(_WIN64))
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
40 # define DM_ARCH 64
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
41 #endif
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
42
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
43 #if !defined(DM_ARCH) && (defined(__WIN32) || defined(_WIN32))
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
44 # define DM_ARCH 32
1143
e7c3de96b6fd Check if we are compiling for Windows and if we are compiling under MINGW.
Matti Hamalainen <ccr@tnsp.org>
parents: 1106
diff changeset
45 #endif
1145
af2c9f76c782 MinGW does not define PRI* format specifiers, so define them ourselves :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1143
diff changeset
46
af2c9f76c782 MinGW does not define PRI* format specifiers, so define them ourselves :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1143
diff changeset
47 #if !defined(DM_ARCH)
2394
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
48 # if UINTPTR_MAX == 0xffffffff
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
49 # define DM_ARCH 32
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
50 # elif UINTPTR_MAX == 0xffffffffffffffff
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
51 # define DM_ARCH 64
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
52 # endif
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
53 #endif
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
54
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
55
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
56 #if !defined(DM_ARCH)
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
57 # if defined(__LP64__) || defined(_LP64)
1145
af2c9f76c782 MinGW does not define PRI* format specifiers, so define them ourselves :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1143
diff changeset
58 # define DM_ARCH 64
af2c9f76c782 MinGW does not define PRI* format specifiers, so define them ourselves :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1143
diff changeset
59 # else
af2c9f76c782 MinGW does not define PRI* format specifiers, so define them ourselves :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1143
diff changeset
60 # define DM_ARCH 32
af2c9f76c782 MinGW does not define PRI* format specifiers, so define them ourselves :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1143
diff changeset
61 # endif
af2c9f76c782 MinGW does not define PRI* format specifiers, so define them ourselves :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1143
diff changeset
62 #endif
af2c9f76c782 MinGW does not define PRI* format specifiers, so define them ourselves :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1143
diff changeset
63
af2c9f76c782 MinGW does not define PRI* format specifiers, so define them ourselves :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1143
diff changeset
64
2385
5ffc48a0bebe Conditionally define DM_ATTR_PRINTF_FMT(xstart, xend) instead of using
Matti Hamalainen <ccr@tnsp.org>
parents: 2383
diff changeset
65 // Kludge, as MinGW64 cross-compiler does not like certain printf() format specifiers
5ffc48a0bebe Conditionally define DM_ATTR_PRINTF_FMT(xstart, xend) instead of using
Matti Hamalainen <ccr@tnsp.org>
parents: 2383
diff changeset
66 #if defined(__MINGW64__)
5ffc48a0bebe Conditionally define DM_ATTR_PRINTF_FMT(xstart, xend) instead of using
Matti Hamalainen <ccr@tnsp.org>
parents: 2383
diff changeset
67 # define DM_ATTR_PRINTF_FMT(xstart, xend)
5ffc48a0bebe Conditionally define DM_ATTR_PRINTF_FMT(xstart, xend) instead of using
Matti Hamalainen <ccr@tnsp.org>
parents: 2383
diff changeset
68 #else
5ffc48a0bebe Conditionally define DM_ATTR_PRINTF_FMT(xstart, xend) instead of using
Matti Hamalainen <ccr@tnsp.org>
parents: 2383
diff changeset
69 # define DM_ATTR_PRINTF_FMT(xstart, xend) __attribute__ ((__format__ (__printf__, (xstart), (xend))))
5ffc48a0bebe Conditionally define DM_ATTR_PRINTF_FMT(xstart, xend) instead of using
Matti Hamalainen <ccr@tnsp.org>
parents: 2383
diff changeset
70 #endif
5ffc48a0bebe Conditionally define DM_ATTR_PRINTF_FMT(xstart, xend) instead of using
Matti Hamalainen <ccr@tnsp.org>
parents: 2383
diff changeset
71
5ffc48a0bebe Conditionally define DM_ATTR_PRINTF_FMT(xstart, xend) instead of using
Matti Hamalainen <ccr@tnsp.org>
parents: 2383
diff changeset
72
1145
af2c9f76c782 MinGW does not define PRI* format specifiers, so define them ourselves :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1143
diff changeset
73 // Do we have a valid arch?
af2c9f76c782 MinGW does not define PRI* format specifiers, so define them ourselves :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1143
diff changeset
74 // If so, set some printf specifiers
2392
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
75 #define DM_PRIu32 PRIu32
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
76 #define DM_PRId32 PRId32
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
77 #define DM_PRIx32 PRIx32
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
78 #define DM_PRIX32 PRIX32
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
79
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
80 #define DM_PRIu64 PRIu64
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
81 #define DM_PRId64 PRId64
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
82 #define DM_PRIx64 PRIx64
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
83 #define DM_PRIX64 PRIX64
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
84
1145
af2c9f76c782 MinGW does not define PRI* format specifiers, so define them ourselves :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1143
diff changeset
85 #if DM_ARCH == 32
2392
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
86 # define DM_PRIu_SIZE_T PRIu32
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
87 # define DM_PRId_SSIZE_T PRId32
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
88 # define DM_PRIx_SIZE_T PRIx32
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
89 # define DM_PRIX_SIZE_T PRIX32
2394
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
90 # ifdef DM_PLAT_WINDOWS
2393
85700c9b7dc8 Add new DM_PRI*_OFF_T specifiers for off_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
91 # define DM_PRId_OFF_T "ld"
85700c9b7dc8 Add new DM_PRI*_OFF_T specifiers for off_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
92 # define DM_PRIx_OFF_T "lx"
85700c9b7dc8 Add new DM_PRI*_OFF_T specifiers for off_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
93 # define DM_PRIX_OFF_T "lX"
2394
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
94 # else
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
95 # define DM_PRId_OFF_T PRId32
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
96 # define DM_PRIx_OFF_T PRIx32
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
97 # define DM_PRIX_OFF_T PRIX32
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
98 # endif
1145
af2c9f76c782 MinGW does not define PRI* format specifiers, so define them ourselves :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1143
diff changeset
99 #elif DM_ARCH == 64
2394
147d40b708ea Copy improvements to the platform 32/64bit logic from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2393
diff changeset
100 # ifdef DM_PLAT_WINDOWS // Unsure if this is MinGW64 only thing?
2392
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
101 # define DM_PRIu_SIZE_T "I64u"
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
102 # define DM_PRId_SSIZE_T "I64d"
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
103 # define DM_PRIx_SIZE_T "I64x"
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
104 # define DM_PRIX_SIZE_T "I64X"
2393
85700c9b7dc8 Add new DM_PRI*_OFF_T specifiers for off_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
105 # define DM_PRId_OFF_T "I64d"
85700c9b7dc8 Add new DM_PRI*_OFF_T specifiers for off_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
106 # define DM_PRIx_OFF_T "I64x"
85700c9b7dc8 Add new DM_PRI*_OFF_T specifiers for off_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
107 # define DM_PRIX_OFF_T "I64X"
2353
a1265a407524 Fix / improve DM_PRI* constants generated for Windows 64bit platform.
Matti Hamalainen <ccr@tnsp.org>
parents: 2352
diff changeset
108 # else
2392
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
109 # define DM_PRIu_SIZE_T PRIu64
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
110 # define DM_PRId_SSIZE_T PRId64
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
111 # define DM_PRIx_SIZE_T PRIx64
835b231d8083 Use standard inttypes.h for defining the DM_PRI* format specifiers, except
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
112 # define DM_PRIX_SIZE_T PRIX64
2393
85700c9b7dc8 Add new DM_PRI*_OFF_T specifiers for off_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
113 # define DM_PRId_OFF_T PRId64
85700c9b7dc8 Add new DM_PRI*_OFF_T specifiers for off_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
114 # define DM_PRIx_OFF_T PRIx64
85700c9b7dc8 Add new DM_PRI*_OFF_T specifiers for off_t type.
Matti Hamalainen <ccr@tnsp.org>
parents: 2392
diff changeset
115 # define DM_PRIX_OFF_T PRIX64
2353
a1265a407524 Fix / improve DM_PRI* constants generated for Windows 64bit platform.
Matti Hamalainen <ccr@tnsp.org>
parents: 2352
diff changeset
116 # endif
1145
af2c9f76c782 MinGW does not define PRI* format specifiers, so define them ourselves :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1143
diff changeset
117 #else
af2c9f76c782 MinGW does not define PRI* format specifiers, so define them ourselves :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1143
diff changeset
118 # error Could not determine architecture (32/64bit), please define DM_ARCH=32 or 64
af2c9f76c782 MinGW does not define PRI* format specifiers, so define them ourselves :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1143
diff changeset
119 #endif
af2c9f76c782 MinGW does not define PRI* format specifiers, so define them ourselves :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1143
diff changeset
120
af2c9f76c782 MinGW does not define PRI* format specifiers, so define them ourselves :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1143
diff changeset
121
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 #ifdef __cplusplus
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 extern "C" {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 // Defaults
2361
c801995cbb13 Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 2353
diff changeset
127 #define DM_PROG_AUTHOR "By Matti 'ccr' Hamalainen (C) Copyright 2020 TNSP"
341
9f16badc4bd3 License/copyright.
Matti Hamalainen <ccr@tnsp.org>
parents: 305
diff changeset
128 #define DM_PROG_LICENSE "Et all, see README / COPYING for more information."
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 /* Error codes
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 enum {
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
133 // General error codes
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
134 DMERR_OK = 0,
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
135 DMERR_PROGRESS, // Status OK, but operation in progress
831
a855f88f86ee Reorder internal error code.
Matti Hamalainen <ccr@tnsp.org>
parents: 816
diff changeset
136
a855f88f86ee Reorder internal error code.
Matti Hamalainen <ccr@tnsp.org>
parents: 816
diff changeset
137 DMERR_INTERNAL,
26
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
138
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
139 DMERR_FOPEN,
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
140 DMERR_FREAD,
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
141 DMERR_FWRITE,
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
142 DMERR_FSEEK,
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
143 DMERR_NOT_FOUND, // Resource/data not found
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
145 DMERR_INVALID_DATA, // Some data was invalid
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
146 DMERR_MALLOC, // Memory allocation failure
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
147 DMERR_ALREADY_INIT, // Resource has already been initialized
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
148 DMERR_INIT_FAIL, // General initialization failure
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
149 DMERR_INVALID_ARGS,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
151 DMERR_NULLPTR, // NULL pointer specified in critical argument
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
152 DMERR_NOT_SUPPORTED,// Operation not supported
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
153 DMERR_OUT_OF_DATA,
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
154 DMERR_EXTRA_DATA,
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
155 DMERR_BOUNDS,
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1048
diff changeset
156
908
03bda6477ad4 Add new error code DMERR_DATA_ERROR.
Matti Hamalainen <ccr@tnsp.org>
parents: 889
diff changeset
157 DMERR_DATA_ERROR, // Data decoding/encoding/parsing error
1817
ca9fe688ab6b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1686
diff changeset
158
1273
132706e3b94b Improve error handling and reporting slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 1172
diff changeset
159 DMERR_VERSION, // Unsupported data version
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
161 // PACK-file subsystem
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
162 DMERR_NOTPACK,
1273
132706e3b94b Improve error handling and reporting slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 1172
diff changeset
163 DMERR_PACK_VERSION,
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
164 DMERR_INVALID,
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
165 DMERR_COMPRESSION,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167
955
6b2f41844580 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
168
813
b0cd28b6c9f3 Add new utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
169 // Directory/path separator stuff
b0cd28b6c9f3 Add new utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
170 #define DM_DIR_SEPARATOR '/'
b0cd28b6c9f3 Add new utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
171
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 // Resource management defines
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 #define DMRES_NAME_LEN 32
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 #define DMRES_RES_FILE "res.txt" // Resource data file
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 /* Define a boolean type
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 #if !defined(FALSE) && !defined(TRUE) && !defined(BOOL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 typedef enum { FALSE = 0, TRUE = 1 } BOOL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 #ifndef BOOL
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
185 # ifdef bool
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
186 # define BOOL bool
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
187 # else
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
188 # define BOOL int
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
189 # endif
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192
305
036fde2fd630 Add mathematical constants DM_PI, DM_PI2 and DM_E.
Matti Hamalainen <ccr@tnsp.org>
parents: 294
diff changeset
193 /* Math constants
036fde2fd630 Add mathematical constants DM_PI, DM_PI2 and DM_E.
Matti Hamalainen <ccr@tnsp.org>
parents: 294
diff changeset
194 */
036fde2fd630 Add mathematical constants DM_PI, DM_PI2 and DM_E.
Matti Hamalainen <ccr@tnsp.org>
parents: 294
diff changeset
195 #define DM_PI 3.14159265358f
036fde2fd630 Add mathematical constants DM_PI, DM_PI2 and DM_E.
Matti Hamalainen <ccr@tnsp.org>
parents: 294
diff changeset
196 #define DM_PI2 6.28318530718f
036fde2fd630 Add mathematical constants DM_PI, DM_PI2 and DM_E.
Matti Hamalainen <ccr@tnsp.org>
parents: 294
diff changeset
197 #define DM_E 2.71828182846f
036fde2fd630 Add mathematical constants DM_PI, DM_PI2 and DM_E.
Matti Hamalainen <ccr@tnsp.org>
parents: 294
diff changeset
198
036fde2fd630 Add mathematical constants DM_PI, DM_PI2 and DM_E.
Matti Hamalainen <ccr@tnsp.org>
parents: 294
diff changeset
199
1146
b412470ec606 Plurality.
Matti Hamalainen <ccr@tnsp.org>
parents: 1145
diff changeset
200 /* Fixed point math types
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 typedef union
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 {
36
f3407a58e01e Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
204 Sint64 dw;
f3407a58e01e Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
205 Sint32 w[2];
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 } DMFixedPoint;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 typedef union
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 {
36
f3407a58e01e Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
211 Sint32 dw;
f3407a58e01e Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
212 Sint16 w[2];
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 } DMFixedPoint32;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 /* Macros for fixed point math
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 */
956
d4e411192238 Remove check for GCC >= 3.x, it's only sane to support 4+.
Matti Hamalainen <ccr@tnsp.org>
parents: 955
diff changeset
218 #define FP_SET(a, k) a.dw = k ## ULL
138
459a1be2bd0f A minor improvement to FP_CONV() fixed point macro.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
219 #define FP_CONV(a, k) a.dw = (k)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 #ifndef SDL_BYTEORDER
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 # error Undefined byteorder!
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 # define FP_SETH(a, k) a.w[0] = (k)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 # define FP_SETL(a, k) a.w[1] = (k)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 # define FP_SETHL(a, h, l) { a.w[0] = (h); a.w[1] = (l); }
809
eba3b87f3f84 Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents: 805
diff changeset
229 # define FP_GETH32(a) a.w[0]
eba3b87f3f84 Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents: 805
diff changeset
230 # define FP_GETL32(a) a.w[1]
eba3b87f3f84 Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents: 805
diff changeset
231 # define FP_GETH16(a) a.w[0]
eba3b87f3f84 Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents: 805
diff changeset
232 # define FP_GETL16(a) a.w[1]
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 #elif (SDL_BYTEORDER == SDL_LIL_ENDIAN)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 # define FP_SETH(a, k) a.w[1] = (k)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 # define FP_SETL(a, k) a.w[0] = (k)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 # define FP_SETHL(a, h, l) { a.w[1] = (h); a.w[0] = (l); }
809
eba3b87f3f84 Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents: 805
diff changeset
237 # define FP_GETH32(a) a.w[1]
eba3b87f3f84 Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents: 805
diff changeset
238 # define FP_GETL32(a) a.w[0]
eba3b87f3f84 Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents: 805
diff changeset
239 # define FP_GETH16(a) a.w[1]
eba3b87f3f84 Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents: 805
diff changeset
240 # define FP_GETL16(a) a.w[0]
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 #else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 # error Unsupported byte order!
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244
809
eba3b87f3f84 Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents: 805
diff changeset
245 #define FP_PRINTF64(a) printf("%.8x:%.8x", FP_GETH32(a), FP_GETL32(a))
eba3b87f3f84 Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents: 805
diff changeset
246 #define FP_PRINTF32(a) printf("%.4x:%.4x", FP_GETH16(a), FP_GETL16(a))
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 #define FP_ADD(a, b) a.dw += b.dw
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 #define FP_SUB(a, b) a.dw -= b.dw
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 #define FP_ADD_R(r, a, b) r.dw = a.dw + b.dw
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 #define FP_SUB_R(r, a, b) r.dw = a.dw - b.dw
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 #define FP_DIV(a, b) a.dw /= b.dw
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 #define FP_MUL(a, b) a.dw *= b.dw
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 #define FP_DIV_R(r, a, b) r.dw = (a.dw / b.dw)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 #define FP_MUL_R(r, a, b) r.dw = (a.dw * b.dw)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 /* Miscellaneous types
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 Uint8 a,g,b,r;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 #elif (SDL_BYTEORDER == SDL_LIL_ENDIAN)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 Uint8 r,g,b,a;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 #endif
971
f654435df15e Rename DMRGBA32 struct to DMColor and remove the original redundant DMColor
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
267 } DMColor;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270 typedef float DMFloat;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272
118
c36e0316de9f Move DM_SWAP() macro to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
273 // Macro for swapping two lvalues of same type
c36e0316de9f Move DM_SWAP() macro to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
274 #define DM_SWAP(T, A, B) { if ((B) < (A)) { T swtmp = (B); B = (A); A = swtmp; } }
c36e0316de9f Move DM_SWAP() macro to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
275
c36e0316de9f Move DM_SWAP() macro to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
276
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 /* Drawing modes used by blitting and some other functions.
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 enum
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 DMD_NONE = 0x0000,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 DMD_TRANSPARENT = 0x0001,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 DMD_SATURATE = 0x0002,
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1048
diff changeset
284
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 DMD_ANTIALIAS = 0x0004,
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1048
diff changeset
286
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 DMD_NMODES = 6
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 // Available bitdepths. Not all functions may support every one of these.
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 enum
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 DMD_8BIT = 0,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 DMD_32BIT,
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1048
diff changeset
296
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 DMD_NBITDEPTHS
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 static inline int dmBitsPerPixel2Index(int bpp)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 return (bpp == 8 ? 0 : (bpp == 32 ? 1 : -1));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306
980
43594ac98f91 Move dmClamp*() functions back to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents: 976
diff changeset
307 static inline DMFloat dmClamp10(const DMFloat a)
43594ac98f91 Move dmClamp*() functions back to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents: 976
diff changeset
308 {
43594ac98f91 Move dmClamp*() functions back to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents: 976
diff changeset
309 return (a < 0.0f ? 0.0f : (a > 1.0f ? 1.0f : a));
43594ac98f91 Move dmClamp*() functions back to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents: 976
diff changeset
310 }
43594ac98f91 Move dmClamp*() functions back to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents: 976
diff changeset
311
43594ac98f91 Move dmClamp*() functions back to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents: 976
diff changeset
312
43594ac98f91 Move dmClamp*() functions back to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents: 976
diff changeset
313 static inline int dmClamp(const int v, const int min, const int max)
43594ac98f91 Move dmClamp*() functions back to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents: 976
diff changeset
314 {
43594ac98f91 Move dmClamp*() functions back to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents: 976
diff changeset
315 return (v < min ? min : (v > max ? max : v));
43594ac98f91 Move dmClamp*() functions back to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents: 976
diff changeset
316 }
43594ac98f91 Move dmClamp*() functions back to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents: 976
diff changeset
317
43594ac98f91 Move dmClamp*() functions back to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents: 976
diff changeset
318
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 /* Arbitrary line drawing
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 #ifdef DM_GFX_LINES
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
322 #define DM_HEADER
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
323 #include "dmlinefunc.h"
234
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
324
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
325 enum
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
326 {
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
327 CLIP_TOP = 1,
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
328 CLIP_BOTTOM = 2,
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
329 CLIP_RIGHT = 4,
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
330 CLIP_LEFT = 8
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
331 };
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
332
234
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
333 #define DM_CLIP_FUNC dmClipLineCoordsFloat
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
334 #define DM_COORD_TYPE DMFloat
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
335 #include "dmlineclip.h"
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
336
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
337 #undef DM_HEADER
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339
95
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
340
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
341 /* Various blitting functions
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 #ifdef DM_GFX_BLITS
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 typedef int (*DMScaledBlitFunc)(SDL_Surface *src, const int x0, const int y0, const int dwidth, const int dheight, SDL_Surface *dst);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345 DMScaledBlitFunc dmGetScaledBlitFunc(SDL_PixelFormat *src, SDL_PixelFormat *dst, int mode);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 int dmScaledBlitSurfaceAny(SDL_Surface *src, const int x0, const int y0, const int dwidth, const int dheight, SDL_Surface *dst, int mode);
19
10f58ff516b3 Add function prototypes for two special case scaled blit functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
347
95
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
348 typedef int (*DMUnscaledBlitFunc)(SDL_Surface *src, const int x0, const int y0, SDL_Surface *dst);
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
349 DMUnscaledBlitFunc dmGetUnscaledBlitFunc(SDL_PixelFormat *src, SDL_PixelFormat *dst, int mode);
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
350 int dmUnscaledBlitSurfaceAny(SDL_Surface *src, const int x0, const int y0, SDL_Surface *dst, int mode);
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
351
1601
a3023fe79c43 Change dmConvertScaledSurface() interface by remove flags.
Matti Hamalainen <ccr@tnsp.org>
parents: 1557
diff changeset
352 SDL_Surface *dmConvertScaledSurface(SDL_Surface *src, SDL_PixelFormat *fmt, const int dwidth, const int dheight);
610
e74ad60b1e85 Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents: 601
diff changeset
353
e74ad60b1e85 Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents: 601
diff changeset
354
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
355 #define DM_HEADER
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
356 #include "dmblitfunc.h"
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
357 #undef DM_HEADER
612
696f03f30c0e Make certain static inline graphics functions always available, no need to
Matti Hamalainen <ccr@tnsp.org>
parents: 611
diff changeset
358
696f03f30c0e Make certain static inline graphics functions always available, no need to
Matti Hamalainen <ccr@tnsp.org>
parents: 611
diff changeset
359 #endif // DM_GFX_BLITS
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360
95
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
361
90
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
362 static inline void dmClearSurface(SDL_Surface *screen, const Uint32 col)
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
363 {
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
364 SDL_FillRect(screen, NULL, col);
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
365 }
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
366
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
367
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
368 static inline Uint32 dmMapRGB(SDL_Surface *screen, int r, int g, int b)
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
369 {
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
370 return SDL_MapRGB(screen->format, r, g, b);
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
371 }
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
372
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
373
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
374 static inline Uint32 dmMapRGBA(SDL_Surface *screen, int r, int g, int b, int a)
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
375 {
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
376 return SDL_MapRGBA(screen->format, r, g, b, a);
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
377 }
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
378
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
379
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
380 static inline int dmDirectBlitSurface(SDL_Surface *bmp, SDL_Surface *screen)
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
381 {
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
382 return SDL_BlitSurface(bmp, NULL, screen, NULL);
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
383 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385
611
828d86cd10e0 Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
386 static inline SDL_Surface *dmCopySurface(SDL_Surface *src)
828d86cd10e0 Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
387 {
828d86cd10e0 Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
388 if (src != NULL)
828d86cd10e0 Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
389 return SDL_ConvertSurface(src, src->format, src->flags);
828d86cd10e0 Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
390 else
828d86cd10e0 Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
391 return NULL;
828d86cd10e0 Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
392 }
828d86cd10e0 Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
393
828d86cd10e0 Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
394
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 /* Global variables
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 extern char *dmProgName,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 *dmProgDesc,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 *dmProgVersion,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400 *dmProgAuthor,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 *dmProgLicense;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 extern int dmVerbosity;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 void dmInitProg(char *name, char *desc, char *version, char *author, char *license);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 void dmPrintBanner(FILE *outFile, const char *name, const char *usage);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 void dmMsgVA(int level, const char *fmt, va_list ap);
2383
43e39d9ec42f Add __attribute__(__format__ ..) specifiers for functions that use printf() style format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents: 2361
diff changeset
408 void dmMsg(int level, const char *fmt, ...)
2385
5ffc48a0bebe Conditionally define DM_ATTR_PRINTF_FMT(xstart, xend) instead of using
Matti Hamalainen <ccr@tnsp.org>
parents: 2383
diff changeset
409 DM_ATTR_PRINTF_FMT(2, 3);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410 void dmPrintVA(int level, const char *fmt, va_list ap);
2383
43e39d9ec42f Add __attribute__(__format__ ..) specifiers for functions that use printf() style format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents: 2361
diff changeset
411 void dmPrint(int level, const char *fmt, ...)
2385
5ffc48a0bebe Conditionally define DM_ATTR_PRINTF_FMT(xstart, xend) instead of using
Matti Hamalainen <ccr@tnsp.org>
parents: 2383
diff changeset
412 DM_ATTR_PRINTF_FMT(2, 3);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 956
diff changeset
414 int dmErrorVA(const int error, const char *fmt, va_list);
2383
43e39d9ec42f Add __attribute__(__format__ ..) specifiers for functions that use printf() style format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents: 2361
diff changeset
415 int dmError(const int error, const char *fmt, ...)
2385
5ffc48a0bebe Conditionally define DM_ATTR_PRINTF_FMT(xstart, xend) instead of using
Matti Hamalainen <ccr@tnsp.org>
parents: 2383
diff changeset
416 DM_ATTR_PRINTF_FMT(2, 3);
2383
43e39d9ec42f Add __attribute__(__format__ ..) specifiers for functions that use printf() style format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents: 2361
diff changeset
417 void dmErrorMsg(const char *fmt, ...)
2385
5ffc48a0bebe Conditionally define DM_ATTR_PRINTF_FMT(xstart, xend) instead of using
Matti Hamalainen <ccr@tnsp.org>
parents: 2383
diff changeset
418 DM_ATTR_PRINTF_FMT(1, 2);
955
6b2f41844580 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
419 int dmGetErrno();
6b2f41844580 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
420 const char *dmErrorStr(const int error);
6b2f41844580 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
421
1046
7e54b2d08ce7 Add special debug error message function/macro that can be
Matti Hamalainen <ccr@tnsp.org>
parents: 980
diff changeset
422 #ifdef DM_DEBUG
7e54b2d08ce7 Add special debug error message function/macro that can be
Matti Hamalainen <ccr@tnsp.org>
parents: 980
diff changeset
423 # define dmErrorDBG dmError
1048
509e6ed3a24e Finishing touches to the DM_DEBUG stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 1047
diff changeset
424 # define dmErrorDBGMsg dmErrorMsg
1046
7e54b2d08ce7 Add special debug error message function/macro that can be
Matti Hamalainen <ccr@tnsp.org>
parents: 980
diff changeset
425 #else
7e54b2d08ce7 Add special debug error message function/macro that can be
Matti Hamalainen <ccr@tnsp.org>
parents: 980
diff changeset
426 # define dmErrorDBG(ecode, fmt, ...) (ecode) // Dummy
1048
509e6ed3a24e Finishing touches to the DM_DEBUG stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 1047
diff changeset
427 # define dmErrorDBGMsg(fmt, ...)
1046
7e54b2d08ce7 Add special debug error message function/macro that can be
Matti Hamalainen <ccr@tnsp.org>
parents: 980
diff changeset
428 #endif
7e54b2d08ce7 Add special debug error message function/macro that can be
Matti Hamalainen <ccr@tnsp.org>
parents: 980
diff changeset
429
1451
4f82e7cda289 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1323
diff changeset
430 void * dmMalloc(size_t len);
4f82e7cda289 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1323
diff changeset
431 void * dmMalloc0(size_t len);
4f82e7cda289 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1323
diff changeset
432 void * dmRealloc(void *ptr, size_t len);
4f82e7cda289 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1323
diff changeset
433 void * dmCalloc(size_t n, size_t len);
4f82e7cda289 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1323
diff changeset
434 void dmFree(void *ptr);
1453
73a4158b2e55 Add missing dmFreeRReal() function prototype.
Matti Hamalainen <ccr@tnsp.org>
parents: 1452
diff changeset
435 void dmFreeRReal(void **ptr);
1452
3a1f4e810874 Add dmFreeR() macro/function.
Matti Hamalainen <ccr@tnsp.org>
parents: 1451
diff changeset
436 #define dmFreeR(ptr) dmFreeRReal((void **) ptr)
1451
4f82e7cda289 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1323
diff changeset
437
1172
0ec370b1c8d4 Check for DM_HAVE_STRING_H.
Matti Hamalainen <ccr@tnsp.org>
parents: 1166
diff changeset
438 #if defined(DM_HAVE_MEMSET) || defined(DM_HAVE_STRING_H)
1166
f29fa5b6b748 Add dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1146
diff changeset
439 static inline void * dmMemset(void *ptr, const int c, size_t n)
f29fa5b6b748 Add dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1146
diff changeset
440 {
f29fa5b6b748 Add dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1146
diff changeset
441 return memset(ptr, c, n);
f29fa5b6b748 Add dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1146
diff changeset
442 }
f29fa5b6b748 Add dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1146
diff changeset
443 #else
f29fa5b6b748 Add dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1146
diff changeset
444 void * dmMemset(void *ptr, const int c, size_t n);
f29fa5b6b748 Add dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1146
diff changeset
445 #endif
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446
2027
750a7e125546 Add in several string helper functions from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2004
diff changeset
447
750a7e125546 Add in several string helper functions from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2004
diff changeset
448 /** String trimming option flags for dm_strdup_trim()
750a7e125546 Add in several string helper functions from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2004
diff changeset
449 */
750a7e125546 Add in several string helper functions from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2004
diff changeset
450 enum
750a7e125546 Add in several string helper functions from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2004
diff changeset
451 {
750a7e125546 Add in several string helper functions from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2004
diff changeset
452 DM_TRIM_START = 1,
750a7e125546 Add in several string helper functions from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2004
diff changeset
453 DM_TRIM_END = 2,
750a7e125546 Add in several string helper functions from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2004
diff changeset
454 DM_TRIM_BOTH = 3
750a7e125546 Add in several string helper functions from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2004
diff changeset
455 };
750a7e125546 Add in several string helper functions from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2004
diff changeset
456
750a7e125546 Add in several string helper functions from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2004
diff changeset
457
750a7e125546 Add in several string helper functions from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2004
diff changeset
458
1882
8e3ebeabb2d9 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
459 char * dm_strdup(const char *str);
8e3ebeabb2d9 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
460 char * dm_strndup(const char *str, const size_t n);
2027
750a7e125546 Add in several string helper functions from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2004
diff changeset
461 char * dm_strdup_trim(const char *src, const int flags);
750a7e125546 Add in several string helper functions from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2004
diff changeset
462 char * dm_strndup_trim(const char *src, const size_t n, const int flags);
1884
47fe47f01fea Implement dm_strdup_vprintf_len(const char *fmt, va_list args, int *len), which
Matti Hamalainen <ccr@tnsp.org>
parents: 1882
diff changeset
463 char * dm_strdup_vprintf_len(const char *fmt, va_list args, int *len);
1882
8e3ebeabb2d9 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
464 char * dm_strdup_vprintf(const char *fmt, va_list args);
8e3ebeabb2d9 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
465 char * dm_strdup_printf(const char *fmt, ...);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466
2027
750a7e125546 Add in several string helper functions from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2004
diff changeset
467 int dm_strcasecmp(const char *haystack, const char *needle);
750a7e125546 Add in several string helper functions from th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2004
diff changeset
468 int dm_strncasecmp(const char *haystack, const char *needle, size_t n);
816
091461e0213f Add new utility function.
Matti Hamalainen <ccr@tnsp.org>
parents: 813
diff changeset
469 char * dm_strrcasecmp(char *str, const char *needle);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470
2004
161e731eb152 Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents: 1884
diff changeset
471 BOOL dmGetIntVal(const char *str, unsigned int *value, BOOL *neg);
955
6b2f41844580 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
472
6b2f41844580 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
473
294
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
474 /* Mutexes
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
475 */
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
476 #ifdef DM_MUTEX_DEBUG
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
477
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
478 typedef struct
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
479 {
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
480 BOOL used;
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
481 Uint32 id;
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
482 int state;
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
483 } DMMutexLock;
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
484
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
485 typedef struct
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
486 {
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
487 char *cr_file;
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
488 int cr_line;
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
489 SDL_mutex *m;
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
490 DMMutexLock locks[8];
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
491 } DMMutex;
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
492
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
493 #define dmMutexLock(x) dmDOMutexLock(x, __FILE__, (int) __LINE__)
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
494 #define dmMutexUnlock(x) dmDOMutexUnlock(x, __FILE__, (int) __LINE__)
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
495 #define dmCreateMutex(x) dmDOCreateMutex(__FILE__, (int) __LINE__)
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
496
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
497 int dmDOMutexLock(DMMutex *mutex, const char *file, const int line);
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
498 int dmDOMutexUnlock(DMMutex *mutex, const char *file, const int line);
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
499 DMMutex * dmDOCreateMutex(const char *file, const int line);
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
500 void dmDestroyMutex(DMMutex *mutex);
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
501
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
502 #else
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
503 #define DMMutex SDL_mutex
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
504 #define dmCreateMutex() SDL_CreateMutex()
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
505 #define dmDestroyMutex(x) SDL_DestroyMutex(x)
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
506 #define dmMutexLock(x) SDL_mutexP(x)
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
507 #define dmMutexUnlock(x) SDL_mutexV(x)
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
508 #endif
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
509
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 /* Endianess swapping macros
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 */
955
6b2f41844580 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
512 #define DM_SWAP_16_LE_BE(value) ((Uint16) ( \
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513 (Uint16) ((Uint16) (value) >> 8) | \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
514 (Uint16) ((Uint16) (value) << 8)) )
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516
955
6b2f41844580 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
517 #define DM_SWAP_32_LE_BE(value) ((Uint32) ( \
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
518 (((Uint32) (value) & (Uint32) 0x000000ffU) << 24) | \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
519 (((Uint32) (value) & (Uint32) 0x0000ff00U) << 8) | \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
520 (((Uint32) (value) & (Uint32) 0x00ff0000U) >> 8) | \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521 (((Uint32) (value) & (Uint32) 0xff000000U) >> 24)))
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
522
955
6b2f41844580 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
523 #define DM_SWAP_64_LE_BE(value) ((Uint64) ( \
6b2f41844580 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
524 (((Uint64) (value) & (Uint64) 0x00000000000000ffULL) << 56) | \
6b2f41844580 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
525 (((Uint64) (value) & (Uint64) 0x000000000000ff00ULL) << 40) | \
6b2f41844580 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
526 (((Uint64) (value) & (Uint64) 0x0000000000ff0000ULL) << 24) | \
6b2f41844580 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
527 (((Uint64) (value) & (Uint64) 0x00000000ff000000ULL) << 8) | \
6b2f41844580 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
528 (((Uint64) (value) & (Uint64) 0x000000ff00000000ULL) >> 8) | \
6b2f41844580 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
529 (((Uint64) (value) & (Uint64) 0x0000ff0000000000ULL) >> 24) | \
6b2f41844580 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 913
diff changeset
530 (((Uint64) (value) & (Uint64) 0x00ff000000000000ULL) >> 40) | \
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 (((Uint64) (value) & (Uint64) 0xff00000000000000ULL) >> 56)))
873
26ea35e914ca Oops. 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 872
diff changeset
532
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
533
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
534 /* Macros that swap only when needed ...
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
535 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
536 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
537 # define DM_LE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value)
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
538 # define DM_LE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value)
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
539 # define DM_NATIVE_TO_LE16(value) DM_SWAP_16_LE_BE(value)
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
540 # define DM_NATIVE_TO_LE32(value) DM_SWAP_32_LE_BE(value)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
541
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
542 # define DM_BE16_TO_NATIVE(value) ((Uint16) (value))
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
543 # define DM_BE32_TO_NATIVE(value) ((Uint32) (value))
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
544 # define DM_NATIVE_TO_BE16(value) ((Uint16) (value))
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
545 # define DM_NATIVE_TO_BE32(value) ((Uint32) (value))
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
546
872
b01d04e44b6f Assume we always have 64bit type.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
547 # define DM_LE64_TO_NATIVE(value) DM_SWAP_64_LE_BE(value)
b01d04e44b6f Assume we always have 64bit type.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
548 # define DM_NATIVE_TO_LE64(value) DM_SWAP_64_LE_BE(value)
b01d04e44b6f Assume we always have 64bit type.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
549 # define DM_BE64_TO_NATIVE(value) ((Uint64) (value))
b01d04e44b6f Assume we always have 64bit type.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
550 # define DM_NATIVE_TO_BE64(value) ((Uint64) (value))
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
551
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
552 #elif (SDL_BYTEORDER == SDL_LIL_ENDIAN)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
553
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
554 # define DM_LE16_TO_NATIVE(value) ((Uint16) (value))
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
555 # define DM_LE32_TO_NATIVE(value) ((Uint32) (value))
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
556 # define DM_NATIVE_TO_LE16(value) ((Uint16) (value))
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
557 # define DM_NATIVE_TO_LE32(value) ((Uint32) (value))
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
558
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
559 # define DM_BE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value)
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
560 # define DM_BE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value)
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
561 # define DM_NATIVE_TO_BE16(value) DM_SWAP_16_LE_BE(value)
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
562 # define DM_NATIVE_TO_BE32(value) DM_SWAP_32_LE_BE(value)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
563
872
b01d04e44b6f Assume we always have 64bit type.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
564 # define DM_LE64_TO_NATIVE(value) ((Uint64) (value))
b01d04e44b6f Assume we always have 64bit type.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
565 # define DM_NATIVE_TO_LE64(value) ((Uint64) (value))
b01d04e44b6f Assume we always have 64bit type.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
566 # define DM_BE64_TO_NATIVE(value) DM_SWAP_64_LE_BE(value)
b01d04e44b6f Assume we always have 64bit type.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
567 # define DM_NATIVE_TO_BE64(value) DM_SWAP_64_LE_BE(value)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
568 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
570
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571 #ifdef __cplusplus
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
572 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
573 #endif
359
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 341
diff changeset
574
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
575 #endif // DMLIB_H