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