~jazzva/fakenes/ubuntu

« back to all changes in this revision

Viewing changes to src/include/common.h

  • Committer: Sasa Bodiroza
  • Date: 2007-08-15 05:37:49 UTC
  • Revision ID: jazzva@gmail.com-20070815053749-76l0xj66tzgt290p
Upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* FakeNES - A free, portable, Open Source NES emulator.
 
2
 
 
3
   common.h: Global common definitions.
 
4
 
 
5
   Copyright (c) 2001-2006, FakeNES Team.
 
6
   This is free software.  See 'LICENSE' for details.
 
7
   You must read and accept the license prior to use. */
 
8
 
 
9
#ifndef COMMON_H_INCLUDED
 
10
#define COMMON_H_INCLUDED
 
11
#include <allegro.h>
 
12
#include "debug.h"
 
13
#include "types.h"
 
14
#ifdef __cplusplus
 
15
extern "C" {
 
16
#endif
 
17
 
 
18
#undef TRUE
 
19
#define TRUE   1
 
20
#undef FALSE
 
21
#define FALSE  0
 
22
 
 
23
#define TRUE_OR_FALSE(x)   ((x) ? TRUE : FALSE)
 
24
 
 
25
#undef NULL
 
26
#define NULL   0
 
27
 
 
28
#define ROUND(x)  ((x) + 0.5)
 
29
 
 
30
#ifndef M_PI
 
31
#define M_PI      3.14159265358979323846
 
32
#endif
 
33
 
 
34
/* <+KittyCat> $ grep EPSILON include/3dobject.h
 
35
   <+KittyCat> #define EPSILON (1.0f/1024.0f)
 
36
   */
 
37
#define EPSILON   (1.0 / 1024.0)
 
38
 
 
39
#ifdef __cplusplus
 
40
/* Cleaner lowercase versions for use in 'pure' C++ code. */
 
41
#define true   TRUE
 
42
#define false  FALSE
 
43
 
 
44
#define min(x,y)   MIN((x),(y))
 
45
#define max(x,y)   MAX((x),(y))
 
46
 
 
47
#define true_or_false(x)   ((x) ? true : false)
 
48
 
 
49
#define null   NULL
 
50
 
 
51
#define inline    INLINE
 
52
#define linear    INLINE   // for functions that are called only once
 
53
 
 
54
#define epsilon   EPSILON
 
55
#endif /* __cplusplus */
 
56
 
 
57
/* Macro to compare 2 REALs. */
 
58
#define COMPARE_TWO_REALS(a, b)  \
 
59
   TRUE_OR_FALSE(((a) >= ((b) - EPSILON)) && ((a) <= ((b) + EPSILON)))
 
60
 
 
61
/* TODO: Remove all references to NIL and correct compiler warnings. */
 
62
#define NIL    0
 
63
 
 
64
static INLINE int fix (int value, int base, int limit)
 
65
{
 
66
   if (value < base)
 
67
      value = base;
 
68
   if (value > limit)
 
69
      value = limit;
 
70
 
 
71
   return (value);
 
72
}
 
73
 
 
74
static INLINE REAL fixf (REAL value, REAL base, REAL limit)
 
75
{
 
76
   if (value < base)
 
77
      value = base;
 
78
   if (value > limit)
 
79
      value = limit;
 
80
 
 
81
   return (value);
 
82
}
 
83
 
 
84
#define MAX3(a, b, c)   (MAX((a), MAX((b), (c))))
 
85
      
 
86
#ifdef __cplusplus
 
87
}
 
88
#endif   /* __cplusplus */
 
89
#endif   /* !COMMON_H_INCLUDED */