1 /*         ______   ___    ___
2  *        /\  _  \ /\_ \  /\_ \
3  *        \ \ \L\ \\//\ \ \//\ \      __     __   _ __   ___
4  *         \ \  __ \ \ \ \  \ \ \   /'__`\ /'_ `\/\`'__\/ __`\
5  *          \ \ \/\ \ \_\ \_ \_\ \_/\  __//\ \L\ \ \ \//\ \L\ \
6  *           \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
7  *            \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/
8  *                                           /\____/
9  *                                           \_/__/
10  *
11  *      Configuration defines.
12  *
13  *      By Shawn Hargreaves.
14  *
15  *      See readme.txt for copyright information.
16  */
17 
18 
19 /* which color depths to include? */
20 #define ALLEGRO_COLOR8
21 #define ALLEGRO_COLOR16
22 #define ALLEGRO_COLOR24
23 #define ALLEGRO_COLOR32
24 
25 
26 /* for backward compatibility */
27 #ifdef USE_CONSOLE
28    #define ALLEGRO_NO_MAGIC_MAIN
29    #define ALLEGRO_USE_CONSOLE
30 #endif
31 
32 
33 /* include platform-specific stuff */
34 #ifndef SCAN_EXPORT
35    #ifndef SCAN_DEPEND
36       #include "allegro/platform/alplatf.h"
37    #endif
38 
39    #if defined ALLEGRO_DJGPP
40       #include "allegro/platform/aldjgpp.h"
41    #elif defined ALLEGRO_WATCOM
42       #include "allegro/platform/alwatcom.h"
43    #elif defined ALLEGRO_MINGW32
44       #include "allegro/platform/almngw32.h"
45    #elif defined ALLEGRO_DMC
46       #include "allegro/platform/aldmc.h"
47    #elif defined ALLEGRO_BCC32
48       #include "allegro/platform/albcc32.h"
49    #elif defined ALLEGRO_MSVC
50       #include "allegro/platform/almsvc.h"
51    #elif defined ALLEGRO_HAIKU
52       #include "allegro/platform/albecfg.h"
53    #elif defined ALLEGRO_BEOS
54       #include "allegro/platform/albecfg.h"
55    #elif defined ALLEGRO_MPW
56       #include "allegro/platform/almaccfg.h"
57    #elif defined ALLEGRO_MACOSX
58       #include "allegro/platform/alosxcfg.h"
59    #elif defined ALLEGRO_QNX
60       #include "allegro/platform/alqnxcfg.h"
61    #elif defined ALLEGRO_UNIX
62       #include "allegro/platform/alucfg.h"
63    #elif defined ALLEGRO_PSP
64       #include "allegro/platform/alpspcfg.h"
65    #else
66       #error platform not supported
67    #endif
68 
69    #ifndef SCAN_DEPEND
70       #include "allegro/platform/astdint.h"
71    #endif
72 #endif
73 
74 
75 /* special definitions for the GCC compiler */
76 #ifdef __GNUC__
77    #define ALLEGRO_GCC
78 
79    #ifndef AL_INLINE
80       #ifdef __cplusplus
81          #define AL_INLINE(type, name, args, code)    \
82             static inline type name args;             \
83             static inline type name args code
84       /* Needed if this header is included by C99 user code, as
85        * "extern __inline__" is defined differently in C99 (it exports
86        * a new global function symbol).
87        */
88       #elif __GNUC_STDC_INLINE__
89          #define AL_INLINE(type, name, args, code)    \
90             extern __inline__ __attribute__((__gnu_inline__)) type name args;         \
91             extern __inline__ __attribute__((__gnu_inline__)) type name args code
92       #else
93          #define AL_INLINE(type, name, args, code)    \
94             extern __inline__ type name args;         \
95             extern __inline__ type name args code
96       #endif
97    #endif
98 
99    #define AL_PRINTFUNC(type, name, args, a, b)    AL_FUNC(type, name, args) __attribute__ ((format (printf, a, b)))
100 
101    #ifndef INLINE
102       #define INLINE          __inline__
103    #endif
104 
105    #if __GNUC__ >= 3
106       /* SET: According to gcc volatile is ignored for a return type.
107        * I think the code should just ensure that inportb is declared as an
108        * __asm__ __volatile__ macro. If that's the case the extra volatile
109        * doesn't have any sense.
110        */
111       #define RET_VOLATILE
112    #else
113       #define RET_VOLATILE    volatile
114    #endif
115 
116    #ifndef ZERO_SIZE_ARRAY
117       #if __GNUC__ < 3
118          #define ZERO_SIZE_ARRAY(type, name)  __extension__ type name[0]
119       #else
120          #define ZERO_SIZE_ARRAY(type, name)  type name[] /* ISO C99 flexible array members */
121       #endif
122    #endif
123 
124    #ifndef LONG_LONG
125       #define LONG_LONG       long long
126       #ifdef ALLEGRO_GUESS_INTTYPES_OK
127          #define int64_t      signed long long
128          #define uint64_t     unsigned long long
129       #endif
130    #endif
131 
132    #ifdef __i386__
133       #define ALLEGRO_I386
134       #ifndef ALLEGRO_NO_ASM
135          #define _AL_SINCOS(x, s, c)  __asm__ ("fsincos" : "=t" (c), "=u" (s) : "0" (x))
136       #endif
137    #endif
138 
139    #ifdef __amd64__
140       #define ALLEGRO_AMD64
141       #ifndef ALLEGRO_NO_ASM
142          #define _AL_SINCOS(x, s, c)  __asm__ ("fsincos" : "=t" (c), "=u" (s) : "0" (x))
143       #endif
144    #endif
145 
146    #ifdef __arm__
147       #define ALLEGRO_ARM
148    #endif
149 
150    #ifndef AL_CONST
151       #define AL_CONST     const
152    #endif
153 
154    #ifndef AL_FUNC_DEPRECATED
155       #if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
156          #define AL_FUNC_DEPRECATED(type, name, args)              AL_FUNC(__attribute__ ((deprecated)) type, name, args)
157          #define AL_PRINTFUNC_DEPRECATED(type, name, args, a, b)   AL_PRINTFUNC(__attribute__ ((deprecated)) type, name, args, a, b)
158          #define AL_INLINE_DEPRECATED(type, name, args, code)      AL_INLINE(__attribute__ ((deprecated)) type, name, args, code)
159       #endif
160    #endif
161 
162    #ifndef AL_ALIAS
163       #define AL_ALIAS(DECL, CALL)                      \
164       static __attribute__((unused)) __inline__ DECL    \
165       {                                                 \
166          return CALL;                                   \
167       }
168    #endif
169 
170    #ifndef AL_ALIAS_VOID_RET
171       #define AL_ALIAS_VOID_RET(DECL, CALL)                  \
172       static __attribute__((unused)) __inline__ void DECL    \
173       {                                                      \
174          CALL;                                               \
175       }
176    #endif
177 #endif
178 
179 
180 /* use constructor functions, if supported */
181 #ifdef ALLEGRO_USE_CONSTRUCTOR
182    #define CONSTRUCTOR_FUNCTION(func)              func __attribute__ ((constructor))
183    #define DESTRUCTOR_FUNCTION(func)               func __attribute__ ((destructor))
184 #endif
185 
186 
187 /* the rest of this file fills in some default definitions of language
188  * features and helper functions, which are conditionalised so they will
189  * only be included if none of the above headers defined custom versions.
190  */
191 
192 #ifndef _AL_SINCOS
193    #define _AL_SINCOS(x, s, c)  do { (c) = cos(x); (s) = sin(x); } while (0)
194 #endif
195 
196 #ifndef INLINE
197    #define INLINE
198 #endif
199 
200 #ifndef RET_VOLATILE
201    #define RET_VOLATILE   volatile
202 #endif
203 
204 #ifndef ZERO_SIZE_ARRAY
205    #define ZERO_SIZE_ARRAY(type, name)             type name[]
206 #endif
207 
208 #ifndef AL_CONST
209    #define AL_CONST
210 #endif
211 
212 #ifndef AL_VAR
213    #define AL_VAR(type, name)                      extern type name
214 #endif
215 
216 #ifndef AL_ARRAY
217    #define AL_ARRAY(type, name)                    extern type name[]
218 #endif
219 
220 #ifndef AL_FUNC
221    #define AL_FUNC(type, name, args)               type name args
222 #endif
223 
224 #ifndef AL_PRINTFUNC
225    #define AL_PRINTFUNC(type, name, args, a, b)    AL_FUNC(type, name, args)
226 #endif
227 
228 #ifndef AL_METHOD
229    #define AL_METHOD(type, name, args)             type (*name) args
230 #endif
231 
232 #ifndef AL_FUNCPTR
233    #define AL_FUNCPTR(type, name, args)            extern type (*name) args
234 #endif
235 
236 #ifndef AL_FUNCPTRARRAY
237    #define AL_FUNCPTRARRAY(type, name, args)       extern type (*name[]) args
238 #endif
239 
240 #ifndef AL_INLINE
241    #define AL_INLINE(type, name, args, code)       type name args;
242 #endif
243 
244 #ifndef AL_FUNC_DEPRECATED
245    #define AL_FUNC_DEPRECATED(type, name, args)              AL_FUNC(type, name, args)
246    #define AL_PRINTFUNC_DEPRECATED(type, name, args, a, b)   AL_PRINTFUNC(type, name, args, a, b)
247    #define AL_INLINE_DEPRECATED(type, name, args, code)      AL_INLINE(type, name, args, code)
248 #endif
249 
250 #ifndef AL_ALIAS
251    #define AL_ALIAS(DECL, CALL)              \
252    static INLINE DECL                        \
253    {                                         \
254       return CALL;                           \
255    }
256 #endif
257 
258 #ifndef AL_ALIAS_VOID_RET
259    #define AL_ALIAS_VOID_RET(DECL, CALL)     \
260    static INLINE void DECL                   \
261    {                                         \
262       CALL;                                  \
263    }
264 #endif
265 
266 #ifndef END_OF_MAIN
267    #define END_OF_MAIN()
268 #endif
269 
270 
271 /* fill in default memory locking macros */
272 #ifndef END_OF_FUNCTION
273    #define END_OF_FUNCTION(x)
274    #define END_OF_STATIC_FUNCTION(x)
275    #define LOCK_DATA(d, s)
276    #define LOCK_CODE(c, s)
277    #define UNLOCK_DATA(d, s)
278    #define LOCK_VARIABLE(x)
279    #define LOCK_FUNCTION(x)
280 #endif
281 
282 
283 /* fill in default filename behaviour */
284 #ifndef ALLEGRO_LFN
285    #define ALLEGRO_LFN  1
286 #endif
287 
288 #if (defined ALLEGRO_DOS) || (defined ALLEGRO_WINDOWS)
289    #define OTHER_PATH_SEPARATOR  '\\'
290    #define DEVICE_SEPARATOR      ':'
291 #else
292    #define OTHER_PATH_SEPARATOR  '/'
293    #define DEVICE_SEPARATOR      '\0'
294 #endif
295 
296 
297 /* emulate the FA_* flags for platforms that don't already have them */
298 #ifndef FA_RDONLY
299    #define FA_RDONLY       1
300    #define FA_HIDDEN       2
301    #define FA_SYSTEM       4
302    #define FA_LABEL        8
303    #define FA_DIREC        16
304    #define FA_ARCH         32
305 #endif
306    #define FA_NONE         0
307    #define FA_ALL          (~FA_NONE)
308 
309 
310 #ifdef __cplusplus
311    extern "C" {
312 #endif
313 
314 /* emulate missing library functions */
315 #ifdef ALLEGRO_NO_STRICMP
316    AL_FUNC(int, _alemu_stricmp, (AL_CONST char *s1, AL_CONST char *s2));
317    #define stricmp _alemu_stricmp
318 #endif
319 
320 #ifdef ALLEGRO_NO_STRLWR
321    AL_FUNC(char *, _alemu_strlwr, (char *string));
322    #define strlwr _alemu_strlwr
323 #endif
324 
325 #ifdef ALLEGRO_NO_STRUPR
326    AL_FUNC(char *, _alemu_strupr, (char *string));
327    #define strupr _alemu_strupr
328 #endif
329 
330 #ifdef ALLEGRO_NO_MEMCMP
331    AL_FUNC(int, _alemu_memcmp, (AL_CONST void *s1, AL_CONST void *s2, size_t num));
332    #define memcmp _alemu_memcmp
333 #endif
334 
335 
336 /* if nobody put them elsewhere, video bitmaps go in regular memory */
337 #ifndef _video_ds
338    #define _video_ds()  _default_ds()
339 #endif
340 
341 
342 /* not many places actually use these, but still worth emulating */
343 #ifndef ALLEGRO_DJGPP
344    #define _farsetsel(seg)
345    #define _farnspokeb(addr, val)   (*((uint8_t  *)(addr)) = (val))
346    #define _farnspokew(addr, val)   (*((uint16_t *)(addr)) = (val))
347    #define _farnspokel(addr, val)   (*((uint32_t *)(addr)) = (val))
348    #define _farnspeekb(addr)        (*((uint8_t  *)(addr)))
349    #define _farnspeekw(addr)        (*((uint16_t *)(addr)))
350    #define _farnspeekl(addr)        (*((uint32_t *)(addr)))
351 #endif
352 
353 
354 /* endian-independent 3-byte accessor macros */
355 #ifdef ALLEGRO_LITTLE_ENDIAN
356 
357    #define READ3BYTES(p)  ((*(unsigned char *)(p))               \
358                            | (*((unsigned char *)(p) + 1) << 8)  \
359                            | (*((unsigned char *)(p) + 2) << 16))
360 
361    #define WRITE3BYTES(p,c)  ((*(unsigned char *)(p) = (c)),             \
362                               (*((unsigned char *)(p) + 1) = (c) >> 8),  \
363                               (*((unsigned char *)(p) + 2) = (c) >> 16))
364 
365 #elif defined ALLEGRO_BIG_ENDIAN
366 
367    #define READ3BYTES(p)  ((*(unsigned char *)(p) << 16)         \
368                            | (*((unsigned char *)(p) + 1) << 8)  \
369                            | (*((unsigned char *)(p) + 2)))
370 
371    #define WRITE3BYTES(p,c)  ((*(unsigned char *)(p) = (c) >> 16),       \
372                               (*((unsigned char *)(p) + 1) = (c) >> 8),  \
373                               (*((unsigned char *)(p) + 2) = (c)))
374 
375 #elif defined SCAN_DEPEND
376 
377    #define READ3BYTES(p)
378    #define WRITE3BYTES(p,c)
379 
380 #else
381    #error endianess not defined
382 #endif
383 
384 
385 /* generic versions of the video memory access helpers */
386 #ifndef bmp_select
387    #define bmp_select(bmp)
388 #endif
389 
390 #ifndef bmp_write8
391    #define bmp_write8(addr, c)         (*((uint8_t  *)(addr)) = (c))
392    #define bmp_write15(addr, c)        (*((uint16_t *)(addr)) = (c))
393    #define bmp_write16(addr, c)        (*((uint16_t *)(addr)) = (c))
394    #define bmp_write32(addr, c)        (*((uint32_t *)(addr)) = (c))
395 
396    #define bmp_read8(addr)             (*((uint8_t  *)(addr)))
397    #define bmp_read15(addr)            (*((uint16_t *)(addr)))
398    #define bmp_read16(addr)            (*((uint16_t *)(addr)))
399    #define bmp_read32(addr)            (*((uint32_t *)(addr)))
400 
401    AL_INLINE(int, bmp_read24, (uintptr_t addr),
402    {
403       unsigned char *p = (unsigned char *)addr;
404       int c;
405 
406       c = READ3BYTES(p);
407 
408       return c;
409    })
410 
411    AL_INLINE(void, bmp_write24, (uintptr_t addr, int c),
412    {
413       unsigned char *p = (unsigned char *)addr;
414 
415       WRITE3BYTES(p, c);
416    })
417 
418 #endif
419 
420 
421 /* default random function definition */
422 #ifndef AL_RAND
423    #define AL_RAND()       (rand())
424 #endif
425 
426 #ifdef __cplusplus
427    }
428 #endif
429 
430 
431 /* parameters for the color conversion code */
432 #if (defined ALLEGRO_WINDOWS) || (defined ALLEGRO_QNX)
433    #define ALLEGRO_COLORCONV_ALIGNED_WIDTH
434    #define ALLEGRO_NO_COLORCOPY
435 #endif
436 
437