pcdisplay_subr.c revision 1.14 1 /* $NetBSD: pcdisplay_subr.c,v 1.14 2000/01/25 02:44:03 ad 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/param.h>
31 #include <sys/systm.h>
32 #include <sys/device.h>
33 #include <machine/bus.h>
34
35 #include <dev/isa/isavar.h>
36 #include <dev/isa/isareg.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->active is
59 * false and scr->mem is NULL (no backing store), so we
60 * can't use pcdisplay_cursor() to 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 }
70 #endif
71 scr->cursoron = 1;
72 }
73
74 void
75 pcdisplay_cursor(id, on, row, col)
76 void *id;
77 int on, row, col;
78 {
79 #ifdef PCDISPLAY_SOFTCURSOR
80 struct pcdisplayscreen *scr = id;
81 bus_space_tag_t memt = scr->hdl->ph_memt;
82 bus_space_handle_t memh = scr->hdl->ph_memh;
83 int off;
84
85 /* Remove old cursor image */
86 if (scr->cursoron) {
87 off = scr->vc_crow * scr->type->ncols + scr->vc_ccol;
88 if (scr->active)
89 bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
90 scr->cursortmp);
91 else
92 scr->mem[off] = scr->cursortmp;
93 }
94
95 scr->vc_crow = row;
96 scr->vc_ccol = col;
97
98 if ((scr->cursoron = on) == 0)
99 return;
100
101 off = (scr->vc_crow * scr->type->ncols + scr->vc_ccol);
102 if (scr->active) {
103 off = off * 2 + scr->dispoffset;
104 scr->cursortmp = bus_space_read_2(memt, memh, off);
105 bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700);
106 } else {
107 scr->cursortmp = scr->mem[off];
108 scr->mem[off] = scr->cursortmp ^ 0x7700;
109 }
110 #else /* PCDISPLAY_SOFTCURSOR */
111 struct pcdisplayscreen *scr = id;
112 int pos;
113
114 scr->vc_crow = row;
115 scr->vc_ccol = col;
116 scr->cursoron = on;
117
118 if (scr->active) {
119 if (!on)
120 pos = 0x1010;
121 else
122 pos = scr->dispoffset / 2
123 + row * scr->type->ncols + col;
124
125 pcdisplay_6845_write(scr->hdl, cursorh, pos >> 8);
126 pcdisplay_6845_write(scr->hdl, cursorl, pos);
127 }
128 #endif /* PCDISPLAY_SOFTCURSOR */
129 }
130
131 #if 0
132 unsigned int
133 pcdisplay_mapchar_simple(id, uni)
134 void *id;
135 int uni;
136 {
137 if (uni < 128)
138 return (uni);
139
140 return (1); /* XXX ??? smiley */
141 }
142 #endif
143
144 void
145 pcdisplay_putchar(id, row, col, c, attr)
146 void *id;
147 int row, col;
148 u_int c;
149 long attr;
150 {
151 struct pcdisplayscreen *scr = id;
152 bus_space_tag_t memt = scr->hdl->ph_memt;
153 bus_space_handle_t memh = scr->hdl->ph_memh;
154 int off;
155
156 off = row * scr->type->ncols + col;
157
158 if (scr->active)
159 bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
160 c | (attr << 8));
161 else
162 scr->mem[off] = c | (attr << 8);
163 }
164
165 void
166 pcdisplay_copycols(id, row, srccol, dstcol, ncols)
167 void *id;
168 int row, srccol, dstcol, ncols;
169 {
170 struct pcdisplayscreen *scr = id;
171 bus_space_tag_t memt = scr->hdl->ph_memt;
172 bus_space_handle_t memh = scr->hdl->ph_memh;
173 bus_size_t srcoff, dstoff;
174
175 srcoff = dstoff = row * scr->type->ncols;
176 srcoff += srccol;
177 dstoff += dstcol;
178
179 if (scr->active)
180 bus_space_copy_region_2(memt, memh,
181 scr->dispoffset + srcoff * 2,
182 memh, scr->dispoffset + dstoff * 2,
183 ncols);
184 else
185 bcopy(&scr->mem[srcoff], &scr->mem[dstoff], ncols * 2);
186 }
187
188 void
189 pcdisplay_erasecols(id, row, startcol, ncols, fillattr)
190 void *id;
191 int row, startcol, ncols;
192 long fillattr;
193 {
194 struct pcdisplayscreen *scr = id;
195 bus_space_tag_t memt = scr->hdl->ph_memt;
196 bus_space_handle_t memh = scr->hdl->ph_memh;
197 bus_size_t off;
198 u_int16_t val;
199 int i;
200
201 off = row * scr->type->ncols + startcol;
202
203 val = (fillattr << 8) | ' ';
204
205 if (scr->active)
206 bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
207 val, ncols);
208 else
209 for (i = 0; i < ncols; i++)
210 scr->mem[off + i] = val;
211 }
212
213 void
214 pcdisplay_copyrows(id, srcrow, dstrow, nrows)
215 void *id;
216 int srcrow, dstrow, nrows;
217 {
218 struct pcdisplayscreen *scr = id;
219 bus_space_tag_t memt = scr->hdl->ph_memt;
220 bus_space_handle_t memh = scr->hdl->ph_memh;
221 int ncols = scr->type->ncols;
222 bus_size_t srcoff, dstoff;
223
224 srcoff = srcrow * ncols + 0;
225 dstoff = dstrow * ncols + 0;
226
227 if (scr->active)
228 bus_space_copy_region_2(memt, memh,
229 scr->dispoffset + srcoff * 2,
230 memh, scr->dispoffset + dstoff * 2,
231 nrows * ncols);
232 else
233 bcopy(&scr->mem[srcoff], &scr->mem[dstoff],
234 nrows * ncols * 2);
235 }
236
237 void
238 pcdisplay_eraserows(id, startrow, nrows, fillattr)
239 void *id;
240 int startrow, nrows;
241 long fillattr;
242 {
243 struct pcdisplayscreen *scr = id;
244 bus_space_tag_t memt = scr->hdl->ph_memt;
245 bus_space_handle_t memh = scr->hdl->ph_memh;
246 bus_size_t off, count;
247 u_int16_t val;
248 int i;
249
250 off = startrow * scr->type->ncols;
251 count = nrows * scr->type->ncols;
252
253 val = (fillattr << 8) | ' ';
254
255 if (scr->active)
256 bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
257 val, count);
258 else
259 for (i = 0; i < count; i++)
260 scr->mem[off + i] = val;
261 }
262