summaryrefslogtreecommitdiff
path: root/apps/plugins/doom/m_fixed.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/doom/m_fixed.h')
-rw-r--r--apps/plugins/doom/m_fixed.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/apps/plugins/doom/m_fixed.h b/apps/plugins/doom/m_fixed.h
new file mode 100644
index 0000000000..3c922e8f50
--- /dev/null
+++ b/apps/plugins/doom/m_fixed.h
@@ -0,0 +1,94 @@
1// Emacs style mode select -*- C++ -*-
2//-----------------------------------------------------------------------------
3//
4// $Id$
5//
6// Copyright (C) 1993-1996 by id Software, Inc.
7//
8// This program is free software; you can redistribute it and/or
9// modify it under the terms of the GNU General Public License
10// as published by the Free Software Foundation; either version 2
11// of the License, or (at your option) any later version.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// DESCRIPTION:
19// Fixed point arithemtics, implementation.
20//
21//-----------------------------------------------------------------------------
22
23
24#ifndef __M_FIXED__
25#define __M_FIXED__
26
27
28#ifdef __GNUG__
29#pragma interface
30#endif
31
32#include "doomtype.h"
33#include "rockmacros.h"
34
35//
36// Fixed point, 32bit as 16.16.
37//
38#define FRACBITS 16
39#define FRACUNIT (1<<FRACBITS)
40
41#define D_abs(x) ({fixed_t _t = (x), _s = _t >> (8*sizeof _t-1); (_t^_s)-_s;})
42
43typedef int fixed_t;
44
45inline static int FixedMul( int a, int b )
46{
47#if defined(CPU_COLDFIRE) && !defined(SIMULATOR)
48 // Code contributed by Thom Johansen
49 register int result;
50 asm volatile (
51 "mac.l %[x],%[y],%%acc0 \n" /* multiply */
52 "move.l %[y],%%d2 \n"
53 "mulu.l %[x],%%d2 \n" /* get lower half, avoid emac stall */
54 "movclr.l %%acc0,%[result] \n" /* get higher half */
55 "moveq.l #15,%%d1 \n"
56 "asl.l %%d1,%[result] \n" /* hi <<= 15, plus one free */
57 "moveq.l #16,%%d1 \n"
58 "lsr.l %%d1,%%d2 \n" /* (unsigned)lo >>= 16 */
59 "or.l %%d2 ,%[result] \n" /* combine result */
60 : /* outputs */
61 [result]"=&d"(result)
62 : /* inputs */
63 [x] "d" (a),
64 [y] "d" (b)
65 : /* clobbers */
66 "d1", "d2"
67 );
68 return result;
69#else
70 return (fixed_t)((long long) a*b >> FRACBITS);
71#endif
72}
73
74inline static fixed_t FixedDiv( fixed_t a, fixed_t b )
75{
76 return (D_abs(a)>>14) >= D_abs(b) ? ((a^b)>>31) ^ MAXINT :
77 (fixed_t)(((long long) a << FRACBITS) / b);
78}
79
80/* CPhipps -
81 * FixedMod - returns a % b, guaranteeing 0<=a<b
82 * (notice that the C standard for % does not guarantee this)
83 */
84
85inline static fixed_t FixedMod(fixed_t a, fixed_t b)
86{
87 if (b & (b-1)) {
88 fixed_t r = a % b;
89 return ((r<0) ? r+b : r);
90 } else
91 return (a & (b-1));
92}
93
94#endif