xref: /netbsd-src/sys/arch/hpc/stand/hpcboot/framebuffer.cpp (revision 17dd36da8292193180754d5047c0926dbb56818c)
1 /* -*-C++-*-	$NetBSD: framebuffer.cpp,v 1.6 2001/03/25 17:14:04 uch Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by UCHIYAMA Yasushi.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include <hpcmenu.h>
40 #include <machine/bootinfo.h>
41 #include <machine/platid.h>
42 #include <machine/platid_mask.h>
43 
44 #include <framebuffer.h>
45 
46 //
47 // framebuffer configuration table can be found in machine_config.cpp
48 //
49 
50 FrameBufferInfo::FrameBufferInfo(u_int32_t cpu, u_int32_t machine)
51 {
52 	struct framebuffer_info *tab = _table;
53 	platid_mask_t target, entry;
54 
55 	target.dw.dw0 = cpu;
56 	target.dw.dw1 = machine;
57 	// search apriori setting if any.
58 	for (; tab->cpu; tab++) {
59 		entry.dw.dw0 = tab->cpu;
60 		entry.dw.dw1 = tab->machine;
61 		if (platid_match(&target, &entry)) {
62 			_fb = tab;
63 			return;
64 		}
65 	}
66 
67 	// fill default setting.
68 	memset(&_default, 0, sizeof(struct framebuffer_info));
69 
70 	_default.cpu = cpu;
71 	_default.machine = machine;
72 	HDC hdc = GetDC(0);
73 	_default.bpp = GetDeviceCaps(hdc, BITSPIXEL);
74 	_default.width = GetDeviceCaps(hdc, HORZRES);
75 	_default.height = GetDeviceCaps(hdc, VERTRES);
76 	ReleaseDC(0, hdc);
77 	_fb = &_default;
78 }
79 
80 FrameBufferInfo::~FrameBufferInfo()
81 {
82 	/* NO-OP */
83 }
84 
85 int
86 FrameBufferInfo::type()
87 {
88 	HpcMenuInterface &menu = HpcMenuInterface::Instance();
89 	BOOL reverse = menu._pref.reverse_video;
90 	int type;
91 
92 	switch(_fb->bpp) {
93 	default:
94 		// FALLTHROUGH
95 	case 2:
96 		type = reverse ? BIFB_D2_M2L_3 : BIFB_D2_M2L_0;
97 		break;
98 	case 4:
99 		type = reverse ? BIFB_D4_M2L_F : BIFB_D4_M2L_0;
100 		break;
101 	case 8:
102 		type = reverse ? BIFB_D8_FF : BIFB_D8_00;
103 		break;
104 	case 16:
105 		type = reverse ? BIFB_D16_FFFF : BIFB_D16_0000;
106 		break;
107 	}
108 
109 	return type;
110 }
111