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