pcdisplay_subr.c revision 1.20 1 /* $NetBSD: pcdisplay_subr.c,v 1.20 2001/11/13 13:14:43 lukem Exp $ */
2
3 /*
4 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Chris G. Demetriou
8 *
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: pcdisplay_subr.c,v 1.20 2001/11/13 13:14:43 lukem Exp $");
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/device.h>
36 #include <machine/bus.h>
37
38 #include <dev/ic/mc6845reg.h>
39 #include <dev/ic/pcdisplayvar.h>
40
41 #include <dev/wscons/wsdisplayvar.h>
42
43 void
44 pcdisplay_cursor_init(scr, existing)
45 struct pcdisplayscreen *scr;
46 int existing;
47 {
48 #ifdef PCDISPLAY_SOFTCURSOR
49 bus_space_tag_t memt;
50 bus_space_handle_t memh;
51 int off;
52
53 pcdisplay_6845_write(scr->hdl, curstart, 0x10);
54 pcdisplay_6845_write(scr->hdl, curend, 0x10);
55
56 if (existing) {
57 /*
58 * This is the first screen. At this point, scr->mem is NULL
59 * (no backing store), so we can't use pcdisplay_cursor() to
60 * do this.
61 */
62 memt = scr->hdl->ph_memt;
63 memh = scr->hdl->ph_memh;
64 off = (scr->vc_crow * scr->type->ncols + scr->vc_ccol) * 2 +
65 scr->dispoffset;
66
67 scr->cursortmp = bus_space_read_2(memt, memh, off);
68 bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700);
69 } else
70 scr->cursortmp = 0;
71 #else
72 /*
73 * Firmware might not have initialized the cursor shape. Make
74 * sure there's something we can see.
75 * Don't touch the hardware if this is not the first screen.
76 */
77 if (existing) {
78 pcdisplay_6845_write(scr->hdl, curstart,
79 scr->type->fontheight - 2);
80 pcdisplay_6845_write(scr->hdl, curend,
81 scr->type->fontheight - 1);
82 }
83 #endif
84 scr->cursoron = 1;
85 }
86
87 void
88 pcdisplay_cursor(id, on, row, col)
89 void *id;
90 int on, row, col;
91 {
92 #ifdef PCDISPLAY_SOFTCURSOR
93 struct pcdisplayscreen *scr = id;
94 bus_space_tag_t memt = scr->hdl->ph_memt;
95 bus_space_handle_t memh = scr->hdl->ph_memh;
96 int off;
97
98 /* Remove old cursor image */
99 if (scr->cursoron) {
100 off = scr->vc_crow * scr->type->ncols + scr->vc_ccol;
101 if (scr->active)
102 bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
103 scr->cursortmp);
104 else
105 scr->mem[off] = scr->cursortmp;
106 }
107
108 scr->vc_crow = row;
109 scr->vc_ccol = col;
110
111 if ((scr->cursoron = on) == 0)
112 return;
113
114 off = (scr->vc_crow * scr->type->ncols + scr->vc_ccol);
115 if (scr->active) {
116 off = off * 2 + scr->dispoffset;
117 scr->cursortmp = bus_space_read_2(memt, memh, off);
118 bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700);
119 } else {
120 scr->cursortmp = scr->mem[off];
121 scr->mem[off] = scr->cursortmp ^ 0x7700;
122 }
123 #else /* PCDISPLAY_SOFTCURSOR */
124 struct pcdisplayscreen *scr = id;
125 int pos;
126
127 scr->vc_crow = row;
128 scr->vc_ccol = col;
129 scr->cursoron = on;
130
131 if (scr->active) {
132 if (!on)
133 pos = 0x3fff;
134 else
135 pos = scr->dispoffset / 2
136 + row * scr->type->ncols + col;
137
138 pcdisplay_6845_write(scr->hdl, cursorh, pos >> 8);
139 pcdisplay_6845_write(scr->hdl, cursorl, pos);
140 }
141 #endif /* PCDISPLAY_SOFTCURSOR */
142 }
143
144 #if 0
145 unsigned int
146 pcdisplay_mapchar_simple(id, uni)
147 void *id;
148 int uni;
149 {
150 if (uni < 128)
151 return (uni);
152
153 return (1); /* XXX ??? smiley */
154 }
155 #endif
156
157 void
158 pcdisplay_putchar(id, row, col, c, attr)
159 void *id;
160 int row, col;
161 u_int c;
162 long attr;
163 {
164 struct pcdisplayscreen *scr = id;
165 bus_space_tag_t memt = scr->hdl->ph_memt;
166 bus_space_handle_t memh = scr->hdl->ph_memh;
167 int off;
168
169 off = row * scr->type->ncols + col;
170
171 if (scr->active)
172 bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
173 c | (attr << 8));
174 else
175 scr->mem[off] = c | (attr << 8);
176 }
177
178 void
179 pcdisplay_copycols(id, row, srccol, dstcol, ncols)
180 void *id;
181 int row, srccol, dstcol, ncols;
182 {
183 struct pcdisplayscreen *scr = id;
184 bus_space_tag_t memt = scr->hdl->ph_memt;
185 bus_space_handle_t memh = scr->hdl->ph_memh;
186 bus_size_t srcoff, dstoff;
187
188 srcoff = dstoff = row * scr->type->ncols;
189 srcoff += srccol;
190 dstoff += dstcol;
191
192 if (scr->active)
193 bus_space_copy_region_2(memt, memh,
194 scr->dispoffset + srcoff * 2,
195 memh, scr->dispoffset + dstoff * 2,
196 ncols);
197 else
198 memcpy(&scr->mem[dstoff], &scr->mem[srcoff], ncols * 2);
199 }
200
201 void
202 pcdisplay_erasecols(id, row, startcol, ncols, fillattr)
203 void *id;
204 int row, startcol, ncols;
205 long fillattr;
206 {
207 struct pcdisplayscreen *scr = id;
208 bus_space_tag_t memt = scr->hdl->ph_memt;
209 bus_space_handle_t memh = scr->hdl->ph_memh;
210 bus_size_t off;
211 u_int16_t val;
212 int i;
213
214 off = row * scr->type->ncols + startcol;
215
216 val = (fillattr << 8) | ' ';
217
218 if (scr->active)
219 bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
220 val, ncols);
221 else
222 for (i = 0; i < ncols; i++)
223 scr->mem[off + i] = val;
224 }
225
226 void
227 pcdisplay_copyrows(id, srcrow, dstrow, nrows)
228 void *id;
229 int srcrow, dstrow, nrows;
230 {
231 struct pcdisplayscreen *scr = id;
232 bus_space_tag_t memt = scr->hdl->ph_memt;
233 bus_space_handle_t memh = scr->hdl->ph_memh;
234 int ncols = scr->type->ncols;
235 bus_size_t srcoff, dstoff;
236
237 srcoff = srcrow * ncols + 0;
238 dstoff = dstrow * ncols + 0;
239
240 if (scr->active)
241 bus_space_copy_region_2(memt, memh,
242 scr->dispoffset + srcoff * 2,
243 memh, scr->dispoffset + dstoff * 2,
244 nrows * ncols);
245 else
246 memcpy(&scr->mem[dstoff], &scr->mem[srcoff],
247 nrows * ncols * 2);
248 }
249
250 void
251 pcdisplay_eraserows(id, startrow, nrows, fillattr)
252 void *id;
253 int startrow, nrows;
254 long fillattr;
255 {
256 struct pcdisplayscreen *scr = id;
257 bus_space_tag_t memt = scr->hdl->ph_memt;
258 bus_space_handle_t memh = scr->hdl->ph_memh;
259 bus_size_t off, count;
260 u_int16_t val;
261 int i;
262
263 off = startrow * scr->type->ncols;
264 count = nrows * scr->type->ncols;
265
266 val = (fillattr << 8) | ' ';
267
268 if (scr->active)
269 bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
270 val, count);
271 else
272 for (i = 0; i < count; i++)
273 scr->mem[off + i] = val;
274 }
275