summaryrefslogtreecommitdiff
path: root/hw/kdrive/savage/s3.nick
diff options
context:
space:
mode:
Diffstat (limited to 'hw/kdrive/savage/s3.nick')
-rw-r--r--hw/kdrive/savage/s3.nick41
1 files changed, 41 insertions, 0 deletions
diff --git a/hw/kdrive/savage/s3.nick b/hw/kdrive/savage/s3.nick
new file mode 100644
index 000000000..500b03d7b
--- /dev/null
+++ b/hw/kdrive/savage/s3.nick
@@ -0,0 +1,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);
+}