1 /* $NetBSD: grfconfig.c,v 1.4 1996/05/19 09:02:44 veego 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("grfconfig: bad monitor " 134 "definition for mode #%d.\n", 135 gv->mode_num); 136 } else { 137 printf("grfconfig: bad line in mode " 138 "definition file.\n"); 139 } 140 } 141 fclose(fp); 142 } else { 143 ioctl(grffd, GRFGETNUMVM, &y); 144 y += 2; 145 for (c = 1; c < y; c++) { 146 c = gv->mode_num = (c != (y - 1)) ? c : 255; 147 if (ioctl(grffd, GRFGETVMODE, gv) < 0) 148 continue; 149 if (rawdata) { 150 if (c == 255) 151 printf("c "); 152 else 153 printf("%d ", c); 154 printf("%d %d %d %d %d %d %d " 155 "%d %d %d %d %d %d %d\n", 156 gv->pixel_clock, 157 gv->disp_width, 158 gv->disp_height, 159 gv->depth, 160 gv->hblank_start, 161 gv->hsync_start, 162 gv->hsync_stop, 163 gv->hblank_stop, 164 gv->htotal, 165 gv->vblank_start, 166 gv->vsync_start, 167 gv->vsync_stop, 168 gv->vblank_stop, 169 gv->vtotal 170 ); 171 continue; 172 } 173 if (c == 255) 174 printf("Console: "); 175 else 176 printf("%2d: ", gv->mode_num); 177 178 printf("%dx%d", 179 gv->disp_width, 180 gv->disp_height); 181 182 if (c != 255) 183 printf("x%d", gv->depth); 184 else 185 printf(" (%dx%d)", 186 gv->disp_width / 8, 187 gv->disp_height / gv->depth); 188 189 printf("\t%d.%dkHz @ %dHz %s\n", 190 gv->pixel_clock / (gv->htotal * 1000 * oldmode), 191 (gv->pixel_clock / (gv->htotal * 100 * oldmode)) 192 % 10, 193 gv->pixel_clock / (gv->htotal * gv->vtotal * 194 oldmode), 195 gv->vblank_start + 100 < gv->disp_height ? 196 "I" : 197 (gv->vblank_start - 100) > gv->disp_height ? 198 "SD" : 199 "NI" 200 ); 201 } 202 } 203 204 close(grffd); 205 return (0); 206 } 207