home *** CD-ROM | disk | FTP | other *** search
/ Dream 57 / Amiga_Dream_57.iso / Amiga / Programmation / c / QuakeC / qtools0.2-src.lha / src / libqsys / generic.h.in < prev    next >
Encoding:
Text File  |  1998-07-16  |  7.5 KB  |  303 lines

  1. #ifndef    GENERIC_H
  2. #define    GENERIC_H
  3. #include "rawkeys.h"
  4. #include "rawmouse.h"
  5.  
  6. #if defined(BROKEN_SPRINTF) && defined(HAVE_SNPRINTF)
  7. # undef     sprintf
  8. # define sprintf(str, format, args...) snprintf(str, 256, format, ##args)
  9. #endif                                /* BROKEN_SPRINTF */
  10.  
  11. #ifdef    __GNUC__
  12. # define __packed __attribute__ ((packed))
  13. #else
  14. # define __packed
  15. #endif
  16.  
  17. #ifdef    PROFILE
  18. # undef  inline
  19. # define inline                            /* no inlining while profiling */
  20. # undef  static                            /* no statics while profiling */
  21. # define static
  22. # define NOASM                            /* profile implies NOASM */
  23. #endif
  24.  
  25. #ifdef    __STRICT_ANSI__
  26. # undef  inline
  27. # define inline                            /* no inlining in ANSI-C */
  28. #endif
  29.  
  30. #define    HANDLE    int
  31. #include "generic-debug.h"
  32.  
  33. #ifdef    NOASM
  34. # undef  __asm__
  35. # define __asm__                        /* no asm-statements while compiling */
  36. # define staticvar
  37. #else
  38. # define staticvar static
  39. #endif
  40.  
  41. #undef    FALSE
  42. #undef    TRUE
  43. typedef enum {
  44.   FALSE =  0,                            /* nothing */
  45.   TRUE  = ~0                            /* everything */
  46. } __packed bool;
  47.  
  48. struct rgb {                            /* red/green/blue */
  49.   unsigned char r, g, b;
  50. } __packed;
  51.  
  52. struct argb {                            /* alpha/red/green/blue */
  53.   unsigned char a;
  54.   struct rgb rgb;
  55. } __packed;
  56.  
  57. struct DisplayDimension {
  58.   bool changedOffset;                        /* offset of display-device in global desktop (eg. the window on a screen) */
  59.   short int X, Y;
  60.   bool changedSize;                        /* size of display-device in global desktop (eg. the window on a screen) */
  61.   short int Width, Height;
  62.   bool changedDesktopOffset;                    /* offset of global desktop (eg. the screen) */
  63.   short int dtX, dtY;
  64.   bool changedDesktopSize;                    /* size of global desktop (eg. the screen) */
  65.   short int dtWidth, dtHeight;
  66.  
  67.   bool changedBuffer;                        /* the actual used framebuffer */
  68.   void *frameBuffer;                        /* address of the buffer to use for offscreen-rendering */
  69. #ifdef    USE_ZBUFFER
  70.   unsigned short int *zBuffer;                    /* address for zbuffer-comparisons */
  71. #endif
  72.   char frameDepth;                        /* the depth in bits */
  73.   char frameBPP;                        /* the depth in BitPerPel */
  74.   int frameSize;                        /* maximum size allowed to use */
  75.  
  76.   short int ID;                            /* id-field of display */
  77.   struct DisplayDimension *nextDim;                /* maybe we need more displays than one */
  78.   void *driverPrivate;                        /* some datas we need nothing know about; */
  79. };
  80.  
  81. extern struct DisplayDimension localDim;
  82.  
  83. /*
  84.  * here are the structs, externals and functions descripted,
  85.  * that could but must not be implemented by the system-drivers
  86.  * the file generic will ever compiled, you can activate
  87.  * your functions with defines
  88.  */
  89.  
  90. #undef    OPENDISPLAY
  91. struct DisplayDimension *OpenDisplay(short int width, short int height, char depth, struct rgb *Palette);
  92.  
  93. #undef    SWAPDISPLAY
  94. void *SwapDisplay(void *oldBuffer);
  95.  
  96. /*
  97.  * x,y are the offsets in the display-buffer
  98.  * width, height are the sizes of the buffer to be displayed
  99.  * (o offsets in the buffer to be displayed, must be width*height sized)
  100.  */
  101. #undef    UPDATEDISPLAY
  102. void *UpdateDisplay(void *oldBuffer, short int x, short int y, short int width, short int height);
  103.  
  104. #undef    CHANGEDISPLAY
  105. struct DisplayDimension *ChangeDisplay(short int width, short int height, char depth, struct rgb *Palette, char *Title);
  106.  
  107. #undef    CLOSEDISPLAY
  108. void CloseDisplay(void);
  109.  
  110. #undef    OPENKEYS
  111. void OpenKeys(void);
  112.  
  113. #undef    GETKEYS
  114. bool GetKeys(struct keyEvent *eventBuffer);
  115.  
  116. #undef    CLOSEKEYS
  117. void CloseKeys(void);
  118.  
  119. #undef    OPENMOUSE
  120. void OpenMouse(void);
  121.  
  122. #undef    GETMOUSE
  123. void GetMouse(struct mouseEvent *eventBuffer);
  124.  
  125. #undef    CLOSEMOUSE
  126. void CloseMouse(void);
  127.  
  128. void SetDisplay(struct DisplayDimension *dim);
  129.  
  130. /*
  131.  * canonical system
  132.  *
  133.  * everything you would like to replace you must replace
  134.  * in the include-files for your system, that could be a
  135.  * cpu-type or os-type
  136.  */
  137. #include "@target_cpu@/@target_cpu@.h"
  138. #include "@target_cpu@/@target_os@/@target_os@.h"
  139.  
  140. /*
  141.  * if you like you can specify a global register to pass the base
  142.  * in, then it is like indirect variable-access via the framepointer
  143.  */
  144. #ifndef    __memBase
  145. #define    __memBase    register struct memory *bspMem
  146. #endif
  147.  
  148. /*
  149.  * some system aspecially little-endian systems requires some
  150.  * special kind of file-attributes, textfiles could be opened
  151.  * as standard, binary file must have the binary-attribute
  152.  * upto now i dont know if the low-level-io functions support
  153.  * that behaviour
  154.  */
  155. #ifndef    READ_BINARY
  156. # if (WORDS_BIGENDIAN == 1)
  157. #   define H_READ_BINARY        O_RDONLY
  158. #   define F_READ_BINARY        "r"
  159. # else
  160. #   define H_READ_BINARY        O_RDONLY
  161. #   define F_READ_BINARY        "rb"
  162. # endif
  163. #endif
  164. #ifndef    WRITE_BINARY
  165. # if (WORDS_BIGENDIAN == 1)
  166. #  define H_WRITE_BINARY        (O_WRONLY | O_CREAT | O_TRUNC)
  167. #  define F_WRITE_BINARY        "w"
  168. # else
  169. #  define H_WRITE_BINARY        (O_WRONLY | O_CREAT | O_TRUNC)
  170. #  define F_WRITE_BINARY        "wb"
  171. # endif
  172. #endif
  173. #ifndef    READWRITE_BINARY_OLD
  174. # if (WORDS_BIGENDIAN == 1)
  175. #  define H_READWRITE_BINARY_OLD    (O_RDWR | O_CREAT)
  176. #  define F_READWRITE_BINARY_OLD    "r+"
  177. # else
  178. #  define H_READWRITE_BINARY_OLD    (O_RDWR | O_CREAT)
  179. #  define F_READWRITE_BINARY_OLD    "rb+"
  180. # endif
  181. #endif
  182. #ifndef    READWRITE_BINARY_NEW
  183. # if (WORDS_BIGENDIAN == 1)
  184. #  define H_READWRITE_BINARY_NEW    (O_RDWR | O_CREAT | O_TRUNC)
  185. #  define F_READWRITE_BINARY_NEW    "w+"
  186. # else
  187. #  define H_READWRITE_BINARY_NEW    (O_RDWR | O_CREAT | O_TRUNC)
  188. #  define F_READWRITE_BINARY_NEW    "wb+"
  189. # endif
  190. #endif
  191.  
  192. #ifndef    MATCH
  193. unsigned char Match(register struct rgb *rawpix, register struct rgb *Palette);
  194. #endif
  195.  
  196. /*
  197.  * at the moment the special compressor isnt available for other systems
  198.  * than m68k, take a look at the LZWSfiles in this directory for the
  199.  * growing c-version, maybe you could help
  200.  */
  201. #ifndef    LZWS
  202. #define    LZWSCrunch(a, b, c, d, e) (0)
  203. #define    LZWSDecrunch(a, b, c) (0)
  204. #define    LZWSSize(a) (0)
  205. #define    ERROR 0
  206. #endif
  207.  
  208. #ifndef    OPENDISPLAY                        /* our offscreen-renderer supports all display-modes */
  209. #define    DRIVER_8BIT
  210. #define    DRIVER_16BIT
  211. #define    DRIVER_24BIT
  212. #define    DRIVER_32BIT
  213. #define    DRIVER_DEFAULT    8
  214. #endif
  215.  
  216. /*
  217.  * if you have choosen an unsupported defaultdriver
  218.  * you getll get a error here
  219.  */
  220. #if !defined(DRIVER_8BIT) && (DRIVER_DEFAULT == 8)
  221. #error    "unsupported default driver choosen"
  222. #endif
  223. #if !defined(DRIVER_16BIT) && (DRIVER_DEFAULT == 16)
  224. #error    "unsupported default driver choosen"
  225. #endif
  226. #if !defined(DRIVER_24BIT) && (DRIVER_DEFAULT == 24)
  227. #error    "unsupported default driver choosen"
  228. #endif
  229. #if !defined(DRIVER_32BIT) && (DRIVER_DEFAULT == 32)
  230. #error    "unsupported default driver choosen"
  231. #endif
  232.  
  233. #ifdef INLINE_BIGENDIAN
  234. #ifndef    SWAPSHORT
  235. #define    SWAPSHORT
  236. static short SwapShort(short l);
  237. static inline short SwapShort(short l)
  238. {
  239.   unsigned char b1, b2;
  240.  
  241.   b1 = l & 255;
  242.   b2 = (l >> 8) & 255;
  243.  
  244.   return (b1 << 8) + b2;
  245. }
  246. #endif
  247.  
  248. #ifndef    SWAPLONG
  249. #define    SWAPLONG
  250. static int SwapLong(int l);
  251. static inline int SwapLong(int l)
  252. {
  253.   unsigned char b1, b2, b3, b4;
  254.  
  255.   b1 = l & 255;
  256.   b2 = (l >> 8) & 255;
  257.   b3 = (l >> 16) & 255;
  258.   b4 = (l >> 24) & 255;
  259.  
  260.   return ((int)b1 << 24) + ((int)b2 << 16) + ((int)b3 << 8) + b4;
  261. }
  262.  
  263. #endif
  264.  
  265. #ifndef    SWAPFLOAT
  266. #define    SWAPFLOAT
  267. static float SwapFloat(float l);
  268. static inline float SwapFloat(float l)
  269. {
  270.   union {
  271.     unsigned char b[4];
  272.     float f;
  273.   } in, out;
  274.  
  275.   in.f = l;
  276.   out.b[0] = in.b[3];
  277.   out.b[1] = in.b[2];
  278.   out.b[2] = in.b[1];
  279.   out.b[3] = in.b[0];
  280.  
  281.   return out.f;
  282. }
  283. #endif
  284. #endif
  285.  
  286. #if (WORDS_BIGENDIAN == 1)
  287. #define BigShort(a) (a)
  288. #define LittleShort(a) SwapShort(a)
  289. #define BigLong(a) (a)
  290. #define LittleLong(a) SwapLong(a)
  291. #define BigFloat(a) (a)
  292. #define LittleFloat(a) SwapFloat(a)
  293. #else
  294. #define BigShort(a) SwapShort(a)
  295. #define LittleShort(a) (a)
  296. #define BigLong(a) SwapLong(a)
  297. #define LittleLong(a) (a)
  298. #define BigFloat(a) SwapFoat(a)
  299. #define LittleFloat(a) (a)
  300. #endif
  301.  
  302. #endif
  303.