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