1 # $NetBSD: makemodes.awk,v 1.6 2006/08/19 11:01:56 bjh21 Exp $
4 # Copyright (c) 1998 The NetBSD Foundation, Inc.
7 # This code is derived from software contributed to The NetBSD Foundation
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
13 # 1. Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
19 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
32 # This parses a Acorn monitor definition file and constructs an array of
33 # parameters for each mode.
34 # Once the file has been parsed the list of modes is examined to find modes
35 # that match the mode specifications specified on the command line.
36 # The matching mode definitions are written to stdout in the form of a C file.
37 # Parsing information is written to stderr.
40 # Syntax for using this program
42 # awk -f makemodes.awk <MDF file> <mode spec> [<mode spec> ...]
44 # where <mode spec> is
49 # Note: Spaces are NOT allowed in a mode specifier
51 # where x = x resolution
54 # c = colour depth (16, 256, 32768, 65536)
58 # Number of modes parsed and valid in the modes array.
65 # Non zero if we are translating a mode
68 # ':' character is used to separate the tokens.
71 # Note the real number of arguments and truncate ARGC so that only the first
72 # argument is used as a filename.
76 # Translation of sync_pol to videomode.flags
85 # Currently we only understand format 1 MDF files
87 printf("Unrecognised MDF format (%d)\n", $
2);
102 # Start of mode definition
107 # End of mode definition
113 # The mode definition name (only valid within startmode/endmode section)
121 # The horizontal resolution (only valid within startmode/endmode section)
129 # The vertical resolution (only valid within startmode/endmode section)
137 # The pixel rate (only valid within startmode/endmode section)
145 # The horizontal timings (only valid within startmode/endmode section)
153 # The vertical timings (only valid within startmode/endmode section)
161 # The sync polarity (only valid within startmode/endmode section)
171 # Now generate the C file
174 # Create the file header
176 printf(" * MACHINE GENERATED: DO NOT EDIT\n");
178 printf(" * Created from %s\n", FILENAME);
180 printf("#include <sys/types.h>\n");
181 printf("#include <arm/iomd/vidc.h>\n\n");
182 printf("const char * const monitor = \"%s\";\n", monitor
);
183 printf("const int dpms = %d;\n", dpms
);
184 printf("#define HP VID_PHSYNC\n");
185 printf("#define HN VID_NHSYNC\n");
186 printf("#define VP VID_PVSYNC\n");
187 printf("#define VN VID_NVSYNC\n");
190 # Now define the modes array
191 printf("const struct videomode vidc_videomode_list[] = {\n");
194 # Loop round all the modespecs on the command line
195 for (res =
2; res
< realargc
; res = res
+ 1) {
200 # Report the mode specifier being processed
201 printf("%s ==> ", ARGV[res
]) | "cat 1>&2";
203 # Pull apart the modespec
204 args =
split(ARGV[res
], modespec
, ",");
206 # We need at least 2 arguments
208 printf("Invalid mode specifier\n") | "cat 1>&2";
212 # If we only have x,y default c and f
217 # If we have x,y,f default c and re-arrange.
219 modespec
[4] = modespec
[3];
223 # Report the full mode specifier
224 printf("%d x %d x %d x %d : ", modespec
[1], modespec
[2],
225 modespec
[3], modespec
[4]) | "cat 1>&2";
227 # Now loop round all the modes we parsed and find the matches
228 for (loop =
0; loop
< mode
; loop = loop
+ 1) {
230 if (modespec
[1] != modes
[loop
, 1]) continue;
231 if (modespec
[2] != modes
[loop
, 2]) continue;
233 # Split the horizontal and vertical timings
234 # This is needed for the frame rate calculation
235 ht =
split(modes
[loop
, 4], htimings
, ",");
236 if (ht
!= 6) continue;
237 vt =
split(modes
[loop
, 5], vtimings
, ",");
238 if (vt
!= 6) continue;
240 # Calculate the frame rate
241 fr = modes
[loop
, 3] / (htimings
[1] + htimings
[2] + \
242 htimings
[3] + htimings
[4] + htimings
[5] + \
243 htimings
[6]) / ( vtimings
[1] + vtimings
[2] + \
244 vtimings
[3] + vtimings
[4] + vtimings
[5] + \
248 # Remember the frame rate
249 modes
[loop
, 7] = int
(fr
+ 0.5);
251 # Create the internal version of the timings
252 modes
[loop
, "timings"] = \
254 "{ %d, %d,%d,%d,%d, %d,%d,%d,%d, %s, \"%s\" }",\
255 modes
[loop
, 3], htimings
[4], \
256 htimings
[4] + htimings
[5] + htimings
[6], \
257 htimings
[4] + htimings
[5] + htimings
[6] + \
259 htimings
[4] + htimings
[5] + htimings
[6] + \
260 htimings
[1] + htimings
[2] + htimings
[3], \
262 vtimings
[4] + vtimings
[5] + vtimings
[6], \
263 vtimings
[4] + vtimings
[5] + vtimings
[6] + \
265 vtimings
[4] + vtimings
[5] + vtimings
[6] + \
266 vtimings
[1] + vtimings
[2] + vtimings
[3], \
267 pol
[modes
[loop
, 6]], modes
[loop
, 0]);
269 # Report the frame rate
270 printf("%d ", modes
[loop
, 7]) | "cat 1>&2";
272 # Is this the closest
273 if (closest
> mod
(modes
[loop
, 7] - modespec
[4])) {
274 closest = mod
(modes
[loop
, 7] - modespec
[4]);
278 # Do we have an exact match ?
279 if (modes
[loop
, 7] == modespec
[4])
283 # If no exact match use the nearest
287 # Did we find any sort of match ?
289 printf("Cannot find mode") | "cat 1>&2";
293 # Report the frame rate matched
294 printf("- %d", modes
[found
, 7]) | "cat 1>&2";
296 # Output the mode as part of the mode definition array
297 printf("\t%s,\n", modes
[found
, "timings"]);
299 printf("\n") | "cat 1>&2";
305 printf("const int vidc_videomode_count = %d;\n", nmodes
);
309 # Simple mod() function