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