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