logo_saver.c revision 93011
142120Sdes/*- 242120Sdes * Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav 342120Sdes * All rights reserved. 442120Sdes * 542120Sdes * Redistribution and use in source and binary forms, with or without 642120Sdes * modification, are permitted provided that the following conditions 742120Sdes * are met: 842120Sdes * 1. Redistributions of source code must retain the above copyright 942120Sdes * notice, this list of conditions and the following disclaimer 1042120Sdes * in this position and unchanged. 1142120Sdes * 2. Redistributions in binary form must reproduce the above copyright 1242120Sdes * notice, this list of conditions and the following disclaimer in the 1342120Sdes * documentation and/or other materials provided with the distribution. 1442120Sdes * 3. The name of the author may not be used to endorse or promote products 1542120Sdes * derived from this software without specific prior written permission 1642120Sdes * 1742120Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1842120Sdes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1942120Sdes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2042120Sdes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2142120Sdes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2242120Sdes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2342120Sdes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2442120Sdes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2542120Sdes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2642120Sdes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2742120Sdes * 2850477Speter * $FreeBSD: head/sys/dev/syscons/logo/logo_saver.c 93011 2002-03-23 12:36:19Z amorita $ 2942120Sdes */ 3042120Sdes 3142120Sdes#include <sys/param.h> 3242120Sdes#include <sys/systm.h> 3342120Sdes#include <sys/kernel.h> 3442120Sdes#include <sys/module.h> 3542120Sdes#include <sys/syslog.h> 3648104Syokota#include <sys/consio.h> 3748104Syokota#include <sys/fbio.h> 3842120Sdes 3948104Syokota#include <dev/fb/fbreg.h> 4048104Syokota#include <dev/fb/splashreg.h> 4148104Syokota#include <dev/syscons/syscons.h> 4242120Sdes 4386120Sdes#define SAVER_NAME "logo_saver" 4442120Sdes 4586120Sdesextern unsigned int logo_w; 4686120Sdesextern unsigned int logo_h; 4786120Sdesextern unsigned char logo_pal[]; 4886120Sdesextern unsigned char logo_img[]; 4986120Sdesextern unsigned int logo_img_size; 5042120Sdes 5186120Sdesstatic u_char *vid; 5286120Sdesstatic int banksize, scrmode, bpsl, scrw, scrh; 5386120Sdesstatic int blanked; 5486120Sdes 5542120Sdesstatic void 5642504Syokotalogo_blit(video_adapter_t *adp, int x, int y) 5742120Sdes{ 5886120Sdes int d, l, o, p; 5986120Sdes 6086120Sdes for (o = 0, p = y * bpsl + x; p > banksize; p -= banksize) 6186120Sdes o += banksize; 6286120Sdes set_origin(adp, o); 6386120Sdes 6486120Sdes for (d = 0; d < logo_img_size; d += logo_w) { 6586120Sdes if (p + logo_w < banksize) { 6686120Sdes bcopy(logo_img + d, vid + p, logo_w); 6786120Sdes p += bpsl; 6886120Sdes } else if (p < banksize) { 6986120Sdes l = banksize - p; 7086120Sdes bcopy(logo_img + d, vid + p, l); 7186120Sdes set_origin(adp, (o += banksize)); 7286120Sdes bcopy(logo_img + d + l, vid, logo_w - l); 7386120Sdes p += bpsl - banksize; 7486120Sdes } else { 7586120Sdes p -= banksize; 7686120Sdes set_origin(adp, (o += banksize)); 7786120Sdes bcopy(logo_img + d, vid + p, logo_w); 7886120Sdes p += bpsl; 7986120Sdes } 8042120Sdes } 8142120Sdes} 8242120Sdes 8342120Sdesstatic void 8442504Syokotalogo_update(video_adapter_t *adp) 8542120Sdes{ 8686120Sdes static int xpos = 0, ypos = 0; 8786120Sdes static int xinc = 1, yinc = 1; 8842120Sdes 8986120Sdes /* Turn when you hit the edge */ 9086120Sdes if ((xpos + logo_w + xinc > scrw) || (xpos + xinc < 0)) 9186120Sdes xinc = -xinc; 9286120Sdes if ((ypos + logo_h + yinc > scrh) || (ypos + yinc < 0)) 9386120Sdes yinc = -yinc; 9486120Sdes xpos += xinc; 9586120Sdes ypos += yinc; 9686120Sdes 9786120Sdes /* XXX Relies on margin around logo to erase trail */ 9886120Sdes logo_blit(adp, xpos, ypos); 9942120Sdes} 10042120Sdes 10142504Syokotastatic int 10242504Syokotalogo_saver(video_adapter_t *adp, int blank) 10342120Sdes{ 10486120Sdes int i, pl; 10586120Sdes 10686120Sdes if (blank) { 10786120Sdes /* switch to graphics mode */ 10886120Sdes if (blanked <= 0) { 10986120Sdes pl = splhigh(); 11086120Sdes set_video_mode(adp, scrmode); 11186120Sdes load_palette(adp, logo_pal); 11286120Sdes set_border(adp, 0); 11386120Sdes blanked++; 11486120Sdes vid = (u_char *)adp->va_window; 11586120Sdes banksize = adp->va_window_size; 11686120Sdes bpsl = adp->va_line_width; 11786120Sdes splx(pl); 11886120Sdes for (i = 0; i < bpsl * scrh; i += banksize) { 11986120Sdes set_origin(adp, i); 12086120Sdes bzero(vid, banksize); 12186120Sdes } 12286120Sdes } 12386120Sdes logo_update(adp); 12486120Sdes } else { 12586120Sdes blanked = 0; 12642120Sdes } 12786120Sdes return (0); 12842120Sdes} 12942120Sdes 13042120Sdesstatic int 13142504Syokotalogo_init(video_adapter_t *adp) 13242120Sdes{ 13386120Sdes video_info_t info; 13486120Sdes 13586120Sdes if (!get_mode_info(adp, M_VESA_CG800x600, &info)) { 13686120Sdes scrmode = M_VESA_CG800x600; 13786120Sdes } else if (!get_mode_info(adp, M_VGA_CG320, &info)) { 13886120Sdes scrmode = M_VGA_CG320; 13993011Samorita } else if (!get_mode_info(adp, M_PC98_PEGC640x480, &info)) { 14093011Samorita scrmode = M_PC98_PEGC640x480; 14193011Samorita } else if (!get_mode_info(adp, M_PC98_PEGC640x400, &info)) { 14293011Samorita scrmode = M_PC98_PEGC640x400; 14386120Sdes } else { 14486120Sdes log(LOG_NOTICE, 14586120Sdes "%s: the console does not support M_VGA_CG320\n", 14686120Sdes SAVER_NAME); 14786120Sdes return (ENODEV); 14886120Sdes } 14986120Sdes 15086120Sdes scrw = info.vi_width; 15186120Sdes scrh = info.vi_height; 15286120Sdes 15386120Sdes return (0); 15442120Sdes} 15542120Sdes 15642120Sdesstatic int 15742504Syokotalogo_term(video_adapter_t *adp) 15842120Sdes{ 15986120Sdes return (0); 16042120Sdes} 16142120Sdes 16242504Syokotastatic scrn_saver_t logo_module = { 16386120Sdes SAVER_NAME, 16486120Sdes logo_init, 16586120Sdes logo_term, 16686120Sdes logo_saver, 16786120Sdes NULL 16842504Syokota}; 16942504Syokota 17042504SyokotaSAVER_MODULE(logo_saver, logo_module); 171