Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / x68k / usr.bin / palette / palette.c
blobfaf45d377b05ce5b15e063781bb30fdbc4922838
1 /* $NetBSD: palette.c,v 1.6 2006/08/04 02:30:00 mhitch Exp $ */
2 /*
3 * pelette - manipulate text colormap for NetBSD/x68k.
4 * author: Masaru Oki
6 * This software is in the Public Domain.
7 */
9 #include <sys/cdefs.h>
10 __RCSID("$NetBSD: palette.c,v 1.6 2006/08/04 02:30:00 mhitch Exp $");
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <sys/param.h>
15 #include <sys/ioctl.h>
16 #include <sys/mman.h>
17 #include <sys/fcntl.h>
19 #define PALETTE_OFFSET 0x2000 /* physical addr: 0xe82000 */
20 #define PALETTE_SIZE 0x1000 /* at least 1 page */
22 int
23 main(int argc, char *argv[])
25 int fd;
26 u_short *palette;
27 char *mapaddr;
28 int r, g, b;
29 int c = 7;
31 #ifdef DEBUG
33 int i;
34 printf("argc = %d\n", argc);
35 for (i = 0; i < argc; i++)
36 printf("argv[%d] = \"%s\"\n", i, argv[i]);
38 #endif
40 if ((fd = open("/dev/grf0", O_RDWR, 0)) < 0) {
41 perror("open");
42 exit(1);
45 mapaddr = mmap(0, PALETTE_SIZE, PROT_READ | PROT_WRITE,
46 MAP_FILE | MAP_SHARED, fd, PALETTE_OFFSET);
47 if (mapaddr == (void *)-1) {
48 perror("mmap");
49 close(fd);
50 exit(1);
52 close(fd);
53 palette = (u_short *)(mapaddr + 0x0200);
55 if (argc == 5) {
56 c = atoi(argv[--argc]);
57 if (c > 15) {
58 printf("Usage: %s [red green blue [code]]\n", argv[0]);
59 exit(1);
62 if (argc != 4)
63 r = g = b = 31;
64 else {
65 r = atoi(argv[1]);
66 g = atoi(argv[2]);
67 b = atoi(argv[3]);
68 if (r > 31 || g > 31 || b > 31) {
69 printf("Usage: %s [red green blue [code]]\n", argv[0]);
70 r = g = b = 31;
73 #ifdef DEBUG
74 printf("color table offset = %d\n", c);
75 printf("r = %d, g = %d, b = %d\n", r, g, b);
76 #endif
77 r <<= 6;
78 g <<= 11;
79 b <<= 1;
81 palette[c] = r | g | b | 1;
83 exit(0);