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