1278798Shselasky#! /usr/bin/awk -f 2278798Shselasky# $NetBSD: modelines2c.awk,v 1.4 2006/10/26 23:19:50 bjh21 Exp $ 3278798Shselasky# $FreeBSD$ 4278798Shselasky# 5278798Shselasky# Copyright (c) 2006 Itronix Inc. 6278798Shselasky# All rights reserved. 7278798Shselasky# 8278798Shselasky# Written by Garrett D'Amore for Itronix Inc. 9278798Shselasky# 10278798Shselasky# Redistribution and use in source and binary forms, with or without 11278798Shselasky# modification, are permitted provided that the following conditions 12278798Shselasky# are met: 13278798Shselasky# 1. Redistributions of source code must retain the above copyright 14278798Shselasky# notice, this list of conditions and the following disclaimer. 15278798Shselasky# 2. Redistributions in binary form must reproduce the above copyright 16278798Shselasky# notice, this list of conditions and the following disclaimer in the 17278798Shselasky# documentation and/or other materials provided with the distribution. 18278798Shselasky# 3. The name of Itronix Inc. may not be used to endorse 19278798Shselasky# or promote products derived from this software without specific 20278798Shselasky# prior written permission. 21278798Shselasky# 22278798Shselasky# THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND 23278798Shselasky# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 24278798Shselasky# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25278798Shselasky# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY 26278798Shselasky# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27278798Shselasky# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28278798Shselasky# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29278798Shselasky# ON ANY THEORY OF LIABILITY, WHETHER IN 30278798Shselasky# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31278798Shselasky# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32278798Shselasky# POSSIBILITY OF SUCH DAMAGE. 33278798Shselasky# 34278798Shselasky 35278798ShselaskyBEGIN { 36278798Shselasky nmodes = 0; 37278798Shselasky} 38278798Shselasky 39278798ShselaskyNR == 1 { 40278798Shselasky split($0,v,"$"); 41278798Shselasky 42278798Shselasky VERSION=v[2]; 43278798Shselasky 44278798Shselasky printf("/*\t$NetBSD" "$\t*/\n\n"); 45278798Shselasky printf("/*\n") ; 46278798Shselasky printf(" * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n"); 47278798Shselasky printf(" *\n"); 48278798Shselasky printf(" * generated from:\n"); 49278798Shselasky printf(" *\t%s\n", VERSION); 50278798Shselasky printf(" */\n\n"); 51278798Shselasky 52278798Shselasky printf("#include <sys/cdefs.h>\n"); 53278798Shselasky printf("__KERNEL_RCSID(0, \"$NetBSD" "$\");\n\n"); 54278798Shselasky 55278798Shselasky printf("#include <dev/videomode/videomode.h>\n\n"); 56278798Shselasky 57278798Shselasky printf("/*\n"); 58278798Shselasky printf(" * These macros help the modelines below fit on one line.\n"); 59278798Shselasky printf(" */\n"); 60278798Shselasky printf("#define HP VID_PHSYNC\n"); 61278798Shselasky printf("#define HN VID_NHSYNC\n"); 62278798Shselasky printf("#define VP VID_PVSYNC\n"); 63278798Shselasky printf("#define VN VID_NVSYNC\n"); 64278798Shselasky printf("#define I VID_INTERLACE\n"); 65278798Shselasky printf("#define DS VID_DBLSCAN\n"); 66278798Shselasky printf("\n"); 67278798Shselasky 68278798Shselasky printf("#define M(nm,hr,vr,clk,hs,he,ht,vs,ve,vt,f) \\\n"); 69278798Shselasky printf("\t{ clk, hr, hs, he, ht, vr, vs, ve, vt, f, nm } \n\n"); 70278798Shselasky 71278798Shselasky printf("const struct videomode videomode_list[] = {\n"); 72278798Shselasky 73278798Shselasky next 74278798Shselasky} 75278798Shselasky 76278798Shselasky(/^ModeLine/) { 77278798Shselasky dotclock = $3; 78278798Shselasky 79278798Shselasky hdisplay = $4; 80278798Shselasky hsyncstart = $5; 81278798Shselasky hsyncend = $6; 82278798Shselasky htotal = $7; 83278798Shselasky 84278798Shselasky vdisplay = $8; 85278798Shselasky vsyncstart = $9; 86278798Shselasky vsyncend = $10; 87278798Shselasky vtotal = $11; 88278798Shselasky 89278798Shselasky macro = "MODE"; 90278798Shselasky iflag = ""; 91278798Shselasky iflags = ""; 92278798Shselasky hflags = "HP"; 93278798Shselasky vflags = "VP"; 94278798Shselasky 95278798Shselasky if ($12 ~ "^-") 96278798Shselasky hflags = "HN"; 97278798Shselasky 98278798Shselasky if ($13 ~ "^-") 99278798Shselasky vflags = "VN"; 100278798Shselasky 101278798Shselasky ifactor=1.0; 102278798Shselasky if ($14 ~ "[Ii][Nn][Tt][Ee][Rr][Ll][Aa][Cc][Ee]") { 103278798Shselasky iflag = "i"; 104278798Shselasky iflags = "|I"; 105278798Shselasky ifactor = 2.0; 106278798Shselasky } 107278798Shselasky 108278798Shselasky # We truncate the vrefresh figure, but some mode descriptions rely 109278798Shselasky # on rounding, so we can't win here. Adding an additional .1 110278798Shselasky # compensates to some extent. 111278798Shselasky 112278798Shselasky hrefresh= (dotclock * 1000000) / htotal; 113278798Shselasky vrefresh= int(((hrefresh * ifactor) / vtotal) + .1); 114278798Shselasky 115278798Shselasky modestr = sprintf("%dx%dx%d%s", hdisplay, vdisplay, vrefresh, iflag); 116278798Shselasky 117278798Shselasky# printf("/* %dx%d%s refresh %d Hz, hsync %d kHz */\n", 118278798Shselasky# hdisplay, vdisplay, iflag, vrefresh, hrefresh/1000); 119278798Shselasky printf("M(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%s),\n", 120278798Shselasky modestr, 121278798Shselasky hdisplay, vdisplay, dotclock * 1000, 122278798Shselasky hsyncstart, hsyncend, htotal, 123278798Shselasky vsyncstart, vsyncend, vtotal, hflags "|" vflags iflags); 124278798Shselasky 125278798Shselasky modestr = sprintf("%dx%dx%d%s", 126278798Shselasky hdisplay/2 , vdisplay/2, vrefresh, iflag); 127278798Shselasky 128278798Shselasky dmodes[nmodes]=sprintf("M(\"%s\",%d,%d,%d,%d,%d,%d,%d,%d,%d,%s),", 129278798Shselasky modestr, 130278798Shselasky hdisplay/2, vdisplay/2, dotclock * 1000 / 2, 131278798Shselasky hsyncstart/2, hsyncend/2, htotal/2, 132278798Shselasky vsyncstart/2, vsyncend/2, vtotal/2, 133278798Shselasky hflags "|" vflags "|DS" iflags); 134278798Shselasky 135278798Shselasky nmodes = nmodes + 1 136278798Shselasky 137278798Shselasky} 138278798Shselasky 139278798ShselaskyEND { 140278798Shselasky 141278798Shselasky printf("\n/* Derived Double Scan Modes */\n\n"); 142278798Shselasky 143278798Shselasky for ( i = 0; i < nmodes; i++ ) 144278798Shselasky { 145278798Shselasky print dmodes[i]; 146278798Shselasky } 147278798Shselasky 148278798Shselasky printf("};\n\n"); 149278798Shselasky printf("const int videomode_count = %d;\n", nmodes); 150278798Shselasky} 151