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