#include "xf86.h"
static Bool
CVTCheckStandard(int HDisplay, int VDisplay, float VRefresh, Bool Reduced,
Bool Verbose)
{
Bool IsCVT = TRUE;
if ((!(VDisplay % 3) && ((VDisplay * 4 / 3) == HDisplay)) ||
(!(VDisplay % 9) && ((VDisplay * 16 / 9) == HDisplay)) ||
(!(VDisplay % 10) && ((VDisplay * 16 / 10) == HDisplay)) ||
(!(VDisplay % 4) && ((VDisplay * 5 / 4) == HDisplay)) ||
(!(VDisplay % 9) && ((VDisplay * 15 / 9) == HDisplay)))
;
else {
if (Verbose)
fprintf(stderr, "Warning: Aspect Ratio is not CVT standard.\n");
IsCVT = FALSE;
}
if ((VRefresh != 50.0) && (VRefresh != 60.0) &&
(VRefresh != 75.0) && (VRefresh != 85.0)) {
if (Verbose)
fprintf(stderr, "Warning: Refresh Rate is not CVT standard "
"(50, 60, 75 or 85Hz).\n");
IsCVT = FALSE;
}
return IsCVT;
}
static void
PrintUsage(char *Name)
{
fprintf(stderr, "\n");
fprintf(stderr, "usage: %s [-v|--verbose] [-r|--reduced] X Y [refresh]\n",
Name);
fprintf(stderr, "\n");
fprintf(stderr, " -v|--verbose : Warn about CVT standard adherance.\n");
fprintf(stderr, " -r|--reduced : Create a mode with reduced blanking "
"(default: normal blanking).\n");
fprintf(stderr, " X : Desired horizontal resolution "
"(multiple of 8, required).\n");
fprintf(stderr, " Y : Desired vertical resolution (required).\n");
fprintf(stderr, " refresh : Desired refresh rate (default: 60.0Hz).\n");
fprintf(stderr, "\n");
fprintf(stderr, "Calculates VESA CVT (Coordinated Video Timing) modelines"
" for use with X.\n");
}
static void
PrintComment(DisplayModeRec *Mode, Bool CVT, Bool Reduced)
{
printf("# %dx%d %.2f Hz ", Mode->HDisplay, Mode->VDisplay, Mode->VRefresh);
if (CVT) {
printf("(CVT %.2fM",
((float) Mode->HDisplay * Mode->VDisplay) / 1000000.0);
if (!(Mode->VDisplay % 3) &&
((Mode->VDisplay * 4 / 3) == Mode->HDisplay))
printf("3");
else if (!(Mode->VDisplay % 9) &&
((Mode->VDisplay * 16 / 9) == Mode->HDisplay))
printf("9");
else if (!(Mode->VDisplay % 10) &&
((Mode->VDisplay * 16 / 10) == Mode->HDisplay))
printf("A");
else if (!(Mode->VDisplay % 4) &&
((Mode->VDisplay * 5 / 4) == Mode->HDisplay))
printf("4");
else if (!(Mode->VDisplay % 9) &&
((Mode->VDisplay * 15 / 9) == Mode->HDisplay))
printf("9");
if (Reduced)
printf("-R");
printf(") ");
} else
printf("(CVT) ");
printf("hsync: %.2f kHz; ", Mode->HSync);
printf("pclk: %.2f MHz", ((float ) Mode->Clock) / 1000.0);
printf("\n");
}
static void
PrintModeline(DisplayModePtr Mode, int HDisplay, int VDisplay, float VRefresh,
Bool Reduced)
{
if (Reduced)
printf("Modeline \"%dx%dR\" ", HDisplay, VDisplay);
else
printf("Modeline \"%dx%d_%.2f\" ", HDisplay, VDisplay, VRefresh);
printf("%6.2f %i %i %i %i %i %i %i %i", Mode->Clock/1000., Mode->HDisplay,
Mode->HSyncStart, Mode->HSyncEnd, Mode->HTotal, Mode->VDisplay,
Mode->VSyncStart, Mode->VSyncEnd, Mode->VTotal);
if (Mode->Flags & V_INTERLACE)
printf(" interlace");
if (Mode->Flags & V_PHSYNC)
printf(" +hsync");
if (Mode->Flags & V_NHSYNC)
printf(" -hsync");
if (Mode->Flags & V_PVSYNC)
printf(" +vsync");
if (Mode->Flags & V_NVSYNC)
printf(" -vsync");
printf("\n");
}
int
main (int argc, char *argv[])
{
DisplayModeRec *Mode;
int HDisplay = 0, VDisplay = 0;
float VRefresh = 0.0;
Bool Reduced = FALSE, Verbose = FALSE, IsCVT;
Bool Interlaced = FALSE;
int n;
if ((argc < 3) || (argc > 7)) {
PrintUsage(argv[0]);
return 0;
}
for (n = 1; n < argc; n++) {
if (!strcmp(argv[n], "-r") || !strcmp(argv[n], "--reduced"))
Reduced = TRUE;
else if (!strcmp(argv[n], "-i") || !strcmp(argv[n], "--interlaced"))
Interlaced = TRUE;
else if (!strcmp(argv[n], "-v") || !strcmp(argv[n], "--verbose"))
Verbose = TRUE;
else if (!strcmp(argv[n], "-h") || !strcmp(argv[n], "--help")) {
PrintUsage(argv[0]);
return 0;
} else if (!HDisplay)
HDisplay = atoi(argv[n]);
else if (!VDisplay)
VDisplay = atoi(argv[n]);
else if (!VRefresh)
VRefresh = atof(argv[n]);
else {
PrintUsage(argv[0]);
return 0;
}
}
if (!HDisplay || !VDisplay) {
PrintUsage(argv[0]);
return 0;
}
if (!VRefresh)
VRefresh = 60.0;
if (HDisplay & 0x07) {
HDisplay &= ~0x07;
HDisplay += 8;
}
if (Reduced && (VRefresh != 60.0)) {
fprintf(stderr, "\nERROR: 60Hz refresh rate required for reduced"
" blanking.\n");
PrintUsage(argv[0]);
return 0;
}
IsCVT = CVTCheckStandard(HDisplay, VDisplay, VRefresh, Reduced, Verbose);
Mode = xf86CVTMode(HDisplay, VDisplay, VRefresh, Reduced, Interlaced);
PrintComment(Mode, IsCVT, Reduced);
PrintModeline(Mode, HDisplay, VDisplay, VRefresh, Reduced);
return 0;
}