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: src/sys/modules/syscons/logo/logo_saver.c,v 1.8 1999/08/28 00:47:51 peter Exp $ 29 * $DragonFly: src/sys/dev/misc/syscons/logo/logo_saver.c,v 1.4 2005/06/11 00:26:48 dillon Exp $ 30 */ 31 32 #include <sys/param.h> 33 #include <sys/systm.h> 34 #include <sys/kernel.h> 35 #include <sys/module.h> 36 #include <sys/syslog.h> 37 #include <sys/consio.h> 38 #include <sys/fbio.h> 39 #include <sys/thread.h> 40 #include <sys/thread2.h> 41 42 #include <dev/video/fb/fbreg.h> 43 #include <dev/video/fb/splashreg.h> 44 #include "../syscons.h" 45 46 static u_char *vid; 47 static int banksize, scrmode, bpsl, scrw, scrh; 48 static int blanked; 49 50 #include "logo.c" 51 52 static void 53 logo_blit(video_adapter_t *adp, int x, int y) 54 { 55 int d, l, o, p; 56 57 for (o = 0, p = y * bpsl + x; p > banksize; p -= banksize) 58 o += banksize; 59 set_origin(adp, o); 60 61 for (d = 0; d < sizeof logo_img; d += logo_w) { 62 if (p + logo_w < banksize) { 63 bcopy(logo_img + d, vid + p, logo_w); 64 p += bpsl; 65 } else if (p < banksize) { 66 l = banksize - p; 67 bcopy(logo_img + d, vid + p, l); 68 set_origin(adp, (o += banksize)); 69 bcopy(logo_img + d + l, vid, logo_w - l); 70 p += bpsl - banksize; 71 } else { 72 p -= banksize; 73 set_origin(adp, (o += banksize)); 74 bcopy(logo_img + d, vid + p, logo_w); 75 p += bpsl; 76 } 77 } 78 } 79 80 static void 81 logo_update(video_adapter_t *adp) 82 { 83 static int xpos = 0, ypos = 0; 84 static int xinc = 1, yinc = 1; 85 86 /* Turn when you hit the edge */ 87 if ((xpos + logo_w + xinc > scrw) || (xpos + xinc < 0)) 88 xinc = -xinc; 89 if ((ypos + logo_h + yinc > scrh) || (ypos + yinc < 0)) 90 yinc = -yinc; 91 xpos += xinc; 92 ypos += yinc; 93 94 /* XXX Relies on margin around logo to erase trail */ 95 logo_blit(adp, xpos, ypos); 96 } 97 98 static int 99 logo_saver(video_adapter_t *adp, int blank) 100 { 101 int i; 102 103 if (blank) { 104 /* switch to graphics mode */ 105 if (blanked <= 0) { 106 crit_enter(); 107 set_video_mode(adp, scrmode); 108 load_palette(adp, logo_pal); 109 #if 0 /* XXX conflict */ 110 set_border(adp, 0); 111 #endif 112 blanked++; 113 vid = (u_char *)adp->va_window; 114 banksize = adp->va_window_size; 115 bpsl = adp->va_line_width; 116 crit_exit(); 117 for (i = 0; i < bpsl*scrh; i += banksize) { 118 set_origin(adp, i); 119 bzero(vid, banksize); 120 } 121 } 122 logo_update(adp); 123 } else { 124 blanked = 0; 125 } 126 return 0; 127 } 128 129 static int 130 logo_init(video_adapter_t *adp) 131 { 132 video_info_t info; 133 134 if (!get_mode_info(adp, M_VESA_CG800x600, &info)) { 135 scrmode = M_VESA_CG800x600; 136 } else if (!get_mode_info(adp, M_VGA_CG320, &info)) { 137 scrmode = M_VGA_CG320; 138 } else { 139 log(LOG_NOTICE, "logo_saver: no suitable graphics mode\n"); 140 return ENODEV; 141 } 142 143 scrw = info.vi_width; 144 scrh = info.vi_height; 145 blanked = 0; 146 147 return 0; 148 } 149 150 static int 151 logo_term(video_adapter_t *adp) 152 { 153 return 0; 154 } 155 156 static scrn_saver_t logo_module = { 157 "logo_saver", logo_init, logo_term, logo_saver, NULL, 158 }; 159 160 SAVER_MODULE(logo_saver, logo_module); 161