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