pcdisplay_subr.c revision 1.18.2.1 1 1.18.2.1 thorpej /* $NetBSD: pcdisplay_subr.c,v 1.18.2.1 2001/09/13 01:15:41 thorpej Exp $ */
2 1.1 drochner
3 1.1 drochner /*
4 1.1 drochner * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 1.1 drochner * All rights reserved.
6 1.1 drochner *
7 1.1 drochner * Author: Chris G. Demetriou
8 1.1 drochner *
9 1.1 drochner * Permission to use, copy, modify and distribute this software and
10 1.1 drochner * its documentation is hereby granted, provided that both the copyright
11 1.1 drochner * notice and this permission notice appear in all copies of the
12 1.1 drochner * software, derivative works or modified versions, and any portions
13 1.1 drochner * thereof, and that both notices appear in supporting documentation.
14 1.1 drochner *
15 1.1 drochner * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 1.1 drochner * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 1.1 drochner * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 1.1 drochner *
19 1.1 drochner * Carnegie Mellon requests users of this software to return to
20 1.1 drochner *
21 1.1 drochner * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 1.1 drochner * School of Computer Science
23 1.1 drochner * Carnegie Mellon University
24 1.1 drochner * Pittsburgh PA 15213-3890
25 1.1 drochner *
26 1.1 drochner * any improvements or extensions that they make and grant Carnegie the
27 1.1 drochner * rights to redistribute these changes.
28 1.1 drochner */
29 1.1 drochner
30 1.1 drochner #include <sys/param.h>
31 1.1 drochner #include <sys/systm.h>
32 1.1 drochner #include <sys/device.h>
33 1.1 drochner #include <machine/bus.h>
34 1.1 drochner
35 1.1 drochner #include <dev/ic/mc6845reg.h>
36 1.1 drochner #include <dev/ic/pcdisplayvar.h>
37 1.1 drochner
38 1.1 drochner #include <dev/wscons/wsdisplayvar.h>
39 1.12 ad
40 1.12 ad void
41 1.14 ad pcdisplay_cursor_init(scr, existing)
42 1.12 ad struct pcdisplayscreen *scr;
43 1.14 ad int existing;
44 1.12 ad {
45 1.14 ad #ifdef PCDISPLAY_SOFTCURSOR
46 1.14 ad bus_space_tag_t memt;
47 1.14 ad bus_space_handle_t memh;
48 1.14 ad int off;
49 1.12 ad
50 1.13 ad pcdisplay_6845_write(scr->hdl, curstart, 0x10);
51 1.13 ad pcdisplay_6845_write(scr->hdl, curend, 0x10);
52 1.14 ad
53 1.14 ad if (existing) {
54 1.14 ad /*
55 1.18.2.1 thorpej * This is the first screen. At this point, scr->mem is NULL
56 1.18.2.1 thorpej * (no backing store), so we can't use pcdisplay_cursor() to
57 1.18.2.1 thorpej * do this.
58 1.14 ad */
59 1.14 ad memt = scr->hdl->ph_memt;
60 1.14 ad memh = scr->hdl->ph_memh;
61 1.14 ad off = (scr->vc_crow * scr->type->ncols + scr->vc_ccol) * 2 +
62 1.14 ad scr->dispoffset;
63 1.14 ad
64 1.14 ad scr->cursortmp = bus_space_read_2(memt, memh, off);
65 1.14 ad bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700);
66 1.15 ad } else
67 1.15 ad scr->cursortmp = 0;
68 1.17 thorpej #else
69 1.17 thorpej /*
70 1.17 thorpej * Firmware might not have initialized the cursor shape. Make
71 1.17 thorpej * sure there's something we can see.
72 1.18.2.1 thorpej * Don't touch the hardware if this is not the first screen.
73 1.17 thorpej */
74 1.18.2.1 thorpej if (existing) {
75 1.18.2.1 thorpej pcdisplay_6845_write(scr->hdl, curstart,
76 1.18.2.1 thorpej scr->type->fontheight - 2);
77 1.18.2.1 thorpej pcdisplay_6845_write(scr->hdl, curend,
78 1.18.2.1 thorpej scr->type->fontheight - 1);
79 1.18.2.1 thorpej }
80 1.12 ad #endif
81 1.14 ad scr->cursoron = 1;
82 1.12 ad }
83 1.1 drochner
84 1.1 drochner void
85 1.1 drochner pcdisplay_cursor(id, on, row, col)
86 1.1 drochner void *id;
87 1.1 drochner int on, row, col;
88 1.1 drochner {
89 1.7 ad #ifdef PCDISPLAY_SOFTCURSOR
90 1.7 ad struct pcdisplayscreen *scr = id;
91 1.7 ad bus_space_tag_t memt = scr->hdl->ph_memt;
92 1.7 ad bus_space_handle_t memh = scr->hdl->ph_memh;
93 1.7 ad int off;
94 1.7 ad
95 1.7 ad /* Remove old cursor image */
96 1.7 ad if (scr->cursoron) {
97 1.7 ad off = scr->vc_crow * scr->type->ncols + scr->vc_ccol;
98 1.7 ad if (scr->active)
99 1.7 ad bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
100 1.7 ad scr->cursortmp);
101 1.7 ad else
102 1.7 ad scr->mem[off] = scr->cursortmp;
103 1.7 ad }
104 1.7 ad
105 1.7 ad scr->vc_crow = row;
106 1.7 ad scr->vc_ccol = col;
107 1.7 ad
108 1.7 ad if ((scr->cursoron = on) == 0)
109 1.7 ad return;
110 1.7 ad
111 1.7 ad off = (scr->vc_crow * scr->type->ncols + scr->vc_ccol);
112 1.8 ad if (scr->active) {
113 1.14 ad off = off * 2 + scr->dispoffset;
114 1.14 ad scr->cursortmp = bus_space_read_2(memt, memh, off);
115 1.14 ad bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700);
116 1.8 ad } else {
117 1.8 ad scr->cursortmp = scr->mem[off];
118 1.9 ad scr->mem[off] = scr->cursortmp ^ 0x7700;
119 1.8 ad }
120 1.7 ad #else /* PCDISPLAY_SOFTCURSOR */
121 1.1 drochner struct pcdisplayscreen *scr = id;
122 1.1 drochner int pos;
123 1.1 drochner
124 1.1 drochner scr->vc_crow = row;
125 1.1 drochner scr->vc_ccol = col;
126 1.1 drochner scr->cursoron = on;
127 1.1 drochner
128 1.1 drochner if (scr->active) {
129 1.7 ad if (!on)
130 1.18.2.1 thorpej pos = 0x3fff;
131 1.7 ad else
132 1.6 drochner pos = scr->dispoffset / 2
133 1.6 drochner + row * scr->type->ncols + col;
134 1.1 drochner
135 1.1 drochner pcdisplay_6845_write(scr->hdl, cursorh, pos >> 8);
136 1.1 drochner pcdisplay_6845_write(scr->hdl, cursorl, pos);
137 1.1 drochner }
138 1.7 ad #endif /* PCDISPLAY_SOFTCURSOR */
139 1.1 drochner }
140 1.1 drochner
141 1.5 drochner #if 0
142 1.5 drochner unsigned int
143 1.5 drochner pcdisplay_mapchar_simple(id, uni)
144 1.5 drochner void *id;
145 1.5 drochner int uni;
146 1.4 drochner {
147 1.5 drochner if (uni < 128)
148 1.5 drochner return (uni);
149 1.5 drochner
150 1.5 drochner return (1); /* XXX ??? smiley */
151 1.5 drochner }
152 1.5 drochner #endif
153 1.4 drochner
154 1.1 drochner void
155 1.4 drochner pcdisplay_putchar(id, row, col, c, attr)
156 1.1 drochner void *id;
157 1.1 drochner int row, col;
158 1.4 drochner u_int c;
159 1.1 drochner long attr;
160 1.1 drochner {
161 1.1 drochner struct pcdisplayscreen *scr = id;
162 1.1 drochner bus_space_tag_t memt = scr->hdl->ph_memt;
163 1.1 drochner bus_space_handle_t memh = scr->hdl->ph_memh;
164 1.4 drochner int off;
165 1.1 drochner
166 1.1 drochner off = row * scr->type->ncols + col;
167 1.1 drochner
168 1.4 drochner if (scr->active)
169 1.6 drochner bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
170 1.5 drochner c | (attr << 8));
171 1.4 drochner else
172 1.5 drochner scr->mem[off] = c | (attr << 8);
173 1.1 drochner }
174 1.1 drochner
175 1.1 drochner void
176 1.1 drochner pcdisplay_copycols(id, row, srccol, dstcol, ncols)
177 1.1 drochner void *id;
178 1.1 drochner int row, srccol, dstcol, ncols;
179 1.1 drochner {
180 1.1 drochner struct pcdisplayscreen *scr = id;
181 1.1 drochner bus_space_tag_t memt = scr->hdl->ph_memt;
182 1.1 drochner bus_space_handle_t memh = scr->hdl->ph_memh;
183 1.1 drochner bus_size_t srcoff, dstoff;
184 1.1 drochner
185 1.1 drochner srcoff = dstoff = row * scr->type->ncols;
186 1.1 drochner srcoff += srccol;
187 1.1 drochner dstoff += dstcol;
188 1.1 drochner
189 1.1 drochner if (scr->active)
190 1.6 drochner bus_space_copy_region_2(memt, memh,
191 1.6 drochner scr->dispoffset + srcoff * 2,
192 1.6 drochner memh, scr->dispoffset + dstoff * 2,
193 1.6 drochner ncols);
194 1.1 drochner else
195 1.18 thorpej memcpy(&scr->mem[dstoff], &scr->mem[srcoff], ncols * 2);
196 1.1 drochner }
197 1.1 drochner
198 1.1 drochner void
199 1.1 drochner pcdisplay_erasecols(id, row, startcol, ncols, fillattr)
200 1.1 drochner void *id;
201 1.1 drochner int row, startcol, ncols;
202 1.1 drochner long fillattr;
203 1.1 drochner {
204 1.1 drochner struct pcdisplayscreen *scr = id;
205 1.1 drochner bus_space_tag_t memt = scr->hdl->ph_memt;
206 1.1 drochner bus_space_handle_t memh = scr->hdl->ph_memh;
207 1.1 drochner bus_size_t off;
208 1.1 drochner u_int16_t val;
209 1.1 drochner int i;
210 1.1 drochner
211 1.1 drochner off = row * scr->type->ncols + startcol;
212 1.1 drochner
213 1.1 drochner val = (fillattr << 8) | ' ';
214 1.1 drochner
215 1.1 drochner if (scr->active)
216 1.6 drochner bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
217 1.6 drochner val, ncols);
218 1.1 drochner else
219 1.1 drochner for (i = 0; i < ncols; i++)
220 1.1 drochner scr->mem[off + i] = val;
221 1.1 drochner }
222 1.1 drochner
223 1.1 drochner void
224 1.1 drochner pcdisplay_copyrows(id, srcrow, dstrow, nrows)
225 1.1 drochner void *id;
226 1.1 drochner int srcrow, dstrow, nrows;
227 1.1 drochner {
228 1.1 drochner struct pcdisplayscreen *scr = id;
229 1.1 drochner bus_space_tag_t memt = scr->hdl->ph_memt;
230 1.1 drochner bus_space_handle_t memh = scr->hdl->ph_memh;
231 1.1 drochner int ncols = scr->type->ncols;
232 1.1 drochner bus_size_t srcoff, dstoff;
233 1.1 drochner
234 1.1 drochner srcoff = srcrow * ncols + 0;
235 1.1 drochner dstoff = dstrow * ncols + 0;
236 1.1 drochner
237 1.1 drochner if (scr->active)
238 1.6 drochner bus_space_copy_region_2(memt, memh,
239 1.6 drochner scr->dispoffset + srcoff * 2,
240 1.6 drochner memh, scr->dispoffset + dstoff * 2,
241 1.6 drochner nrows * ncols);
242 1.1 drochner else
243 1.18 thorpej memcpy(&scr->mem[dstoff], &scr->mem[srcoff],
244 1.1 drochner nrows * ncols * 2);
245 1.1 drochner }
246 1.1 drochner
247 1.1 drochner void
248 1.1 drochner pcdisplay_eraserows(id, startrow, nrows, fillattr)
249 1.1 drochner void *id;
250 1.1 drochner int startrow, nrows;
251 1.1 drochner long fillattr;
252 1.1 drochner {
253 1.1 drochner struct pcdisplayscreen *scr = id;
254 1.1 drochner bus_space_tag_t memt = scr->hdl->ph_memt;
255 1.1 drochner bus_space_handle_t memh = scr->hdl->ph_memh;
256 1.1 drochner bus_size_t off, count;
257 1.1 drochner u_int16_t val;
258 1.1 drochner int i;
259 1.1 drochner
260 1.1 drochner off = startrow * scr->type->ncols;
261 1.1 drochner count = nrows * scr->type->ncols;
262 1.1 drochner
263 1.1 drochner val = (fillattr << 8) | ' ';
264 1.1 drochner
265 1.1 drochner if (scr->active)
266 1.6 drochner bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
267 1.6 drochner val, count);
268 1.1 drochner else
269 1.1 drochner for (i = 0; i < count; i++)
270 1.1 drochner scr->mem[off + i] = val;
271 1.1 drochner }
272