xref: /netbsd-src/sys/arch/amiga/dev/grfabs.c (revision 1ea4df81a8a1aaaafb447d669aca48016dd9041f)
1*1ea4df81Saymeric /*	$NetBSD: grfabs.c,v 1.7 2002/01/28 09:56:57 aymeric Exp $ */
2ec77f0b3Scgd 
37bb75ba6Schopps /*
47bb75ba6Schopps  * Copyright (c) 1994 Christian E. Hopps
57bb75ba6Schopps  * All rights reserved.
67bb75ba6Schopps  *
77bb75ba6Schopps  * Redistribution and use in source and binary forms, with or without
87bb75ba6Schopps  * modification, are permitted provided that the following conditions
97bb75ba6Schopps  * are met:
107bb75ba6Schopps  * 1. Redistributions of source code must retain the above copyright
117bb75ba6Schopps  *    notice, this list of conditions and the following disclaimer.
127bb75ba6Schopps  * 2. Redistributions in binary form must reproduce the above copyright
137bb75ba6Schopps  *    notice, this list of conditions and the following disclaimer in the
147bb75ba6Schopps  *    documentation and/or other materials provided with the distribution.
157bb75ba6Schopps  * 3. All advertising materials mentioning features or use of this software
167bb75ba6Schopps  *    must display the following acknowledgement:
177bb75ba6Schopps  *      This product includes software developed by Christian E. Hopps.
187bb75ba6Schopps  * 4. The name of the author may not be used to endorse or promote products
197bb75ba6Schopps  *    derived from this software without specific prior written permission
207bb75ba6Schopps  *
217bb75ba6Schopps  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
227bb75ba6Schopps  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
237bb75ba6Schopps  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
247bb75ba6Schopps  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
257bb75ba6Schopps  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
267bb75ba6Schopps  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
277bb75ba6Schopps  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
287bb75ba6Schopps  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
297bb75ba6Schopps  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
307bb75ba6Schopps  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31ec77f0b3Scgd  */
32ec77f0b3Scgd 
33*1ea4df81Saymeric #include <sys/cdefs.h>
34*1ea4df81Saymeric __KERNEL_RCSID(0, "$NetBSD: grfabs.c,v 1.7 2002/01/28 09:56:57 aymeric Exp $");
35*1ea4df81Saymeric 
36ec77f0b3Scgd /*
377bb75ba6Schopps  *  amiga abstract graphics driver.
387bb75ba6Schopps  */
39e9dc4428Schopps #include <sys/param.h>
40e9dc4428Schopps #include <sys/queue.h>
417bb75ba6Schopps 
42e9dc4428Schopps #include <amiga/amiga/color.h>
437bb75ba6Schopps #include <amiga/amiga/cc.h>
447bb75ba6Schopps #include <amiga/dev/grfabs_reg.h>
457bb75ba6Schopps 
467bb75ba6Schopps /*
477bb75ba6Schopps  * General and init.
487bb75ba6Schopps  */
497bb75ba6Schopps 
507bb75ba6Schopps /* add your monitor here. */
517bb75ba6Schopps monitor_t *cc_init_monitor (void);
527bb75ba6Schopps 
537bb75ba6Schopps /* and here. */
547bb75ba6Schopps monitor_t *(*init_monitor[])(void) = {
557bb75ba6Schopps     cc_init_monitor,
567bb75ba6Schopps     NULL
577bb75ba6Schopps };
587bb75ba6Schopps 
59e9dc4428Schopps struct monitor_list instance_monitors, *monitors;
607bb75ba6Schopps 
617bb75ba6Schopps struct vbl_node grf_vbl_node;
627bb75ba6Schopps 
637bb75ba6Schopps #define ABS(type, val) \
647bb75ba6Schopps     (type) (((int)(val) < 0) ? -(val) : (val))
657bb75ba6Schopps 
669382c873Saymeric void grf_vbl_function(void *data);
679382c873Saymeric dmode_t *get_best_display_mode(u_long, u_long, u_char);
68974e9f6eSveego 
69974e9f6eSveego 
707bb75ba6Schopps void
grf_vbl_function(void * data)719382c873Saymeric grf_vbl_function(void *data)
727bb75ba6Schopps {
73e9dc4428Schopps 	monitor_t *m;
747bb75ba6Schopps 
75e9dc4428Schopps 	if (monitors == NULL)
76e9dc4428Schopps 		return;
77e9dc4428Schopps 
78e9dc4428Schopps 	for (m = monitors->lh_first; m != NULL; m = m->link.le_next) {
797bb75ba6Schopps 		if (m->vbl_handler)
807bb75ba6Schopps 			m->vbl_handler(m);
817bb75ba6Schopps 	}
827bb75ba6Schopps }
837bb75ba6Schopps 
847bb75ba6Schopps /*
857bb75ba6Schopps  * XXX: called from ite console init routine.
867bb75ba6Schopps  * Does just what configure will do later but without printing anything.
877bb75ba6Schopps  */
887bb75ba6Schopps 
897bb75ba6Schopps int
grfcc_probe(void)909382c873Saymeric grfcc_probe(void)
917bb75ba6Schopps {
927bb75ba6Schopps 	int i = 0;
937bb75ba6Schopps 
947bb75ba6Schopps 	grf_vbl_node.function = grf_vbl_function;
957bb75ba6Schopps 
967bb75ba6Schopps 	if (NULL == monitors) {
97e9dc4428Schopps 		LIST_INIT(&instance_monitors);
987bb75ba6Schopps 		monitors = &instance_monitors;
997bb75ba6Schopps 
1007bb75ba6Schopps 		while (init_monitor[i]) {
1017bb75ba6Schopps 			init_monitor[i] ();
1027bb75ba6Schopps 			i++;
1037bb75ba6Schopps 		}
1047bb75ba6Schopps 		if (i) {
1057bb75ba6Schopps 			add_vbl_function(&grf_vbl_node, 1, 0);
1067bb75ba6Schopps 			return(1);
1077bb75ba6Schopps 		}
1087bb75ba6Schopps 		return(0);
1097bb75ba6Schopps 	}
1107bb75ba6Schopps 	return(1);
1117bb75ba6Schopps }
1127bb75ba6Schopps 
1137bb75ba6Schopps dmode_t *
get_best_display_mode(u_long width,u_long height,u_char depth)1149382c873Saymeric get_best_display_mode(u_long width, u_long height, u_char depth)
1157bb75ba6Schopps {
116e9dc4428Schopps 	monitor_t *m;
117e9dc4428Schopps 	dmode_t *d, *save;
1187bb75ba6Schopps 	dimen_t dim;
119974e9f6eSveego 	long dx, dy, ct, dt = 0;
1207bb75ba6Schopps 
121e9dc4428Schopps 	save = NULL;
122e9dc4428Schopps 	for (m = monitors->lh_first; m != NULL; m = m->link.le_next) {
1237bb75ba6Schopps 		dim.width = width;
1247bb75ba6Schopps 		dim.height = height;
1257bb75ba6Schopps 		d = m->get_best_mode(&dim, depth);
1267bb75ba6Schopps 		if (d) {
1277bb75ba6Schopps 			dx = ABS(long, (d->nominal_size.width - width));
1287bb75ba6Schopps 			dy = ABS(long, (d->nominal_size.height - height));
1297bb75ba6Schopps 			ct = dx + dy;
1307bb75ba6Schopps 
1317bb75ba6Schopps 			if (ct < dt || save == NULL) {
1327bb75ba6Schopps 				save = d;
1337bb75ba6Schopps 				dt = ct;
1347bb75ba6Schopps 			}
1357bb75ba6Schopps 		}
1367bb75ba6Schopps 	}
1377bb75ba6Schopps 	return(save);
1387bb75ba6Schopps }
1397bb75ba6Schopps 
1407bb75ba6Schopps 
1417bb75ba6Schopps /*
1427bb75ba6Schopps  * Monitor stuff.
1437bb75ba6Schopps  */
1447bb75ba6Schopps 
1457bb75ba6Schopps dmode_t *
grf_get_next_mode(monitor_t * m,dmode_t * d)1469382c873Saymeric grf_get_next_mode(monitor_t *m, dmode_t *d)
1477bb75ba6Schopps {
1487bb75ba6Schopps 	return(m->get_next_mode(d));
1497bb75ba6Schopps }
1507bb75ba6Schopps 
1517bb75ba6Schopps dmode_t *
grf_get_current_mode(monitor_t * m)1529382c873Saymeric grf_get_current_mode(monitor_t *m)
1537bb75ba6Schopps {
1547bb75ba6Schopps 	return(m->get_current_mode());
1557bb75ba6Schopps }
1567bb75ba6Schopps 
1577bb75ba6Schopps dmode_t *
grf_get_best_mode(monitor_t * m,dimen_t * size,u_char depth)1589382c873Saymeric grf_get_best_mode(monitor_t *m, dimen_t *size, u_char depth)
1597bb75ba6Schopps {
1607bb75ba6Schopps 	return(m->get_best_mode(size, depth));
1617bb75ba6Schopps }
1627bb75ba6Schopps 
1637bb75ba6Schopps bmap_t *
grf_alloc_bitmap(monitor_t * m,u_short w,u_short h,u_short d,u_short f)1649382c873Saymeric grf_alloc_bitmap(monitor_t *m, u_short w, u_short h, u_short d, u_short f)
1657bb75ba6Schopps {
1667bb75ba6Schopps 	return(m->alloc_bitmap(w, h, d, f));
1677bb75ba6Schopps }
1687bb75ba6Schopps 
1697bb75ba6Schopps void
grf_free_bitmap(monitor_t * m,bmap_t * bm)1709382c873Saymeric grf_free_bitmap(monitor_t *m, bmap_t *bm)
1717bb75ba6Schopps {
1727bb75ba6Schopps 	m->free_bitmap(bm);
1737bb75ba6Schopps }
1747bb75ba6Schopps 
1757bb75ba6Schopps /*
1767bb75ba6Schopps  * Mode stuff.
1777bb75ba6Schopps  */
1787bb75ba6Schopps 
1797bb75ba6Schopps view_t *
grf_get_current_view(dmode_t * d)1809382c873Saymeric grf_get_current_view(dmode_t *d)
1817bb75ba6Schopps {
1827bb75ba6Schopps 	return(d->get_current_view(d));
1837bb75ba6Schopps }
1847bb75ba6Schopps 
1857bb75ba6Schopps monitor_t *
grf_get_monitor(dmode_t * d)1869382c873Saymeric grf_get_monitor(dmode_t *d)
1877bb75ba6Schopps {
1887bb75ba6Schopps 	return(d->get_monitor(d));
1897bb75ba6Schopps }
1907bb75ba6Schopps 
1917bb75ba6Schopps /*
1927bb75ba6Schopps  * View stuff.
1937bb75ba6Schopps  */
1947bb75ba6Schopps 
1957bb75ba6Schopps void
grf_display_view(view_t * v)1969382c873Saymeric grf_display_view(view_t *v)
1977bb75ba6Schopps {
1987bb75ba6Schopps 	v->display_view(v);
1997bb75ba6Schopps }
2007bb75ba6Schopps 
2017bb75ba6Schopps view_t *
grf_alloc_view(dmode_t * d,dimen_t * dim,u_char depth)2029382c873Saymeric grf_alloc_view(dmode_t *d, dimen_t *dim, u_char depth)
2037bb75ba6Schopps {
2047bb75ba6Schopps 	if (!d)
2057bb75ba6Schopps 		d = get_best_display_mode(dim->width, dim->height, depth);
2067bb75ba6Schopps 	if (d)
2077bb75ba6Schopps 		return(d->alloc_view(d, dim, depth));
2087bb75ba6Schopps 	return(NULL);
2097bb75ba6Schopps }
2107bb75ba6Schopps 
2117bb75ba6Schopps void
grf_remove_view(view_t * v)2129382c873Saymeric grf_remove_view(view_t *v)
2137bb75ba6Schopps {
2147bb75ba6Schopps 	v->remove_view(v);
2157bb75ba6Schopps }
2167bb75ba6Schopps 
2177bb75ba6Schopps void
grf_free_view(view_t * v)2189382c873Saymeric grf_free_view(view_t *v)
2197bb75ba6Schopps {
2207bb75ba6Schopps 	v->free_view(v);
2217bb75ba6Schopps }
2227bb75ba6Schopps 
2237bb75ba6Schopps dmode_t *
grf_get_display_mode(view_t * v)2249382c873Saymeric grf_get_display_mode(view_t *v)
2257bb75ba6Schopps {
2267bb75ba6Schopps 	return(v->get_display_mode(v));
2277bb75ba6Schopps }
2287bb75ba6Schopps 
2297bb75ba6Schopps int
grf_get_colormap(view_t * v,colormap_t * cm)2309382c873Saymeric grf_get_colormap(view_t *v, colormap_t *cm)
2317bb75ba6Schopps {
2327bb75ba6Schopps 	return(v->get_colormap(v, cm));
2337bb75ba6Schopps }
2347bb75ba6Schopps 
2357bb75ba6Schopps int
grf_use_colormap(view_t * v,colormap_t * cm)2369382c873Saymeric grf_use_colormap(view_t *v, colormap_t *cm)
2377bb75ba6Schopps {
2387bb75ba6Schopps 	return(v->use_colormap(v, cm));
2397bb75ba6Schopps }
240