annotate TVout/fbset/modeline2fb @ 9834:5c639ec8c39e

Unbreak
author rguyom
date Fri, 04 Apr 2003 20:40:57 +0000
parents 3b5f5d1c5041
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 #!/usr/bin/perl
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 # Simple modeline-to-fb.modes translator
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 # (c) 1998 by Patrick Reynolds
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 # distributed under the GNU General Public License
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 # mapping of modeline options to fb.modes options
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 %options_map = (
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 "-hsync" => "hsync low",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 "-vsync" => "vsync low",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 "+hsync" => "hsync high",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 "+vsync" => "vsync high",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 "interlace" => "laced true",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 "doublescan" => "double true"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 @possible_vxres = ( 640, 800, 1024, 1152, 1280, 1600, 1920, 2048 );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 # default settings (override with -d and -r)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 $depth = 8;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 $rounding = 128;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 # parse options
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 while ($ARGV[0] =~ /^-/) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 $arg = shift;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 if ($arg eq "-d" || $arg eq "--depth") {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 if (!($arg = shift @ARGV)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 usage("-d requires an argument");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 $depth = $arg;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 elsif ($arg eq "-r" || $arg eq "--rounding") {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 if (!($arg = shift @ARGV)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 usage("-r requires an argument");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 $rounding = $arg;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 elsif ($arg eq "-x" || $arg eq "--vxres") {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 if (!($arg = shift @ARGV)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 usage("-x requires an argument");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 push @possible_vxres, (split/,/,$arg);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 @possible_vxres = sort { $a <=> $b } @possible_vxres;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 print "new vxres: " . (join ",", @possible_vxres) . "\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 elsif ($arg eq "-h" || $arg eq "--help") {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 usage();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 usage("unknown option: $arg");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 # find out how much video memory is available
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 open(FBSET, "fbset -i|") || die "could not detect available video memory";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 while (<FBSET>) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 if (/Size\s*:\s*(\d+)/) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 $size = $1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 last;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 if (!$size) { die "could not detect available video memory"; }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 # huge kludge (hey, that rhymes!) ...
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 # subtract 16384 from the available memory $size
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 # why? the default 640x480 mode uses all but 16384, and when I set it
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 # to use more than that, it oopses (!). So... for safety's sake, and
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 # because you probably don't use those 15-25 lines anyway...
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 $size -= 16384;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 print "# modes.fb - video mode descriptions for fbset
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 #
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 # See fbset(8) and fb.modes(5) for more information
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 ";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 $flag = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 # read all XF86Config files
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 while(<>) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 chomp;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 next if !(($name, $clock, $xres, $xsyncstart, $xsyncend, $xfres,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 $yres, $ysyncstart, $ysyncend, $yfres, $extra) =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 /^\s*modeline\s+"([^"]+)"\s+([0-9.]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*(.*)$/i);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 $flag = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 # timing transformations, as described in the fb HOWTO
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 $pixtime = int(1000000/$clock);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 $left = $xfres - $xsyncend;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 $right = $xsyncstart - $xres;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 $hsynclen = $xsyncend - $xsyncstart;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 $top = $yfres - $ysyncend;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 $bottom = $ysyncstart - $yres;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 $vsynclen = $ysyncend - $ysyncstart;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 # pick a virtual X and Y resolution
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 $vxres = get_vxres($xres);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 if ($vxres < 0) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 print STDERR "Could not guess a good virtual resolution for mode $name.\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 print STDERR "Use the advanced options --rounding and --vxres.\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 next;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 $vyres = int($size/$vxres);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 # print out our entry
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 print "mode \"$name\"\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 print " geometry $xres $yres $vxres $vyres $depth\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 print " timings $pixtime $left $right $top $bottom $hsynclen $vsynclen\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 # handle extra options at the end of the modeline
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 $extra =~ tr/A-Z/a-z/;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 @options = split/\s+/,$extra;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 foreach (@options) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 if ($options_map{$_}) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 print " $options_map{$_}\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 print " # unknown option: $_\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 print "endmode\n\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 if (!$flag) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 print STDERR "No modelines found.\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 print STDERR "Make sure the file you specified was an XF86Config file and\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 print STDERR "used the single-line Modeline format.\n\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 print STDERR "Use \"$0 --help\" for help.\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 sub get_vxres {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 foreach (@possible_vxres) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 return $_ if ($_ >= $_[0] && ($_ % $rounding) == 0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 return -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 sub usage {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 print STDERR "$_[0]\n" if ($_[0]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 print STDERR "$0 [OPTION] [FILES]\n\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 print STDERR " -d,--depth depth use a certain display depth (default is 8)\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 print STDERR " -h,--help what you see here\n\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 print STDERR "Advanced options:\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 print STDERR " -r,--rounding div vxres divisor (default is 128)\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 print STDERR " -x,--vxres X,X,X,... extra possible vxres values\n\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 print STDERR "[FILES] refers to one or more XF86Config files. Note that\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 print STDERR "all modelines must be in single-line format.\n\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 print STDERR "Example:\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 print STDERR " $0 -d 16 /etc/X11/XF86Config\n";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 exit 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 }