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