void main(int argc,char *argv[]) { FILE *f; double xPixels,yPixels,freq; ibool interlace; GTF_timings t; if (argc != 5 && argc != 6) { printf("Usage: GTFCALC <xPixels> <yPixels> <freq> [[Hz] [KHz] [MHz]] [I]\n"); printf("\n"); printf("where <xPixels> is the horizontal resolution of the mode, <yPixels> is the\n"); printf("vertical resolution of the mode. The <freq> value will be the frequency to\n"); printf("drive the calculations, and will be either the vertical frequency (in Hz)\n"); printf("the horizontal frequency (in KHz) or the dot clock (in MHz). To generate\n"); printf("timings for an interlaced mode, add 'I' to the end of the command line.\n"); printf("\n"); printf("For example to generate timings for 640x480 at 60Hz vertical:\n"); printf("\n"); printf(" GTFCALC 640 480 60 Hz\n"); printf("\n"); printf("For example to generate timings for 640x480 at 31.5KHz horizontal:\n"); printf("\n"); printf(" GTFCALC 640 480 31.5 KHz\n"); printf("\n"); printf("For example to generate timings for 640x480 with a 25.175Mhz dot clock:\n"); printf("\n"); printf(" GTFCALC 640 480 25.175 MHz\n"); printf("\n"); printf("GTFCALC will print a summary of the results found, and dump the CRTC\n"); printf("values to the UVCONFIG.CRT file in the format used by SciTech Display Doctor.\n"); exit(1); } /* Get values from command line */ xPixels = atof(argv[1]); yPixels = atof(argv[2]); freq = atof(argv[3]); interlace = ((argc == 6) && (argv[5][0] == 'I')); /* Compute the CRTC timings */ if (toupper(argv[4][0]) == 'H') GTF_calcTimings(xPixels,yPixels,freq,GTF_lockVF,false,interlace,&t); else if (toupper(argv[4][0]) == 'K') GTF_calcTimings(xPixels,yPixels,freq,GTF_lockHF,false,interlace,&t); else if (toupper(argv[4][0]) == 'M') GTF_calcTimings(xPixels,yPixels,freq,GTF_lockPF,false,interlace,&t); else { printf("Unknown command line!\n"); exit(1); } /* Dump summary info to standard output */ printf("CRTC values for %.0fx%.0f @ %.2f %s\n", xPixels, yPixels, freq, argv[4]); printf("\n"); printf(" hTotal = %-4d vTotal = %-4d\n", t.h.hTotal, t.v.vTotal); printf(" hDisp = %-4d vDisp = %-4d\n", t.h.hDisp, t.v.vDisp); printf(" hSyncStart = %-4d vSyncStart = %-4d\n", t.h.hSyncStart, t.v.vSyncStart); printf(" hSyncEnd = %-4d vSyncEnd = %-4d\n", t.h.hSyncEnd, t.v.vSyncEnd); printf(" hFrontPorch = %-4d vFrontPorch = %-4d\n", t.h.hFrontPorch, t.v.vFrontPorch); printf(" hSyncWidth = %-4d vSyncWidth = %-4d\n", t.h.hSyncWidth, t.v.vSyncWidth); printf(" hBackPorch = %-4d vBackPorch = %-4d\n", t.h.hBackPorch, t.v.vBackPorch); printf("\n"); printf(" Interlaced = %s\n", (t.interlace == 'I') ? "Yes" : "No"); printf(" H sync pol = %c\n", t.hSyncPol); printf(" V sync pol = %c\n", t.vSyncPol); printf("\n"); printf(" Vert freq = %.2f Hz\n", t.vFreq); printf(" Horiz freq = %.2f KHz\n", t.hFreq); printf(" Dot Clock = %.2f Mhz\n", t.dotClock); /* Dump to file in format used by SciTech Display Doctor */ if ((f = fopen("UVCONFIG.CRT","w")) != NULL) { fprintf(f, "[%.0f %.0f]\n", xPixels, yPixels); fprintf(f, "%d %d %d %d '%c' %s\n", t.h.hTotal, t.h.hDisp, t.h.hSyncStart, t.h.hSyncEnd, t.hSyncPol, (t.interlace == 'I') ? "I" : "NI"); fprintf(f, "%d %d %d %d '%c'\n", t.v.vTotal, t.v.vDisp, t.v.vSyncStart, t.v.vSyncEnd, t.vSyncPol); fprintf(f, "%.2f\n", t.dotClock); fclose(f); } }
int vga_guesstiming(int x, int y, int clue, int arg) { /* This functions tries to add timings that fit a specific mode, by changing the timings of a similar mode currently only works for x:y = 4:3, clue means: 0- scale down timing of a higher res mode 1- scale up timings of a lower res mode */ MonitorModeTiming mmt, *bestmodetiming = NULL ; int bestx, besty, flag, mx, my /*, bestclock */ ; int aspect_ratio=1000*y/x; switch(clue) { case 0: /* 0,1 only 4:3 ratio, find close mode, and up/down scale timing */ case 1: if((aspect_ratio>765)||(aspect_ratio<735))return 0; if(clue==0)find_up_timing(x,y,&bestx,&besty,&bestmodetiming); if(clue==1)find_down_timing(x,y,&bestx,&besty,&bestmodetiming); if(bestmodetiming){ mmt=*bestmodetiming; mmt.pixelClock=(mmt.pixelClock*x)/bestx; mmt.HDisplay=x; mmt.VDisplay=y; mmt.HSyncStart=(mmt.HSyncStart*x)/bestx; mmt.HSyncEnd=(mmt.HSyncEnd*x)/bestx; mmt.HTotal=(mmt.HTotal*x)/bestx; mmt.VSyncStart=(mmt.VSyncStart*x)/bestx; mmt.VSyncEnd=(mmt.VSyncEnd*x)/bestx; mmt.VTotal=(mmt.VTotal*x)/bestx; __svgalib_addusertiming(&mmt); return 1; }; break; case 2: /* Use GTF, caller provides all parameters. */ flag = arg>>16; GTF_calcTimings(x , y, arg&0xffff, flag&3, flag&4, flag&8, flag&16, &mmt); __svgalib_addusertiming(&mmt); return 1; case 256: /* 256,257: find a 4:3 mode with y close to requested, and */ case 257: /* up/down scale timing */ mx=y*4/3; if((clue&1)==0)find_up_timing(mx,y,&bestx,&besty,&bestmodetiming); if((clue&1)==1)find_down_timing(mx,y,&bestx,&besty,&bestmodetiming); if(bestmodetiming){ mmt=*bestmodetiming; mmt.pixelClock=(mmt.pixelClock*x)/bestx; mmt.HDisplay=x; mmt.HSyncStart=(mmt.HSyncStart*x)/bestx; mmt.HSyncEnd=(mmt.HSyncEnd*x)/bestx; mmt.HTotal=(mmt.HTotal*x)/bestx; mmt.VDisplay=y; mmt.VSyncStart=(mmt.VSyncStart*mx)/bestx; mmt.VSyncEnd=(mmt.VSyncEnd*mx)/bestx; mmt.VTotal=(mmt.VTotal*mx)/bestx; __svgalib_addusertiming(&mmt); return 1; }; break; case 258: /* 258,259: find a 4:3 mode with x close to requested, and */ case 259: /* up/down scale timing */ my=(x*3)>>2; if((clue&1)==0)find_up_timing(x,my,&bestx,&besty,&bestmodetiming); if((clue&1)==1)find_down_timing(x,my,&bestx,&besty,&bestmodetiming); if(bestmodetiming){ mmt=*bestmodetiming; mmt.pixelClock=(mmt.pixelClock*x)/bestx; mmt.HDisplay=x; mmt.HSyncStart=(mmt.HSyncStart*x)/bestx; mmt.HSyncEnd=(mmt.HSyncEnd*x)/bestx; mmt.HTotal=(mmt.HTotal*x)/bestx; mmt.VDisplay=y; mmt.VSyncStart=(mmt.VSyncStart*y)/besty; mmt.VSyncEnd=(mmt.VSyncEnd*y)/besty; mmt.VTotal=(mmt.VTotal*y)/besty; __svgalib_addusertiming(&mmt); return 1; }; break; }; return 0; };