grfabs.c revision 1.4 1 1.4 cgd /* $NetBSD: grfabs.c,v 1.4 1994/10/26 02:03:21 cgd Exp $ */
2 1.4 cgd
3 1.1 chopps /*
4 1.1 chopps * Copyright (c) 1994 Christian E. Hopps
5 1.1 chopps * All rights reserved.
6 1.1 chopps *
7 1.1 chopps * Redistribution and use in source and binary forms, with or without
8 1.1 chopps * modification, are permitted provided that the following conditions
9 1.1 chopps * are met:
10 1.1 chopps * 1. Redistributions of source code must retain the above copyright
11 1.1 chopps * notice, this list of conditions and the following disclaimer.
12 1.1 chopps * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 chopps * notice, this list of conditions and the following disclaimer in the
14 1.1 chopps * documentation and/or other materials provided with the distribution.
15 1.1 chopps * 3. All advertising materials mentioning features or use of this software
16 1.1 chopps * must display the following acknowledgement:
17 1.1 chopps * This product includes software developed by Christian E. Hopps.
18 1.1 chopps * 4. The name of the author may not be used to endorse or promote products
19 1.1 chopps * derived from this software without specific prior written permission
20 1.1 chopps *
21 1.1 chopps * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 chopps * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 chopps * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 chopps * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 chopps * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 chopps * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 chopps * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 chopps * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 chopps * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 chopps * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.4 cgd */
32 1.4 cgd
33 1.4 cgd /*
34 1.1 chopps * amiga abstract graphics driver.
35 1.1 chopps */
36 1.2 chopps #include <sys/param.h>
37 1.2 chopps #include <sys/queue.h>
38 1.1 chopps
39 1.2 chopps #include <amiga/amiga/color.h>
40 1.1 chopps #include <amiga/amiga/cc.h>
41 1.1 chopps #include <amiga/dev/grfabs_reg.h>
42 1.1 chopps
43 1.1 chopps /*
44 1.1 chopps * General and init.
45 1.1 chopps */
46 1.1 chopps
47 1.1 chopps /* add your monitor here. */
48 1.1 chopps monitor_t *cc_init_monitor (void);
49 1.1 chopps
50 1.1 chopps /* and here. */
51 1.1 chopps monitor_t *(*init_monitor[])(void) = {
52 1.1 chopps cc_init_monitor,
53 1.1 chopps NULL
54 1.1 chopps };
55 1.1 chopps
56 1.2 chopps struct monitor_list instance_monitors, *monitors;
57 1.1 chopps
58 1.1 chopps struct vbl_node grf_vbl_node;
59 1.1 chopps
60 1.1 chopps #define ABS(type, val) \
61 1.2 chopps (type) (((int)(val) < 0) ? -(val) : (val))
62 1.1 chopps
63 1.1 chopps void
64 1.2 chopps grf_vbl_function(data)
65 1.1 chopps void *data;
66 1.1 chopps {
67 1.2 chopps monitor_t *m;
68 1.2 chopps
69 1.2 chopps if (monitors == NULL)
70 1.2 chopps return;
71 1.1 chopps
72 1.2 chopps for (m = monitors->lh_first; m != NULL; m = m->link.le_next) {
73 1.1 chopps if (m->vbl_handler)
74 1.2 chopps m->vbl_handler(m);
75 1.1 chopps }
76 1.1 chopps }
77 1.1 chopps
78 1.1 chopps /*
79 1.1 chopps * XXX: called from ite console init routine.
80 1.1 chopps * Does just what configure will do later but without printing anything.
81 1.1 chopps */
82 1.1 chopps
83 1.1 chopps int
84 1.2 chopps grfcc_probe()
85 1.1 chopps {
86 1.1 chopps int i = 0;
87 1.1 chopps
88 1.1 chopps grf_vbl_node.function = grf_vbl_function;
89 1.1 chopps
90 1.1 chopps if (NULL == monitors) {
91 1.2 chopps LIST_INIT(&instance_monitors);
92 1.1 chopps monitors = &instance_monitors;
93 1.1 chopps
94 1.1 chopps while (init_monitor[i]) {
95 1.1 chopps init_monitor[i] ();
96 1.1 chopps i++;
97 1.1 chopps }
98 1.1 chopps if (i) {
99 1.2 chopps add_vbl_function(&grf_vbl_node, 1, 0);
100 1.2 chopps return(1);
101 1.1 chopps }
102 1.2 chopps return(0);
103 1.1 chopps }
104 1.2 chopps return(1);
105 1.1 chopps }
106 1.1 chopps
107 1.1 chopps dmode_t *
108 1.2 chopps get_best_display_mode(width, height, depth)
109 1.1 chopps u_long width, height;
110 1.1 chopps u_char depth;
111 1.1 chopps {
112 1.2 chopps monitor_t *m;
113 1.2 chopps dmode_t *d, *save;
114 1.2 chopps dimen_t dim;
115 1.2 chopps long dx, dy, ct, dt;
116 1.2 chopps
117 1.2 chopps save = NULL;
118 1.2 chopps for (m = monitors->lh_first; m != NULL; m = m->link.le_next) {
119 1.1 chopps dim.width = width;
120 1.1 chopps dim.height = height;
121 1.2 chopps d = m->get_best_mode(&dim, depth);
122 1.1 chopps if (d) {
123 1.2 chopps dx = ABS(long, (d->nominal_size.width - width));
124 1.2 chopps dy = ABS(long, (d->nominal_size.height - height));
125 1.1 chopps ct = dx + dy;
126 1.1 chopps
127 1.1 chopps if (ct < dt || save == NULL) {
128 1.1 chopps save = d;
129 1.1 chopps dt = ct;
130 1.1 chopps }
131 1.1 chopps }
132 1.1 chopps }
133 1.2 chopps return(save);
134 1.1 chopps }
135 1.1 chopps
136 1.1 chopps
137 1.1 chopps /*
138 1.1 chopps * Monitor stuff.
139 1.1 chopps */
140 1.1 chopps
141 1.1 chopps dmode_t *
142 1.2 chopps grf_get_next_mode(m, d)
143 1.1 chopps monitor_t *m;
144 1.1 chopps dmode_t *d;
145 1.1 chopps {
146 1.2 chopps return(m->get_next_mode(d));
147 1.1 chopps }
148 1.1 chopps
149 1.1 chopps dmode_t *
150 1.2 chopps grf_get_current_mode(m)
151 1.1 chopps monitor_t *m;
152 1.1 chopps {
153 1.2 chopps return(m->get_current_mode());
154 1.1 chopps }
155 1.1 chopps
156 1.1 chopps dmode_t *
157 1.2 chopps grf_get_best_mode(m, size, depth)
158 1.1 chopps monitor_t *m;
159 1.1 chopps dimen_t *size;
160 1.1 chopps u_char depth;
161 1.1 chopps {
162 1.2 chopps return(m->get_best_mode(size, depth));
163 1.1 chopps }
164 1.1 chopps
165 1.1 chopps bmap_t *
166 1.2 chopps grf_alloc_bitmap(m, w, h, d, f)
167 1.1 chopps monitor_t *m;
168 1.1 chopps u_short w, h, d, f;
169 1.1 chopps {
170 1.2 chopps return(m->alloc_bitmap(w, h, d, f));
171 1.1 chopps }
172 1.1 chopps
173 1.1 chopps void
174 1.2 chopps grf_free_bitmap(m, bm)
175 1.1 chopps monitor_t *m;
176 1.1 chopps bmap_t *bm;
177 1.1 chopps {
178 1.2 chopps m->free_bitmap(bm);
179 1.1 chopps }
180 1.1 chopps
181 1.1 chopps /*
182 1.1 chopps * Mode stuff.
183 1.1 chopps */
184 1.1 chopps
185 1.1 chopps view_t *
186 1.2 chopps grf_get_current_view(d)
187 1.1 chopps dmode_t *d;
188 1.1 chopps {
189 1.2 chopps return(d->get_current_view(d));
190 1.1 chopps }
191 1.1 chopps
192 1.1 chopps monitor_t *
193 1.2 chopps grf_get_monitor(d)
194 1.1 chopps dmode_t *d;
195 1.1 chopps {
196 1.2 chopps return(d->get_monitor(d));
197 1.1 chopps }
198 1.1 chopps
199 1.1 chopps /*
200 1.1 chopps * View stuff.
201 1.1 chopps */
202 1.1 chopps
203 1.1 chopps void
204 1.2 chopps grf_display_view(v)
205 1.1 chopps view_t *v;
206 1.1 chopps {
207 1.2 chopps v->display_view(v);
208 1.1 chopps }
209 1.1 chopps
210 1.1 chopps view_t *
211 1.2 chopps grf_alloc_view(d, dim, depth)
212 1.1 chopps dmode_t *d;
213 1.1 chopps dimen_t *dim;
214 1.1 chopps u_char depth;
215 1.1 chopps {
216 1.1 chopps if (!d)
217 1.2 chopps d = get_best_display_mode(dim->width, dim->height, depth);
218 1.1 chopps if (d)
219 1.2 chopps return(d->alloc_view(d, dim, depth));
220 1.2 chopps return(NULL);
221 1.1 chopps }
222 1.1 chopps
223 1.1 chopps void
224 1.2 chopps grf_remove_view(v)
225 1.1 chopps view_t *v;
226 1.1 chopps {
227 1.2 chopps v->remove_view(v);
228 1.1 chopps }
229 1.1 chopps
230 1.1 chopps void
231 1.2 chopps grf_free_view(v)
232 1.1 chopps view_t *v;
233 1.1 chopps {
234 1.2 chopps v->free_view(v);
235 1.1 chopps }
236 1.1 chopps
237 1.1 chopps dmode_t *
238 1.2 chopps grf_get_display_mode(v)
239 1.1 chopps view_t *v;
240 1.1 chopps {
241 1.2 chopps return(v->get_display_mode(v));
242 1.1 chopps }
243 1.1 chopps
244 1.1 chopps int
245 1.2 chopps grf_get_colormap(v, cm)
246 1.1 chopps view_t *v;
247 1.1 chopps colormap_t *cm;
248 1.1 chopps {
249 1.2 chopps return(v->get_colormap(v, cm));
250 1.1 chopps }
251 1.1 chopps
252 1.1 chopps int
253 1.2 chopps grf_use_colormap(v, cm)
254 1.1 chopps view_t *v;
255 1.1 chopps colormap_t *cm;
256 1.1 chopps {
257 1.2 chopps return(v->use_colormap(v, cm));
258 1.1 chopps }
259