logo_saver.c revision 42120
142120Sdes/*-
242120Sdes * Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav
342120Sdes * All rights reserved.
442120Sdes *
542120Sdes * Redistribution and use in source and binary forms, with or without
642120Sdes * modification, are permitted provided that the following conditions
742120Sdes * are met:
842120Sdes * 1. Redistributions of source code must retain the above copyright
942120Sdes *    notice, this list of conditions and the following disclaimer
1042120Sdes *    in this position and unchanged.
1142120Sdes * 2. Redistributions in binary form must reproduce the above copyright
1242120Sdes *    notice, this list of conditions and the following disclaimer in the
1342120Sdes *    documentation and/or other materials provided with the distribution.
1442120Sdes * 3. The name of the author may not be used to endorse or promote products
1542120Sdes *    derived from this software without specific prior written permission
1642120Sdes *
1742120Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1842120Sdes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1942120Sdes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2042120Sdes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2142120Sdes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2242120Sdes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2342120Sdes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2442120Sdes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2542120Sdes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2642120Sdes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2742120Sdes *
2842120Sdes *	$Id$
2942120Sdes */
3042120Sdes
3142120Sdes#include <sys/param.h>
3242120Sdes#include <sys/systm.h>
3342120Sdes#include <sys/kernel.h>
3442120Sdes#include <sys/module.h>
3542120Sdes#include <sys/syslog.h>
3642120Sdes
3742120Sdes#include <machine/md_var.h>
3842120Sdes
3942120Sdes#include <saver.h>
4042120Sdes
4142120Sdesstatic u_char *vid;
4242120Sdesstatic int banksize;
4342120Sdesstatic u_char save_pal[768];
4442120Sdes
4542120Sdes#define SCRW 800
4642120Sdes#define SCRH 600
4742120Sdes
4842120Sdes#include "logo.c"
4942120Sdes
5042120Sdes#define set_origin(scp, o) (*biosvidsw.set_win_org)((scp)->adp, o)
5142120Sdes
5242120Sdesstatic void
5342120Sdeslogo_blit(int x, int y)
5442120Sdes{
5542120Sdes    int d, l, o, p;
5642120Sdes
5742120Sdes    for (o = 0, p = y * SCRW + x; p > banksize; p -= banksize)
5842120Sdes	o += banksize;
5942120Sdes    set_origin(cur_console, o);
6042120Sdes
6142120Sdes    for (d = 0; d < sizeof logo_img; d += logo_w) {
6242120Sdes	if (p + logo_w < banksize) {
6342120Sdes	    bcopy(logo_img + d, vid + p, logo_w);
6442120Sdes	    p += SCRW;
6542120Sdes	} else if (p < banksize) {
6642120Sdes	    l = banksize - p;
6742120Sdes	    bcopy(logo_img + d, vid + p, l);
6842120Sdes	    set_origin(cur_console, (o += banksize));
6942120Sdes	    bcopy(logo_img + d + l, vid, logo_w - l);
7042120Sdes	    p += SCRW - banksize;
7142120Sdes	} else {
7242120Sdes	    p -= banksize;
7342120Sdes	    set_origin(cur_console, (o += banksize));
7442120Sdes	    bcopy(logo_img + d, vid + p, logo_w);
7542120Sdes	    p += SCRW;
7642120Sdes	}
7742120Sdes    }
7842120Sdes}
7942120Sdes
8042120Sdesstatic void
8142120Sdeslogo_update(void)
8242120Sdes{
8342120Sdes    static int xpos = 0, ypos = 0;
8442120Sdes    static int xinc = 1, yinc = 1;
8542120Sdes
8642120Sdes    /* Turn when you hit the edge */
8742120Sdes    if ((xpos + logo_w + xinc > SCRW) || (xpos + xinc < 0)) xinc = -xinc;
8842120Sdes    if ((ypos + logo_h + yinc > SCRH) || (ypos + yinc < 0)) yinc = -yinc;
8942120Sdes    xpos += xinc; ypos += yinc;
9042120Sdes
9142120Sdes    /* XXX Relies on margin around logo to erase trail */
9242120Sdes    logo_blit(xpos, ypos);
9342120Sdes}
9442120Sdes
9542120Sdesstatic void
9642120Sdeslogo_saver(int blank)
9742120Sdes{
9842120Sdes    scr_stat *scp = cur_console;
9942120Sdes    static int saved_mode;
10042120Sdes    int pl;
10142120Sdes
10242120Sdes    if (blank) {
10342120Sdes	/* switch to graphics mode */
10442120Sdes	if (scrn_blanked <= 0) {
10542120Sdes	    pl = splhigh();
10642120Sdes	    saved_mode = scp->mode;
10742120Sdes	    scp->mode = M_VESA_CG800x600;
10842120Sdes	    scp->status |= SAVER_RUNNING|GRAPHICS_MODE;
10942120Sdes	    save_palette(scp, (char *)save_pal);
11042120Sdes	    set_mode(scp);
11142120Sdes	    load_palette(scp, (char *)logo_pal);
11242120Sdes	    scrn_blanked++;
11342120Sdes	    vid = (u_char *)Crtat;
11442120Sdes	    splx(pl);
11542120Sdes	    /* XXX should clear all banks */
11642120Sdes	}
11742120Sdes	logo_update();
11842120Sdes    } else {
11942120Sdes	/* return to previous video mode */
12042120Sdes	if (scrn_blanked > 0) {
12142120Sdes	    if (saved_mode) {
12242120Sdes		pl = splhigh();
12342120Sdes		scrn_blanked = 0;
12442120Sdes		scp->mode = saved_mode;
12542120Sdes		scp->status &= ~(SAVER_RUNNING|GRAPHICS_MODE);
12642120Sdes		set_mode(scp);
12742120Sdes		load_palette(scp, (char *)save_pal);
12842120Sdes		saved_mode = 0;
12942120Sdes		splx(pl);
13042120Sdes	    }
13142120Sdes	}
13242120Sdes    }
13342120Sdes}
13442120Sdes
13542120Sdesstatic int
13642120Sdeslogo_saver_load(void)
13742120Sdes{
13842120Sdes    video_info_t info;
13942120Sdes
14042120Sdes    /* check that the console is capable of running in 800x600x256 */
14142120Sdes    if ((*biosvidsw.get_info)(cur_console->adp, M_VESA_CG800x600, &info)) {
14242120Sdes        log(LOG_NOTICE, "logo_saver: the console does not support M_VESA_CG800x600\n");
14342120Sdes	return ENODEV;
14442120Sdes    }
14542120Sdes
14642120Sdes    /* is it possible for window_size not to be a multiple of window_gran? */
14742120Sdes    while (banksize + info.vi_window_gran <= info.vi_window_size)
14842120Sdes	banksize += info.vi_window_gran;
14942120Sdes
15042120Sdes    return add_scrn_saver(logo_saver);
15142120Sdes}
15242120Sdes
15342120Sdesstatic int
15442120Sdeslogo_saver_unload(void)
15542120Sdes{
15642120Sdes    return remove_scrn_saver(logo_saver);
15742120Sdes}
15842120Sdes
15942120SdesSAVER_MODULE(logo_saver);
160