No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / atari / dev / grfabs.c
blobf655c638427ae286d730e2fe3bcee03f7d307dd6
1 /* $NetBSD: grfabs.c,v 1.16 2009/03/18 16:00:10 cegger Exp $ */
3 /*
4 * Copyright (c) 1995 Leo Weppelman.
5 * All rights reserved.
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.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * atari abstract graphics driver.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: grfabs.c,v 1.16 2009/03/18 16:00:10 cegger Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/queue.h>
38 #include <sys/malloc.h>
40 #include <machine/cpu.h>
41 #include <machine/iomap.h>
42 #include <machine/video.h>
43 #include <machine/mfp.h>
44 #include <atari/dev/grfabs_reg.h>
47 * Function decls
49 static dmode_t *get_best_display_mode(dimen_t *, int, dmode_t *);
52 * List of available graphic modes
54 static MODES modes;
57 * Ugh.. Stuff needed to allocate console structures before the VM-system
58 * is running. There is no malloc() available at that time.
59 * Decision to use these: atari_realconfig == 0
61 view_t gra_con_view;
62 colormap_t gra_con_cmap;
63 long gra_con_colors[MAX_CENTRIES];
66 * Default colors.....
67 * Currently the TT-low (256 colors) just uses 16 times the 16-color default.
68 * If you have a sensible 256 scale, feel free to add.....
69 * The first 2 colors in all maps are {black,white}, so ite (text) displays
70 * are initially readable. Also, this enables me to supply only 1 map. The
71 * 4 color mode uses the first four entries of the 16 color mode thus giving
72 * a gray scale display. (Maybe we can add an intensity bit to the ite...)
74 u_long gra_def_color16[16] = {
75 0x00000000, /* black */
76 0x00ffffff, /* white */
77 0x000c0c0c, /* light gray */
78 0x00808008, /* gray */
79 0x0000000c, /* blue */
80 0x00000c00, /* green */
81 0x00000c0c, /* cyan */
82 0x00c00000, /* red */
83 0x00c0000c, /* magenta */
84 0x00c00c00, /* brown */
85 0x000000ff, /* light blue */
86 0x0000ff00, /* light green */
87 0x0000ffff, /* light cyan */
88 0x00ff0000, /* light red */
89 0x00ff00ff, /* light magenta */
90 0x00ffff00 /* light brown */
94 * XXX: called from ite console init routine.
95 * Initialize list of possible video modes.
97 int
98 grfabs_probe(grf_probe_t probe_fun)
100 static int inited = 0;
102 if (!inited) {
103 LIST_INIT(&modes);
104 inited = 1;
106 (*probe_fun)(&modes);
108 return ((modes.lh_first == NULL) ? 0 : 1);
111 view_t *
112 grf_alloc_view(dmode_t *d, dimen_t *dim, u_char depth)
114 if (!d)
115 d = get_best_display_mode(dim, depth, NULL);
116 if (d)
117 return ((d->grfabs_funcs->alloc_view)(d, dim, depth));
118 return(NULL);
121 dmode_t *
122 grf_get_best_mode(dimen_t *dim, u_char depth)
124 return (get_best_display_mode(dim, depth, NULL));
127 void grf_display_view(v)
128 view_t *v;
130 (v->mode->grfabs_funcs->display_view)(v);
133 void grf_remove_view(v)
134 view_t *v;
136 (v->mode->grfabs_funcs->remove_view)(v);
139 void grf_save_view(v)
140 view_t *v;
142 (v->mode->grfabs_funcs->save_view)(v);
145 void grf_free_view(v)
146 view_t *v;
148 (v->mode->grfabs_funcs->free_view)(v);
152 grf_get_colormap(view_t *v, colormap_t *cm)
154 colormap_t *gcm;
155 int i, n;
156 u_long *sv_entry;
158 gcm = v->colormap;
159 n = cm->size < gcm->size ? cm->size : gcm->size;
162 * Copy struct from view but be carefull to keep 'entry'
164 sv_entry = cm->entry;
165 *cm = *gcm;
166 cm->entry = sv_entry;
169 * Copy the colors
171 memset(cm->entry, 0, cm->size * sizeof(long));
172 for (i = 0; i < n; i++)
173 cm->entry[i] = gcm->entry[i];
174 return (0);
178 grf_use_colormap(view_t *v, colormap_t *cm)
180 return (v->mode->grfabs_funcs->use_colormap)(v, cm);
183 static dmode_t *
184 get_best_display_mode(dimen_t *dim, int depth, dmode_t *curr_mode)
186 dmode_t *save;
187 dmode_t *dm;
188 long dx, dy, dd, ct;
189 long size_diff, depth_diff;
191 save = NULL;
192 size_diff = 0;
193 depth_diff = 0;
194 dm = modes.lh_first;
195 while (dm != NULL) {
196 dx = abs(dm->size.width - dim->width);
197 dy = abs(dm->size.height - dim->height);
198 dd = abs(dm->depth - depth);
199 ct = dx + dy;
201 if ((save != NULL) && (size_diff == 0)) {
202 if (dd > depth_diff) {
203 dm = dm->link.le_next;
204 continue;
207 if ((save == NULL) || (ct <= size_diff)) {
208 save = dm;
209 size_diff = ct;
210 depth_diff = dd;
212 dm = dm->link.le_next;
215 * Did we do better than the current mode?
217 if ((save != NULL) && (curr_mode != NULL)) {
218 dx = abs(curr_mode->size.width - dim->width);
219 dy = abs(curr_mode->size.height - dim->height);
220 dd = abs(curr_mode->depth - depth);
221 ct = dx + dy;
222 if ((ct <= size_diff) && (dd <= depth_diff))
223 return (NULL);
225 return (save);