1 /* $NetBSD: videomode.c,v 1.6 2009/01/14 22:57:48 he Exp $ */
4 * Copyright (c) 1995 Christian E. Hopps
5 * Copyright (c) 1994 Markus Wild
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Markus Wild
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/types.h>
36 #include <sys/ioctl.h>
37 #include <sys/device.h>
38 #include <amiga/dev/grfioctl.h>
39 #include <amiga/dev/grfvar.h>
48 void dump_mode
__P((int));
49 void dump_vm
__P((struct grfvideo_mode
*));
50 int get_grf
__P((void));
51 int main
__P((int, char **));
52 void set_mode
__P((int));
53 void usage
__P((void));
67 while ((c
= getopt(argc
, argv
, "as:")) != -1) {
76 if (m
== 0 || optind
< argc
)
88 dump_mode(atoi(*argv
));
100 /* find out on which ite/grf we are */
101 if (fstat(0, &stb
) == -1)
103 if (!S_ISCHR(stb
.st_mode
) || !isatty(0))
104 errx(1, "stdin not a tty");
105 if (major(stb
.st_rdev
) != 13)
106 errx(1, "stdin not an ite device");
107 (void)snprintf(grfname
, sizeof(grfname
), "/dev/grf%u",
108 (u_int
)minor(stb
.st_rdev
) & 0x7);
109 if ((grffd
= open(grfname
, 2)) < 0)
110 err(1, "%s", grfname
);
118 struct grfvideo_mode vm
;
124 if (ioctl(grffd
, GRFGETNUMVM
, &num_vm
) < 0)
125 err(1, "GRFGETNUMVM");
126 if (m
> 0 && m
> num_vm
)
127 errx(1, "no such mode");
129 (void)printf("Current mode:\n");
131 if (ioctl(grffd
, GRFGETVMODE
, &vm
) == 0)
137 for (m
= 1; m
<= num_vm
; m
++) {
139 if (ioctl(grffd
, GRFGETVMODE
, &vm
) == -1)
152 (void)ioctl(grffd
, GRFSETVMODE
, &m
);
157 struct grfvideo_mode
*vm
;
159 (void)printf("%d: %s\n", vm
->mode_num
, vm
->mode_descr
);
161 "pixel_clock = %lu, width = %d, height = %d, depth = %d\n",
162 vm
->pixel_clock
, vm
->disp_width
, vm
->disp_height
, vm
->depth
);
168 (void)fprintf(stderr
, "usage: videomode [mode]\n");
169 (void)fprintf(stderr
, "usage: videomode -a\n");
170 (void)fprintf(stderr
, "usage: videomode -s mode\n");