xref: /freebsd/sys/dev/syscons/fade/fade_saver.c (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
117ee9d00SSøren Schmidt /*-
2*718cf2ccSPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*718cf2ccSPedro F. Giffuni  *
49a14aa01SUlrich Spörlein  * Copyright (c) 1995-1998 Søren Schmidt
517ee9d00SSøren Schmidt  * All rights reserved.
617ee9d00SSøren Schmidt  *
717ee9d00SSøren Schmidt  * Redistribution and use in source and binary forms, with or without
817ee9d00SSøren Schmidt  * modification, are permitted provided that the following conditions
917ee9d00SSøren Schmidt  * are met:
1017ee9d00SSøren Schmidt  * 1. Redistributions of source code must retain the above copyright
11a8445737SSøren Schmidt  *    notice, this list of conditions and the following disclaimer,
12a8445737SSøren Schmidt  *    without modification, immediately at the beginning of the file.
1317ee9d00SSøren Schmidt  * 2. Redistributions in binary form must reproduce the above copyright
1417ee9d00SSøren Schmidt  *    notice, this list of conditions and the following disclaimer in the
1517ee9d00SSøren Schmidt  *    documentation and/or other materials provided with the distribution.
1617ee9d00SSøren Schmidt  * 3. The name of the author may not be used to endorse or promote products
17a8445737SSøren Schmidt  *    derived from this software without specific prior written permission.
1817ee9d00SSøren Schmidt  *
1917ee9d00SSøren Schmidt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2017ee9d00SSøren Schmidt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2117ee9d00SSøren Schmidt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2217ee9d00SSøren Schmidt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2317ee9d00SSøren Schmidt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2417ee9d00SSøren Schmidt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2517ee9d00SSøren Schmidt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2617ee9d00SSøren Schmidt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2717ee9d00SSøren Schmidt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2817ee9d00SSøren Schmidt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 
442ad872c5SKazutaka YOKOTA static int
fade_saver(video_adapter_t * adp,int blank)452ad872c5SKazutaka YOKOTA fade_saver(video_adapter_t *adp, int blank)
4617ee9d00SSøren Schmidt {
4717ee9d00SSøren Schmidt 	static int count = 0;
48d74e86d9SSøren Schmidt 	u_char pal[256*3];
4917ee9d00SSøren Schmidt 	int i;
5017ee9d00SSøren Schmidt 
5117ee9d00SSøren Schmidt 	if (blank) {
526e8394b8SKazutaka YOKOTA 		if (ISPALAVAIL(adp->va_flags)) {
532ad872c5SKazutaka YOKOTA 			if (count <= 0)
549336e069SWojciech A. Koszek 				vidd_save_palette(adp, palette);
556e8394b8SKazutaka YOKOTA 			if (count < 256) {
56d74e86d9SSøren Schmidt 				pal[0] = pal[1] = pal[2] = 0;
57d74e86d9SSøren Schmidt 				for (i = 3; i < 256*3; i++) {
58d74e86d9SSøren Schmidt 					if (palette[i] - count > 60)
59d74e86d9SSøren Schmidt 						pal[i] = palette[i] - count;
6017ee9d00SSøren Schmidt 					else
61d74e86d9SSøren Schmidt 						pal[i] = 60;
6217ee9d00SSøren Schmidt 				}
639336e069SWojciech A. Koszek 				vidd_load_palette(adp, pal);
6417ee9d00SSøren Schmidt 				count++;
6517ee9d00SSøren Schmidt 			}
666e8394b8SKazutaka YOKOTA 		} else {
679336e069SWojciech A. Koszek 	    		vidd_blank_display(adp, V_DISPLAY_BLANK);
680de89efeSKazutaka YOKOTA 		}
696e8394b8SKazutaka YOKOTA 	} else {
706e8394b8SKazutaka YOKOTA 		if (ISPALAVAIL(adp->va_flags)) {
719336e069SWojciech A. Koszek 			vidd_load_palette(adp, palette);
720de89efeSKazutaka YOKOTA 			count = 0;
736e8394b8SKazutaka YOKOTA 		} else {
749336e069SWojciech A. Koszek 	    		vidd_blank_display(adp, V_DISPLAY_ON);
750de89efeSKazutaka YOKOTA 		}
7617ee9d00SSøren Schmidt 	}
772ad872c5SKazutaka YOKOTA 	return 0;
7817ee9d00SSøren Schmidt }
7917ee9d00SSøren Schmidt 
80b3e24f9cSBruce Evans static int
fade_init(video_adapter_t * adp)812ad872c5SKazutaka YOKOTA fade_init(video_adapter_t *adp)
8217ee9d00SSøren Schmidt {
839336e069SWojciech A. Koszek 	if (!ISPALAVAIL(adp->va_flags) &&
849336e069SWojciech A. Koszek 	    vidd_blank_display(adp, V_DISPLAY_ON) != 0)
850de89efeSKazutaka YOKOTA 		return ENODEV;
862ad872c5SKazutaka YOKOTA 	return 0;
8717ee9d00SSøren Schmidt }
8817ee9d00SSøren Schmidt 
89b3e24f9cSBruce Evans static int
fade_term(video_adapter_t * adp)902ad872c5SKazutaka YOKOTA fade_term(video_adapter_t *adp)
9117ee9d00SSøren Schmidt {
922ad872c5SKazutaka YOKOTA 	return 0;
9317ee9d00SSøren Schmidt }
9417ee9d00SSøren Schmidt 
952ad872c5SKazutaka YOKOTA static scrn_saver_t fade_module = {
962ad872c5SKazutaka YOKOTA 	"fade_saver", fade_init, fade_term, fade_saver, NULL,
972ad872c5SKazutaka YOKOTA };
982ad872c5SKazutaka YOKOTA 
992ad872c5SKazutaka YOKOTA SAVER_MODULE(fade_saver, fade_module);
100