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