xref: /netbsd-src/sys/arch/hpc/stand/hpcboot/framebuffer.cpp (revision bd926f64c671a91f9d55422aa2553d9dc36a54c5)
1*bd926f64Such /* -*-C++-*-	$NetBSD: framebuffer.cpp,v 1.7 2001/04/24 19:27:59 uch Exp $	*/
29173eae7Such 
39173eae7Such /*-
49173eae7Such  * Copyright (c) 2001 The NetBSD Foundation, Inc.
59173eae7Such  * All rights reserved.
69173eae7Such  *
79173eae7Such  * This code is derived from software contributed to The NetBSD Foundation
89173eae7Such  * by UCHIYAMA Yasushi.
99173eae7Such  *
109173eae7Such  * Redistribution and use in source and binary forms, with or without
119173eae7Such  * modification, are permitted provided that the following conditions
129173eae7Such  * are met:
139173eae7Such  * 1. Redistributions of source code must retain the above copyright
149173eae7Such  *    notice, this list of conditions and the following disclaimer.
159173eae7Such  * 2. Redistributions in binary form must reproduce the above copyright
169173eae7Such  *    notice, this list of conditions and the following disclaimer in the
179173eae7Such  *    documentation and/or other materials provided with the distribution.
189173eae7Such  * 3. All advertising materials mentioning features or use of this software
199173eae7Such  *    must display the following acknowledgement:
209173eae7Such  *        This product includes software developed by the NetBSD
219173eae7Such  *        Foundation, Inc. and its contributors.
229173eae7Such  * 4. Neither the name of The NetBSD Foundation nor the names of its
239173eae7Such  *    contributors may be used to endorse or promote products derived
249173eae7Such  *    from this software without specific prior written permission.
259173eae7Such  *
269173eae7Such  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
279173eae7Such  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
289173eae7Such  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
299173eae7Such  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
309173eae7Such  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
319173eae7Such  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
329173eae7Such  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
339173eae7Such  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
349173eae7Such  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
359173eae7Such  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
369173eae7Such  * POSSIBILITY OF SUCH DAMAGE.
379173eae7Such  */
389173eae7Such 
399173eae7Such #include <hpcmenu.h>
409173eae7Such #include <machine/bootinfo.h>
419173eae7Such #include <machine/platid.h>
429173eae7Such #include <machine/platid_mask.h>
439173eae7Such 
449173eae7Such #include <framebuffer.h>
459173eae7Such 
46bf58a25fSuch //
47bf58a25fSuch // framebuffer configuration table can be found in machine_config.cpp
48bf58a25fSuch //
499173eae7Such 
509173eae7Such FrameBufferInfo::FrameBufferInfo(u_int32_t cpu, u_int32_t machine)
519173eae7Such {
529173eae7Such 	struct framebuffer_info *tab = _table;
53bf58a25fSuch 	platid_mask_t target, entry;
549173eae7Such 
55bf58a25fSuch 	target.dw.dw0 = cpu;
56bf58a25fSuch 	target.dw.dw1 = machine;
579173eae7Such 	// search apriori setting if any.
58bf58a25fSuch 	for (; tab->cpu; tab++) {
59bf58a25fSuch 		entry.dw.dw0 = tab->cpu;
60bf58a25fSuch 		entry.dw.dw1 = tab->machine;
61bf58a25fSuch 		if (platid_match(&target, &entry)) {
629173eae7Such 			_fb = tab;
639173eae7Such 			return;
649173eae7Such 		}
65bf58a25fSuch 	}
669173eae7Such 
679173eae7Such 	// fill default setting.
689173eae7Such 	memset(&_default, 0, sizeof(struct framebuffer_info));
699173eae7Such 
709173eae7Such 	_default.cpu = cpu;
719173eae7Such 	_default.machine = machine;
729173eae7Such 	HDC hdc = GetDC(0);
739173eae7Such 	_default.bpp = GetDeviceCaps(hdc, BITSPIXEL);
749173eae7Such 	_default.width = GetDeviceCaps(hdc, HORZRES);
759173eae7Such 	_default.height = GetDeviceCaps(hdc, VERTRES);
769173eae7Such 	ReleaseDC(0, hdc);
779173eae7Such 	_fb = &_default;
789173eae7Such }
799173eae7Such 
809173eae7Such FrameBufferInfo::~FrameBufferInfo()
819173eae7Such {
829173eae7Such 	/* NO-OP */
839173eae7Such }
849173eae7Such 
859173eae7Such int
869173eae7Such FrameBufferInfo::type()
879173eae7Such {
88*bd926f64Such 	BOOL reverse = HPC_PREFERENCE.reverse_video;
899173eae7Such 	int type;
909173eae7Such 
919173eae7Such 	switch(_fb->bpp) {
929173eae7Such 	default:
939173eae7Such 		// FALLTHROUGH
949173eae7Such 	case 2:
9524beb5ffSuch 		type = reverse ? BIFB_D2_M2L_3 : BIFB_D2_M2L_0;
9624beb5ffSuch 		break;
9724beb5ffSuch 	case 4:
9824beb5ffSuch 		type = reverse ? BIFB_D4_M2L_F : BIFB_D4_M2L_0;
999173eae7Such 		break;
1009173eae7Such 	case 8:
10124beb5ffSuch 		type = reverse ? BIFB_D8_FF : BIFB_D8_00;
1029173eae7Such 		break;
1039173eae7Such 	case 16:
10424beb5ffSuch 		type = reverse ? BIFB_D16_FFFF : BIFB_D16_0000;
1059173eae7Such 		break;
1069173eae7Such 	}
1079173eae7Such 
1089173eae7Such 	return type;
1099173eae7Such }
110