grfabs.c revision 1.7 1 /* $NetBSD: grfabs.c,v 1.7 1995/09/23 20:29:16 leo Exp $ */
2
3 /*
4 * Copyright (c) 1995 Leo Weppelman.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Leo Weppelman.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * atari abstract graphics driver.
35 */
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/queue.h>
39 #include <sys/malloc.h>
40
41 #include <machine/cpu.h>
42 #include <machine/iomap.h>
43 #include <machine/video.h>
44 #include <machine/mfp.h>
45 #include <atari/dev/grfabs_reg.h>
46
47 /*
48 * Function decls
49 */
50 static dmode_t *get_best_display_mode __P((dimen_t *, int, dmode_t *));
51
52 /*
53 * List of available graphic modes
54 */
55 static MODES modes;
56
57 /*
58 * Ugh.. Stuff needed to allocate console structures before the VM-system
59 * is running. There is no malloc() available at that time.
60 * Decision to use these: atari_realconfig == 0
61 */
62 view_t gra_con_view;
63 colormap_t gra_con_cmap;
64 long gra_con_colors[MAX_CENTRIES];
65
66 /*
67 * Default colors.....
68 * Currently the TT-low (256 colors) just uses 16 times the 16-color default.
69 * If you have a sensible 256 scale, feel free to add.....
70 * The first 2 colors in all maps are {black,white}, so ite (text) displays
71 * are initially readable. Also, this enables me to supply only 1 map. The
72 * 4 color mode uses the first four entries of the 16 color mode thus giving
73 * a gray scale display. (Maybe we can add an intensity bit to the ite...)
74 */
75 u_long gra_def_color16[16] = {
76 0x00000000, /* black */
77 0x00ffffff, /* white */
78 0x000c0c0c, /* light gray */
79 0x00808008, /* gray */
80 0x0000000c, /* blue */
81 0x00000c00, /* green */
82 0x00000c0c, /* cyan */
83 0x00c00000, /* red */
84 0x00c0000c, /* magenta */
85 0x00c00c00, /* brown */
86 0x000000ff, /* light blue */
87 0x0000ff00, /* light green */
88 0x0000ffff, /* light cyan */
89 0x00ff0000, /* light red */
90 0x00ff00ff, /* light magenta */
91 0x00ffff00 /* light brown */
92 };
93
94 /*
95 * XXX: called from ite console init routine.
96 * Initialize list of posible video modes.
97 */
98 int
99 grfabs_probe()
100 {
101 static int inited = 0;
102
103 if (inited)
104 return (1); /* Has to be done only once */
105 inited++;
106
107 LIST_INIT(&modes);
108
109 #ifdef FALCON_VIDEO
110 if (machineid & ATARI_FALCON)
111 falcon_probe_video(&modes);
112 #endif /* FALCON_VIDEO */
113 #ifdef TT_VIDEO
114 if (machineid & ATARI_TT)
115 tt_probe_video(&modes);
116 #endif /* TT_VIDEO */
117 return ((modes.lh_first == NULL) ? 0 : 1);
118 }
119
120 view_t *
121 grf_alloc_view(d, dim, depth)
122 dmode_t *d;
123 dimen_t *dim;
124 u_char depth;
125 {
126 if (!d)
127 d = get_best_display_mode(dim, depth, NULL);
128 if (d)
129 return ((d->grfabs_funcs->alloc_view)(d, dim, depth));
130 return(NULL);
131 }
132
133 dmode_t *
134 grf_get_best_mode(dim, depth)
135 dimen_t *dim;
136 u_char depth;
137 {
138 return (get_best_display_mode(dim, depth, NULL));
139 }
140
141 void grf_display_view(v)
142 view_t *v;
143 {
144 (v->mode->grfabs_funcs->display_view)(v);
145 }
146
147 void grf_remove_view(v)
148 view_t *v;
149 {
150 (v->mode->grfabs_funcs->remove_view)(v);
151 }
152
153 void grf_free_view(v)
154 view_t *v;
155 {
156 (v->mode->grfabs_funcs->free_view)(v);
157 }
158
159 int
160 grf_get_colormap(v, cm)
161 view_t *v;
162 colormap_t *cm;
163 {
164 colormap_t *gcm;
165 int i, n;
166 u_long *sv_entry;
167
168 gcm = v->colormap;
169 n = cm->size < gcm->size ? cm->size : gcm->size;
170
171 /*
172 * Copy struct from view but be carefull to keep 'entry'
173 */
174 sv_entry = cm->entry;
175 *cm = *gcm;
176 cm->entry = sv_entry;
177
178 /*
179 * Copy the colors
180 */
181 bzero(cm->entry, cm->size * sizeof(long));
182 for (i = 0; i < n; i++)
183 cm->entry[i] = gcm->entry[i];
184 return (0);
185 }
186
187 int
188 grf_use_colormap(v, cm)
189 view_t *v;
190 colormap_t *cm;
191 {
192 return (v->mode->grfabs_funcs->use_colormap)(v, cm);
193 }
194
195 static dmode_t *
196 get_best_display_mode(dim, depth, curr_mode)
197 int depth;
198 dimen_t *dim;
199 dmode_t *curr_mode;
200 {
201 dmode_t *save;
202 dmode_t *dm;
203 long dt, dx, dy, ct;
204
205 save = NULL;
206 dm = modes.lh_first;
207 while (dm != NULL) {
208 dx = abs(dm->size.width - dim->width);
209 dy = abs(dm->size.height - dim->height);
210 ct = dx + dy;
211
212 if (ct < dt || save == NULL) {
213 save = dm;
214 dt = ct;
215 }
216 dm = dm->link.le_next;
217 }
218 /*
219 * Did we do better than the current mode?
220 */
221 if ((save != NULL) && (curr_mode != NULL)) {
222 dx = abs(curr_mode->size.width - dim->width);
223 dy = abs(curr_mode->size.height - dim->height);
224 ct = dx + dy;
225 if (ct <= dt)
226 return (NULL);
227 }
228 return (save);
229 }
230