xref: /openbsd-src/sys/dev/ic/pcdisplay_subr.c (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1 /* $OpenBSD: pcdisplay_subr.c,v 1.4 2001/04/14 04:44:01 aaron 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
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
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
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 u_int16_t
167 pcdisplay_getchar(id, row, col)
168 	void *id;
169 	int row, col;
170 {
171 	struct pcdisplayscreen *scr = id;
172 	bus_space_tag_t memt = scr->hdl->ph_memt;
173 	bus_space_handle_t memh = scr->hdl->ph_memh;
174 	int off;
175 
176 	off = row * scr->type->ncols + col;
177 
178 	if (scr->active)
179 		return (bus_space_read_2(memt, memh,
180 					scr->dispoffset + off * 2));
181 	else
182 		return (scr->mem[off]);
183 }
184 
185 void
186 pcdisplay_copycols(id, row, srccol, dstcol, ncols)
187 	void *id;
188 	int row, srccol, dstcol, ncols;
189 {
190 	struct pcdisplayscreen *scr = id;
191 	bus_space_tag_t memt = scr->hdl->ph_memt;
192 	bus_space_handle_t memh = scr->hdl->ph_memh;
193 	bus_size_t srcoff, dstoff;
194 
195 	srcoff = dstoff = row * scr->type->ncols;
196 	srcoff += srccol;
197 	dstoff += dstcol;
198 
199 	if (scr->active)
200 		bus_space_copy_2(memt, memh,
201 					scr->dispoffset + srcoff * 2,
202 					memh, scr->dispoffset + dstoff * 2,
203 					ncols);
204 	else
205 		bcopy(&scr->mem[srcoff], &scr->mem[dstoff], ncols * 2);
206 }
207 
208 void
209 pcdisplay_erasecols(id, row, startcol, ncols, fillattr)
210 	void *id;
211 	int row, startcol, ncols;
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;
218 	u_int16_t val;
219 	int i;
220 
221 	off = row * scr->type->ncols + startcol;
222 
223 	val = (fillattr << 8) | ' ';
224 
225 	if (scr->active)
226 		bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
227 				       val, ncols);
228 	else
229 		for (i = 0; i < ncols; i++)
230 			scr->mem[off + i] = val;
231 }
232 
233 void
234 pcdisplay_copyrows(id, srcrow, dstrow, nrows)
235 	void *id;
236 	int srcrow, dstrow, nrows;
237 {
238 	struct pcdisplayscreen *scr = id;
239 	bus_space_tag_t memt = scr->hdl->ph_memt;
240 	bus_space_handle_t memh = scr->hdl->ph_memh;
241 	int ncols = scr->type->ncols;
242 	bus_size_t srcoff, dstoff;
243 
244 	srcoff = srcrow * ncols + 0;
245 	dstoff = dstrow * ncols + 0;
246 
247 	if (scr->active)
248 		bus_space_copy_2(memt, memh,
249 					scr->dispoffset + srcoff * 2,
250 					memh, scr->dispoffset + dstoff * 2,
251 					nrows * ncols);
252 	else
253 		bcopy(&scr->mem[srcoff], &scr->mem[dstoff],
254 		      nrows * ncols * 2);
255 }
256 
257 void
258 pcdisplay_eraserows(id, startrow, nrows, fillattr)
259 	void *id;
260 	int startrow, nrows;
261 	long fillattr;
262 {
263 	struct pcdisplayscreen *scr = id;
264 	bus_space_tag_t memt = scr->hdl->ph_memt;
265 	bus_space_handle_t memh = scr->hdl->ph_memh;
266 	bus_size_t off, count;
267 	u_int16_t val;
268 	int i;
269 
270 	off = startrow * scr->type->ncols;
271 	count = nrows * scr->type->ncols;
272 
273 	val = (fillattr << 8) | ' ';
274 
275 	if (scr->active)
276 		bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
277 				       val, count);
278 	else
279 		for (i = 0; i < count; i++)
280 			scr->mem[off + i] = val;
281 }
282