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