xref: /freebsd/sys/dev/videomode/modelines2c.awk (revision 4543ef516683042d46f3bd3bb8a4f3f746e00499)
1#! /usr/bin/awk -f
2#	$NetBSD: modelines2c.awk,v 1.4 2006/10/26 23:19:50 bjh21 Exp $
3#
4# Copyright (c) 2006 Itronix Inc.
5# All rights reserved.
6#
7# Written by Garrett D'Amore for Itronix Inc.
8#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions
11# are met:
12# 1. Redistributions of source code must retain the above copyright
13#    notice, this list of conditions and the following disclaimer.
14# 2. Redistributions in binary form must reproduce the above copyright
15#    notice, this list of conditions and the following disclaimer in the
16#    documentation and/or other materials provided with the distribution.
17# 3. The name of Itronix Inc. may not be used to endorse
18#    or promote products derived from this software without specific
19#    prior written permission.
20#
21# THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
22# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
25# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28# ON ANY THEORY OF LIABILITY, WHETHER IN
29# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31# POSSIBILITY OF SUCH DAMAGE.
32#
33
34BEGIN {
35	nmodes = 0;
36}
37
38NR == 1 {
39	split($0,v,"$");
40
41	VERSION=v[2];
42
43	printf("/*\t$NetBSD" "$\t*/\n\n");
44	printf("/*\n") ;
45	printf(" * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.\n");
46	printf(" *\n");
47	printf(" * generated from:\n");
48	printf(" *\t%s\n", VERSION);
49	printf(" */\n\n");
50
51	printf("#include <sys/cdefs.h>\n");
52	printf("__KERNEL_RCSID(0, \"$NetBSD" "$\");\n\n");
53
54	printf("#include <dev/videomode/videomode.h>\n\n");
55
56	printf("/*\n");
57	printf(" * These macros help the modelines below fit on one line.\n");
58	printf(" */\n");
59	printf("#define HP VID_PHSYNC\n");
60	printf("#define HN VID_NHSYNC\n");
61	printf("#define VP VID_PVSYNC\n");
62	printf("#define VN VID_NVSYNC\n");
63	printf("#define I VID_INTERLACE\n");
64	printf("#define DS VID_DBLSCAN\n");
65	printf("\n");
66
67	printf("#define M(nm,hr,vr,clk,hs,he,ht,vs,ve,vt,f) \\\n");
68	printf("\t{ clk, hr, hs, he, ht, vr, vs, ve, vt, f, nm } \n\n");
69
70	printf("const struct videomode videomode_list[] = {\n");
71
72	next
73}
74
75(/^ModeLine/) {
76	dotclock =   $3;
77
78	hdisplay =   $4;
79	hsyncstart = $5;
80	hsyncend =   $6;
81	htotal =     $7;
82
83	vdisplay =   $8;
84	vsyncstart = $9;
85	vsyncend =   $10;
86	vtotal =     $11;
87
88	macro =      "MODE";
89	iflag =      "";
90	iflags =     "";
91	hflags =     "HP";
92	vflags =     "VP";
93
94	if ($12 ~ "^-")
95		hflags = "HN";
96
97	if ($13 ~ "^-")
98		vflags = "VN";
99
100	ifactor=1.0;
101	if ($14 ~ "[Ii][Nn][Tt][Ee][Rr][Ll][Aa][Cc][Ee]") {
102		iflag = "i";
103		iflags = "|I";
104		ifactor = 2.0;
105	}
106
107	# We truncate the vrefresh figure, but some mode descriptions rely
108	# on rounding, so we can't win here.  Adding an additional .1
109	# compensates to some extent.
110
111	hrefresh= (dotclock * 1000000) / htotal;
112	vrefresh= int(((hrefresh * ifactor) / vtotal) + .1);
113
114	modestr = sprintf("%dx%dx%d%s", hdisplay, vdisplay, vrefresh, iflag);
115
116#	printf("/* %dx%d%s refresh %d Hz, hsync %d kHz */\n",
117#	    hdisplay, vdisplay, iflag, vrefresh, hrefresh/1000);
118	printf("M(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%s),\n",
119	    modestr,
120	    hdisplay, vdisplay, dotclock * 1000,
121	    hsyncstart, hsyncend, htotal,
122	    vsyncstart, vsyncend, vtotal, hflags "|" vflags iflags);
123
124	modestr = sprintf("%dx%dx%d%s",
125	    hdisplay/2 , vdisplay/2, vrefresh, iflag);
126
127	dmodes[nmodes]=sprintf("M(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%s),",
128	    modestr,
129	    hdisplay/2, vdisplay/2, dotclock * 1000 / 2,
130	    hsyncstart/2, hsyncend/2, htotal/2,
131	    vsyncstart/2, vsyncend/2, vtotal/2,
132	    hflags "|" vflags "|DS" iflags);
133
134	nmodes = nmodes + 1
135
136}
137
138END {
139
140	printf("\n/* Derived Double Scan Modes */\n\n");
141
142	for ( i = 0; i < nmodes; i++ )
143	{
144		print dmodes[i];
145	}
146
147	printf("};\n\n");
148	printf("const int videomode_count = %d;\n", nmodes);
149}
150