Home | History | Annotate | Line # | Download | only in grfconfig
grfconfig.c revision 1.2
      1 /*	$NetBSD: grfconfig.c,v 1.2 1995/10/09 04:11:20 chopps Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1995 Ezra Story
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *      This product includes software developed by Ezra Story.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 #include <stdio.h>
     33 #include <stdlib.h>
     34 #include <string.h>
     35 #include <sys/file.h>
     36 #include <sys/ioctl.h>
     37 
     38 #include <amiga/dev/grfioctl.h>
     39 
     40 extern char *optarg;
     41 extern int optind;
     42 
     43 /*
     44  * Dynamic mode loader for NetBSD/Amiga grf devices.
     45  */
     46 int
     47 main(ac, av)
     48 	int     ac;
     49 	char  **av;
     50 {
     51 	int     c, y, grffd;
     52 	char    rawdata = 0;
     53     	char    oldmode = 1;
     54 	char   *grfdevice = 0;
     55 	char   *modefile = 0;
     56 	char    buf[102];
     57 	char    ystr[20];
     58 	FILE   *fp;
     59 	struct grfvideo_mode gv[1];
     60 
     61 	while ((c = getopt(ac, av, "ro")) != -1) {
     62 		switch (c) {
     63 		case 'r':	/* raw output */
     64 			rawdata = 1;
     65 			break;
     66     	    	case 'o':
     67     	    	    	oldmode = 8;
     68     	    	    	break;
     69 		default:
     70 			printf("grfconfig [-r] device [file]\n");
     71 			return (1);
     72 		}
     73 	}
     74 	ac -= optind;
     75 	av += optind;
     76 
     77 
     78 	if (ac >= 1)
     79 		grfdevice = av[0];
     80 	else {
     81 		printf("grfconfig: No grf device specified.\n");
     82 		return (1);
     83 	}
     84 
     85 	if (ac >= 2)
     86 		modefile = av[1];
     87 
     88 	if ((grffd = open(grfdevice, O_RDWR)) < 0) {
     89 		printf("grfconfig: can't open grf device.\n");
     90 		return (1);
     91 	}
     92 	/* If a mode file is specificied, load it in, don't display any info. */
     93 
     94 	if (modefile) {
     95 		if (!(fp = fopen(modefile, "r"))) {
     96 			printf("grfconfig: Cannot open mode definition file.\n");
     97 			return (1);
     98 		}
     99 		while (fgets(buf, 300, fp)) {
    100 			if (buf[0] == '#')
    101 				continue;
    102 
    103 			/* num clk wid hi dep hbs hss hse hbe ht vbs vss vse
    104 			 * vbe vt */
    105 
    106 			c = sscanf(buf, "%9s %d %hd %hd %hd %hd %hd %hd "
    107 			    "%hd %hd %hd %hd %hd %hd %hd",
    108 			    ystr,
    109 			    &gv->pixel_clock,
    110 			    &gv->disp_width,
    111 			    &gv->disp_height,
    112 			    &gv->depth,
    113 			    &gv->hblank_start,
    114 			    &gv->hsync_start,
    115 			    &gv->hsync_stop,
    116 			    &gv->hblank_stop,
    117 			    &gv->htotal,
    118 			    &gv->vblank_start,
    119 			    &gv->vsync_start,
    120 			    &gv->vsync_stop,
    121 			    &gv->vblank_stop,
    122 			    &gv->vtotal);
    123 			if (c == 15) {
    124 				if (y = atoi(ystr))
    125 					gv->mode_num = y;
    126 				else
    127 					if (ystr[0] == 'c') {
    128 						gv->mode_num = 255;
    129 						gv->depth = 4;
    130 					}
    131 				gv->mode_descr[0] = 0;
    132 				if (ioctl(grffd, GRFIOCSETMON, (char *) gv) < 0)
    133 					printf("grfocnfig: bad monitor "
    134 					    "definition.\n");
    135 			} else {
    136 				printf("grfconfig: bad line in mode "
    137 				    "definition file.\n");
    138 			}
    139 		}
    140 		fclose(fp);
    141 	} else {
    142 		ioctl(grffd, GRFGETNUMVM, &y);
    143 		y += 2;
    144 		for (c = 1; c < y; c++) {
    145 			c = gv->mode_num = (c != (y - 1)) ? c : 255;
    146 			if (ioctl(grffd, GRFGETVMODE, gv) < 0)
    147 				continue;
    148 			if (rawdata) {
    149 				if (c == 255)
    150 					printf("c ");
    151 				else
    152 					printf("%d ", c);
    153 				printf("%d %d %d %d %d %d %d "
    154 				    "%d %d %d %d %d %d %d\n",
    155 				    gv->pixel_clock,
    156 				    gv->disp_width,
    157 				    gv->disp_height,
    158 				    gv->depth,
    159 				    gv->hblank_start,
    160 				    gv->hsync_start,
    161 				    gv->hsync_stop,
    162 				    gv->hblank_stop,
    163 				    gv->htotal,
    164 				    gv->vblank_start,
    165 				    gv->vsync_start,
    166 				    gv->vsync_stop,
    167 				    gv->vblank_stop,
    168 				    gv->vtotal
    169 				    );
    170 				continue;
    171 			}
    172 			if (c == 255)
    173 				printf("Console: ");
    174 			else
    175 				printf("%2d: ", gv->mode_num);
    176 
    177 			printf("%dx%d",
    178 			    gv->disp_width,
    179 			    gv->disp_height);
    180 
    181 			if (c != 255)
    182 				printf("x%d", gv->depth);
    183 			else
    184 				printf(" (%dx%d)",
    185 				    gv->disp_width / 8,
    186 				    gv->disp_height / gv->depth);
    187 
    188 			printf("\t%d.%dkHz @ %dHz %s\n",
    189 			    gv->pixel_clock / (gv->htotal * 1000 * oldmode),
    190 			    (gv->pixel_clock / (gv->htotal * 100 * oldmode))
    191     	    	    	    	% 10,
    192 			    gv->pixel_clock / (gv->htotal * gv->vtotal *
    193     	    	    	    	oldmode),
    194 			    gv->vblank_start + 100 < gv->disp_height ?
    195 			    "I" :
    196 			    (gv->vblank_start - 100) > gv->disp_height ?
    197 			    "SD" :
    198 			    "NI"
    199 			    );
    200 		}
    201 	}
    202 
    203 	close(grffd);
    204 	return (0);
    205 }
    206