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