xref: /freebsd/sys/dev/syscons/snake/snake_saver.c (revision f4acf7e936caf7d34acf3894c8380f378919f3c5)
117ee9d00SSøren Schmidt /*-
2a8445737SSøren Schmidt  * Copyright (c) 1995-1998 S�ren Schmidt
317ee9d00SSøren Schmidt  * All rights reserved.
417ee9d00SSøren Schmidt  *
517ee9d00SSøren Schmidt  * Redistribution and use in source and binary forms, with or without
617ee9d00SSøren Schmidt  * modification, are permitted provided that the following conditions
717ee9d00SSøren Schmidt  * are met:
817ee9d00SSøren Schmidt  * 1. Redistributions of source code must retain the above copyright
9a8445737SSøren Schmidt  *    notice, this list of conditions and the following disclaimer,
10a8445737SSøren Schmidt  *    without modification, immediately at the beginning of the file.
1117ee9d00SSøren Schmidt  * 2. Redistributions in binary form must reproduce the above copyright
1217ee9d00SSøren Schmidt  *    notice, this list of conditions and the following disclaimer in the
1317ee9d00SSøren Schmidt  *    documentation and/or other materials provided with the distribution.
1417ee9d00SSøren Schmidt  * 3. The name of the author may not be used to endorse or promote products
15a8445737SSøren Schmidt  *    derived from this software without specific prior written permission.
1617ee9d00SSøren Schmidt  *
1717ee9d00SSøren Schmidt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1817ee9d00SSøren Schmidt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1917ee9d00SSøren Schmidt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2017ee9d00SSøren Schmidt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2117ee9d00SSøren Schmidt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2217ee9d00SSøren Schmidt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2317ee9d00SSøren Schmidt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2417ee9d00SSøren Schmidt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2517ee9d00SSøren Schmidt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2617ee9d00SSøren Schmidt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2717ee9d00SSøren Schmidt  *
28c3aac50fSPeter Wemm  * $FreeBSD$
2917ee9d00SSøren Schmidt  */
3017ee9d00SSøren Schmidt 
3117ee9d00SSøren Schmidt #include <sys/param.h>
3217ee9d00SSøren Schmidt #include <sys/systm.h>
330640d357SPeter Wemm #include <sys/module.h>
34ce834215SKazutaka YOKOTA #include <sys/malloc.h>
35ce834215SKazutaka YOKOTA #include <sys/kernel.h>
36ce834215SKazutaka YOKOTA #include <sys/sysctl.h>
376e8394b8SKazutaka YOKOTA #include <sys/consio.h>
386e8394b8SKazutaka YOKOTA #include <sys/fbio.h>
39f6b4ae3cSBruce Evans 
4033b77e2dSBruce Evans #include <machine/pc/display.h>
41f6b4ae3cSBruce Evans 
426e8394b8SKazutaka YOKOTA #include <dev/fb/fbreg.h>
436e8394b8SKazutaka YOKOTA #include <dev/fb/splashreg.h>
446e8394b8SKazutaka YOKOTA #include <dev/syscons/syscons.h>
4517ee9d00SSøren Schmidt 
462eb8169aSYoshihiro Takahashi static u_char	*message;
476e8394b8SKazutaka YOKOTA static int	*messagep;
48ce834215SKazutaka YOKOTA static int	messagelen;
492ad872c5SKazutaka YOKOTA static int	blanked;
5017ee9d00SSøren Schmidt 
512ad872c5SKazutaka YOKOTA static int
522ad872c5SKazutaka YOKOTA snake_saver(video_adapter_t *adp, int blank)
5317ee9d00SSøren Schmidt {
5417ee9d00SSøren Schmidt 	static int	dirx, diry;
5517ee9d00SSøren Schmidt 	int		f;
566e8394b8SKazutaka YOKOTA 	sc_softc_t	*sc;
576e8394b8SKazutaka YOKOTA 	scr_stat	*scp;
5817ee9d00SSøren Schmidt 
59ce834215SKazutaka YOKOTA /* XXX hack for minimal changes. */
60ce834215SKazutaka YOKOTA #define	save	message
61ce834215SKazutaka YOKOTA #define	savs	messagep
62ce834215SKazutaka YOKOTA 
636e8394b8SKazutaka YOKOTA 	sc = sc_find_softc(adp, NULL);
646e8394b8SKazutaka YOKOTA 	if (sc == NULL)
656e8394b8SKazutaka YOKOTA 		return EAGAIN;
666e8394b8SKazutaka YOKOTA 	scp = sc->cur_scp;
676e8394b8SKazutaka YOKOTA 
6817ee9d00SSøren Schmidt 	if (blank) {
692da199daSDag-Erling Smørgrav 		if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
70f9e730bbSKazutaka YOKOTA 			return EAGAIN;
712ad872c5SKazutaka YOKOTA 		if (blanked <= 0) {
726e8394b8SKazutaka YOKOTA 			sc_vtb_clear(&scp->scr, sc->scr_map[0x20],
736e8394b8SKazutaka YOKOTA 				     (FG_LIGHTGREY | BG_BLACK) << 8);
746e8394b8SKazutaka YOKOTA 			(*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
752b944ee2SKazutaka YOKOTA 			sc_set_border(scp, 0);
7617ee9d00SSøren Schmidt 			dirx = (scp->xpos ? 1 : -1);
7717ee9d00SSøren Schmidt 			diry = (scp->ypos ?
7817ee9d00SSøren Schmidt 				scp->xsize : -scp->xsize);
79ce834215SKazutaka YOKOTA 			for (f=0; f< messagelen; f++)
806e8394b8SKazutaka YOKOTA 				savs[f] = scp->xpos + scp->ypos*scp->xsize;
816e8394b8SKazutaka YOKOTA 			sc_vtb_putc(&scp->scr, savs[0], sc->scr_map[*save],
826e8394b8SKazutaka YOKOTA 				    (FG_LIGHTGREY | BG_BLACK) << 8);
832ad872c5SKazutaka YOKOTA 			blanked = 1;
8417ee9d00SSøren Schmidt 		}
852ad872c5SKazutaka YOKOTA 		if (blanked++ < 4)
862ad872c5SKazutaka YOKOTA 			return 0;
872ad872c5SKazutaka YOKOTA 		blanked = 1;
886e8394b8SKazutaka YOKOTA 		sc_vtb_putc(&scp->scr, savs[messagelen - 1], sc->scr_map[0x20],
896e8394b8SKazutaka YOKOTA 			    (FG_LIGHTGREY | BG_BLACK) << 8);
90ce834215SKazutaka YOKOTA 		for (f=messagelen-1; f > 0; f--)
9117ee9d00SSøren Schmidt 			savs[f] = savs[f-1];
926e8394b8SKazutaka YOKOTA 		f = savs[0];
9317ee9d00SSøren Schmidt 		if ((f % scp->xsize) == 0 ||
9417ee9d00SSøren Schmidt 		    (f % scp->xsize) == scp->xsize - 1 ||
9517ee9d00SSøren Schmidt 		    (random() % 50) == 0)
9617ee9d00SSøren Schmidt 			dirx = -dirx;
9717ee9d00SSøren Schmidt 		if ((f / scp->xsize) == 0 ||
9817ee9d00SSøren Schmidt 		    (f / scp->xsize) == scp->ysize - 1 ||
9917ee9d00SSøren Schmidt 		    (random() % 20) == 0)
10017ee9d00SSøren Schmidt 			diry = -diry;
1016e8394b8SKazutaka YOKOTA 		savs[0] += dirx + diry;
102ce834215SKazutaka YOKOTA 		for (f=messagelen-1; f>=0; f--)
1036e8394b8SKazutaka YOKOTA 			sc_vtb_putc(&scp->scr, savs[f], sc->scr_map[save[f]],
1046e8394b8SKazutaka YOKOTA 				    (FG_LIGHTGREY | BG_BLACK) << 8);
105f4acf7e9SYoshihiro Takahashi 	} else
1062ad872c5SKazutaka YOKOTA 		blanked = 0;
107f4acf7e9SYoshihiro Takahashi 
1082ad872c5SKazutaka YOKOTA 	return 0;
10917ee9d00SSøren Schmidt }
11017ee9d00SSøren Schmidt 
111b3e24f9cSBruce Evans static int
1122ad872c5SKazutaka YOKOTA snake_init(video_adapter_t *adp)
11317ee9d00SSøren Schmidt {
114ce834215SKazutaka YOKOTA 	messagelen = strlen(ostype) + 1 + strlen(osrelease);
115a163d034SWarner Losh 	message = malloc(messagelen + 1, M_DEVBUF, M_WAITOK);
116ce834215SKazutaka YOKOTA 	sprintf(message, "%s %s", ostype, osrelease);
117a163d034SWarner Losh 	messagep = malloc(messagelen * sizeof *messagep, M_DEVBUF, M_WAITOK);
1182ad872c5SKazutaka YOKOTA 	return 0;
11917ee9d00SSøren Schmidt }
12017ee9d00SSøren Schmidt 
121b3e24f9cSBruce Evans static int
1222ad872c5SKazutaka YOKOTA snake_term(video_adapter_t *adp)
12317ee9d00SSøren Schmidt {
124ce834215SKazutaka YOKOTA 	free(message, M_DEVBUF);
125ce834215SKazutaka YOKOTA 	free(messagep, M_DEVBUF);
1262ad872c5SKazutaka YOKOTA 	return 0;
12717ee9d00SSøren Schmidt }
12817ee9d00SSøren Schmidt 
1292ad872c5SKazutaka YOKOTA static scrn_saver_t snake_module = {
1302ad872c5SKazutaka YOKOTA 	"snake_saver", snake_init, snake_term, snake_saver, NULL,
1312ad872c5SKazutaka YOKOTA };
1322ad872c5SKazutaka YOKOTA 
1332ad872c5SKazutaka YOKOTA SAVER_MODULE(snake_saver, snake_module);
134