Home | History | Annotate | Line # | Download | only in dev
grfabs.c revision 1.6
      1 /*	$NetBSD: grfabs.c,v 1.6 1995/09/04 19:41:39 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/queue.h>
     38 #include <sys/malloc.h>
     39 
     40 #include <machine/cpu.h>
     41 #include <machine/iomap.h>
     42 #include <machine/video.h>
     43 #include <machine/mfp.h>
     44 #include <atari/dev/grfabs_reg.h>
     45 
     46 /*
     47  * Function decls
     48  */
     49 static dmode_t    *get_best_display_mode __P((dimen_t *, int, dmode_t *));
     50 
     51 /*
     52  * List of available graphic modes
     53  */
     54 static MODES modes;
     55 
     56 /*
     57  * Ugh.. Stuff needed to allocate console structures before the VM-system
     58  * is running. There is no malloc() available at that time.
     59  * Decision to use these: atari_realconfig == 0
     60  */
     61 view_t		gra_con_view;
     62 colormap_t	gra_con_cmap;
     63 long		gra_con_colors[MAX_CENTRIES];
     64 
     65 /*
     66  * Default colors.....
     67  * Currently the TT-low (256 colors) just uses 16 times the 16-color default.
     68  * If you have a sensible 256 scale, feel free to add.....
     69  * The first 2 colors in all maps are {black,white}, so ite (text) displays
     70  * are initially readable. Also, this enables me to supply only 1 map. The
     71  * 4 color mode uses the first four entries of the 16 color mode thus giving
     72  * a gray scale display. (Maybe we can add an intensity bit to the ite...)
     73  */
     74 u_long gra_def_color16[16] = {
     75 	0x00000000,	/* black		*/
     76 	0x00ffffff,	/* white		*/
     77 	0x000c0c0c,	/* light gray		*/
     78 	0x00808008,	/* gray			*/
     79 	0x0000000c,	/* blue			*/
     80 	0x00000c00,	/* green		*/
     81 	0x00000c0c,	/* cyan			*/
     82 	0x00c00000,	/* red			*/
     83 	0x00c0000c,	/* magenta		*/
     84 	0x00c00c00,	/* brown		*/
     85 	0x000000ff,	/* light blue		*/
     86 	0x0000ff00,	/* light green		*/
     87 	0x0000ffff,	/* light cyan		*/
     88 	0x00ff0000,	/* light red		*/
     89 	0x00ff00ff,	/* light magenta	*/
     90 	0x00ffff00	/* light brown		*/
     91 };
     92 
     93 /*
     94  * XXX: called from ite console init routine.
     95  * Initialize list of posible video modes.
     96  */
     97 int
     98 grfabs_probe()
     99 {
    100 	static int	inited = 0;
    101 
    102 	if (inited)
    103 		return (1);	/* Has to be done only once */
    104 	inited++;
    105 
    106 	LIST_INIT(&modes);
    107 
    108 #ifdef FALCON_VIDEO
    109 	if (machineid & ATARI_FALCON)
    110 		falcon_probe_video(&modes);
    111 #endif /* FALCON_VIDEO */
    112 #ifdef TT_VIDEO
    113 	if (machineid & ATARI_TT)
    114 		tt_probe_video(&modes);
    115 #endif /* TT_VIDEO */
    116 	return ((modes.lh_first == NULL) ? 0 : 1);
    117 }
    118 
    119 view_t *
    120 grf_alloc_view(d, dim, depth)
    121 dmode_t	*d;
    122 dimen_t	*dim;
    123 u_char	depth;
    124 {
    125 	if (!d)
    126 		d = get_best_display_mode(dim, depth, NULL);
    127 	if (d)
    128 		return ((d->grfabs_funcs->alloc_view)(d, dim, depth));
    129 	return(NULL);
    130 }
    131 
    132 dmode_t	*
    133 grf_get_best_mode(dim, depth)
    134 dimen_t	*dim;
    135 u_char	depth;
    136 {
    137 	return (get_best_display_mode(dim, depth, NULL));
    138 }
    139 
    140 void grf_display_view(v)
    141 view_t *v;
    142 {
    143 	(v->mode->grfabs_funcs->display_view)(v);
    144 }
    145 
    146 void grf_remove_view(v)
    147 view_t *v;
    148 {
    149 	(v->mode->grfabs_funcs->remove_view)(v);
    150 }
    151 
    152 void grf_free_view(v)
    153 view_t *v;
    154 {
    155 	(v->mode->grfabs_funcs->free_view)(v);
    156 }
    157 
    158 int
    159 grf_get_colormap(v, cm)
    160 view_t		*v;
    161 colormap_t	*cm;
    162 {
    163 	colormap_t	*gcm;
    164 	int		i, n;
    165 	u_long		*sv_entry;
    166 
    167 	gcm = v->colormap;
    168 	n   = cm->size < gcm->size ? cm->size : gcm->size;
    169 
    170 	/*
    171 	 * Copy struct from view but be carefull to keep 'entry'
    172 	 */
    173 	sv_entry = cm->entry;
    174 	*cm = *gcm;
    175 	cm->entry = sv_entry;
    176 
    177 	/*
    178 	 * Copy the colors
    179 	 */
    180 	bzero(cm->entry, cm->size * sizeof(long));
    181 	for (i = 0; i < n; i++)
    182 		cm->entry[i] = gcm->entry[i];
    183 	return (0);
    184 }
    185 
    186 int
    187 grf_use_colormap(v, cm)
    188 view_t		*v;
    189 colormap_t	*cm;
    190 {
    191 	return (v->mode->grfabs_funcs->use_colormap)(v, cm);
    192 }
    193 
    194 static dmode_t *
    195 get_best_display_mode(dim, depth, curr_mode)
    196 int	depth;
    197 dimen_t	*dim;
    198 dmode_t	*curr_mode;
    199 {
    200 	dmode_t		*save;
    201 	dmode_t		*dm;
    202 	long   		dt, dx, dy, ct;
    203 
    204 	save = NULL;
    205 	dm = modes.lh_first;
    206 	while (dm != NULL) {
    207 		dx = abs(dm->size.width  - dim->width);
    208 		dy = abs(dm->size.height - dim->height);
    209 		ct = dx + dy;
    210 
    211 		if (ct < dt || save == NULL) {
    212 			save = dm;
    213 			dt = ct;
    214 		}
    215 		dm = dm->link.le_next;
    216 	}
    217 	/*
    218 	 * Did we do better than the current mode?
    219 	 */
    220 	if ((save != NULL) && (curr_mode != NULL)) {
    221 		dx = abs(curr_mode->size.width  - dim->width);
    222 		dy = abs(curr_mode->size.height - dim->height);
    223 		ct = dx + dy;
    224 		if (ct <= dt)
    225 			return (NULL);
    226 	}
    227 	return (save);
    228 }
    229