Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 4 Nov 2001 15:18:41 -0800
From:      Marcus Reid <marcus@blazingdot.com>
To:        freebsd-chat@FreeBSD.Org
Subject:   simplicity_saver
Message-ID:  <20011104151840.A13030@blazingdot.com>

next in thread | raw e-mail | index | archive | help

--FCuugMFkClbJLl1L
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi:

I thought I'd share this screensaver module that I wrote. I find it
interesting what the effect is achieved with only a few lines of code,
yet it looks very complicated.

-- 
Marcus Reid
Blazingdot

 "They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety." -- Benjamin Franklin, 1759

--FCuugMFkClbJLl1L
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=Makefile

KMOD=   simplicity_saver
SRCS=   simplicity_saver.c

CWARNFLAGS= -Wall -pedantic

.include <bsd.kmod.mk>

--FCuugMFkClbJLl1L
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="simplicity_saver.c"

/*-
 * Copyright (c) 2001 Marcus L. Reid
 * 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,
 *    without modification, immediately at the beginning of the file.
 * 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.
 *
 * 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.
 *
 */

/*
 * 20011103 Marcus L. Reid <marcus@punq.net>
 *
 * written with much help from fire_saver.c
 *
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/syslog.h>
#include <sys/consio.h>
#include <sys/fbio.h>

#include <dev/fb/fbreg.h>
#include <dev/fb/splashreg.h>
#include <dev/syscons/syscons.h>

#define X_SIZE 320
#define Y_SIZE 200

static int      blanked;
static u_char   k_pal[768];
static u_char   buf[X_SIZE * (Y_SIZE + 1)];
static u_char  *vid;
static int	z, cv;

static int
simplicity_saver(video_adapter_t *adp, int blank)
{
    int             x, y;

    if (blank) {
	if (blanked <= 0) {
	    int             red, green, blue;
	    int             palette_index;

	    set_video_mode(adp, M_VGA_CG320);

	    /* build and load palette */
	    red = green = blue = 0;
	    for (palette_index = 0; palette_index < 256; palette_index++) {
		if(palette_index < 64) {
		    k_pal[(palette_index * 3) + 0] = palette_index * 4;
		    k_pal[(palette_index * 3) + 1] = 0;
		    k_pal[(palette_index * 3) + 2] = 0;
		} else if(palette_index < 128) {
		    k_pal[(palette_index * 3) + 0] = 0;
		    k_pal[(palette_index * 3) + 1] = (palette_index - 64) * 4;
		    k_pal[(palette_index * 3) + 2] = 0;
		} else if(palette_index < 192) {
		    k_pal[(palette_index * 3) + 0] = 0;
		    k_pal[(palette_index * 3) + 1] = 0;
		    k_pal[(palette_index * 3) + 2] = (palette_index - 128) * 4;
		} else if(palette_index < 256) {
		    k_pal[(palette_index * 3) + 0] = (palette_index - 192) * 4;
		    k_pal[(palette_index * 3) + 1] = (palette_index - 192) * 4;
		    k_pal[(palette_index * 3) + 2] = (palette_index - 192) * 4;
		}
	    }
	    load_palette(adp, k_pal);

	    blanked++;
	    vid = (u_char *) adp->va_window;
	}

	/* Now that we have the colors, time for simple magic. */
	for (y = 0; y < Y_SIZE; cv += y++) {
		for (x = 0; x < X_SIZE; cv += x++) {
			buf[y*X_SIZE+x] = cv % 256;
		}
	}
	cv += z++;
	/* Done. */

	/* blit our buffer into video ram */
	memcpy(vid, buf, X_SIZE * Y_SIZE);
    } else {
	blanked = 0;
    }

    return 0;
}

static int
simplicity_initialise(video_adapter_t *adp)
{
    video_info_t    info;

    /* check that the console is capable of running in 320x200x256 */
    if (get_mode_info(adp, M_VGA_CG320, &info)) {
	log(LOG_NOTICE, "simplicity_saver: the console does not support M_VGA_CG320\n");
	return (ENODEV);
    }
    blanked = 0;
    z = 0;

    return 0;
}

static int
simplicity_terminate(video_adapter_t *adp)
{
    return 0;
}

static scrn_saver_t simplicity_module = {
    "simplicity_saver", simplicity_initialise, simplicity_terminate, simplicity_saver, NULL
};

SAVER_MODULE(simplicity_saver, simplicity_module);

--FCuugMFkClbJLl1L--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-chat" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011104151840.A13030>