summaryrefslogtreecommitdiff
path: root/hw/kdrive/savage/s3.nick
blob: 500b03d7bee5d5c4cc4dd1384b9e2262f99f8c14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* $XFree86: $ */

global f_ref = 14318000;

function s3_clock (m, n, r)
{
    return f_ref * (m + 2) / ((n + 2) * (2 ^ r));
}

function s3_near (f1, f2)
{
    return abs (f1 - f2) < f1 / 10;
}

function s3_clocks (f)
{
    auto    m, n, r, ft;
    auto    dist, min_dist;
    auto    min_m, min_n, min_r;

    min_dist = f / 5;
    for (r = 0; r <= 3; r++)
	for (n = 0; n <= 31; n++)
		for (m = 0; m <= 127; m++)
		{
		    ft = s3_clock (m, n, r);
		    if (s3_near (ft, f))
			printf ("m %d n %d r %d = %d\n",
				m, n, r, ft);
		    dist = abs (f - ft);
		    if (dist < min_dist)
		    {
			min_dist = dist;
			min_m = m;
			min_n = n;
			min_r = r;
		    }
		}
    printf ("m %d n %d r %d f %d dist %d\n",
	    min_m, min_n, min_r, s3_clock(min_m, min_n, min_r), min_dist);
}