1 /* $NetBSD: palette.c,v 1.8 2011/05/19 21:26:39 tsutsui 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.8 2011/05/19 21:26:39 tsutsui Exp $");
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include <sys/param.h>
16 #include <sys/ioctl.h>
17 #include <sys/mman.h>
18 #include <sys/fcntl.h>
19
20 #define PALETTE_OFFSET 0x2000 /* physical addr: 0xe82000 */
21 #define PALETTE_SIZE 0x1000 /* at least 1 page */
22
23 int
main(int argc,char * argv[])24 main(int argc, char *argv[])
25 {
26 int fd;
27 u_short *palette;
28 char *mapaddr;
29 int r, g, b;
30 int c = 7;
31
32 #ifdef DEBUG
33 {
34 int i;
35 printf("argc = %d\n", argc);
36 for (i = 0; i < argc; i++)
37 printf("argv[%d] = \"%s\"\n", i, argv[i]);
38 }
39 #endif
40
41 if ((fd = open("/dev/grf0", O_RDWR, 0)) < 0) {
42 perror("open");
43 exit(1);
44 }
45
46 mapaddr = mmap(0, PALETTE_SIZE, PROT_READ | PROT_WRITE,
47 MAP_FILE | MAP_SHARED, fd, PALETTE_OFFSET);
48 if (mapaddr == (void *)-1) {
49 perror("mmap");
50 close(fd);
51 exit(1);
52 }
53 close(fd);
54 palette = (u_short *)(mapaddr + 0x0200);
55
56 if (argc == 5) {
57 c = atoi(argv[--argc]);
58 if (c > 15) {
59 printf("Usage: %s [red green blue [code]]\n", argv[0]);
60 exit(1);
61 }
62 }
63 if (argc != 4)
64 r = g = b = 31;
65 else {
66 r = atoi(argv[1]);
67 g = atoi(argv[2]);
68 b = atoi(argv[3]);
69 if (r > 31 || g > 31 || b > 31) {
70 printf("Usage: %s [red green blue [code]]\n", argv[0]);
71 r = g = b = 31;
72 }
73 }
74 #ifdef DEBUG
75 printf("color table offset = %d\n", c);
76 printf("r = %d, g = %d, b = %d\n", r, g, b);
77 #endif
78 r <<= 6;
79 g <<= 11;
80 b <<= 1;
81
82 palette[c] = r | g | b | 1;
83
84 exit(0);
85 }
86