xref: /netbsd-src/sys/arch/hpc/stand/hpcboot/framebuffer.cpp (revision ce099b40997c43048fb78bd578195f81d2456523)
1*ce099b40Smartin /* -*-C++-*-	$NetBSD: framebuffer.cpp,v 1.12 2008/04/28 20:23:20 martin 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  *
199173eae7Such  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
209173eae7Such  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
219173eae7Such  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
229173eae7Such  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
239173eae7Such  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
249173eae7Such  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
259173eae7Such  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
269173eae7Such  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
279173eae7Such  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
289173eae7Such  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
299173eae7Such  * POSSIBILITY OF SUCH DAMAGE.
309173eae7Such  */
319173eae7Such 
329173eae7Such #include <hpcmenu.h>
339173eae7Such #include <machine/bootinfo.h>
349173eae7Such #include <machine/platid.h>
359173eae7Such #include <machine/platid_mask.h>
369173eae7Such 
379173eae7Such #include <framebuffer.h>
389173eae7Such 
39bf58a25fSuch //
40bf58a25fSuch // framebuffer configuration table can be found in machine_config.cpp
41bf58a25fSuch //
429173eae7Such 
FrameBufferInfo(uint32_t cpu,uint32_t machine)4324c8a902Suwe FrameBufferInfo::FrameBufferInfo(uint32_t cpu, uint32_t machine)
449173eae7Such {
459173eae7Such 	struct framebuffer_info *tab = _table;
46bf58a25fSuch 	platid_mask_t target, entry;
477b262bfeSuch 	framebuffer_info *alt = 0;
487b262bfeSuch 
497b262bfeSuch 	// get current bpp.
507b262bfeSuch 	HDC hdc = GetDC(0);
517b262bfeSuch 	int bpp = GetDeviceCaps(hdc, BITSPIXEL);
527b262bfeSuch 	ReleaseDC(0, hdc);
539173eae7Such 
54bf58a25fSuch 	target.dw.dw0 = cpu;
55bf58a25fSuch 	target.dw.dw1 = machine;
569173eae7Such 	// search apriori setting if any.
57bf58a25fSuch 	for (; tab->cpu; tab++) {
58bf58a25fSuch 		entry.dw.dw0 = tab->cpu;
59bf58a25fSuch 		entry.dw.dw1 = tab->machine;
60bf58a25fSuch 		if (platid_match(&target, &entry)) {
617b262bfeSuch 			if (tab->bpp == bpp) {
629173eae7Such 				_fb = tab;
639173eae7Such 				return;
647b262bfeSuch 			} else {
657b262bfeSuch 				alt = tab;
667b262bfeSuch 			}
679173eae7Such 		}
68bf58a25fSuch 	}
699173eae7Such 
707b262bfeSuch 	// use alternative framebuffer setting, if any.
717b262bfeSuch 	if (alt) {
727b262bfeSuch 		_fb = alt;
737b262bfeSuch 		return;
747b262bfeSuch 	}
757b262bfeSuch 
767b262bfeSuch 	// no apriori setting. fill default.
779173eae7Such 	memset(&_default, 0, sizeof(struct framebuffer_info));
789173eae7Such 
799173eae7Such 	_default.cpu = cpu;
809173eae7Such 	_default.machine = machine;
817b262bfeSuch 	hdc = GetDC(0);
827b262bfeSuch 	_default.bpp = bpp;
839173eae7Such 	_default.width = GetDeviceCaps(hdc, HORZRES);
849173eae7Such 	_default.height = GetDeviceCaps(hdc, VERTRES);
859173eae7Such 	ReleaseDC(0, hdc);
869173eae7Such 	_fb = &_default;
879173eae7Such }
889173eae7Such 
~FrameBufferInfo()899173eae7Such FrameBufferInfo::~FrameBufferInfo()
909173eae7Such {
919173eae7Such 	/* NO-OP */
929173eae7Such }
939173eae7Such 
949173eae7Such int
type()959173eae7Such FrameBufferInfo::type()
969173eae7Such {
97bd926f64Such 	BOOL reverse = HPC_PREFERENCE.reverse_video;
989173eae7Such 	int type;
999173eae7Such 
1009173eae7Such 	switch(_fb->bpp) {
1019173eae7Such 	default:
1029173eae7Such 		// FALLTHROUGH
1039173eae7Such 	case 2:
10424beb5ffSuch 		type = reverse ? BIFB_D2_M2L_3 : BIFB_D2_M2L_0;
10524beb5ffSuch 		break;
10624beb5ffSuch 	case 4:
10724beb5ffSuch 		type = reverse ? BIFB_D4_M2L_F : BIFB_D4_M2L_0;
1089173eae7Such 		break;
1099173eae7Such 	case 8:
11024beb5ffSuch 		type = reverse ? BIFB_D8_FF : BIFB_D8_00;
1119173eae7Such 		break;
1129173eae7Such 	case 16:
11324beb5ffSuch 		type = reverse ? BIFB_D16_FFFF : BIFB_D16_0000;
1149173eae7Such 		break;
1159173eae7Such 	}
1169173eae7Such 
1179173eae7Such 	return type;
1189173eae7Such }
119