logo_saver.c revision 117833
1/*- 2 * Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer 10 * in this position and unchanged. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * $FreeBSD: head/sys/dev/syscons/logo/logo_saver.c 117833 2003-07-21 13:04:54Z nyan $ 29 */ 30 31#include <sys/param.h> 32#include <sys/systm.h> 33#include <sys/kernel.h> 34#include <sys/module.h> 35#include <sys/syslog.h> 36#include <sys/consio.h> 37#include <sys/fbio.h> 38 39#include <dev/fb/fbreg.h> 40#include <dev/fb/splashreg.h> 41#include <dev/syscons/syscons.h> 42 43#define SAVER_NAME "logo_saver" 44 45extern unsigned int logo_w; 46extern unsigned int logo_h; 47extern unsigned char logo_pal[]; 48extern unsigned char logo_img[]; 49extern unsigned int logo_img_size; 50 51static u_char *vid; 52static int banksize, scrmode, bpsl, scrw, scrh; 53static int blanked; 54 55static void 56logo_blit(video_adapter_t *adp, int x, int y) 57{ 58 int d, l, o, p; 59 60 for (o = 0, p = y * bpsl + x; p > banksize; p -= banksize) 61 o += banksize; 62 set_origin(adp, o); 63 64 for (d = 0; d < logo_img_size; d += logo_w) { 65 if (p + logo_w < banksize) { 66 bcopy(logo_img + d, vid + p, logo_w); 67 p += bpsl; 68 } else if (p < banksize) { 69 l = banksize - p; 70 bcopy(logo_img + d, vid + p, l); 71 set_origin(adp, (o += banksize)); 72 bcopy(logo_img + d + l, vid, logo_w - l); 73 p += bpsl - banksize; 74 } else { 75 p -= banksize; 76 set_origin(adp, (o += banksize)); 77 bcopy(logo_img + d, vid + p, logo_w); 78 p += bpsl; 79 } 80 } 81} 82 83static void 84logo_update(video_adapter_t *adp) 85{ 86 static int xpos = 0, ypos = 0; 87 static int xinc = 1, yinc = 1; 88 89 /* Turn when you hit the edge */ 90 if ((xpos + logo_w + xinc > scrw) || (xpos + xinc < 0)) 91 xinc = -xinc; 92 if ((ypos + logo_h + yinc > scrh) || (ypos + yinc < 0)) 93 yinc = -yinc; 94 xpos += xinc; 95 ypos += yinc; 96 97 /* XXX Relies on margin around logo to erase trail */ 98 logo_blit(adp, xpos, ypos); 99} 100 101static int 102logo_saver(video_adapter_t *adp, int blank) 103{ 104 int pl; 105 106 if (blank) { 107 /* switch to graphics mode */ 108 if (blanked <= 0) { 109 pl = splhigh(); 110 set_video_mode(adp, scrmode); 111 load_palette(adp, logo_pal); 112 set_border(adp, 0); 113 blanked++; 114 vid = (u_char *)adp->va_window; 115 banksize = adp->va_window_size; 116 bpsl = adp->va_line_width; 117 splx(pl); 118 (*vidsw[adp->va_index]->clear)(adp); 119 } 120 logo_update(adp); 121 } else { 122 blanked = 0; 123 } 124 return (0); 125} 126 127static int 128logo_init(video_adapter_t *adp) 129{ 130 video_info_t info; 131 132 if (!get_mode_info(adp, M_VESA_CG800x600, &info)) { 133 scrmode = M_VESA_CG800x600; 134 } else if (!get_mode_info(adp, M_VGA_CG320, &info)) { 135 scrmode = M_VGA_CG320; 136 } else if (!get_mode_info(adp, M_PC98_PEGC640x480, &info)) { 137 scrmode = M_PC98_PEGC640x480; 138 } else if (!get_mode_info(adp, M_PC98_PEGC640x400, &info)) { 139 scrmode = M_PC98_PEGC640x400; 140 } else { 141 log(LOG_NOTICE, 142 "%s: the console does not support M_VGA_CG320\n", 143 SAVER_NAME); 144 return (ENODEV); 145 } 146 147 scrw = info.vi_width; 148 scrh = info.vi_height; 149 150 return (0); 151} 152 153static int 154logo_term(video_adapter_t *adp) 155{ 156 return (0); 157} 158 159static scrn_saver_t logo_module = { 160 SAVER_NAME, 161 logo_init, 162 logo_term, 163 logo_saver, 164 NULL 165}; 166 167SAVER_MODULE(logo_saver, logo_module); 168