1 /*- 2 * (MPSAFE) 3 * 4 * Copyright (c) 1995-1998 S�ren Schmidt 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer, 12 * without modification, immediately at the beginning of the file. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. The name of the author may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * 30 * $FreeBSD: src/sys/modules/syscons/snake/snake_saver.c,v 1.26.2.2 2001/05/06 05:44:29 nyan Exp $ 31 * $DragonFly: src/sys/dev/misc/syscons/snake/snake_saver.c,v 1.8 2006/12/20 18:14:39 dillon Exp $ 32 */ 33 34 #include <sys/param.h> 35 #include <sys/systm.h> 36 #include <sys/module.h> 37 #include <sys/malloc.h> 38 #include <sys/kernel.h> 39 #include <sys/sysctl.h> 40 #include <sys/consio.h> 41 #include <sys/fbio.h> 42 #include <sys/thread.h> 43 44 #include <machine/pc/display.h> 45 46 #include <dev/video/fb/fbreg.h> 47 #include <dev/video/fb/splashreg.h> 48 #include "../syscons.h" 49 50 static u_char *message; 51 static int *messagep; 52 static int messagelen; 53 static int blanked; 54 55 static int 56 snake_saver(video_adapter_t *adp, int blank) 57 { 58 static int dirx, diry; 59 int f; 60 sc_softc_t *sc; 61 scr_stat *scp; 62 63 /* XXX hack for minimal changes. */ 64 #define save message 65 #define savs messagep 66 67 lwkt_gettoken(&tty_token); 68 69 sc = sc_find_softc(adp, NULL); 70 if (sc == NULL) { 71 lwkt_reltoken(&tty_token); 72 return EAGAIN; 73 } 74 scp = sc->cur_scp; 75 76 if (blank) { 77 if (adp->va_info.vi_flags & V_INFO_GRAPHICS) { 78 lwkt_reltoken(&tty_token); 79 return EAGAIN; 80 } 81 if (blanked <= 0) { 82 sc_vtb_clear(&scp->scr, sc->scr_map[0x20], 83 (FG_LIGHTGREY | BG_BLACK) << 8); 84 (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1); 85 sc_set_border(scp, 0); 86 dirx = (scp->xpos ? 1 : -1); 87 diry = (scp->ypos ? 88 scp->xsize : -scp->xsize); 89 for (f=0; f< messagelen; f++) 90 savs[f] = scp->xpos + scp->ypos*scp->xsize; 91 sc_vtb_putc(&scp->scr, savs[0], sc->scr_map[*save], 92 (FG_LIGHTGREY | BG_BLACK) << 8); 93 blanked = 1; 94 } 95 if (blanked++ < 4) { 96 lwkt_reltoken(&tty_token); 97 return 0; 98 } 99 blanked = 1; 100 sc_vtb_putc(&scp->scr, savs[messagelen - 1], sc->scr_map[0x20], 101 (FG_LIGHTGREY | BG_BLACK) << 8); 102 for (f=messagelen-1; f > 0; f--) 103 savs[f] = savs[f-1]; 104 f = savs[0]; 105 if ((f % scp->xsize) == 0 || 106 (f % scp->xsize) == scp->xsize - 1 || 107 (krandom() % 50) == 0) 108 dirx = -dirx; 109 if ((f / scp->xsize) == 0 || 110 (f / scp->xsize) == scp->ysize - 1 || 111 (krandom() % 20) == 0) 112 diry = -diry; 113 savs[0] += dirx + diry; 114 for (f=messagelen-1; f>=0; f--) 115 sc_vtb_putc(&scp->scr, savs[f], sc->scr_map[save[f]], 116 (FG_LIGHTGREY | BG_BLACK) << 8); 117 } else { 118 blanked = 0; 119 } 120 121 lwkt_reltoken(&tty_token); 122 return 0; 123 } 124 125 static int 126 snake_init(video_adapter_t *adp) 127 { 128 messagelen = strlen(ostype) + 1 + strlen(osrelease); 129 message = kmalloc(messagelen + 1, M_SYSCONS, M_WAITOK); 130 ksprintf(message, "%s %s", ostype, osrelease); 131 messagep = kmalloc(messagelen * sizeof *messagep, M_SYSCONS, M_WAITOK); 132 return 0; 133 } 134 135 static int 136 snake_term(video_adapter_t *adp) 137 { 138 kfree(message, M_SYSCONS); 139 kfree(messagep, M_SYSCONS); 140 return 0; 141 } 142 143 static scrn_saver_t snake_module = { 144 "snake_saver", snake_init, snake_term, snake_saver, NULL, 145 }; 146 147 SAVER_MODULE(snake_saver, snake_module); 148