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