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