1996-10-04 11:27:52 +04:00
|
|
|
/* $NetBSD: grfabs.c,v 1.10 1996/10/04 07:27:53 leo Exp $ */
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Leo Weppelman.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Leo Weppelman.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* atari abstract graphics driver.
|
|
|
|
*/
|
|
|
|
#include <sys/param.h>
|
1995-09-24 00:29:16 +04:00
|
|
|
#include <sys/systm.h>
|
1995-03-26 11:12:03 +04:00
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
1995-08-20 22:17:09 +04:00
|
|
|
#include <machine/cpu.h>
|
1995-03-26 11:12:03 +04:00
|
|
|
#include <machine/iomap.h>
|
|
|
|
#include <machine/video.h>
|
|
|
|
#include <machine/mfp.h>
|
|
|
|
#include <atari/dev/grfabs_reg.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function decls
|
|
|
|
*/
|
1995-04-28 15:34:33 +04:00
|
|
|
static dmode_t *get_best_display_mode __P((dimen_t *, int, dmode_t *));
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
1995-08-20 22:17:09 +04:00
|
|
|
* List of available graphic modes
|
1995-03-26 11:12:03 +04:00
|
|
|
*/
|
1995-08-20 22:17:09 +04:00
|
|
|
static MODES modes;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
1995-08-20 22:17:09 +04:00
|
|
|
* Ugh.. Stuff needed to allocate console structures before the VM-system
|
|
|
|
* is running. There is no malloc() available at that time.
|
|
|
|
* Decision to use these: atari_realconfig == 0
|
1995-03-26 11:12:03 +04:00
|
|
|
*/
|
1995-08-20 22:17:09 +04:00
|
|
|
view_t gra_con_view;
|
|
|
|
colormap_t gra_con_cmap;
|
|
|
|
long gra_con_colors[MAX_CENTRIES];
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Default colors.....
|
1995-08-20 22:17:09 +04:00
|
|
|
* Currently the TT-low (256 colors) just uses 16 times the 16-color default.
|
1995-03-26 11:12:03 +04:00
|
|
|
* If you have a sensible 256 scale, feel free to add.....
|
|
|
|
* The first 2 colors in all maps are {black,white}, so ite (text) displays
|
|
|
|
* are initially readable. Also, this enables me to supply only 1 map. The
|
|
|
|
* 4 color mode uses the first four entries of the 16 color mode thus giving
|
|
|
|
* a gray scale display. (Maybe we can add an intensity bit to the ite...)
|
|
|
|
*/
|
1995-08-20 22:17:09 +04:00
|
|
|
u_long gra_def_color16[16] = {
|
|
|
|
0x00000000, /* black */
|
|
|
|
0x00ffffff, /* white */
|
1995-09-04 23:41:39 +04:00
|
|
|
0x000c0c0c, /* light gray */
|
|
|
|
0x00808008, /* gray */
|
|
|
|
0x0000000c, /* blue */
|
|
|
|
0x00000c00, /* green */
|
|
|
|
0x00000c0c, /* cyan */
|
1995-08-20 22:17:09 +04:00
|
|
|
0x00c00000, /* red */
|
1995-09-04 23:41:39 +04:00
|
|
|
0x00c0000c, /* magenta */
|
|
|
|
0x00c00c00, /* brown */
|
1995-08-20 22:17:09 +04:00
|
|
|
0x000000ff, /* light blue */
|
|
|
|
0x0000ff00, /* light green */
|
|
|
|
0x0000ffff, /* light cyan */
|
|
|
|
0x00ff0000, /* light red */
|
|
|
|
0x00ff00ff, /* light magenta */
|
|
|
|
0x00ffff00 /* light brown */
|
1995-03-26 11:12:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: called from ite console init routine.
|
|
|
|
* Initialize list of posible video modes.
|
|
|
|
*/
|
|
|
|
int
|
1996-09-16 10:49:03 +04:00
|
|
|
grfabs_probe(probe_fun)
|
|
|
|
grf_probe_t probe_fun;
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
1995-08-20 22:17:09 +04:00
|
|
|
static int inited = 0;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1996-09-16 10:49:03 +04:00
|
|
|
if (!inited) {
|
|
|
|
LIST_INIT(&modes);
|
|
|
|
inited = 1;
|
|
|
|
}
|
|
|
|
(*probe_fun)(&modes);
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1995-08-20 22:17:09 +04:00
|
|
|
return ((modes.lh_first == NULL) ? 0 : 1);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
view_t *
|
|
|
|
grf_alloc_view(d, dim, depth)
|
|
|
|
dmode_t *d;
|
|
|
|
dimen_t *dim;
|
|
|
|
u_char depth;
|
|
|
|
{
|
1995-08-20 22:17:09 +04:00
|
|
|
if (!d)
|
1995-04-28 15:34:33 +04:00
|
|
|
d = get_best_display_mode(dim, depth, NULL);
|
1995-08-20 22:17:09 +04:00
|
|
|
if (d)
|
|
|
|
return ((d->grfabs_funcs->alloc_view)(d, dim, depth));
|
1995-03-26 11:12:03 +04:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
1995-05-21 14:54:44 +04:00
|
|
|
dmode_t *
|
|
|
|
grf_get_best_mode(dim, depth)
|
|
|
|
dimen_t *dim;
|
|
|
|
u_char depth;
|
|
|
|
{
|
1995-08-20 22:17:09 +04:00
|
|
|
return (get_best_display_mode(dim, depth, NULL));
|
1995-05-21 14:54:44 +04:00
|
|
|
}
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
void grf_display_view(v)
|
|
|
|
view_t *v;
|
|
|
|
{
|
1995-08-20 22:17:09 +04:00
|
|
|
(v->mode->grfabs_funcs->display_view)(v);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void grf_remove_view(v)
|
|
|
|
view_t *v;
|
|
|
|
{
|
1995-08-20 22:17:09 +04:00
|
|
|
(v->mode->grfabs_funcs->remove_view)(v);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
1996-10-04 11:27:52 +04:00
|
|
|
void grf_save_view(v)
|
|
|
|
view_t *v;
|
|
|
|
{
|
|
|
|
(v->mode->grfabs_funcs->save_view)(v);
|
|
|
|
}
|
|
|
|
|
1995-03-26 11:12:03 +04:00
|
|
|
void grf_free_view(v)
|
|
|
|
view_t *v;
|
|
|
|
{
|
1995-08-20 22:17:09 +04:00
|
|
|
(v->mode->grfabs_funcs->free_view)(v);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
grf_get_colormap(v, cm)
|
|
|
|
view_t *v;
|
|
|
|
colormap_t *cm;
|
|
|
|
{
|
|
|
|
colormap_t *gcm;
|
|
|
|
int i, n;
|
1995-05-21 14:54:44 +04:00
|
|
|
u_long *sv_entry;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
|
|
|
gcm = v->colormap;
|
1995-03-28 10:35:40 +04:00
|
|
|
n = cm->size < gcm->size ? cm->size : gcm->size;
|
1995-05-21 14:54:44 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy struct from view but be carefull to keep 'entry'
|
|
|
|
*/
|
|
|
|
sv_entry = cm->entry;
|
|
|
|
*cm = *gcm;
|
|
|
|
cm->entry = sv_entry;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the colors
|
|
|
|
*/
|
|
|
|
bzero(cm->entry, cm->size * sizeof(long));
|
1995-08-20 22:17:09 +04:00
|
|
|
for (i = 0; i < n; i++)
|
1995-03-28 10:35:40 +04:00
|
|
|
cm->entry[i] = gcm->entry[i];
|
1995-08-20 22:17:09 +04:00
|
|
|
return (0);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
grf_use_colormap(v, cm)
|
|
|
|
view_t *v;
|
|
|
|
colormap_t *cm;
|
|
|
|
{
|
1995-08-20 22:17:09 +04:00
|
|
|
return (v->mode->grfabs_funcs->use_colormap)(v, cm);
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static dmode_t *
|
1995-04-28 15:34:33 +04:00
|
|
|
get_best_display_mode(dim, depth, curr_mode)
|
|
|
|
int depth;
|
|
|
|
dimen_t *dim;
|
|
|
|
dmode_t *curr_mode;
|
1995-03-26 11:12:03 +04:00
|
|
|
{
|
|
|
|
dmode_t *save;
|
|
|
|
dmode_t *dm;
|
1996-03-09 00:52:50 +03:00
|
|
|
long dx, dy, dd, ct;
|
|
|
|
long size_diff, depth_diff;
|
1995-03-26 11:12:03 +04:00
|
|
|
|
1996-03-09 00:52:50 +03:00
|
|
|
save = NULL;
|
|
|
|
size_diff = 0;
|
|
|
|
depth_diff = 0;
|
|
|
|
dm = modes.lh_first;
|
1995-08-20 22:17:09 +04:00
|
|
|
while (dm != NULL) {
|
1995-04-28 15:34:33 +04:00
|
|
|
dx = abs(dm->size.width - dim->width);
|
|
|
|
dy = abs(dm->size.height - dim->height);
|
1996-03-09 00:52:50 +03:00
|
|
|
dd = abs(dm->depth - depth);
|
1995-03-26 11:12:03 +04:00
|
|
|
ct = dx + dy;
|
|
|
|
|
1996-03-09 00:52:50 +03:00
|
|
|
if ((save != NULL) && (size_diff == 0)) {
|
|
|
|
if (dd > depth_diff) {
|
|
|
|
dm = dm->link.le_next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((save == NULL) || (ct <= size_diff)) {
|
|
|
|
save = dm;
|
|
|
|
size_diff = ct;
|
|
|
|
depth_diff = dd;
|
1995-03-26 11:12:03 +04:00
|
|
|
}
|
|
|
|
dm = dm->link.le_next;
|
|
|
|
}
|
1995-04-28 15:34:33 +04:00
|
|
|
/*
|
|
|
|
* Did we do better than the current mode?
|
|
|
|
*/
|
1995-08-20 22:17:09 +04:00
|
|
|
if ((save != NULL) && (curr_mode != NULL)) {
|
1995-04-28 15:34:33 +04:00
|
|
|
dx = abs(curr_mode->size.width - dim->width);
|
|
|
|
dy = abs(curr_mode->size.height - dim->height);
|
1996-03-09 00:52:50 +03:00
|
|
|
dd = abs(curr_mode->depth - depth);
|
1995-04-28 15:34:33 +04:00
|
|
|
ct = dx + dy;
|
1996-03-09 00:52:50 +03:00
|
|
|
if ((ct <= size_diff) && (dd <= depth_diff))
|
1995-08-20 22:17:09 +04:00
|
|
|
return (NULL);
|
1995-04-28 15:34:33 +04:00
|
|
|
}
|
1995-03-26 11:12:03 +04:00
|
|
|
return (save);
|
|
|
|
}
|