xref: /freebsd/sys/dev/syscons/fade/fade_saver.c (revision c3aac50f284c6cca5b4f2eb46aaa13812cb8b630)
117ee9d00SSøren Schmidt /*-
2a8445737SSøren Schmidt  * Copyright (c) 1995-1998 S�ren Schmidt
317ee9d00SSøren Schmidt  * All rights reserved.
417ee9d00SSøren Schmidt  *
517ee9d00SSøren Schmidt  * Redistribution and use in source and binary forms, with or without
617ee9d00SSøren Schmidt  * modification, are permitted provided that the following conditions
717ee9d00SSøren Schmidt  * are met:
817ee9d00SSøren Schmidt  * 1. Redistributions of source code must retain the above copyright
9a8445737SSøren Schmidt  *    notice, this list of conditions and the following disclaimer,
10a8445737SSøren Schmidt  *    without modification, immediately at the beginning of the file.
1117ee9d00SSøren Schmidt  * 2. Redistributions in binary form must reproduce the above copyright
1217ee9d00SSøren Schmidt  *    notice, this list of conditions and the following disclaimer in the
1317ee9d00SSøren Schmidt  *    documentation and/or other materials provided with the distribution.
1417ee9d00SSøren Schmidt  * 3. The name of the author may not be used to endorse or promote products
15a8445737SSøren Schmidt  *    derived from this software without specific prior written permission.
1617ee9d00SSøren Schmidt  *
1717ee9d00SSøren Schmidt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1817ee9d00SSøren Schmidt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1917ee9d00SSøren Schmidt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2017ee9d00SSøren Schmidt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2117ee9d00SSøren Schmidt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2217ee9d00SSøren Schmidt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2317ee9d00SSøren Schmidt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2417ee9d00SSøren Schmidt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2517ee9d00SSøren Schmidt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2617ee9d00SSøren Schmidt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2717ee9d00SSøren Schmidt  *
28c3aac50fSPeter Wemm  * $FreeBSD$
2917ee9d00SSøren Schmidt  */
3017ee9d00SSøren Schmidt 
3117ee9d00SSøren Schmidt #include <sys/param.h>
3217ee9d00SSøren Schmidt #include <sys/systm.h>
330640d357SPeter Wemm #include <sys/kernel.h>
340640d357SPeter Wemm #include <sys/module.h>
356e8394b8SKazutaka YOKOTA #include <sys/consio.h>
366e8394b8SKazutaka YOKOTA #include <sys/fbio.h>
37ce834215SKazutaka YOKOTA 
386e8394b8SKazutaka YOKOTA #include <dev/fb/fbreg.h>
396e8394b8SKazutaka YOKOTA #include <dev/fb/splashreg.h>
406e8394b8SKazutaka YOKOTA #include <dev/syscons/syscons.h>
4117ee9d00SSøren Schmidt 
422ad872c5SKazutaka YOKOTA static u_char palette[256*3];
432ad872c5SKazutaka YOKOTA static int blanked;
442ad872c5SKazutaka YOKOTA 
452ad872c5SKazutaka YOKOTA static int
462ad872c5SKazutaka YOKOTA fade_saver(video_adapter_t *adp, int blank)
4717ee9d00SSøren Schmidt {
4817ee9d00SSøren Schmidt 	static int count = 0;
49d74e86d9SSøren Schmidt 	u_char pal[256*3];
5017ee9d00SSøren Schmidt 	int i;
5117ee9d00SSøren Schmidt 
5217ee9d00SSøren Schmidt 	if (blank) {
532ad872c5SKazutaka YOKOTA 		blanked = TRUE;
546e8394b8SKazutaka YOKOTA 		if (ISPALAVAIL(adp->va_flags)) {
552ad872c5SKazutaka YOKOTA 			if (count <= 0)
562ad872c5SKazutaka YOKOTA 				save_palette(adp, palette);
576e8394b8SKazutaka YOKOTA 			if (count < 256) {
58d74e86d9SSøren Schmidt 				pal[0] = pal[1] = pal[2] = 0;
59d74e86d9SSøren Schmidt 				for (i = 3; i < 256*3; i++) {
60d74e86d9SSøren Schmidt 					if (palette[i] - count > 60)
61d74e86d9SSøren Schmidt 						pal[i] = palette[i] - count;
6217ee9d00SSøren Schmidt 					else
63d74e86d9SSøren Schmidt 						pal[i] = 60;
6417ee9d00SSøren Schmidt 				}
652ad872c5SKazutaka YOKOTA 				load_palette(adp, pal);
6617ee9d00SSøren Schmidt 				count++;
6717ee9d00SSøren Schmidt 			}
686e8394b8SKazutaka YOKOTA 		} else {
696e8394b8SKazutaka YOKOTA 	    		(*vidsw[adp->va_index]->blank_display)(adp,
706e8394b8SKazutaka YOKOTA 							       V_DISPLAY_BLANK);
710de89efeSKazutaka YOKOTA 		}
726e8394b8SKazutaka YOKOTA 	} else {
736e8394b8SKazutaka YOKOTA 		if (ISPALAVAIL(adp->va_flags)) {
742ad872c5SKazutaka YOKOTA 			load_palette(adp, palette);
750de89efeSKazutaka YOKOTA 			count = 0;
766e8394b8SKazutaka YOKOTA 		} else {
776e8394b8SKazutaka YOKOTA 	    		(*vidsw[adp->va_index]->blank_display)(adp,
786e8394b8SKazutaka YOKOTA 							       V_DISPLAY_ON);
790de89efeSKazutaka YOKOTA 		}
802ad872c5SKazutaka YOKOTA 		blanked = FALSE;
8117ee9d00SSøren Schmidt 	}
822ad872c5SKazutaka YOKOTA 	return 0;
8317ee9d00SSøren Schmidt }
8417ee9d00SSøren Schmidt 
85b3e24f9cSBruce Evans static int
862ad872c5SKazutaka YOKOTA fade_init(video_adapter_t *adp)
8717ee9d00SSøren Schmidt {
886e8394b8SKazutaka YOKOTA 	if (!ISPALAVAIL(adp->va_flags)
896e8394b8SKazutaka YOKOTA 	    && (*vidsw[adp->va_index]->blank_display)(adp, V_DISPLAY_ON) != 0)
900de89efeSKazutaka YOKOTA 		return ENODEV;
912ad872c5SKazutaka YOKOTA 	blanked = FALSE;
922ad872c5SKazutaka YOKOTA 	return 0;
9317ee9d00SSøren Schmidt }
9417ee9d00SSøren Schmidt 
95b3e24f9cSBruce Evans static int
962ad872c5SKazutaka YOKOTA fade_term(video_adapter_t *adp)
9717ee9d00SSøren Schmidt {
982ad872c5SKazutaka YOKOTA 	return 0;
9917ee9d00SSøren Schmidt }
10017ee9d00SSøren Schmidt 
1012ad872c5SKazutaka YOKOTA static scrn_saver_t fade_module = {
1022ad872c5SKazutaka YOKOTA 	"fade_saver", fade_init, fade_term, fade_saver, NULL,
1032ad872c5SKazutaka YOKOTA };
1042ad872c5SKazutaka YOKOTA 
1052ad872c5SKazutaka YOKOTA SAVER_MODULE(fade_saver, fade_module);
106