142120Sdes/*- 2230132Suqs * 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: releng/10.3/sys/dev/syscons/logo/logo_saver.c 230132 2012-01-15 13:23:18Z uqs $ 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 45166868Sphilip#define SET_ORIGIN(adp, o) do { \ 46166868Sphilip int oo = o; \ 47166868Sphilip if (oo != last_origin) \ 48174985Swkoszek vidd_set_win_org(adp, last_origin = oo); \ 49166868Sphilip } while (0) 50166868Sphilip 5186120Sdesextern unsigned int logo_w; 5286120Sdesextern unsigned int logo_h; 5386120Sdesextern unsigned char logo_pal[]; 5486120Sdesextern unsigned char logo_img[]; 5586120Sdesextern unsigned int logo_img_size; 5642120Sdes 5786120Sdesstatic u_char *vid; 5886120Sdesstatic int banksize, scrmode, bpsl, scrw, scrh; 5986120Sdesstatic int blanked; 6086120Sdes 6142120Sdesstatic void 6242504Syokotalogo_blit(video_adapter_t *adp, int x, int y) 6342120Sdes{ 6486120Sdes int d, l, o, p; 65166868Sphilip int last_origin = -1; 6686120Sdes 6786120Sdes for (o = 0, p = y * bpsl + x; p > banksize; p -= banksize) 6886120Sdes o += banksize; 69166868Sphilip SET_ORIGIN(adp, o); 7086120Sdes 7186120Sdes for (d = 0; d < logo_img_size; d += logo_w) { 7286120Sdes if (p + logo_w < banksize) { 7386120Sdes bcopy(logo_img + d, vid + p, logo_w); 7486120Sdes p += bpsl; 7586120Sdes } else if (p < banksize) { 7686120Sdes l = banksize - p; 7786120Sdes bcopy(logo_img + d, vid + p, l); 78166868Sphilip SET_ORIGIN(adp, (o += banksize)); 7986120Sdes bcopy(logo_img + d + l, vid, logo_w - l); 8086120Sdes p += bpsl - banksize; 8186120Sdes } else { 8286120Sdes p -= banksize; 83166868Sphilip SET_ORIGIN(adp, (o += banksize)); 8486120Sdes bcopy(logo_img + d, vid + p, logo_w); 8586120Sdes p += bpsl; 8686120Sdes } 8742120Sdes } 8842120Sdes} 8942120Sdes 9042120Sdesstatic void 9142504Syokotalogo_update(video_adapter_t *adp) 9242120Sdes{ 9386120Sdes static int xpos = 0, ypos = 0; 9486120Sdes static int xinc = 1, yinc = 1; 9542120Sdes 9686120Sdes /* Turn when you hit the edge */ 9786120Sdes if ((xpos + logo_w + xinc > scrw) || (xpos + xinc < 0)) 9886120Sdes xinc = -xinc; 9986120Sdes if ((ypos + logo_h + yinc > scrh) || (ypos + yinc < 0)) 10086120Sdes yinc = -yinc; 10186120Sdes xpos += xinc; 10286120Sdes ypos += yinc; 10386120Sdes 10486120Sdes /* XXX Relies on margin around logo to erase trail */ 10586120Sdes logo_blit(adp, xpos, ypos); 10642120Sdes} 10742120Sdes 10842504Syokotastatic int 10942504Syokotalogo_saver(video_adapter_t *adp, int blank) 11042120Sdes{ 111117833Snyan int pl; 11286120Sdes 11386120Sdes if (blank) { 11486120Sdes /* switch to graphics mode */ 11586120Sdes if (blanked <= 0) { 11686120Sdes pl = splhigh(); 117174985Swkoszek vidd_set_mode(adp, scrmode); 118174985Swkoszek vidd_load_palette(adp, logo_pal); 119174985Swkoszek vidd_set_border(adp, 0); 12086120Sdes blanked++; 12186120Sdes vid = (u_char *)adp->va_window; 12286120Sdes banksize = adp->va_window_size; 12386120Sdes bpsl = adp->va_line_width; 12486120Sdes splx(pl); 125174985Swkoszek vidd_clear(adp); 12686120Sdes } 12786120Sdes logo_update(adp); 12886120Sdes } else { 12986120Sdes blanked = 0; 13042120Sdes } 13186120Sdes return (0); 13242120Sdes} 13342120Sdes 13442120Sdesstatic int 13542504Syokotalogo_init(video_adapter_t *adp) 13642120Sdes{ 13786120Sdes video_info_t info; 13886120Sdes 139174985Swkoszek if (!vidd_get_info(adp, M_VESA_CG800x600, &info)) { 14086120Sdes scrmode = M_VESA_CG800x600; 141174985Swkoszek } else if (!vidd_get_info(adp, M_VGA_CG320, &info)) { 14286120Sdes scrmode = M_VGA_CG320; 143174985Swkoszek } else if (!vidd_get_info(adp, M_PC98_PEGC640x480, &info)) { 14493011Samorita scrmode = M_PC98_PEGC640x480; 145174985Swkoszek } else if (!vidd_get_info(adp, M_PC98_PEGC640x400, &info)) { 14693011Samorita scrmode = M_PC98_PEGC640x400; 14786120Sdes } else { 14886120Sdes log(LOG_NOTICE, 14986120Sdes "%s: the console does not support M_VGA_CG320\n", 15086120Sdes SAVER_NAME); 15186120Sdes return (ENODEV); 15286120Sdes } 15386120Sdes 15486120Sdes scrw = info.vi_width; 15586120Sdes scrh = info.vi_height; 15686120Sdes 15786120Sdes return (0); 15842120Sdes} 15942120Sdes 16042120Sdesstatic int 16142504Syokotalogo_term(video_adapter_t *adp) 16242120Sdes{ 16386120Sdes return (0); 16442120Sdes} 16542120Sdes 16642504Syokotastatic scrn_saver_t logo_module = { 16786120Sdes SAVER_NAME, 16886120Sdes logo_init, 16986120Sdes logo_term, 17086120Sdes logo_saver, 17186120Sdes NULL 17242504Syokota}; 17342504Syokota 174206380Sjkim#ifdef BEASTIE_LOGO 175206380SjkimSAVER_MODULE(beastie_saver, logo_module); 176206380Sjkim#else 17742504SyokotaSAVER_MODULE(logo_saver, logo_module); 178206380Sjkim#endif 179