comparison TOOLS/TVout/fbset/modeline2fb @ 12940:b205f8ca892a

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