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