1996-04-22 01:10:48 +04:00
|
|
|
/* $NetBSD: grfabs.c,v 1.5 1996/04/21 21:11:25 veego Exp $ */
|
1994-10-26 05:01:24 +03:00
|
|
|
|
1994-02-14 00:10:20 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1994 Christian E. Hopps
|
|
|
|
* 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 Christian E. Hopps.
|
|
|
|
* 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.
|
1994-10-26 05:01:24 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1994-02-14 00:10:20 +03:00
|
|
|
* amiga abstract graphics driver.
|
|
|
|
*/
|
1994-03-27 10:23:26 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/queue.h>
|
1994-02-14 00:10:20 +03:00
|
|
|
|
1994-03-27 10:23:26 +04:00
|
|
|
#include <amiga/amiga/color.h>
|
1994-02-14 00:10:20 +03:00
|
|
|
#include <amiga/amiga/cc.h>
|
|
|
|
#include <amiga/dev/grfabs_reg.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* General and init.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* add your monitor here. */
|
|
|
|
monitor_t *cc_init_monitor (void);
|
|
|
|
|
|
|
|
/* and here. */
|
|
|
|
monitor_t *(*init_monitor[])(void) = {
|
|
|
|
cc_init_monitor,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
1994-03-27 10:23:26 +04:00
|
|
|
struct monitor_list instance_monitors, *monitors;
|
1994-02-14 00:10:20 +03:00
|
|
|
|
|
|
|
struct vbl_node grf_vbl_node;
|
|
|
|
|
|
|
|
#define ABS(type, val) \
|
1994-03-27 10:23:26 +04:00
|
|
|
(type) (((int)(val) < 0) ? -(val) : (val))
|
1994-02-14 00:10:20 +03:00
|
|
|
|
1996-04-22 01:10:48 +04:00
|
|
|
void grf_vbl_function __P((void *data));
|
|
|
|
dmode_t *get_best_display_mode __P((u_long, u_long, u_char));
|
|
|
|
|
|
|
|
|
1994-02-14 00:10:20 +03:00
|
|
|
void
|
1994-03-27 10:23:26 +04:00
|
|
|
grf_vbl_function(data)
|
1994-02-14 00:10:20 +03:00
|
|
|
void *data;
|
|
|
|
{
|
1994-03-27 10:23:26 +04:00
|
|
|
monitor_t *m;
|
|
|
|
|
|
|
|
if (monitors == NULL)
|
|
|
|
return;
|
1994-02-14 00:10:20 +03:00
|
|
|
|
1994-03-27 10:23:26 +04:00
|
|
|
for (m = monitors->lh_first; m != NULL; m = m->link.le_next) {
|
1994-02-14 00:10:20 +03:00
|
|
|
if (m->vbl_handler)
|
1994-03-27 10:23:26 +04:00
|
|
|
m->vbl_handler(m);
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: called from ite console init routine.
|
|
|
|
* Does just what configure will do later but without printing anything.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
1994-03-27 10:23:26 +04:00
|
|
|
grfcc_probe()
|
1994-02-14 00:10:20 +03:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
grf_vbl_node.function = grf_vbl_function;
|
|
|
|
|
|
|
|
if (NULL == monitors) {
|
1994-03-27 10:23:26 +04:00
|
|
|
LIST_INIT(&instance_monitors);
|
1994-02-14 00:10:20 +03:00
|
|
|
monitors = &instance_monitors;
|
|
|
|
|
|
|
|
while (init_monitor[i]) {
|
|
|
|
init_monitor[i] ();
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (i) {
|
1994-03-27 10:23:26 +04:00
|
|
|
add_vbl_function(&grf_vbl_node, 1, 0);
|
|
|
|
return(1);
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|
1994-03-27 10:23:26 +04:00
|
|
|
return(0);
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|
1994-03-27 10:23:26 +04:00
|
|
|
return(1);
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dmode_t *
|
1994-03-27 10:23:26 +04:00
|
|
|
get_best_display_mode(width, height, depth)
|
1994-02-14 00:10:20 +03:00
|
|
|
u_long width, height;
|
|
|
|
u_char depth;
|
|
|
|
{
|
1994-03-27 10:23:26 +04:00
|
|
|
monitor_t *m;
|
|
|
|
dmode_t *d, *save;
|
|
|
|
dimen_t dim;
|
1996-04-22 01:10:48 +04:00
|
|
|
long dx, dy, ct, dt = 0;
|
1994-03-27 10:23:26 +04:00
|
|
|
|
|
|
|
save = NULL;
|
|
|
|
for (m = monitors->lh_first; m != NULL; m = m->link.le_next) {
|
1994-02-14 00:10:20 +03:00
|
|
|
dim.width = width;
|
|
|
|
dim.height = height;
|
1994-03-27 10:23:26 +04:00
|
|
|
d = m->get_best_mode(&dim, depth);
|
1994-02-14 00:10:20 +03:00
|
|
|
if (d) {
|
1994-03-27 10:23:26 +04:00
|
|
|
dx = ABS(long, (d->nominal_size.width - width));
|
|
|
|
dy = ABS(long, (d->nominal_size.height - height));
|
1994-02-14 00:10:20 +03:00
|
|
|
ct = dx + dy;
|
|
|
|
|
|
|
|
if (ct < dt || save == NULL) {
|
|
|
|
save = d;
|
|
|
|
dt = ct;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1994-03-27 10:23:26 +04:00
|
|
|
return(save);
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Monitor stuff.
|
|
|
|
*/
|
|
|
|
|
|
|
|
dmode_t *
|
1994-03-27 10:23:26 +04:00
|
|
|
grf_get_next_mode(m, d)
|
1994-02-14 00:10:20 +03:00
|
|
|
monitor_t *m;
|
|
|
|
dmode_t *d;
|
|
|
|
{
|
1994-03-27 10:23:26 +04:00
|
|
|
return(m->get_next_mode(d));
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dmode_t *
|
1994-03-27 10:23:26 +04:00
|
|
|
grf_get_current_mode(m)
|
1994-02-14 00:10:20 +03:00
|
|
|
monitor_t *m;
|
|
|
|
{
|
1994-03-27 10:23:26 +04:00
|
|
|
return(m->get_current_mode());
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dmode_t *
|
1994-03-27 10:23:26 +04:00
|
|
|
grf_get_best_mode(m, size, depth)
|
1994-02-14 00:10:20 +03:00
|
|
|
monitor_t *m;
|
|
|
|
dimen_t *size;
|
|
|
|
u_char depth;
|
|
|
|
{
|
1994-03-27 10:23:26 +04:00
|
|
|
return(m->get_best_mode(size, depth));
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bmap_t *
|
1994-03-27 10:23:26 +04:00
|
|
|
grf_alloc_bitmap(m, w, h, d, f)
|
1994-02-14 00:10:20 +03:00
|
|
|
monitor_t *m;
|
|
|
|
u_short w, h, d, f;
|
|
|
|
{
|
1994-03-27 10:23:26 +04:00
|
|
|
return(m->alloc_bitmap(w, h, d, f));
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1994-03-27 10:23:26 +04:00
|
|
|
grf_free_bitmap(m, bm)
|
1994-02-14 00:10:20 +03:00
|
|
|
monitor_t *m;
|
|
|
|
bmap_t *bm;
|
|
|
|
{
|
1994-03-27 10:23:26 +04:00
|
|
|
m->free_bitmap(bm);
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mode stuff.
|
|
|
|
*/
|
|
|
|
|
|
|
|
view_t *
|
1994-03-27 10:23:26 +04:00
|
|
|
grf_get_current_view(d)
|
1994-02-14 00:10:20 +03:00
|
|
|
dmode_t *d;
|
|
|
|
{
|
1994-03-27 10:23:26 +04:00
|
|
|
return(d->get_current_view(d));
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
monitor_t *
|
1994-03-27 10:23:26 +04:00
|
|
|
grf_get_monitor(d)
|
1994-02-14 00:10:20 +03:00
|
|
|
dmode_t *d;
|
|
|
|
{
|
1994-03-27 10:23:26 +04:00
|
|
|
return(d->get_monitor(d));
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* View stuff.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
1994-03-27 10:23:26 +04:00
|
|
|
grf_display_view(v)
|
1994-02-14 00:10:20 +03:00
|
|
|
view_t *v;
|
|
|
|
{
|
1994-03-27 10:23:26 +04:00
|
|
|
v->display_view(v);
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
view_t *
|
1994-03-27 10:23:26 +04:00
|
|
|
grf_alloc_view(d, dim, depth)
|
1994-02-14 00:10:20 +03:00
|
|
|
dmode_t *d;
|
|
|
|
dimen_t *dim;
|
|
|
|
u_char depth;
|
|
|
|
{
|
|
|
|
if (!d)
|
1994-03-27 10:23:26 +04:00
|
|
|
d = get_best_display_mode(dim->width, dim->height, depth);
|
1994-02-14 00:10:20 +03:00
|
|
|
if (d)
|
1994-03-27 10:23:26 +04:00
|
|
|
return(d->alloc_view(d, dim, depth));
|
|
|
|
return(NULL);
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1994-03-27 10:23:26 +04:00
|
|
|
grf_remove_view(v)
|
1994-02-14 00:10:20 +03:00
|
|
|
view_t *v;
|
|
|
|
{
|
1994-03-27 10:23:26 +04:00
|
|
|
v->remove_view(v);
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1994-03-27 10:23:26 +04:00
|
|
|
grf_free_view(v)
|
1994-02-14 00:10:20 +03:00
|
|
|
view_t *v;
|
|
|
|
{
|
1994-03-27 10:23:26 +04:00
|
|
|
v->free_view(v);
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dmode_t *
|
1994-03-27 10:23:26 +04:00
|
|
|
grf_get_display_mode(v)
|
1994-02-14 00:10:20 +03:00
|
|
|
view_t *v;
|
|
|
|
{
|
1994-03-27 10:23:26 +04:00
|
|
|
return(v->get_display_mode(v));
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1994-03-27 10:23:26 +04:00
|
|
|
grf_get_colormap(v, cm)
|
1994-02-14 00:10:20 +03:00
|
|
|
view_t *v;
|
|
|
|
colormap_t *cm;
|
|
|
|
{
|
1994-03-27 10:23:26 +04:00
|
|
|
return(v->get_colormap(v, cm));
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1994-03-27 10:23:26 +04:00
|
|
|
grf_use_colormap(v, cm)
|
1994-02-14 00:10:20 +03:00
|
|
|
view_t *v;
|
|
|
|
colormap_t *cm;
|
|
|
|
{
|
1994-03-27 10:23:26 +04:00
|
|
|
return(v->use_colormap(v, cm));
|
1994-02-14 00:10:20 +03:00
|
|
|
}
|