summaryrefslogtreecommitdiff
path: root/hw/kdrive/savage/s3.nick
blob: 8f6791f876a83729f202d9035d3a92e67c364c75 (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
/* $RCSId: $ */

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);
}