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