1994-04-05 05:56:24 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1994 Christian E. Hopps
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Christian E. Hopps
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
1994-04-10 04:56:55 +04:00
|
|
|
* $Id: iteconfig.c,v 1.3 1994/04/10 00:56:57 chopps Exp $
|
1994-04-05 05:56:24 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/queue.h>
|
1994-04-05 08:34:51 +04:00
|
|
|
#include <amiga/dev/grfabs_reg.h>
|
|
|
|
#include <amiga/dev/viewioctl.h>
|
|
|
|
#include <amiga/dev/iteioctl.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
1994-04-05 05:56:24 +04:00
|
|
|
#include <fcntl.h>
|
1994-04-05 08:34:51 +04:00
|
|
|
#include <limits.h>
|
1994-04-05 05:56:24 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1994-04-05 08:34:51 +04:00
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
1994-04-05 05:56:24 +04:00
|
|
|
|
1994-04-05 08:34:51 +04:00
|
|
|
#include "pathnames.h"
|
1994-04-05 05:56:24 +04:00
|
|
|
|
1994-04-05 08:34:51 +04:00
|
|
|
void printcmap __P((colormap_t *, int));
|
|
|
|
void usage __P((void));
|
|
|
|
void xioctl __P((int, int, void *));
|
1994-04-05 05:56:24 +04:00
|
|
|
colormap_t *xgetcmap __P((int, int));
|
1994-04-05 08:34:51 +04:00
|
|
|
long xstrtol __P((char *));
|
1994-04-05 05:56:24 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
1994-04-10 04:56:55 +04:00
|
|
|
struct itewinsize is, newis;
|
|
|
|
struct itebell ib, newib;
|
1994-04-05 05:56:24 +04:00
|
|
|
struct winsize ws;
|
|
|
|
colormap_t *cm;
|
1994-04-05 08:34:51 +04:00
|
|
|
int ch, fd, i, iflag, max_colors;
|
1994-04-05 05:56:24 +04:00
|
|
|
long val;
|
|
|
|
|
1994-04-05 08:34:51 +04:00
|
|
|
iflag = 0;
|
1994-04-05 05:56:24 +04:00
|
|
|
|
1994-04-05 08:34:51 +04:00
|
|
|
fd = open(_PATH_AMIGACONSOLE, O_RDONLY | O_NONBLOCK);
|
|
|
|
if (fd == -1)
|
|
|
|
err(1, "open console");
|
1994-04-05 05:56:24 +04:00
|
|
|
|
1994-04-10 04:56:55 +04:00
|
|
|
xioctl(fd, ITEIOCGWINSZ, &is);
|
|
|
|
xioctl(fd, ITEIOCGBELL, &ib);
|
1994-04-05 05:56:24 +04:00
|
|
|
|
1994-04-05 08:34:51 +04:00
|
|
|
memcpy(&newis, &is, sizeof(is));
|
|
|
|
memcpy(&newib, &ib, sizeof(ib));
|
1994-04-05 05:56:24 +04:00
|
|
|
|
1994-04-05 08:34:51 +04:00
|
|
|
while ((ch = getopt(argc, argv, "D:H:P:T:V:W:X:Y:d:h:ip:t:v:w:x:y:"))
|
|
|
|
!= EOF) {
|
|
|
|
switch (ch) {
|
|
|
|
case 'D': /* undocumented backward compat */
|
|
|
|
case 'd':
|
|
|
|
newis.depth = xstrtol(optarg);
|
1994-04-05 05:56:24 +04:00
|
|
|
break;
|
1994-04-05 08:34:51 +04:00
|
|
|
case 'H': /* undocumented backward compat */
|
1994-04-05 05:56:24 +04:00
|
|
|
case 'h':
|
|
|
|
newis.height = xstrtol(optarg);
|
|
|
|
break;
|
1994-04-05 08:34:51 +04:00
|
|
|
case 'i':
|
|
|
|
iflag = 1;
|
1994-04-05 05:56:24 +04:00
|
|
|
break;
|
|
|
|
case 'p':
|
1994-04-10 04:56:55 +04:00
|
|
|
newib.pitch = xstrtol(optarg);
|
1994-04-05 05:56:24 +04:00
|
|
|
break;
|
|
|
|
case 't':
|
1994-04-10 04:56:55 +04:00
|
|
|
newib.msec = xstrtol(optarg);
|
1994-04-05 05:56:24 +04:00
|
|
|
break;
|
1994-04-05 08:34:51 +04:00
|
|
|
case 'V': /* undocumented backward compat */
|
|
|
|
case 'v':
|
|
|
|
newib.volume = xstrtol(optarg);
|
|
|
|
break;
|
|
|
|
case 'W': /* undocumented backward compat */
|
|
|
|
case 'w':
|
|
|
|
newis.width = xstrtol(optarg);
|
|
|
|
break;
|
|
|
|
case 'X': /* undocumented backward compat */
|
|
|
|
case 'x':
|
|
|
|
newis.x = xstrtol(optarg);
|
|
|
|
break;
|
|
|
|
case 'Y': /* undocumented backward compat */
|
|
|
|
case 'y':
|
|
|
|
newis.y = xstrtol(optarg);
|
|
|
|
break;
|
1994-04-05 05:56:24 +04:00
|
|
|
case '?':
|
1994-04-05 08:34:51 +04:00
|
|
|
default:
|
|
|
|
usage();
|
1994-04-05 05:56:24 +04:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
1994-04-05 08:34:51 +04:00
|
|
|
if (memcmp(&newis, &is, sizeof(is))) {
|
1994-04-10 04:56:55 +04:00
|
|
|
xioctl(fd, ITEIOCSWINSZ, &newis);
|
|
|
|
xioctl(fd, ITEIOCGWINSZ, &is);
|
1994-04-05 05:56:24 +04:00
|
|
|
}
|
1994-04-05 08:34:51 +04:00
|
|
|
if (memcmp(&newib, &ib, sizeof(ib))) {
|
1994-04-10 04:56:55 +04:00
|
|
|
xioctl(fd, ITEIOCSBELL, &newib);
|
|
|
|
xioctl(fd, ITEIOCGBELL, &ib);
|
1994-04-05 05:56:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get, set and get colors again
|
|
|
|
*/
|
|
|
|
i = 0;
|
|
|
|
max_colors = 1 << is.depth;
|
|
|
|
cm = xgetcmap(fd, max_colors);
|
|
|
|
while (argc--) {
|
|
|
|
val = xstrtol(*argv++);
|
|
|
|
if (i >= max_colors) {
|
1994-04-05 08:34:51 +04:00
|
|
|
warnx("warning: too many colors");
|
1994-04-05 05:56:24 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
cm->entry[i] = val;
|
|
|
|
i++;
|
|
|
|
}
|
1994-04-10 04:56:55 +04:00
|
|
|
xioctl(fd, VIOCSCMAP, cm);
|
1994-04-05 05:56:24 +04:00
|
|
|
free(cm);
|
|
|
|
cm = xgetcmap(fd, max_colors);
|
|
|
|
|
|
|
|
/* do tty stuff to get it to register the changes. */
|
|
|
|
xioctl(fd, TIOCGWINSZ, &ws);
|
|
|
|
|
1994-04-05 08:34:51 +04:00
|
|
|
if (iflag) {
|
1994-04-05 05:56:24 +04:00
|
|
|
printf("tty size: rows %d cols %d\n", ws.ws_row, ws.ws_col);
|
|
|
|
printf("ite size: w: %d h: %d d: %d [x: %d y: %d]\n",
|
|
|
|
is.width, is.height, is.depth, is.x, is.y);
|
1994-04-10 04:56:55 +04:00
|
|
|
printf("ite bell: vol: %d millisec: %d pitch: %d\n",
|
|
|
|
ib.volume, ib.msec, ib.pitch);
|
1994-04-05 05:56:24 +04:00
|
|
|
printcmap(cm, ws.ws_col);
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xioctl(fd, cmd, addr)
|
|
|
|
int fd, cmd;
|
|
|
|
void *addr;
|
|
|
|
{
|
1994-04-05 08:34:51 +04:00
|
|
|
if (ioctl(fd, cmd, addr) == -1)
|
|
|
|
err(1, "ioctl");
|
1994-04-05 05:56:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
long
|
|
|
|
xstrtol(s)
|
|
|
|
char *s;
|
|
|
|
{
|
|
|
|
long rv;
|
|
|
|
|
|
|
|
rv = strtol(s, NULL, 0);
|
1994-04-05 08:34:51 +04:00
|
|
|
if (errno == ERANGE && (rv == LONG_MIN || rv == LONG_MAX))
|
|
|
|
err(1, "bad format: \"%s\"", s);
|
|
|
|
return(rv);
|
1994-04-05 05:56:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
colormap_t *
|
|
|
|
xgetcmap(fd, ncolors)
|
|
|
|
int fd;
|
|
|
|
int ncolors;
|
|
|
|
{
|
|
|
|
colormap_t *cm;
|
|
|
|
|
|
|
|
cm = malloc(sizeof(colormap_t) + ncolors * sizeof(u_long));
|
1994-04-05 08:34:51 +04:00
|
|
|
if (cm == NULL)
|
|
|
|
err(1, "malloc");
|
1994-04-05 05:56:24 +04:00
|
|
|
cm->first = 0;
|
|
|
|
cm->size = ncolors;
|
|
|
|
cm->entry = (u_long *) & cm[1];
|
1994-04-10 04:56:55 +04:00
|
|
|
xioctl(fd, VIOCGCMAP, cm);
|
1994-04-05 05:56:24 +04:00
|
|
|
return(cm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
printcmap(cm, ncols)
|
|
|
|
colormap_t *cm;
|
|
|
|
int ncols;
|
|
|
|
{
|
|
|
|
int i, nel;
|
|
|
|
|
|
|
|
switch (cm->type) {
|
|
|
|
case CM_MONO:
|
1994-04-05 08:34:51 +04:00
|
|
|
printf("monochrome");
|
1994-04-05 05:56:24 +04:00
|
|
|
return;
|
|
|
|
case CM_COLOR:
|
1994-04-05 08:34:51 +04:00
|
|
|
printf("color levels: red: %d green: %d blue: %d",
|
1994-04-05 05:56:24 +04:00
|
|
|
cm->red_mask + 1, cm->green_mask + 1, cm->blue_mask + 1);
|
|
|
|
break;
|
|
|
|
case CM_GREYSCALE:
|
1994-04-05 08:34:51 +04:00
|
|
|
printf("greyscale levels: %d", cm->grey_mask + 1);
|
1994-04-05 05:56:24 +04:00
|
|
|
break;
|
|
|
|
}
|
1994-04-05 08:34:51 +04:00
|
|
|
printf("\n");
|
1994-04-05 05:56:24 +04:00
|
|
|
|
|
|
|
nel = ncols / 11 - 1;
|
|
|
|
for (i = 0; i < cm->size; i++) {
|
|
|
|
printf("0x%08lx ", cm->entry[i]);
|
|
|
|
if ((i + 1) % nel == 0)
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
if ((i + 1) % nel)
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1994-04-05 08:34:51 +04:00
|
|
|
usage()
|
1994-04-05 05:56:24 +04:00
|
|
|
{
|
1994-04-05 08:34:51 +04:00
|
|
|
fprintf(stderr, "%s\n\t\t%s\n",
|
|
|
|
"usage: iteconfig [-i] [-v volume] [-p period] [-t count]",
|
|
|
|
"[-w width] [-h height] [-d depth] [-x off] [-y off] [color ...]");
|
1994-04-05 05:56:24 +04:00
|
|
|
exit(1);
|
|
|
|
}
|