~ubuntu-branches/ubuntu/karmic/rott/karmic-proposed

« back to all changes in this revision

Viewing changes to rott/rt_sqrt.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabian Greffrath
  • Date: 2008-01-27 20:00:00 UTC
  • mfrom: (1.1.1 upstream) (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080127200000-myle9y0099o45sfv
Tags: 1.0+dfsg-2
* debian/patches/01-custom-datapath.dpatch,
  debian/patches/13-improve-makefile.dpatch:
  + Changed DATADIR back to "/usr/share/games/rott/".

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include "rt_def.h"
2
 
 
3
 
#include "rt_sqrt.h"
4
 
 
5
 
/* 
6
 
  C version of fixed-point Square Root functions 
7
 
 */
8
 
 
9
 
long FixedSqrtLP(long n)  // Low  Precision (8.8)
10
 
{
11
 
        /* 
12
 
           Not used, so unimplemented.
13
 
           If it matters, just copy the first half of the HP version,
14
 
           and multiply the answer by 256.
15
 
         */
16
 
        STUB_FUNCTION;
17
 
        
18
 
        return 0;
19
 
}
20
 
 
21
 
long FixedSqrtHP(long n)  // High Precision (8.16)
22
 
{
23
 
        /* This is more or less a direct C transliteration of the asm code.
24
 
           I've replaced right shifting with division, since right shifting
25
 
           signed values is undefined in ANSI C (though it usually works).
26
 
           ROTT does not use this routine heavily. */
27
 
        unsigned long root, mask, val;
28
 
        signed long d;
29
 
 
30
 
        root = 0;
31
 
        mask = 0x40000000;
32
 
        val = (unsigned long)n;
33
 
 hp1:
34
 
        d = val;
35
 
        d -= mask;
36
 
        if (d < 0)
37
 
            goto hp2;
38
 
        d -= root;
39
 
        if (d < 0)
40
 
            goto hp2;
41
 
        
42
 
        val = d;
43
 
        root /= 2;
44
 
        root |= mask;
45
 
        mask /= 4;
46
 
        if (mask != 0)
47
 
            goto hp1;
48
 
        else
49
 
            goto hp5;
50
 
 hp2:
51
 
        root /= 2;
52
 
        mask /= 4;
53
 
        if (mask != 0)
54
 
            goto hp1;
55
 
 
56
 
 hp5:
57
 
        mask = 0x00004000;
58
 
        root <<= 16;
59
 
        val <<= 16;
60
 
 hp3:
61
 
        /* use add here to properly emulate the asm - SBF */
62
 
        if ((root+mask) > val)
63
 
            goto hp4;
64
 
        
65
 
        val -= (root+mask);
66
 
           
67
 
        root /= 2;
68
 
        root |= mask;
69
 
        mask /= 4;
70
 
        if (mask != 0)
71
 
            goto hp3;
72
 
        else
73
 
            goto hp6;
74
 
 hp4:
75
 
        root /= 2;
76
 
        mask /= 4;
77
 
        if (mask != 0)
78
 
            goto hp3;
79
 
 hp6:
80
 
 
81
 
        return (long)root;
82
 
}