Home | History | Annotate | Line # | Download | only in palette
palette.c revision 1.4
      1 /*	$NetBSD: palette.c,v 1.4 2003/07/15 01:44:54 lukem Exp $	*/
      2 /*
      3  * pelette - manipulate text colormap for NetBSD/x68k.
      4  * author: Masaru Oki
      5  *
      6  * This software is in the Public Domain.
      7  */
      8 
      9 #include <sys/cdefs.h>
     10 __RCSID("$NetBSD: palette.c,v 1.4 2003/07/15 01:44:54 lukem Exp $");
     11 
     12 #include <stdio.h>
     13 #include <sys/param.h>
     14 #include <sys/ioctl.h>
     15 #include <sys/mman.h>
     16 #include <sys/fcntl.h>
     17 
     18 #define PALETTE_OFFSET 0x2000 /* physical addr: 0xe82000 */
     19 #define PALETTE_SIZE   0x1000 /* at least 1 page */
     20 
     21 int
     22 main(int argc, char *argv[])
     23 {
     24 	int fd;
     25 	u_short *palette;
     26 	char *mapaddr;
     27 	int r, g, b;
     28 	int c = 7;
     29 
     30 #ifdef DEBUG
     31 {
     32 	int i;
     33 	printf("argc = %d\n", argc);
     34 	for (i = 0; i < argc; i++)
     35 		printf("argv[%d] = \"%s\"\n", i, argv[i]);
     36 }
     37 #endif
     38 
     39 	if ((fd = open("/dev/grf0", O_RDWR, 0)) < 0) {
     40 		perror("open");
     41 		exit(1);
     42 	}
     43 
     44 	mapaddr = mmap(0, PALETTE_SIZE, PROT_READ | PROT_WRITE,
     45 		       MAP_FILE | MAP_SHARED, fd, PALETTE_OFFSET);
     46 	if (mapaddr == (caddr_t)-1) {
     47 		perror("mmap");
     48 		close(fd);
     49 		exit(1);
     50 	}
     51 	close(fd);
     52 	palette = (u_short *)(mapaddr + 0x0200);
     53 
     54 	if (argc == 5) {
     55 		c = atoi(argv[--argc]);
     56 		if (c > 15) {
     57 			printf("Usage: %s [red green blue [code]]\n", argv[0]);
     58 			exit(1);
     59 		}
     60 	}
     61 	if (argc != 4)
     62 		r = g = b = 31;
     63 	else {
     64 		r = atoi(argv[1]);
     65 		g = atoi(argv[2]);
     66 		b = atoi(argv[3]);
     67 		if (r > 31 || g > 31 || b > 31) {
     68 			printf("Usage: %s [red green blue [code]]\n", argv[0]);
     69 			r = g = b = 31;
     70 		}
     71 	}
     72 #ifdef DEBUG
     73 	printf("color table offset = %d\n", c);
     74 	printf("r = %d, g = %d, b = %d\n", r, g, b);
     75 #endif
     76 	r <<= 6;
     77 	g <<= 11;
     78 	b <<= 1;
     79 
     80 	palette[c] = r | g | b | 1;
     81 
     82 	exit(0);
     83 }
     84