logo_saver.c revision 117833
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 117833 2003-07-21 13:04:54Z nyan $ 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{ 104117833Snyan int 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); 118117833Snyan (*vidsw[adp->va_index]->clear)(adp); 11986120Sdes } 12086120Sdes logo_update(adp); 12186120Sdes } else { 12286120Sdes blanked = 0; 12342120Sdes } 12486120Sdes return (0); 12542120Sdes} 12642120Sdes 12742120Sdesstatic int 12842504Syokotalogo_init(video_adapter_t *adp) 12942120Sdes{ 13086120Sdes video_info_t info; 13186120Sdes 13286120Sdes if (!get_mode_info(adp, M_VESA_CG800x600, &info)) { 13386120Sdes scrmode = M_VESA_CG800x600; 13486120Sdes } else if (!get_mode_info(adp, M_VGA_CG320, &info)) { 13586120Sdes scrmode = M_VGA_CG320; 13693011Samorita } else if (!get_mode_info(adp, M_PC98_PEGC640x480, &info)) { 13793011Samorita scrmode = M_PC98_PEGC640x480; 13893011Samorita } else if (!get_mode_info(adp, M_PC98_PEGC640x400, &info)) { 13993011Samorita scrmode = M_PC98_PEGC640x400; 14086120Sdes } else { 14186120Sdes log(LOG_NOTICE, 14286120Sdes "%s: the console does not support M_VGA_CG320\n", 14386120Sdes SAVER_NAME); 14486120Sdes return (ENODEV); 14586120Sdes } 14686120Sdes 14786120Sdes scrw = info.vi_width; 14886120Sdes scrh = info.vi_height; 14986120Sdes 15086120Sdes return (0); 15142120Sdes} 15242120Sdes 15342120Sdesstatic int 15442504Syokotalogo_term(video_adapter_t *adp) 15542120Sdes{ 15686120Sdes return (0); 15742120Sdes} 15842120Sdes 15942504Syokotastatic scrn_saver_t logo_module = { 16086120Sdes SAVER_NAME, 16186120Sdes logo_init, 16286120Sdes logo_term, 16386120Sdes logo_saver, 16486120Sdes NULL 16542504Syokota}; 16642504Syokota 16742504SyokotaSAVER_MODULE(logo_saver, logo_module); 168