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