pcdisplay_subr.c revision 1.2 1 /* $NetBSD: pcdisplay_subr.c,v 1.2 1998/06/17 20:44:16 drochner 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 struct pcdisplayscreen *scr = id;
49 int pos;
50
51 #if 0
52 printf("pcdisplay_cursor: %d %d\n", row, col);
53 #endif
54 scr->vc_crow = row;
55 scr->vc_ccol = col;
56 scr->cursoron = on;
57
58 if (scr->active) {
59 if (!on) {
60 /* XXX disable cursor how??? */
61 row = col = -1;
62 }
63
64 pos = row * scr->type->ncols + col;
65
66 pcdisplay_6845_write(scr->hdl, cursorh, pos >> 8);
67 pcdisplay_6845_write(scr->hdl, cursorl, pos);
68 }
69 }
70
71 void
72 pcdisplay_putstr(id, row, col, cp, len, attr)
73 void *id;
74 int row, col;
75 char *cp;
76 int len;
77 long attr;
78 {
79 struct pcdisplayscreen *scr = id;
80 bus_space_tag_t memt = scr->hdl->ph_memt;
81 bus_space_handle_t memh = scr->hdl->ph_memh;
82 int i, off;
83
84 off = row * scr->type->ncols + col;
85
86 if (scr->active) {
87 off *= 2;
88
89 for (i = 0; i < len; i++, cp++, off += 2)
90 bus_space_write_2(memt, memh, off,
91 (attr << 8) | (u_char)*cp);
92 } else {
93 u_int16_t *m = &scr->mem[off];
94
95 for (i = 0; i < len; i++, cp++)
96 *m++ = *cp | (attr << 8);
97 }
98 }
99
100 void
101 pcdisplay_copycols(id, row, srccol, dstcol, ncols)
102 void *id;
103 int row, srccol, dstcol, ncols;
104 {
105 struct pcdisplayscreen *scr = id;
106 bus_space_tag_t memt = scr->hdl->ph_memt;
107 bus_space_handle_t memh = scr->hdl->ph_memh;
108 bus_size_t srcoff, dstoff;
109
110 srcoff = dstoff = row * scr->type->ncols;
111 srcoff += srccol;
112 dstoff += dstcol;
113
114 if (scr->active)
115 bus_space_copy_region_2(memt, memh, srcoff * 2,
116 memh, dstoff * 2, ncols);
117 else
118 bcopy(&scr->mem[srcoff], &scr->mem[dstoff], ncols * 2);
119 }
120
121 void
122 pcdisplay_erasecols(id, row, startcol, ncols, fillattr)
123 void *id;
124 int row, startcol, ncols;
125 long fillattr;
126 {
127 struct pcdisplayscreen *scr = id;
128 bus_space_tag_t memt = scr->hdl->ph_memt;
129 bus_space_handle_t memh = scr->hdl->ph_memh;
130 bus_size_t off;
131 u_int16_t val;
132 int i;
133
134 off = row * scr->type->ncols + startcol;
135
136 val = (fillattr << 8) | ' ';
137
138 if (scr->active)
139 bus_space_set_region_2(memt, memh, off * 2, val, ncols);
140 else
141 for (i = 0; i < ncols; i++)
142 scr->mem[off + i] = val;
143 }
144
145 void
146 pcdisplay_copyrows(id, srcrow, dstrow, nrows)
147 void *id;
148 int srcrow, dstrow, nrows;
149 {
150 struct pcdisplayscreen *scr = id;
151 bus_space_tag_t memt = scr->hdl->ph_memt;
152 bus_space_handle_t memh = scr->hdl->ph_memh;
153 int ncols = scr->type->ncols;
154 bus_size_t srcoff, dstoff;
155
156 srcoff = srcrow * ncols + 0;
157 dstoff = dstrow * ncols + 0;
158
159 if (scr->active)
160 bus_space_copy_region_2(memt, memh, srcoff * 2,
161 memh, dstoff * 2, nrows * ncols);
162 else
163 bcopy(&scr->mem[srcoff], &scr->mem[dstoff],
164 nrows * ncols * 2);
165 }
166
167 void
168 pcdisplay_eraserows(id, startrow, nrows, fillattr)
169 void *id;
170 int startrow, nrows;
171 long fillattr;
172 {
173 struct pcdisplayscreen *scr = id;
174 bus_space_tag_t memt = scr->hdl->ph_memt;
175 bus_space_handle_t memh = scr->hdl->ph_memh;
176 bus_size_t off, count;
177 u_int16_t val;
178 int i;
179
180 off = startrow * scr->type->ncols;
181 count = nrows * scr->type->ncols;
182
183 val = (fillattr << 8) | ' ';
184
185 if (scr->active)
186 bus_space_set_region_2(memt, memh, off * 2, val, count);
187 else
188 for (i = 0; i < count; i++)
189 scr->mem[off + i] = val;
190 }
191