1 /* $NetBSD: iteconfig.c,v 1.8 2003/09/27 19:35:14 mhitch Exp $ */
3 * Copyright (c) 1994 Christian E. Hopps
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Christian E. Hopps
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
34 __RCSID("$NetBSD: iteconfig.c,v 1.8 2003/09/27 19:35:14 mhitch Exp $");
37 #include <sys/types.h>
39 #include <sys/ioctl.h>
40 #include <sys/queue.h>
42 #if !defined(amiga) && !defined(atari)
43 #error "This source is not suitable for this architecture!"
47 #include <amiga/dev/grfabs_reg.h>
48 #include <amiga/dev/viewioctl.h>
49 #include <amiga/dev/iteioctl.h>
50 #endif /* defined(amiga) */
53 #include <atari/dev/grfabs_reg.h>
54 #include <atari/dev/viewioctl.h>
55 #include <atari/dev/iteioctl.h>
56 #endif /* defined(atari) */
68 #include "pathnames.h"
70 int initialize
__P((const char *, struct itewinsize
*, struct itebell
*,
71 struct itewinsize
*, struct itebell
*));
72 int main
__P((int, char **));
73 void printcmap
__P((colormap_t
*, int));
74 void xioctl
__P((int, int, void *));
75 colormap_t
*xgetcmap
__P((int, int));
76 long xstrtol
__P((char *));
77 void usage
__P((void));
84 struct itewinsize is
, newis
;
85 struct itebell ib
, newib
;
88 const char *file
= _PATH_CONSOLE
;
89 int ch
, fd
, i
, iflag
, max_colors
, did_reset
;
95 fd
= initialize(_PATH_CONSOLE
, &is
, &ib
, &newis
, &newib
);
97 while ((ch
= getopt(argc
, argv
, "D:H:P:T:V:W:X:Y:d:f:h:ip:t:v:w:x:y:"))
100 case 'D': /* undocumented backward compat */
102 newis
.depth
= xstrtol(optarg
);
110 fd
= initialize(optarg
, &is
, &ib
, &newis
, &newib
);
111 did_reset
= optreset
= optind
= 1;
113 case 'H': /* undocumented backward compat */
115 newis
.height
= xstrtol(optarg
);
121 newib
.pitch
= xstrtol(optarg
);
124 newib
.msec
= xstrtol(optarg
);
126 case 'V': /* undocumented backward compat */
128 newib
.volume
= xstrtol(optarg
);
130 case 'W': /* undocumented backward compat */
132 newis
.width
= xstrtol(optarg
);
134 case 'X': /* undocumented backward compat */
136 newis
.x
= xstrtol(optarg
);
138 case 'Y': /* undocumented backward compat */
140 newis
.y
= xstrtol(optarg
);
151 err(1, "open \"%s\"", file
);
153 if (memcmp(&newis
, &is
, sizeof(is
))) {
154 xioctl(fd
, ITEIOCSWINSZ
, &newis
);
155 xioctl(fd
, ITEIOCGWINSZ
, &is
);
157 if (memcmp(&newib
, &ib
, sizeof(ib
))) {
158 xioctl(fd
, ITEIOCSBELL
, &newib
);
159 xioctl(fd
, ITEIOCGBELL
, &ib
);
163 * get, set and get colors again
166 max_colors
= 1 << is
.depth
;
167 cm
= xgetcmap(fd
, max_colors
);
169 val
= xstrtol(*argv
++);
170 if (i
>= max_colors
) {
171 warnx("warning: too many colors");
177 xioctl(fd
, VIOCSCMAP
, cm
);
179 cm
= xgetcmap(fd
, max_colors
);
181 /* do tty stuff to get it to register the changes. */
182 xioctl(fd
, TIOCGWINSZ
, &ws
);
185 printf("tty size: rows %d cols %d\n", ws
.ws_row
, ws
.ws_col
);
186 printf("ite size: w: %d h: %d d: %d [x: %d y: %d]\n",
187 is
.width
, is
.height
, is
.depth
, is
.x
, is
.y
);
188 printf("ite bell: vol: %d millisec: %d pitch: %d\n",
189 ib
.volume
, ib
.msec
, ib
.pitch
);
190 printcmap(cm
, ws
.ws_col
);
197 xioctl(fd
, cmd
, addr
)
201 if (ioctl(fd
, cmd
, addr
) == -1)
212 rv
= strtol(s
, NULL
, 0);
213 if (errno
== ERANGE
&& (rv
== LONG_MIN
|| rv
== LONG_MAX
))
214 err(1, "bad format: \"%s\"", s
);
219 xgetcmap(fd
, ncolors
)
225 cm
= malloc(sizeof(colormap_t
) + ncolors
* sizeof(u_long
));
230 cm
->entry
= (u_long
*) & cm
[1];
231 xioctl(fd
, VIOCGCMAP
, cm
);
244 printf("monochrome");
247 printf("color levels: red: %d green: %d blue: %d",
248 cm
->red_mask
+ 1, cm
->green_mask
+ 1, cm
->blue_mask
+ 1);
251 printf("greyscale levels: %d", cm
->grey_mask
+ 1);
256 nel
= ncols
/ 11 - 1;
257 for (i
= 0; i
< cm
->size
; i
++) {
258 printf("0x%08lx ", cm
->entry
[i
]);
259 if ((i
+ 1) % nel
== 0)
267 initialize(file
, is
, ib
, newis
, newib
)
269 struct itewinsize
*is
, *newis
;
270 struct itebell
*ib
, *newib
;
274 fd
= open(file
, O_RDONLY
| O_NONBLOCK
);
278 xioctl(fd
, ITEIOCGWINSZ
, is
);
279 xioctl(fd
, ITEIOCGBELL
, ib
);
281 memcpy(newis
, is
, sizeof(*is
));
282 memcpy(newib
, ib
, sizeof(*ib
));
289 fprintf(stderr
, "%s\n\t\t%s\n\t\t%s\n",
290 "usage: iteconfig [-i] [-f file] [-v volume] [-p pitch] [-t msec]",
291 "[-w width] [-h height] [-d depth] [-x off] [-y off]",