xref: /openbsd-src/sys/dev/ic/vga_subr.c (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1 /* $OpenBSD: vga_subr.c,v 1.1 2000/11/15 20:17:38 aaron Exp $ */
2 /* $NetBSD: vga_subr.c,v 1.6 2000/01/25 02:44:03 ad Exp $ */
3 
4 /*
5  * Copyright (c) 1998
6  *	Matthias Drochner.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed for the NetBSD Project
19  *	by Matthias Drochner.
20  * 4. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  */
35 
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39 #include <sys/queue.h>
40 #include <machine/bus.h>
41 
42 #include <dev/ic/mc6845reg.h>
43 #include <dev/ic/pcdisplayvar.h>
44 #include <dev/ic/vgareg.h>
45 #include <dev/ic/vgavar.h>
46 
47 #include <dev/wscons/wsdisplayvar.h>
48 
49 static void fontram __P((struct vga_handle *));
50 static void textram __P((struct vga_handle *));
51 
52 static void
53 fontram(vh)
54 	struct vga_handle *vh;
55 {
56 	/* program sequencer to access character generator */
57 
58 	vga_ts_write(vh, syncreset, 0x01);	/* synchronous reset */
59 	vga_ts_write(vh, wrplmask, 0x04);	/* write to map 2 */
60 	vga_ts_write(vh, memmode, 0x07);	/* sequential addressing */
61 	vga_ts_write(vh, syncreset, 0x03);	/* clear synchronous reset */
62 
63 	/* program graphics controller to access character generator */
64 
65 	vga_gdc_write(vh, rdplanesel, 0x02);	/* select map 2 for cpu reads */
66 	vga_gdc_write(vh, mode, 0x00);	/* disable odd-even addressing */
67 	vga_gdc_write(vh, misc, 0x04);	/* map starts at 0xA000 */
68 }
69 
70 static void
71 textram(vh)
72 	struct vga_handle *vh;
73 {
74 	/* program sequencer to access video ram */
75 
76 	vga_ts_write(vh, syncreset, 0x01);	/* synchronous reset */
77 	vga_ts_write(vh, wrplmask, 0x03);	/* write to map 0 & 1 */
78 	vga_ts_write(vh, memmode, 0x03);	/* odd-even addressing */
79 	vga_ts_write(vh, syncreset, 0x03);	/* clear synchronous reset */
80 
81 	/* program graphics controller for text mode */
82 
83 	vga_gdc_write(vh, rdplanesel, 0x00);	/* select map 0 for cpu reads */
84 	vga_gdc_write(vh, mode, 0x10);		/* enable odd-even addressing */
85 	/* map starts at 0xb800 or 0xb000 (mono) */
86 	vga_gdc_write(vh, misc, (vh->vh_mono ? 0x0a : 0x0e));
87 }
88 
89 void
90 vga_loadchars(vh, fontset, first, num, lpc, data)
91 	struct vga_handle *vh;
92 	int fontset, first, num;
93 	int lpc;
94 	char *data;
95 {
96 	int offset, i, j, s;
97 
98 	/* fontset number swizzle done in vga_setfontset() */
99 	offset = (fontset << 13) | (first << 5);
100 
101 	s = splhigh();
102 	fontram(vh);
103 
104 	for (i = 0; i < num; i++)
105 		for (j = 0; j < lpc; j++)
106 			bus_space_write_1(vh->vh_memt, vh->vh_allmemh,
107 					  offset + (i << 5) + j,
108 					  data[i * lpc + j]);
109 
110 	textram(vh);
111 	splx(s);
112 }
113 
114 void
115 vga_setfontset(vh, fontset1, fontset2)
116 	struct vga_handle *vh;
117 	int fontset1, fontset2;
118 {
119 	u_int8_t cmap;
120 	static u_int8_t cmaptaba[] = {
121 		0x00, 0x10, 0x01, 0x11,
122 		0x02, 0x12, 0x03, 0x13
123 	};
124 	static u_int8_t cmaptabb[] = {
125 		0x00, 0x20, 0x04, 0x24,
126 		0x08, 0x28, 0x0c, 0x2c
127 	};
128 
129 	/* extended font if fontset1 != fontset2 */
130 	cmap = cmaptaba[fontset1] | cmaptabb[fontset2];
131 
132 	vga_ts_write(vh, fontsel, cmap);
133 }
134 
135 void
136 vga_setscreentype(vh, type)
137 	struct vga_handle *vh;
138 	const struct wsscreen_descr *type;
139 {
140 	vga_6845_write(vh, maxrow, type->fontheight - 1);
141 
142 	/* lo byte */
143 	vga_6845_write(vh, vde, type->fontheight * type->nrows - 1);
144 
145 #ifndef PCDISPLAY_SOFTCURSOR
146 	/* set cursor to last 2 lines */
147 	vga_6845_write(vh, curstart, type->fontheight - 2);
148 	vga_6845_write(vh, curend, type->fontheight - 1);
149 #endif
150 	/*
151 	 * disable colour plane 3 if needed for font selection
152 	 */
153 	if (type->capabilities & WSSCREEN_HILIT) {
154 		/*
155 		 * these are the screens which don't support
156 		 * 512-character fonts
157 		 */
158 		vga_attr_write(vh, colplen, 0x0f);
159 	} else
160 		vga_attr_write(vh, colplen, 0x07);
161 }
162