1 /* $OpenBSD: pcdisplay_subr.c,v 1.7 2006/11/29 19:11:15 miod Exp $ */
2 /* $NetBSD: pcdisplay_subr.c,v 1.16 2000/06/08 07:01:19 cgd Exp $ */
3
4 /*
5 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
6 * All rights reserved.
7 *
8 * Author: Chris G. Demetriou
9 *
10 * Permission to use, copy, modify and distribute this software and
11 * its documentation is hereby granted, provided that both the copyright
12 * notice and this permission notice appear in all copies of the
13 * software, derivative works or modified versions, and any portions
14 * thereof, and that both notices appear in supporting documentation.
15 *
16 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
18 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19 *
20 * Carnegie Mellon requests users of this software to return to
21 *
22 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
23 * School of Computer Science
24 * Carnegie Mellon University
25 * Pittsburgh PA 15213-3890
26 *
27 * any improvements or extensions that they make and grant Carnegie the
28 * rights to redistribute these changes.
29 */
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/device.h>
35 #include <machine/bus.h>
36
37 #include <dev/ic/mc6845reg.h>
38 #include <dev/ic/pcdisplayvar.h>
39
40 #include <dev/wscons/wsconsio.h>
41 #include <dev/wscons/wsdisplayvar.h>
42
43 void
pcdisplay_cursor_init(scr,existing)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
pcdisplay_cursor(id,on,row,col)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
pcdisplay_putchar(id,row,col,c,attr)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 int
pcdisplay_getchar(id,row,col,cell)167 pcdisplay_getchar(id, row, col, cell)
168 void *id;
169 int row, col;
170 struct wsdisplay_charcell *cell;
171 {
172 struct pcdisplayscreen *scr = id;
173 bus_space_tag_t memt = scr->hdl->ph_memt;
174 bus_space_handle_t memh = scr->hdl->ph_memh;
175 int off;
176 u_int16_t data;
177
178 off = row * scr->type->ncols + col;
179 /* XXX bounds check? */
180
181 if (scr->active)
182 data = (bus_space_read_2(memt, memh,
183 scr->dispoffset + off * 2));
184 else
185 data = (scr->mem[off]);
186
187 cell->uc = data & 0xff;
188 cell->attr = data >> 8;
189
190 return (0);
191 }
192
193 void
pcdisplay_copycols(id,row,srccol,dstcol,ncols)194 pcdisplay_copycols(id, row, srccol, dstcol, ncols)
195 void *id;
196 int row, srccol, dstcol, ncols;
197 {
198 struct pcdisplayscreen *scr = id;
199 bus_space_tag_t memt = scr->hdl->ph_memt;
200 bus_space_handle_t memh = scr->hdl->ph_memh;
201 bus_size_t srcoff, dstoff;
202
203 srcoff = dstoff = row * scr->type->ncols;
204 srcoff += srccol;
205 dstoff += dstcol;
206
207 if (scr->active)
208 bus_space_copy_2(memt, memh,
209 scr->dispoffset + srcoff * 2,
210 memh, scr->dispoffset + dstoff * 2,
211 ncols);
212 else
213 bcopy(&scr->mem[srcoff], &scr->mem[dstoff], ncols * 2);
214 }
215
216 void
pcdisplay_erasecols(id,row,startcol,ncols,fillattr)217 pcdisplay_erasecols(id, row, startcol, ncols, fillattr)
218 void *id;
219 int row, startcol, ncols;
220 long fillattr;
221 {
222 struct pcdisplayscreen *scr = id;
223 bus_space_tag_t memt = scr->hdl->ph_memt;
224 bus_space_handle_t memh = scr->hdl->ph_memh;
225 bus_size_t off;
226 u_int16_t val;
227 int i;
228
229 off = row * scr->type->ncols + startcol;
230
231 val = (fillattr << 8) | ' ';
232
233 if (scr->active)
234 bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
235 val, ncols);
236 else
237 for (i = 0; i < ncols; i++)
238 scr->mem[off + i] = val;
239 }
240
241 void
pcdisplay_copyrows(id,srcrow,dstrow,nrows)242 pcdisplay_copyrows(id, srcrow, dstrow, nrows)
243 void *id;
244 int srcrow, dstrow, nrows;
245 {
246 struct pcdisplayscreen *scr = id;
247 bus_space_tag_t memt = scr->hdl->ph_memt;
248 bus_space_handle_t memh = scr->hdl->ph_memh;
249 int ncols = scr->type->ncols;
250 bus_size_t srcoff, dstoff;
251
252 srcoff = srcrow * ncols + 0;
253 dstoff = dstrow * ncols + 0;
254
255 if (scr->active)
256 bus_space_copy_2(memt, memh,
257 scr->dispoffset + srcoff * 2,
258 memh, scr->dispoffset + dstoff * 2,
259 nrows * ncols);
260 else
261 bcopy(&scr->mem[srcoff], &scr->mem[dstoff],
262 nrows * ncols * 2);
263 }
264
265 void
pcdisplay_eraserows(id,startrow,nrows,fillattr)266 pcdisplay_eraserows(id, startrow, nrows, fillattr)
267 void *id;
268 int startrow, nrows;
269 long fillattr;
270 {
271 struct pcdisplayscreen *scr = id;
272 bus_space_tag_t memt = scr->hdl->ph_memt;
273 bus_space_handle_t memh = scr->hdl->ph_memh;
274 bus_size_t off, count, n;
275 u_int16_t val;
276
277 off = startrow * scr->type->ncols;
278 count = nrows * scr->type->ncols;
279
280 val = (fillattr << 8) | ' ';
281
282 if (scr->active)
283 bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
284 val, count);
285 else
286 for (n = 0; n < count; n++)
287 scr->mem[off + n] = val;
288 }
289