annotate src/dmlib.h @ 908:03bda6477ad4

Add new error code DMERR_DATA_ERROR.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 23 Feb 2015 22:51:28 +0200
parents e5fde730b4fa
children 7d1696edf244
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
863
27949209238b Update copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents: 831
diff changeset
5 * (C) Copyright 2011-2015 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>
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 #include <stdarg.h>
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 #ifdef DM_USE_ASSERTS
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
19 # include <assert.h>
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 #else
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
21 # define assert(NEXPR) // stub
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 #endif
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 __cplusplus
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 extern "C" {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 // Defaults
805
fc26ec1d315f Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 781
diff changeset
29 #define DM_PROG_AUTHOR "By Matti 'ccr' Hamalainen (C) Copyright 2014 TNSP"
341
9f16badc4bd3 License/copyright.
Matti Hamalainen <ccr@tnsp.org>
parents: 305
diff changeset
30 #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
31
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 /* Error codes
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 enum {
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
35 // General error codes
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
36 DMERR_OK = 0,
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
37 DMERR_PROGRESS, // Status OK, but operation in progress
831
a855f88f86ee Reorder internal error code.
Matti Hamalainen <ccr@tnsp.org>
parents: 816
diff changeset
38
a855f88f86ee Reorder internal error code.
Matti Hamalainen <ccr@tnsp.org>
parents: 816
diff changeset
39 DMERR_INTERNAL,
26
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
40
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
41 DMERR_FOPEN,
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
42 DMERR_FREAD,
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
43 DMERR_FWRITE,
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
44 DMERR_FSEEK,
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
45 DMERR_NOT_FOUND, // Resource/data not found
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
47 DMERR_INVALID_DATA, // Some data was invalid
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
48 DMERR_MALLOC, // Memory allocation failure
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
49 DMERR_ALREADY_INIT, // Resource has already been initialized
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
50 DMERR_INIT_FAIL, // General initialization failure
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
51 DMERR_INVALID_ARGS,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
53 DMERR_NULLPTR, // NULL pointer specified in critical argument
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
54 DMERR_NOT_SUPPORTED,// Operation not supported
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
55 DMERR_OUT_OF_DATA,
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
56 DMERR_EXTRA_DATA,
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
57 DMERR_BOUNDS,
908
03bda6477ad4 Add new error code DMERR_DATA_ERROR.
Matti Hamalainen <ccr@tnsp.org>
parents: 889
diff changeset
58
03bda6477ad4 Add new error code DMERR_DATA_ERROR.
Matti Hamalainen <ccr@tnsp.org>
parents: 889
diff changeset
59 DMERR_DATA_ERROR, // Data decoding/encoding/parsing error
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
61 // PACK-file subsystem
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
62 DMERR_NOTPACK,
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
63 DMERR_VERSION,
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
64 DMERR_INVALID,
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
65 DMERR_COMPRESSION,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67
813
b0cd28b6c9f3 Add new utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
68 // Directory/path separator stuff
b0cd28b6c9f3 Add new utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
69 #define DM_DIR_SEPARATOR '/'
b0cd28b6c9f3 Add new utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
70
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 // Resource management defines
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 #define DMRES_NAME_LEN 32
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 #define DMRES_DATA_PACK "data.pak" // Name of the data-file
601
588998ccc07a Change resource directory path DATA/ -> data/
Matti Hamalainen <ccr@tnsp.org>
parents: 569
diff changeset
75 #define DMRES_DATA_PATH "data/" // Sub-directory path
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 #define DMRES_RES_FILE "res.txt" // Resource data file
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 /* Define a boolean type
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 #if !defined(FALSE) && !defined(TRUE) && !defined(BOOL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 typedef enum { FALSE = 0, TRUE = 1 } BOOL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 #ifndef BOOL
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
86 # ifdef bool
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
87 # define BOOL bool
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
88 # else
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
89 # define BOOL int
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
90 # endif
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93
305
036fde2fd630 Add mathematical constants DM_PI, DM_PI2 and DM_E.
Matti Hamalainen <ccr@tnsp.org>
parents: 294
diff changeset
94 /* Math constants
036fde2fd630 Add mathematical constants DM_PI, DM_PI2 and DM_E.
Matti Hamalainen <ccr@tnsp.org>
parents: 294
diff changeset
95 */
036fde2fd630 Add mathematical constants DM_PI, DM_PI2 and DM_E.
Matti Hamalainen <ccr@tnsp.org>
parents: 294
diff changeset
96 #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
97 #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
98 #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
99
036fde2fd630 Add mathematical constants DM_PI, DM_PI2 and DM_E.
Matti Hamalainen <ccr@tnsp.org>
parents: 294
diff changeset
100
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 /* Fixed point math type
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 typedef union
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 {
36
f3407a58e01e Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
105 Sint64 dw;
f3407a58e01e Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
106 Sint32 w[2];
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 } DMFixedPoint;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 typedef union
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 {
36
f3407a58e01e Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
112 Sint32 dw;
f3407a58e01e Change DMFixedPoint types and appropriate JSS functions back to using signed
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
113 Sint16 w[2];
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 } DMFixedPoint32;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 /* Macros for fixed point math
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 #if __GNUC__ >= 3
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 # define FP_SET(a, k) a.dw = k ## ULL
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 #else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 # define FP_SET(a, k) a.dw = k
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124
138
459a1be2bd0f A minor improvement to FP_CONV() fixed point macro.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
125 #define FP_CONV(a, k) a.dw = (k)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 #ifndef SDL_BYTEORDER
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 # error Undefined byteorder!
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 # define FP_SETH(a, k) a.w[0] = (k)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 # define FP_SETL(a, k) a.w[1] = (k)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 # 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
135 # 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
136 # 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
137 # 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
138 # define FP_GETL16(a) a.w[1]
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 #elif (SDL_BYTEORDER == SDL_LIL_ENDIAN)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 # define FP_SETH(a, k) a.w[1] = (k)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 # define FP_SETL(a, k) a.w[0] = (k)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 # 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
143 # 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
144 # 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
145 # 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
146 # define FP_GETL16(a) a.w[0]
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 #else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 # error Unsupported byte order!
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150
809
eba3b87f3f84 Add some separate macros for 64/32 precision fixed point types.
Matti Hamalainen <ccr@tnsp.org>
parents: 805
diff changeset
151 #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
152 #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
153
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 #define FP_ADD(a, b) a.dw += b.dw
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 #define FP_SUB(a, b) a.dw -= b.dw
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 #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
157 #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
158 #define FP_DIV(a, b) a.dw /= b.dw
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 #define FP_MUL(a, b) a.dw *= b.dw
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 #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
161 #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
162
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 /* Miscellaneous types
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 Uint8 a,g,b,r;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 #elif (SDL_BYTEORDER == SDL_LIL_ENDIAN)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 Uint8 r,g,b,a;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 } DMRGBA32;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 typedef float DMFloat;
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
118
c36e0316de9f Move DM_SWAP() macro to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
179 // 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
180 #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
181
c36e0316de9f Move DM_SWAP() macro to dmlib.h
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
182
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 /* Drawing modes used by blitting and some other functions.
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 enum
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 DMD_NONE = 0x0000,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 DMD_TRANSPARENT = 0x0001,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 DMD_SATURATE = 0x0002,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 DMD_ANTIALIAS = 0x0004,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 DMD_NMODES = 6
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 // Available bitdepths. Not all functions may support every one of these.
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 enum
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 DMD_8BIT = 0,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 DMD_32BIT,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 DMD_NBITDEPTHS
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 static inline int dmBitsPerPixel2Index(int bpp)
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 return (bpp == 8 ? 0 : (bpp == 32 ? 1 : -1));
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 /* Generic parameter interpolation
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 #define DMM_S_CURVE(t) ((t) * (t) * (3.0f - 2.0f * (t)))
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 #define DMM_LERP(t, a, b) ((a) + (t) * ((b) - (a)))
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 DMFloat start, end, nsteps;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 } DMLerpContext;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 void dmLerpInit(DMLerpContext *ctx, DMFloat start, DMFloat end, DMFloat nsteps);
108
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
225 DMFloat dmCatmullRom(const DMFloat t, const DMFloat p0, const DMFloat p1, const DMFloat p2, const DMFloat p3);
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
226
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
227
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
228 static inline DMFloat dmClamp10(const DMFloat a)
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
229 {
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
230 return (a < 0.0f ? 0.0f : (a > 1.0f ? 1.0f : a));
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
231 }
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
232
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
233
153
0b2866e25bf1 Add dmClamp(value, min, max) for clamping integer values.
Matti Hamalainen <ccr@tnsp.org>
parents: 150
diff changeset
234 static inline int dmClamp(const int v, const int min, const int max)
0b2866e25bf1 Add dmClamp(value, min, max) for clamping integer values.
Matti Hamalainen <ccr@tnsp.org>
parents: 150
diff changeset
235 {
0b2866e25bf1 Add dmClamp(value, min, max) for clamping integer values.
Matti Hamalainen <ccr@tnsp.org>
parents: 150
diff changeset
236 return (v < min ? min : (v > max ? max : v));
0b2866e25bf1 Add dmClamp(value, min, max) for clamping integer values.
Matti Hamalainen <ccr@tnsp.org>
parents: 150
diff changeset
237 }
0b2866e25bf1 Add dmClamp(value, min, max) for clamping integer values.
Matti Hamalainen <ccr@tnsp.org>
parents: 150
diff changeset
238
0b2866e25bf1 Add dmClamp(value, min, max) for clamping integer values.
Matti Hamalainen <ccr@tnsp.org>
parents: 150
diff changeset
239
108
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
240 static inline DMFloat dmLerpSCurve(DMLerpContext *ctx, const DMFloat step)
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
241 {
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
242 const DMFloat n = step / ctx->nsteps;
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
243 const DMFloat v = DMM_S_CURVE(n);
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
244 return DMM_LERP(v, ctx->start, ctx->end);
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
245 }
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
246
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
247
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
248 static inline DMFloat dmLerpSCurveClamp(DMLerpContext *ctx, const DMFloat step)
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
249 {
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
250 const DMFloat n = dmClamp10(step / ctx->nsteps);
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
251 const DMFloat v = DMM_S_CURVE(n);
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
252 return DMM_LERP(v, ctx->start, ctx->end);
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
253 }
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
254
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
255
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
256 static inline DMFloat dmLerp1(DMLerpContext *ctx, const DMFloat step)
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
257 {
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
258 const DMFloat v = step / ctx->nsteps;
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
259 return DMM_LERP(v, ctx->start, ctx->end);
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
260 }
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
261
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
262
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
263 static inline DMFloat dmLerp1Clamp(DMLerpContext *ctx, const DMFloat step)
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
264 {
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
265 const DMFloat v = dmClamp10(step / ctx->nsteps);
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
266 return DMM_LERP(v, ctx->start, ctx->end);
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
267 }
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
268
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
269
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
270 static inline DMFloat dmCatmullRomClamp(const DMFloat t, const DMFloat p0, const DMFloat p1, const DMFloat p2, const DMFloat p3)
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
271 {
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
272 return dmCatmullRom(dmClamp10(t), p0, p1, p2, p3);
72813cece1ba Move some lerp functions to the header as static inline functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
273 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 /* Arbitrary line drawing
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 #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
279 #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
280 #include "dmlinefunc.h"
234
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
281
262
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
282 enum
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
283 {
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
284 CLIP_TOP = 1,
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
285 CLIP_BOTTOM = 2,
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
286 CLIP_RIGHT = 4,
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
287 CLIP_LEFT = 8
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
288 };
9d015d32841a Clean up the line clipping a bit, in preparation for fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 234
diff changeset
289
234
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
290 #define DM_CLIP_FUNC dmClipLineCoordsFloat
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
291 #define DM_COORD_TYPE DMFloat
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
292 #include "dmlineclip.h"
a2abd0b991b6 Modularize line drawing related templates and functions, add clipping
Matti Hamalainen <ccr@tnsp.org>
parents: 232
diff changeset
293
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
294 #undef DM_HEADER
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296
95
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
297
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
298 /* Various blitting functions
0
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 #ifdef DM_GFX_BLITS
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 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
302 DMScaledBlitFunc dmGetScaledBlitFunc(SDL_PixelFormat *src, SDL_PixelFormat *dst, int mode);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 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
304
95
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
305 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
306 DMUnscaledBlitFunc dmGetUnscaledBlitFunc(SDL_PixelFormat *src, SDL_PixelFormat *dst, int mode);
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
307 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
308
610
e74ad60b1e85 Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents: 601
diff changeset
309 SDL_Surface *dmConvertScaledSurface(SDL_Surface *src, SDL_PixelFormat *fmt, Uint32 flags, const int dwidth, const int dheight);
e74ad60b1e85 Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents: 601
diff changeset
310
e74ad60b1e85 Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents: 601
diff changeset
311
232
79dac918c81e Modularize line clipping etc. a lot, and export all line drawing and
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
312 #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
313 #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
314 #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
315
696f03f30c0e Make certain static inline graphics functions always available, no need to
Matti Hamalainen <ccr@tnsp.org>
parents: 611
diff changeset
316 #endif // DM_GFX_BLITS
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317
95
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
318
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 /* Misc functions
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_MISC
612
696f03f30c0e Make certain static inline graphics functions always available, no need to
Matti Hamalainen <ccr@tnsp.org>
parents: 611
diff changeset
322
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 void dmFillRect(SDL_Surface *screen, int x0, int y0, int x1, int y1, const Uint32 col);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 void dmDrawHLine(SDL_Surface *screen, int x0, int x1, int yc, const Uint32 col);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 void dmDrawVLine(SDL_Surface *screen, int y0, int y1, int xc, const Uint32 col);
150
e147c07e41cb Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
326
e147c07e41cb Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
327 void dmDrawBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 ucol, Uint32 dcol);
e147c07e41cb Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
328 void dmFillBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 bgcol, Uint32 ucol, Uint32 dcol);
e147c07e41cb Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
329
612
696f03f30c0e Make certain static inline graphics functions always available, no need to
Matti Hamalainen <ccr@tnsp.org>
parents: 611
diff changeset
330 #endif // DM_GFX_MISC
696f03f30c0e Make certain static inline graphics functions always available, no need to
Matti Hamalainen <ccr@tnsp.org>
parents: 611
diff changeset
331
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
332
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 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
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 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
336 }
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
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 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
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 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
342 }
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
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 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
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 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
348 }
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
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 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
352 {
1ab3fd8b9afc Move some very tiny gfx functions to the dmlib header as static inline ones.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
353 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
354 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356
611
828d86cd10e0 Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
357 static inline SDL_Surface *dmCopySurface(SDL_Surface *src)
828d86cd10e0 Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
358 {
828d86cd10e0 Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
359 if (src != NULL)
828d86cd10e0 Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
360 return SDL_ConvertSurface(src, src->format, src->flags);
828d86cd10e0 Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
361 else
828d86cd10e0 Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
362 return NULL;
828d86cd10e0 Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
363 }
828d86cd10e0 Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
364
828d86cd10e0 Add new dmCopySurface() helper/wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
365
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 /* Global variables
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 extern char *dmProgName,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 *dmProgDesc,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 *dmProgVersion,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371 *dmProgAuthor,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 *dmProgLicense;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 extern int dmVerbosity;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 void dmInitProg(char *name, char *desc, char *version, char *author, char *license);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 void dmPrintBanner(FILE *outFile, const char *name, const char *usage);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378 void dmMsgVA(int level, const char *fmt, va_list ap);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 void dmMsg(int level, const char *fmt, ...);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 void dmPrintVA(int level, const char *fmt, va_list ap);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 void dmPrint(int level, const char *fmt, ...);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 void dmErrorVA(const char *fmt, va_list);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 void dmError(const char *fmt, ...);
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 void * dmMalloc(size_t);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 void * dmMalloc0(size_t);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387 void * dmRealloc(void *, size_t);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388 void * dmCalloc(size_t, size_t);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 void dmFree(void *);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
391 BOOL dmGetIntVal(const char *s, unsigned int *i);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 int dmGetErrno();
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 const char *dmErrorStr(int error);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396 char * dm_strdup(const char *);
744
2726d91e3409 Add implementation of dm_strndup().
Matti Hamalainen <ccr@tnsp.org>
parents: 612
diff changeset
397 char * dm_strndup(const char *, const size_t n);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 char * dm_strdup_vprintf(const char *, va_list);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 char * dm_strdup_printf(const char *, ...);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400
813
b0cd28b6c9f3 Add new utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
401 char * dm_basefilename(const char *filename);
b0cd28b6c9f3 Add new utility functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
402 char * dm_strdup_fext(const char *filename, const char *fmt);
816
091461e0213f Add new utility function.
Matti Hamalainen <ccr@tnsp.org>
parents: 813
diff changeset
403 char * dm_strrcasecmp(char *str, const char *needle);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404
294
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
405 /* Mutexes
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
406 */
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
407 #ifdef DM_MUTEX_DEBUG
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
408
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
409 typedef struct
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
410 {
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
411 BOOL used;
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
412 Uint32 id;
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
413 int state;
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
414 } DMMutexLock;
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
415
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
416 typedef struct
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
417 {
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
418 char *cr_file;
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
419 int cr_line;
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
420 SDL_mutex *m;
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
421 DMMutexLock locks[8];
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
422 } DMMutex;
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
423
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
424 #define dmMutexLock(x) dmDOMutexLock(x, __FILE__, (int) __LINE__)
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
425 #define dmMutexUnlock(x) dmDOMutexUnlock(x, __FILE__, (int) __LINE__)
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
426 #define dmCreateMutex(x) dmDOCreateMutex(__FILE__, (int) __LINE__)
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
427
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
428 int dmDOMutexLock(DMMutex *mutex, const char *file, const int line);
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
429 int dmDOMutexUnlock(DMMutex *mutex, const char *file, const int line);
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
430 DMMutex * dmDOCreateMutex(const char *file, const int line);
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
431 void dmDestroyMutex(DMMutex *mutex);
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
432
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
433 #else
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
434 #define DMMutex SDL_mutex
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
435 #define dmCreateMutex() SDL_CreateMutex()
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
436 #define dmDestroyMutex(x) SDL_DestroyMutex(x)
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
437 #define dmMutexLock(x) SDL_mutexP(x)
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
438 #define dmMutexUnlock(x) SDL_mutexV(x)
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
439 #endif
dd9809a93425 Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
440
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 /* Endianess swapping macros
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443 #define DM_SWAP_16_LE_BE(value) ((Uint16) ( \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444 (Uint16) ((Uint16) (value) >> 8) | \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445 (Uint16) ((Uint16) (value) << 8)) )
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448 #define DM_SWAP_32_LE_BE(value) ((Uint32) ( \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 (((Uint32) (value) & (Uint32) 0x000000ffU) << 24) | \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 (((Uint32) (value) & (Uint32) 0x0000ff00U) << 8) | \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 (((Uint32) (value) & (Uint32) 0x00ff0000U) >> 8) | \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 (((Uint32) (value) & (Uint32) 0xff000000U) >> 24)))
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 #define DM_SWAP_64_LE_BE(value) ((Uint64) ( \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455 (((Uint64) (value) & (Uint64) 0x00000000000000ffULL) << 56) | \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456 (((Uint64) (value) & (Uint64) 0x000000000000ff00ULL) << 40) | \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457 (((Uint64) (value) & (Uint64) 0x0000000000ff0000ULL) << 24) | \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458 (((Uint64) (value) & (Uint64) 0x00000000ff000000ULL) << 8) | \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 (((Uint64) (value) & (Uint64) 0x000000ff00000000ULL) >> 8) | \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460 (((Uint64) (value) & (Uint64) 0x0000ff0000000000ULL) >> 24) | \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461 (((Uint64) (value) & (Uint64) 0x00ff000000000000ULL) >> 40) | \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462 (((Uint64) (value) & (Uint64) 0xff00000000000000ULL) >> 56)))
873
26ea35e914ca Oops. 10L.
Matti Hamalainen <ccr@tnsp.org>
parents: 872
diff changeset
463
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465 /* Macros that swap only when needed ...
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
468 # define DM_LE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value)
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
469 # define DM_LE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value)
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
470 # define DM_NATIVE_TO_LE16(value) DM_SWAP_16_LE_BE(value)
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
471 # 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
472
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
473 # define DM_BE16_TO_NATIVE(value) ((Uint16) (value))
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
474 # define DM_BE32_TO_NATIVE(value) ((Uint32) (value))
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
475 # define DM_NATIVE_TO_BE16(value) ((Uint16) (value))
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
476 # define DM_NATIVE_TO_BE32(value) ((Uint32) (value))
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477
872
b01d04e44b6f Assume we always have 64bit type.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
478 # 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
479 # 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
480 # define DM_BE64_TO_NATIVE(value) ((Uint64) (value))
b01d04e44b6f Assume we always have 64bit type.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
481 # define DM_NATIVE_TO_BE64(value) ((Uint64) (value))
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483 #elif (SDL_BYTEORDER == SDL_LIL_ENDIAN)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
485 # define DM_LE16_TO_NATIVE(value) ((Uint16) (value))
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
486 # define DM_LE32_TO_NATIVE(value) ((Uint32) (value))
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
487 # define DM_NATIVE_TO_LE16(value) ((Uint16) (value))
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
488 # define DM_NATIVE_TO_LE32(value) ((Uint32) (value))
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489
770
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
490 # define DM_BE16_TO_NATIVE(value) DM_SWAP_16_LE_BE(value)
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
491 # define DM_BE32_TO_NATIVE(value) DM_SWAP_32_LE_BE(value)
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
492 # define DM_NATIVE_TO_BE16(value) DM_SWAP_16_LE_BE(value)
a8bd679934c7 Indentation cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 744
diff changeset
493 # 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
494
872
b01d04e44b6f Assume we always have 64bit type.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
495 # define DM_LE64_TO_NATIVE(value) ((Uint64) (value))
b01d04e44b6f Assume we always have 64bit type.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
496 # define DM_NATIVE_TO_LE64(value) ((Uint64) (value))
b01d04e44b6f Assume we always have 64bit type.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
497 # 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
498 # 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
499 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
502 #ifdef __cplusplus
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504 #endif
359
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 341
diff changeset
505
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 #endif // DMLIB_H