xref: /freebsd/sys/dev/syscons/snake/snake_saver.c (revision 2eb8169a1ad3bd8c7960767a5bc471c8d8bc677e)
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 
46b95b56c7SYoshihiro Takahashi #ifdef PC98
47b95b56c7SYoshihiro Takahashi #include <pc98/pc98/pc98_machdep.h>
48b95b56c7SYoshihiro Takahashi #endif
49b95b56c7SYoshihiro Takahashi 
502eb8169aSYoshihiro Takahashi static u_char	*message;
516e8394b8SKazutaka YOKOTA static int	*messagep;
52ce834215SKazutaka YOKOTA static int	messagelen;
532ad872c5SKazutaka YOKOTA static int	blanked;
5417ee9d00SSøren Schmidt 
552ad872c5SKazutaka YOKOTA static int
562ad872c5SKazutaka YOKOTA snake_saver(video_adapter_t *adp, int blank)
5717ee9d00SSøren Schmidt {
5817ee9d00SSøren Schmidt 	static int	dirx, diry;
5917ee9d00SSøren Schmidt 	int		f;
606e8394b8SKazutaka YOKOTA 	sc_softc_t	*sc;
616e8394b8SKazutaka YOKOTA 	scr_stat	*scp;
6217ee9d00SSøren Schmidt 
63ce834215SKazutaka YOKOTA /* XXX hack for minimal changes. */
64ce834215SKazutaka YOKOTA #define	save	message
65ce834215SKazutaka YOKOTA #define	savs	messagep
66ce834215SKazutaka YOKOTA 
676e8394b8SKazutaka YOKOTA 	sc = sc_find_softc(adp, NULL);
686e8394b8SKazutaka YOKOTA 	if (sc == NULL)
696e8394b8SKazutaka YOKOTA 		return EAGAIN;
706e8394b8SKazutaka YOKOTA 	scp = sc->cur_scp;
716e8394b8SKazutaka YOKOTA 
7217ee9d00SSøren Schmidt 	if (blank) {
732da199daSDag-Erling Smørgrav 		if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
74f9e730bbSKazutaka YOKOTA 			return EAGAIN;
752ad872c5SKazutaka YOKOTA 		if (blanked <= 0) {
766e8394b8SKazutaka YOKOTA #ifdef PC98
776e8394b8SKazutaka YOKOTA 			if (epson_machine_id == 0x20) {
786e8394b8SKazutaka YOKOTA 				outb(0x43f, 0x42);
796e8394b8SKazutaka YOKOTA 				outb(0x0c17, inb(0xc17) & ~0x08);
806e8394b8SKazutaka YOKOTA 				outb(0x43f, 0x40);
816e8394b8SKazutaka YOKOTA 			}
826e8394b8SKazutaka YOKOTA #endif /* PC98 */
836e8394b8SKazutaka YOKOTA 			sc_vtb_clear(&scp->scr, sc->scr_map[0x20],
846e8394b8SKazutaka YOKOTA 				     (FG_LIGHTGREY | BG_BLACK) << 8);
856e8394b8SKazutaka YOKOTA 			(*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
862b944ee2SKazutaka YOKOTA 			sc_set_border(scp, 0);
8717ee9d00SSøren Schmidt 			dirx = (scp->xpos ? 1 : -1);
8817ee9d00SSøren Schmidt 			diry = (scp->ypos ?
8917ee9d00SSøren Schmidt 				scp->xsize : -scp->xsize);
90ce834215SKazutaka YOKOTA 			for (f=0; f< messagelen; f++)
916e8394b8SKazutaka YOKOTA 				savs[f] = scp->xpos + scp->ypos*scp->xsize;
926e8394b8SKazutaka YOKOTA 			sc_vtb_putc(&scp->scr, savs[0], sc->scr_map[*save],
936e8394b8SKazutaka YOKOTA 				    (FG_LIGHTGREY | BG_BLACK) << 8);
942ad872c5SKazutaka YOKOTA 			blanked = 1;
9517ee9d00SSøren Schmidt 		}
962ad872c5SKazutaka YOKOTA 		if (blanked++ < 4)
972ad872c5SKazutaka YOKOTA 			return 0;
982ad872c5SKazutaka YOKOTA 		blanked = 1;
996e8394b8SKazutaka YOKOTA 		sc_vtb_putc(&scp->scr, savs[messagelen - 1], sc->scr_map[0x20],
1006e8394b8SKazutaka YOKOTA 			    (FG_LIGHTGREY | BG_BLACK) << 8);
101ce834215SKazutaka YOKOTA 		for (f=messagelen-1; f > 0; f--)
10217ee9d00SSøren Schmidt 			savs[f] = savs[f-1];
1036e8394b8SKazutaka YOKOTA 		f = savs[0];
10417ee9d00SSøren Schmidt 		if ((f % scp->xsize) == 0 ||
10517ee9d00SSøren Schmidt 		    (f % scp->xsize) == scp->xsize - 1 ||
10617ee9d00SSøren Schmidt 		    (random() % 50) == 0)
10717ee9d00SSøren Schmidt 			dirx = -dirx;
10817ee9d00SSøren Schmidt 		if ((f / scp->xsize) == 0 ||
10917ee9d00SSøren Schmidt 		    (f / scp->xsize) == scp->ysize - 1 ||
11017ee9d00SSøren Schmidt 		    (random() % 20) == 0)
11117ee9d00SSøren Schmidt 			diry = -diry;
1126e8394b8SKazutaka YOKOTA 		savs[0] += dirx + diry;
113ce834215SKazutaka YOKOTA 		for (f=messagelen-1; f>=0; f--)
1146e8394b8SKazutaka YOKOTA 			sc_vtb_putc(&scp->scr, savs[f], sc->scr_map[save[f]],
1156e8394b8SKazutaka YOKOTA 				    (FG_LIGHTGREY | BG_BLACK) << 8);
11617ee9d00SSøren Schmidt 	}
11717ee9d00SSøren Schmidt 	else {
1186e8394b8SKazutaka YOKOTA #ifdef PC98
1196e8394b8SKazutaka YOKOTA 		if (epson_machine_id == 0x20) {
1206e8394b8SKazutaka YOKOTA 			outb(0x43f, 0x42);
1216e8394b8SKazutaka YOKOTA 			outb(0x0c17, inb(0xc17) | 0x08);
1226e8394b8SKazutaka YOKOTA 			outb(0x43f, 0x40);
1236e8394b8SKazutaka YOKOTA 		}
1246e8394b8SKazutaka YOKOTA #endif /* PC98 */
1252ad872c5SKazutaka YOKOTA 		blanked = 0;
12617ee9d00SSøren Schmidt 	}
1272ad872c5SKazutaka YOKOTA 	return 0;
12817ee9d00SSøren Schmidt }
12917ee9d00SSøren Schmidt 
130b3e24f9cSBruce Evans static int
1312ad872c5SKazutaka YOKOTA snake_init(video_adapter_t *adp)
13217ee9d00SSøren Schmidt {
133ce834215SKazutaka YOKOTA 	messagelen = strlen(ostype) + 1 + strlen(osrelease);
134ce834215SKazutaka YOKOTA 	message = malloc(messagelen + 1, M_DEVBUF, M_WAITOK);
135ce834215SKazutaka YOKOTA 	sprintf(message, "%s %s", ostype, osrelease);
136ce834215SKazutaka YOKOTA 	messagep = malloc(messagelen * sizeof *messagep, M_DEVBUF, M_WAITOK);
1372ad872c5SKazutaka YOKOTA 	return 0;
13817ee9d00SSøren Schmidt }
13917ee9d00SSøren Schmidt 
140b3e24f9cSBruce Evans static int
1412ad872c5SKazutaka YOKOTA snake_term(video_adapter_t *adp)
14217ee9d00SSøren Schmidt {
143ce834215SKazutaka YOKOTA 	free(message, M_DEVBUF);
144ce834215SKazutaka YOKOTA 	free(messagep, M_DEVBUF);
1452ad872c5SKazutaka YOKOTA 	return 0;
14617ee9d00SSøren Schmidt }
14717ee9d00SSøren Schmidt 
1482ad872c5SKazutaka YOKOTA static scrn_saver_t snake_module = {
1492ad872c5SKazutaka YOKOTA 	"snake_saver", snake_init, snake_term, snake_saver, NULL,
1502ad872c5SKazutaka YOKOTA };
1512ad872c5SKazutaka YOKOTA 
1522ad872c5SKazutaka YOKOTA SAVER_MODULE(snake_saver, snake_module);
153