ScummVM API documentation
imath.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef M4_CORE_IMATH_H
23 #define M4_CORE_IMATH_H
24 
25 #include "common/endian.h"
26 #include "m4/m4_types.h"
27 
28 namespace M4 {
29 
30 #define FRAC16(a,b) ((a<<16) + (b))
31 
32 #define Atan2F16(x1, x2) ArcTan(x1, x2)
33 #define MulSF16(x1, x2) FixedMul(x1, x2)
34 #define DivSF16(x1, x2) FixedDiv(x1, x2)
35 #define RecipUF16(x) FixedDiv(1, x)
36 #define SquareSF16(x) FixedMul(x, x)
37 
38 #define SWAP_INT16(x) ((((x)>>8)&0x00ff) + (((x)&0x00ff)<<8))
39 #define SWAP_INT32(x) ((((int32)(x)&0x000000ff)<<24) + (((int32)(x)&0x0000ff00)<<8) + \
40  (((int32)(x)&0x00ff0000)>>8) + (((int32)(x)>>24)&0x000000ff))
41 
42 
43 frac16 FixedMul(frac16 Multiplicand, frac16 Multiplier);
44 frac16 FixedDiv(frac16 Dividend, frac16 Divisor);
45 
46 unsigned long sqrtul(unsigned long v);
47 
48 int32 imath_max(int32 a, int32 b);
49 int32 imath_min(int32 a, int32 b);
50 int32 imath_abs(int32 a);
51 
52 void imath_seed(int32 seednum);
53 uint32 imath_random();
54 int32 imath_ranged_rand(int32 a, int32 b);
55 frac16 imath_ranged_rand16(frac16 a, frac16 b);
56 bool imath_rand_bool(int max);
57 
58 frac16 dist2d(int32 x1, int32 y1, int32 x2, int32 y2);
59 frac16 SqrtF16(frac16 n);
60 frac16 ArcTan(frac16 x, frac16 y);
61 
62 uint16 HighWord(uint32 n);
63 uint16 LowWord(uint32 n);
64 
65 uint32 convert_intel32(uint32 a);
66 uint16 convert_intel16(uint16 a);
67 
68 //
69 // I N L I N E S
70 //
71 
72 inline short abs(short a) {
73  return (a >= 0) ? a : -a;
74 }
75 
76 inline long abs(long a) {
77  return (a >= 0) ? a : -a;
78 }
79 
80 inline int16 convert_intel16(void *src) {
81  return READ_LE_INT16(src);
82 }
83 
84 } // namespace M4
85 
86 #endif
intptr frac16
Definition: m4_types.h:46
Definition: database.h:28