xref: /386bsd/usr/X386/tuner/tuner.c (revision a2142627)
1 /* tuner.c v 0.1 BETA
2  * parameter calculation for Xconfig
3  *
4  * Copyright 1993 by Nye Liu
5  * This program is distributed AS IS, under the terms and conditions
6  * of the GNU Copyleft.
7  *
8  * based on the original by Brett Lymn (blymn@awadi.com.au)
9  */
10 
11 /*
12                                               Front Porch          Back Porch
13 						|<--->|            |<------->|
14  +---------------------- ~ ---------------------+-----+------------+---------+
15  |                                              |   ->| SyncLength |<-       |
16  |         Display Time                         |     | ~3.8us (H) |         |
17  |                                              |     | ~150us (V) |         |
18  +---------------------- ~ ---------------------+-----+------------+---------+
19                                               Dots SyncStart    SyncEnd    Frame
20 
21 */
22 
23 #include <stdio.h>
24 
25 #define RoundTo8(x) ((int)(x) & ~((int)7))
26 #define VDtoVF 1/.95
27 
main()28 int main()
29 {
30   float ClockFreq, MonHFreq;
31   int   HDots, VDots;
32   int   HFrame, HSyncLength, HSyncStart, HSyncEnd;
33   int	VFrame, VSyncLength, VSyncStart, VSyncEnd;
34   int	HFrontPorch, MaxHDot;
35 
36   printf("VGA Clock Rate (MHz) ? ");
37   scanf("%f",&ClockFreq);
38   ClockFreq *= 1e6;
39   printf("Monitor HFreq (kHz) ? ");
40   scanf("%f",&MonHFreq);
41   MonHFreq *= 1e3;
42 
43   HFrame = RoundTo8(0.5 + ClockFreq / MonHFreq);
44   printf("estimated HFrame: %d\n", HFrame);
45 
46   HSyncLength = RoundTo8(0.5 + 3.8e-6 * ClockFreq);
47   /* make room for at least a front porch of 8 and a back porch of 16 */
48   MaxHDot = HFrame - HSyncLength - 24;
49   printf("The recommended maximum horizontal resolution is %d\n", MaxHDot);
50   printf("Exceeding this will require a lower horizontal scan rate than the one supplied\n");
51 
52   printf("Enter the desired resolution: ");
53   scanf("%d",&HDots);
54   HDots=RoundTo8(HDots);
55   /* position H Sync Pulse */
56   /* HFrontPorch is typically 1/2 HBackPorch */
57   HFrontPorch = RoundTo8(0.5 + (HFrame - HSyncLength - HDots)/3.0);
58   if (HFrontPorch < 8) { /* no room for reasonable porches */
59       HFrontPorch = 8;
60       HFrame = HDots + 3*HFrontPorch + HSyncLength;
61       printf("Warning: HFrame has been enlarged to accomodate HDots + sync\n");
62       printf("Required refresh rate no longer matches the one supplied\n");
63   }
64   HSyncStart = RoundTo8(HDots + HFrontPorch);
65   HSyncEnd   = RoundTo8(HSyncStart + HSyncLength);
66   printf("H refresh rate: %.1fkHz\n", ClockFreq/HFrame*1e-3);
67 
68   /* now the vertical calculations */
69   printf("The recommended vertical resolution is %d\n",
70       VDots = (int)(0.5 + 0.75*HDots));
71 #if 1
72   printf("Enter the desired vertical resolution: ");
73   scanf("%d",&VDots);
74 #endif
75   VFrame = VDots * VDtoVF;
76   VSyncLength = (int)(0.5 + 150.0e-6 * ClockFreq / HFrame);
77   VSyncStart = VDots + 1;  /* give it a pixel's worth of front porch */
78   VSyncEnd = VSyncStart + VSyncLength;
79   printf("V refresh rate: %.1f Hz\n",ClockFreq/HFrame/VFrame);
80   printf("Horizontal front porch: %.2f us\n", HFrontPorch/ClockFreq*1e6);
81   printf("The parameters are as follows:\n");
82   printf(" \"%dx%d\"     %.0f     %4d %4d %4d %4d   %4d %4d %4d %4d\n",
83   				     HDots, VDots, ClockFreq/1e6,
84 				     HDots, HSyncStart, HSyncEnd, HFrame,
85                                      VDots, VSyncStart, VSyncEnd, VFrame);
86   return(0);
87 }
88