2 * Amiga Generic Set - set of libraries and includes to ease sw development for all Amiga platforms
3 * Copyright (C) 2001-2011 Tomasz Wiszkowski Tomasz.Wiszkowski at gmail.com.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #ifndef _GENERIC_TYPES_H_
21 #define _GENERIC_TYPES_H_
26 * \brief This file defines types for all four architectures.\n
27 * Carries all the type specifications, array macros and other defines.
31 * default types common for all platforms.
34 typedef unsigned long long uint64
; /**< @brief unsigned 64bit integer */
35 typedef unsigned long int uint32
; /**< @brief unsigned 32bit integer */
36 typedef unsigned short uint16
; /**< @brief unsigned 16bit integer */
37 typedef unsigned char uint8
; /**< @brief unsigned 8bit integer */
38 typedef signed long long int64
; /**< @brief signed 64bit integer */
39 typedef signed long int int32
; /**< @brief signed 32bit integer */
40 typedef signed short int16
; /**< @brief signed 16bit integer */
41 typedef signed char int8
; /**< @brief signed 8bit integer */
43 typedef signed long sint
; /**< @brief architecture specific signed int: sizeof(s_int) = sizeof(void*) */
44 typedef unsigned long uint
; /**< @brief architecture specific unsigned int: sizeof(u_int) = sizeof(void*) */
46 typedef uint
* sized_iptr
; /**< @brief type returned by #SIZEARRAY to differentiate it from normal pointers */
47 typedef uint
* iptr
; /**< @brief type returned by #ARRAY to differentiate it from normal pointers */
49 /* platform specific includes */
52 #elif defined(__mc68000)
53 typedef long unsigned int size_t;
55 #elif defined(__AMIGAOS4__)
56 typedef unsigned int size_t;
58 #elif defined(__MORPHOS__)
59 typedef unsigned int size_t;
61 #error no size_t defined
64 #define PACKED __attribute__((packed))
68 * \brief Suggested enum for all three-state functions that accept or return
69 * true, false or unknown states.
73 stUnknown
= -1, /**< Unknown state */
74 stNo
= 0, /**< No = False */
75 stFalse
= 0, /**< No = False */
76 stYes
= 1, /**< Yes = True */
77 stTrue
= 1 /**< Yes = True */
80 //! Use this macro instead of varargs. Maintains compatibility across platforms.
81 #define ARRAY(arg...) \
84 uint __parm[] = {arg}; \
89 * \brief Use this macro whenever you need to pass varargs along with the array size.\n
90 * \b Size is always stored in \b param[-1].
92 #define SIZEARRAY(arg...) \
95 uint __parm[] = {0, arg}; \
96 __parm[0] = sizeof(__parm) / sizeof(__parm[0]) - 1; \
101 * \def TAGARRAY(arg...)
102 * \brief Use this macro to pass the tagitem structure to any function.\n
103 * Tags defined with \a arg are automatically TAG_DONE terminated.
105 #define TAGARRAY(arg...) \
108 uint __parm[] = {arg, TAG_DONE, TAG_DONE}; \
113 * \def OFFSET(type, field)
114 * \brief this macro calculates offset of field within structure.
116 #define OFFSETOF(type, field) \
117 ((size_t)(&((type*)1)->field)-1)
120 * \def OFFSETWITH(type, field)
121 * \brief this macro calculates offset of first element after the selected field
123 #define OFFSETWITH(type, field) \
124 (((size_t)(&((type*)1)->field))+sizeof(type::field)-1)
127 * \def SWAP_WORD(data)
128 * \brief switches endian of a 16-bit word
130 #define SWAP_WORD(data) (((data & 0xff) << 8) | ((data >> 8) & 0xff))
133 * \def SWAP_LONG(data)
134 * \brief switches endian of a 32-bit word
136 #define SWAP_LONG(data) ({ register uint32 t = (((data & 0xffff) << 16) | ((data >> 16) &0xffff)); \
137 t = ((t >> 8) & 0xff00ff) | ((t & 0xff00ff) << 8); t; })
140 #define ENDIAN BIG /**< @brief Defines endianess for current architecture. Can be either @b BIG or @b LITTLE */
144 * @brief Way to change any word into BigEndian
145 * or change any BigEndian word to current arch.
149 * @brief Way to change any word into LittleEndian
150 * or change andy LittleEndian word to current arch.
152 #define W2LE(x) ((((x)>>8)&255) | (((x)&255)<<8))
154 * @brief Way to change any long into BigEndian
155 * or change any BigEndian long to current arch.
159 * @brief Way to change any long into LittleEndian
160 * or change andy LittleEndian long to current arch.
162 #define L2LE(x) ((((x)>>24)&255) | (((x)>>8)&0xff00) | (((x)<<8)&0xff0000) | (((x)<<24)&0xff000000))
164 #define ENDIAN LITTLE
166 #define W2BE(x) ((((x)>>8)&255) | (((x)&255)<<8))
168 #define L2BE(x) ((((x)>>24)&255) | (((x)>>8)&0xff00) | (((x)<<8)&0xff0000) | (((x)<<24)&0xff000000))