1 /* -*-C++-*-	$NetBSD: framebuffer.cpp,v 1.8 2001/06/20 17:36:00 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 	framebuffer_info *alt = 0;
55 
56 	// get current bpp.
57 	HDC hdc = GetDC(0);
58 	int bpp = GetDeviceCaps(hdc, BITSPIXEL);
59 	ReleaseDC(0, hdc);
60 
61 	target.dw.dw0 = cpu;
62 	target.dw.dw1 = machine;
63 	// search apriori setting if any.
64 	for (; tab->cpu; tab++) {
65 		entry.dw.dw0 = tab->cpu;
66 		entry.dw.dw1 = tab->machine;
67 		if (platid_match(&target, &entry)) {
68 			if (tab->bpp == bpp) {
69 				_fb = tab;
70 				return;
71 			} else {
72 				alt = tab;
73 			}
74 		}
75 	}
76 
77 	// use alternative framebuffer setting, if any.
78 	if (alt) {
79 		_fb = alt;
80 		return;
81 	}
82 
83 	// no apriori setting. fill default.
84 	memset(&_default, 0, sizeof(struct framebuffer_info));
85 
86 	_default.cpu = cpu;
87 	_default.machine = machine;
88 	hdc = GetDC(0);
89 	_default.bpp = bpp;
90 	_default.width = GetDeviceCaps(hdc, HORZRES);
91 	_default.height = GetDeviceCaps(hdc, VERTRES);
92 	ReleaseDC(0, hdc);
93 	_fb = &_default;
94 }
95 
96 FrameBufferInfo::~FrameBufferInfo()
97 {
98 	/* NO-OP */
99 }
100 
101 int
102 FrameBufferInfo::type()
103 {
104 	BOOL reverse = HPC_PREFERENCE.reverse_video;
105 	int type;
106 
107 	switch(_fb->bpp) {
108 	default:
109 		// FALLTHROUGH
110 	case 2:
111 		type = reverse ? BIFB_D2_M2L_3 : BIFB_D2_M2L_0;
112 		break;
113 	case 4:
114 		type = reverse ? BIFB_D4_M2L_F : BIFB_D4_M2L_0;
115 		break;
116 	case 8:
117 		type = reverse ? BIFB_D8_FF : BIFB_D8_00;
118 		break;
119 	case 16:
120 		type = reverse ? BIFB_D16_FFFF : BIFB_D16_0000;
121 		break;
122 	}
123 
124 	return type;
125 }
126