pcdisplay_subr.c revision 1.4 1 /* $NetBSD: pcdisplay_subr.c,v 1.4 1998/06/20 21:55:05 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 static u_char iso2ibm437[] =
72 {
73 0, 0, 0, 0, 0, 0, 0, 0,
74 0, 0, 0, 0, 0, 0, 0, 0,
75 0, 0, 0, 0, 0, 0, 0, 0,
76 0, 0, 0, 0, 0, 0, 0, 0,
77 0xff, 0xad, 0x9b, 0x9c, 0, 0x9d, 0, 0x40,
78 0x6f, 0x63, 0x61, 0xae, 0, 0, 0, 0,
79 0xf8, 0xf1, 0xfd, 0x33, 0, 0xe6, 0, 0xfa,
80 0, 0x31, 0x6f, 0xaf, 0xac, 0xab, 0, 0xa8,
81 0x41, 0x41, 0x41, 0x41, 0x8e, 0x8f, 0x92, 0x80,
82 0x45, 0x90, 0x45, 0x45, 0x49, 0x49, 0x49, 0x49,
83 0x81, 0xa5, 0x4f, 0x4f, 0x4f, 0x4f, 0x99, 0x4f,
84 0x4f, 0x55, 0x55, 0x55, 0x9a, 0x59, 0, 0xe1,
85 0x85, 0xa0, 0x83, 0x61, 0x84, 0x86, 0x91, 0x87,
86 0x8a, 0x82, 0x88, 0x89, 0x8d, 0xa1, 0x8c, 0x8b,
87 0, 0xa4, 0x95, 0xa2, 0x93, 0x6f, 0x94, 0x6f,
88 0x6f, 0x97, 0xa3, 0x96, 0x81, 0x98, 0, 0
89 };
90
91 void
92 pcdisplay_putchar(id, row, col, c, attr)
93 void *id;
94 int row, col;
95 u_int c;
96 long attr;
97 {
98 struct pcdisplayscreen *scr = id;
99 bus_space_tag_t memt = scr->hdl->ph_memt;
100 bus_space_handle_t memh = scr->hdl->ph_memh;
101 u_char dc;
102 int off;
103
104 if (c < 128)
105 dc = c;
106 else if (c < 256)
107 dc = iso2ibm437[c - 128];
108 else
109 return;
110
111 off = row * scr->type->ncols + col;
112
113 if (scr->active)
114 bus_space_write_2(memt, memh, off * 2,
115 dc | (attr << 8));
116 else
117 scr->mem[off] = dc | (attr << 8);
118 }
119
120 void
121 pcdisplay_copycols(id, row, srccol, dstcol, ncols)
122 void *id;
123 int row, srccol, dstcol, ncols;
124 {
125 struct pcdisplayscreen *scr = id;
126 bus_space_tag_t memt = scr->hdl->ph_memt;
127 bus_space_handle_t memh = scr->hdl->ph_memh;
128 bus_size_t srcoff, dstoff;
129
130 srcoff = dstoff = row * scr->type->ncols;
131 srcoff += srccol;
132 dstoff += dstcol;
133
134 if (scr->active)
135 bus_space_copy_region_2(memt, memh, srcoff * 2,
136 memh, dstoff * 2, ncols);
137 else
138 bcopy(&scr->mem[srcoff], &scr->mem[dstoff], ncols * 2);
139 }
140
141 void
142 pcdisplay_erasecols(id, row, startcol, ncols, fillattr)
143 void *id;
144 int row, startcol, ncols;
145 long fillattr;
146 {
147 struct pcdisplayscreen *scr = id;
148 bus_space_tag_t memt = scr->hdl->ph_memt;
149 bus_space_handle_t memh = scr->hdl->ph_memh;
150 bus_size_t off;
151 u_int16_t val;
152 int i;
153
154 off = row * scr->type->ncols + startcol;
155
156 val = (fillattr << 8) | ' ';
157
158 if (scr->active)
159 bus_space_set_region_2(memt, memh, off * 2, val, ncols);
160 else
161 for (i = 0; i < ncols; i++)
162 scr->mem[off + i] = val;
163 }
164
165 void
166 pcdisplay_copyrows(id, srcrow, dstrow, nrows)
167 void *id;
168 int srcrow, dstrow, nrows;
169 {
170 struct pcdisplayscreen *scr = id;
171 bus_space_tag_t memt = scr->hdl->ph_memt;
172 bus_space_handle_t memh = scr->hdl->ph_memh;
173 int ncols = scr->type->ncols;
174 bus_size_t srcoff, dstoff;
175
176 srcoff = srcrow * ncols + 0;
177 dstoff = dstrow * ncols + 0;
178
179 if (scr->active)
180 bus_space_copy_region_2(memt, memh, srcoff * 2,
181 memh, dstoff * 2, nrows * ncols);
182 else
183 bcopy(&scr->mem[srcoff], &scr->mem[dstoff],
184 nrows * ncols * 2);
185 }
186
187 void
188 pcdisplay_eraserows(id, startrow, nrows, fillattr)
189 void *id;
190 int startrow, nrows;
191 long fillattr;
192 {
193 struct pcdisplayscreen *scr = id;
194 bus_space_tag_t memt = scr->hdl->ph_memt;
195 bus_space_handle_t memh = scr->hdl->ph_memh;
196 bus_size_t off, count;
197 u_int16_t val;
198 int i;
199
200 off = startrow * scr->type->ncols;
201 count = nrows * scr->type->ncols;
202
203 val = (fillattr << 8) | ' ';
204
205 if (scr->active)
206 bus_space_set_region_2(memt, memh, off * 2, val, count);
207 else
208 for (i = 0; i < count; i++)
209 scr->mem[off + i] = val;
210 }
211