ite_et.c revision 1.11.8.2 1 1.11.8.2 nathanw /* $NetBSD: ite_et.c,v 1.11.8.2 2002/04/01 07:39:32 nathanw Exp $ */
2 1.11.8.2 nathanw
3 1.11.8.2 nathanw /*
4 1.11.8.2 nathanw * Copyright (c) 1996 Leo Weppelman.
5 1.11.8.2 nathanw * All rights reserved.
6 1.11.8.2 nathanw *
7 1.11.8.2 nathanw * Redistribution and use in source and binary forms, with or without
8 1.11.8.2 nathanw * modification, are permitted provided that the following conditions
9 1.11.8.2 nathanw * are met:
10 1.11.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
11 1.11.8.2 nathanw * notice, this list of conditions and the following disclaimer.
12 1.11.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
13 1.11.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
14 1.11.8.2 nathanw * documentation and/or other materials provided with the distribution.
15 1.11.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
16 1.11.8.2 nathanw * must display the following acknowledgement:
17 1.11.8.2 nathanw * This product includes software developed by Leo Weppelman.
18 1.11.8.2 nathanw * 4. The name of the author may not be used to endorse or promote products
19 1.11.8.2 nathanw * derived from this software without specific prior written permission
20 1.11.8.2 nathanw *
21 1.11.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.11.8.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.11.8.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.11.8.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.11.8.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.11.8.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.11.8.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.11.8.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.11.8.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.11.8.2 nathanw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.11.8.2 nathanw */
32 1.11.8.2 nathanw #include <sys/param.h>
33 1.11.8.2 nathanw #include <sys/systm.h>
34 1.11.8.2 nathanw #include <sys/conf.h>
35 1.11.8.2 nathanw #include <sys/ioctl.h>
36 1.11.8.2 nathanw #include <sys/malloc.h>
37 1.11.8.2 nathanw #include <sys/device.h>
38 1.11.8.2 nathanw #include <dev/cons.h>
39 1.11.8.2 nathanw
40 1.11.8.2 nathanw #include <machine/cpu.h>
41 1.11.8.2 nathanw
42 1.11.8.2 nathanw #include <atari/atari/device.h>
43 1.11.8.2 nathanw
44 1.11.8.2 nathanw #include <atari/dev/itevar.h>
45 1.11.8.2 nathanw #include <atari/dev/iteioctl.h>
46 1.11.8.2 nathanw #include <atari/dev/grfioctl.h>
47 1.11.8.2 nathanw #include <atari/dev/grf_etreg.h>
48 1.11.8.2 nathanw #include <atari/dev/grfabs_reg.h>
49 1.11.8.2 nathanw #include <atari/dev/grfabs_et.h>
50 1.11.8.2 nathanw #include <atari/dev/grfvar.h>
51 1.11.8.2 nathanw #include <atari/dev/font.h>
52 1.11.8.2 nathanw #include <atari/dev/viewioctl.h>
53 1.11.8.2 nathanw #include <atari/dev/viewvar.h>
54 1.11.8.2 nathanw
55 1.11.8.2 nathanw #include "grfet.h"
56 1.11.8.2 nathanw
57 1.11.8.2 nathanw /*
58 1.11.8.2 nathanw * This is what ip->priv points to;
59 1.11.8.2 nathanw * it contains local variables for custom-chip ites.
60 1.11.8.2 nathanw */
61 1.11.8.2 nathanw struct ite_priv {
62 1.11.8.2 nathanw volatile u_char *regkva;
63 1.11.8.2 nathanw };
64 1.11.8.2 nathanw
65 1.11.8.2 nathanw typedef struct ite_priv ipriv_t;
66 1.11.8.2 nathanw
67 1.11.8.2 nathanw static ipriv_t con_ipriv;
68 1.11.8.2 nathanw
69 1.11.8.2 nathanw /* Console colors */
70 1.11.8.2 nathanw static u_char etconscolors[3][3] = { /* background, foreground, hilite */
71 1.11.8.2 nathanw {0x0, 0x0, 0x0}, {0x30, 0x30, 0x30}, { 0x3f, 0x3f, 0x3f}
72 1.11.8.2 nathanw };
73 1.11.8.2 nathanw
74 1.11.8.2 nathanw /* XXX: Shouldn't these be in font.h???? */
75 1.11.8.2 nathanw extern font_info font_info_8x8;
76 1.11.8.2 nathanw extern font_info font_info_8x16;
77 1.11.8.2 nathanw
78 1.11.8.2 nathanw static void grfet_iteinit __P((struct grf_softc *));
79 1.11.8.2 nathanw static void view_init __P((struct ite_softc *));
80 1.11.8.2 nathanw static void view_deinit __P((struct ite_softc *));
81 1.11.8.2 nathanw static int iteet_ioctl __P((struct ite_softc *, u_long, caddr_t, int,
82 1.11.8.2 nathanw struct proc *));
83 1.11.8.2 nathanw static int ite_newsize __P((struct ite_softc *, struct itewinsize *));
84 1.11.8.2 nathanw static void et_inittextmode __P((struct ite_softc *, et_sv_reg_t *, int));
85 1.11.8.2 nathanw void et_cursor __P((struct ite_softc *ip, int flag));
86 1.11.8.2 nathanw void et_clear __P((struct ite_softc *ip, int sy, int sx, int h, int w));
87 1.11.8.2 nathanw void et_putc __P((struct ite_softc *ip, int c, int dy, int dx, int mode));
88 1.11.8.2 nathanw void et_scroll __P((struct ite_softc *ip, int sy, int sx, int count,
89 1.11.8.2 nathanw int dir));
90 1.11.8.2 nathanw
91 1.11.8.2 nathanw /*
92 1.11.8.2 nathanw * grfet config stuff
93 1.11.8.2 nathanw */
94 1.11.8.2 nathanw void grfetattach __P((struct device *, struct device *, void *));
95 1.11.8.2 nathanw int grfetmatch __P((struct device *, struct cfdata *, void *));
96 1.11.8.2 nathanw int grfetprint __P((void *, const char *));
97 1.11.8.2 nathanw
98 1.11.8.2 nathanw struct cfattach grfet_ca = {
99 1.11.8.2 nathanw sizeof(struct grf_softc), grfetmatch, grfetattach
100 1.11.8.2 nathanw };
101 1.11.8.2 nathanw
102 1.11.8.2 nathanw /*
103 1.11.8.2 nathanw * only used in console init.
104 1.11.8.2 nathanw */
105 1.11.8.2 nathanw static struct cfdata *cfdata_grf = NULL;
106 1.11.8.2 nathanw
107 1.11.8.2 nathanw int
108 1.11.8.2 nathanw grfetmatch(pdp, cfp, auxp)
109 1.11.8.2 nathanw struct device *pdp;
110 1.11.8.2 nathanw struct cfdata *cfp;
111 1.11.8.2 nathanw void *auxp;
112 1.11.8.2 nathanw {
113 1.11.8.2 nathanw static int card_probed = -1;
114 1.11.8.2 nathanw static int did_consinit = 0;
115 1.11.8.2 nathanw grf_auxp_t *grf_auxp = auxp;
116 1.11.8.2 nathanw
117 1.11.8.2 nathanw if (card_probed <= 0) {
118 1.11.8.2 nathanw if (card_probed == 0) /* Probed but failed */
119 1.11.8.2 nathanw return 0;
120 1.11.8.2 nathanw card_probed = 0;
121 1.11.8.2 nathanw
122 1.11.8.2 nathanw /*
123 1.11.8.2 nathanw * Check if the layers we depend on exist
124 1.11.8.2 nathanw */
125 1.11.8.2 nathanw if(!(machineid & ATARI_HADES))
126 1.11.8.2 nathanw return 0;
127 1.11.8.2 nathanw if (!et_probe_card())
128 1.11.8.2 nathanw return 0;
129 1.11.8.2 nathanw if (grfabs_probe(&et_probe_video) == 0)
130 1.11.8.2 nathanw return 0;
131 1.11.8.2 nathanw viewprobe();
132 1.11.8.2 nathanw card_probed = 1; /* Probed and found */
133 1.11.8.2 nathanw }
134 1.11.8.2 nathanw
135 1.11.8.2 nathanw if (atari_realconfig == 0) {
136 1.11.8.2 nathanw /*
137 1.11.8.2 nathanw * Early console init. Only match first unit.
138 1.11.8.2 nathanw */
139 1.11.8.2 nathanw if (did_consinit)
140 1.11.8.2 nathanw return 0;
141 1.11.8.2 nathanw if (viewopen(cfp->cf_unit, 0, 0, NULL))
142 1.11.8.2 nathanw return 0;
143 1.11.8.2 nathanw cfdata_grf = cfp;
144 1.11.8.2 nathanw did_consinit = 1;
145 1.11.8.2 nathanw return 1;
146 1.11.8.2 nathanw }
147 1.11.8.2 nathanw
148 1.11.8.2 nathanw /*
149 1.11.8.2 nathanw * Normal config. When we are called directly from the grfbus,
150 1.11.8.2 nathanw * we only match the first unit. The attach function will call us for
151 1.11.8.2 nathanw * the other configured units.
152 1.11.8.2 nathanw */
153 1.11.8.2 nathanw if (grf_auxp->from_bus_match
154 1.11.8.2 nathanw && ((did_consinit > 1) || !et_probe_card()))
155 1.11.8.2 nathanw return 0;
156 1.11.8.2 nathanw
157 1.11.8.2 nathanw if (!grf_auxp->from_bus_match && (grf_auxp->unit != cfp->cf_unit))
158 1.11.8.2 nathanw return 0;
159 1.11.8.2 nathanw
160 1.11.8.2 nathanw /*
161 1.11.8.2 nathanw * Final constraint: each grf needs a view....
162 1.11.8.2 nathanw */
163 1.11.8.2 nathanw if((cfdata_grf == NULL) || (did_consinit > 1)) {
164 1.11.8.2 nathanw if(viewopen(cfp->cf_unit, 0, 0, NULL))
165 1.11.8.2 nathanw return 0;
166 1.11.8.2 nathanw }
167 1.11.8.2 nathanw did_consinit = 2;
168 1.11.8.2 nathanw return 1;
169 1.11.8.2 nathanw }
170 1.11.8.2 nathanw
171 1.11.8.2 nathanw /*
172 1.11.8.2 nathanw * attach: initialize the grf-structure and try to attach an ite to us.
173 1.11.8.2 nathanw * note : dp is NULL during early console init.
174 1.11.8.2 nathanw */
175 1.11.8.2 nathanw void
176 1.11.8.2 nathanw grfetattach(pdp, dp, auxp)
177 1.11.8.2 nathanw struct device *pdp, *dp;
178 1.11.8.2 nathanw void *auxp;
179 1.11.8.2 nathanw {
180 1.11.8.2 nathanw static struct grf_softc congrf;
181 1.11.8.2 nathanw static int first_attach = 1;
182 1.11.8.2 nathanw grf_auxp_t *grf_bus_auxp = auxp;
183 1.11.8.2 nathanw grf_auxp_t grf_auxp;
184 1.11.8.2 nathanw struct grf_softc *gp;
185 1.11.8.2 nathanw int maj;
186 1.11.8.2 nathanw
187 1.11.8.2 nathanw /*
188 1.11.8.2 nathanw * find our major device number
189 1.11.8.2 nathanw */
190 1.11.8.2 nathanw for(maj = 0; maj < nchrdev; maj++)
191 1.11.8.2 nathanw if (cdevsw[maj].d_open == grfopen)
192 1.11.8.2 nathanw break;
193 1.11.8.2 nathanw
194 1.11.8.2 nathanw /*
195 1.11.8.2 nathanw * Handle exeption case: early console init
196 1.11.8.2 nathanw */
197 1.11.8.2 nathanw if(dp == NULL) {
198 1.11.8.2 nathanw congrf.g_unit = cfdata_grf->cf_unit;
199 1.11.8.2 nathanw congrf.g_grfdev = makedev(maj, congrf.g_unit);
200 1.11.8.2 nathanw congrf.g_itedev = (dev_t)-1;
201 1.11.8.2 nathanw congrf.g_flags = GF_ALIVE;
202 1.11.8.2 nathanw congrf.g_mode = grf_mode;
203 1.11.8.2 nathanw congrf.g_conpri = CN_INTERNAL;
204 1.11.8.2 nathanw congrf.g_viewdev = congrf.g_unit;
205 1.11.8.2 nathanw grfet_iteinit(&congrf);
206 1.11.8.2 nathanw grf_viewsync(&congrf);
207 1.11.8.2 nathanw
208 1.11.8.2 nathanw /* Attach console ite */
209 1.11.8.2 nathanw atari_config_found(cfdata_grf, NULL, &congrf, grfetprint);
210 1.11.8.2 nathanw return;
211 1.11.8.2 nathanw }
212 1.11.8.2 nathanw
213 1.11.8.2 nathanw gp = (struct grf_softc *)dp;
214 1.11.8.2 nathanw gp->g_unit = gp->g_device.dv_unit;
215 1.11.8.2 nathanw grfsp[gp->g_unit] = gp;
216 1.11.8.2 nathanw
217 1.11.8.2 nathanw if((cfdata_grf != NULL) && (gp->g_unit == congrf.g_unit)) {
218 1.11.8.2 nathanw /*
219 1.11.8.2 nathanw * We inited earlier just copy the info, take care
220 1.11.8.2 nathanw * not to copy the device struct though.
221 1.11.8.2 nathanw */
222 1.11.8.2 nathanw bcopy(&congrf.g_display, &gp->g_display,
223 1.11.8.2 nathanw (char *)&gp[1] - (char *)&gp->g_display);
224 1.11.8.2 nathanw }
225 1.11.8.2 nathanw else {
226 1.11.8.2 nathanw gp->g_grfdev = makedev(maj, gp->g_unit);
227 1.11.8.2 nathanw gp->g_itedev = (dev_t)-1;
228 1.11.8.2 nathanw gp->g_flags = GF_ALIVE;
229 1.11.8.2 nathanw gp->g_mode = grf_mode;
230 1.11.8.2 nathanw gp->g_conpri = 0;
231 1.11.8.2 nathanw gp->g_viewdev = gp->g_unit;
232 1.11.8.2 nathanw grfet_iteinit(gp);
233 1.11.8.2 nathanw grf_viewsync(gp);
234 1.11.8.2 nathanw }
235 1.11.8.2 nathanw
236 1.11.8.2 nathanw printf(": %dx%d", gp->g_display.gd_dwidth, gp->g_display.gd_dheight);
237 1.11.8.2 nathanw if(gp->g_display.gd_colors == 2)
238 1.11.8.2 nathanw printf(" monochrome\n");
239 1.11.8.2 nathanw else printf(" colors %d\n", gp->g_display.gd_colors);
240 1.11.8.2 nathanw
241 1.11.8.2 nathanw /*
242 1.11.8.2 nathanw * try and attach an ite
243 1.11.8.2 nathanw */
244 1.11.8.2 nathanw config_found(dp, gp, grfetprint);
245 1.11.8.2 nathanw
246 1.11.8.2 nathanw /*
247 1.11.8.2 nathanw * If attaching the first unit, go ahead and 'find' the rest of us
248 1.11.8.2 nathanw */
249 1.11.8.2 nathanw if (first_attach) {
250 1.11.8.2 nathanw first_attach = 0;
251 1.11.8.2 nathanw grf_auxp.from_bus_match = 0;
252 1.11.8.2 nathanw for (grf_auxp.unit=0; grf_auxp.unit < NGRFET; grf_auxp.unit++) {
253 1.11.8.2 nathanw config_found(pdp, (void*)&grf_auxp, grf_bus_auxp->busprint);
254 1.11.8.2 nathanw }
255 1.11.8.2 nathanw }
256 1.11.8.2 nathanw }
257 1.11.8.2 nathanw
258 1.11.8.2 nathanw int
259 1.11.8.2 nathanw grfetprint(auxp, pnp)
260 1.11.8.2 nathanw void *auxp;
261 1.11.8.2 nathanw const char *pnp;
262 1.11.8.2 nathanw {
263 1.11.8.2 nathanw if(pnp) /* XXX */
264 1.11.8.2 nathanw printf("ite at %s", pnp);
265 1.11.8.2 nathanw return(UNCONF);
266 1.11.8.2 nathanw }
267 1.11.8.2 nathanw
268 1.11.8.2 nathanw /*
269 1.11.8.2 nathanw * Init ite portion of grf_softc struct
270 1.11.8.2 nathanw */
271 1.11.8.2 nathanw static void
272 1.11.8.2 nathanw grfet_iteinit(gp)
273 1.11.8.2 nathanw struct grf_softc *gp;
274 1.11.8.2 nathanw {
275 1.11.8.2 nathanw
276 1.11.8.2 nathanw gp->g_itecursor = et_cursor;
277 1.11.8.2 nathanw gp->g_iteputc = et_putc;
278 1.11.8.2 nathanw gp->g_iteclear = et_clear;
279 1.11.8.2 nathanw gp->g_itescroll = et_scroll;
280 1.11.8.2 nathanw gp->g_iteinit = view_init;
281 1.11.8.2 nathanw gp->g_itedeinit = view_deinit;
282 1.11.8.2 nathanw }
283 1.11.8.2 nathanw
284 1.11.8.2 nathanw static void
285 1.11.8.2 nathanw view_deinit(ip)
286 1.11.8.2 nathanw struct ite_softc *ip;
287 1.11.8.2 nathanw {
288 1.11.8.2 nathanw ip->flags &= ~ITE_INITED;
289 1.11.8.2 nathanw }
290 1.11.8.2 nathanw
291 1.11.8.2 nathanw static void
292 1.11.8.2 nathanw view_init(ip)
293 1.11.8.2 nathanw register struct ite_softc *ip;
294 1.11.8.2 nathanw {
295 1.11.8.2 nathanw struct itewinsize wsz;
296 1.11.8.2 nathanw ipriv_t *cci;
297 1.11.8.2 nathanw view_t *view;
298 1.11.8.2 nathanw save_area_t *et_save;
299 1.11.8.2 nathanw
300 1.11.8.2 nathanw if((cci = ip->priv) != NULL)
301 1.11.8.2 nathanw return;
302 1.11.8.2 nathanw
303 1.11.8.2 nathanw ip->itexx_ioctl = iteet_ioctl;
304 1.11.8.2 nathanw
305 1.11.8.2 nathanw #if defined(KFONT_8X8)
306 1.11.8.2 nathanw ip->font = font_info_8x8;
307 1.11.8.2 nathanw #else
308 1.11.8.2 nathanw ip->font = font_info_8x16;
309 1.11.8.2 nathanw #endif
310 1.11.8.2 nathanw
311 1.11.8.2 nathanw /* Find the correct set of rendering routines for this font. */
312 1.11.8.2 nathanw if(ip->font.width != 8)
313 1.11.8.2 nathanw panic("kernel font size not supported");
314 1.11.8.2 nathanw
315 1.11.8.2 nathanw if(!atari_realconfig)
316 1.11.8.2 nathanw ip->priv = cci = &con_ipriv;
317 1.11.8.2 nathanw else ip->priv = cci = (ipriv_t*)malloc(sizeof(*cci), M_DEVBUF,M_WAITOK);
318 1.11.8.2 nathanw if(cci == NULL)
319 1.11.8.2 nathanw panic("No memory for ite-view");
320 1.11.8.2 nathanw bzero(cci, sizeof(*cci));
321 1.11.8.2 nathanw
322 1.11.8.2 nathanw wsz.x = ite_default_x;
323 1.11.8.2 nathanw wsz.y = ite_default_y;
324 1.11.8.2 nathanw wsz.width = ite_default_width;
325 1.11.8.2 nathanw wsz.height = ite_default_height;
326 1.11.8.2 nathanw wsz.depth = ite_default_depth;
327 1.11.8.2 nathanw
328 1.11.8.2 nathanw ite_newsize (ip, &wsz);
329 1.11.8.2 nathanw
330 1.11.8.2 nathanw view = viewview(ip->grf->g_viewdev);
331 1.11.8.2 nathanw cci->regkva = view->bitmap->regs;
332 1.11.8.2 nathanw
333 1.11.8.2 nathanw /*
334 1.11.8.2 nathanw * Only console will be turned on by default..
335 1.11.8.2 nathanw */
336 1.11.8.2 nathanw if(ip->flags & ITE_ISCONS)
337 1.11.8.2 nathanw ip->grf->g_mode(ip->grf, GM_GRFON, NULL, 0, 0);
338 1.11.8.2 nathanw
339 1.11.8.2 nathanw /*
340 1.11.8.2 nathanw * Activate text-mode settings
341 1.11.8.2 nathanw */
342 1.11.8.2 nathanw et_save = (save_area_t *)view->save_area;
343 1.11.8.2 nathanw if (et_save == NULL)
344 1.11.8.2 nathanw et_inittextmode(ip, NULL, view->flags & VF_DISPLAY);
345 1.11.8.2 nathanw else {
346 1.11.8.2 nathanw et_inittextmode(ip, &et_save->sv_regs, view->flags&VF_DISPLAY);
347 1.11.8.2 nathanw et_save->fb_size = ip->cols * ip->rows;
348 1.11.8.2 nathanw }
349 1.11.8.2 nathanw }
350 1.11.8.2 nathanw
351 1.11.8.2 nathanw static int
352 1.11.8.2 nathanw ite_newsize(ip, winsz)
353 1.11.8.2 nathanw struct ite_softc *ip;
354 1.11.8.2 nathanw struct itewinsize *winsz;
355 1.11.8.2 nathanw {
356 1.11.8.2 nathanw struct view_size vs;
357 1.11.8.2 nathanw int error = 0;
358 1.11.8.2 nathanw save_area_t *et_save;
359 1.11.8.2 nathanw view_t *view;
360 1.11.8.2 nathanw
361 1.11.8.2 nathanw vs.x = winsz->x;
362 1.11.8.2 nathanw vs.y = winsz->y;
363 1.11.8.2 nathanw vs.width = winsz->width;
364 1.11.8.2 nathanw vs.height = winsz->height;
365 1.11.8.2 nathanw vs.depth = winsz->depth;
366 1.11.8.2 nathanw
367 1.11.8.2 nathanw error = viewioctl(ip->grf->g_viewdev, VIOCSSIZE, (caddr_t)&vs, 0,
368 1.11.8.2 nathanw NOPROC);
369 1.11.8.2 nathanw view = viewview(ip->grf->g_viewdev);
370 1.11.8.2 nathanw
371 1.11.8.2 nathanw /*
372 1.11.8.2 nathanw * Reinitialize our structs
373 1.11.8.2 nathanw */
374 1.11.8.2 nathanw ip->cols = view->display.width / ip->font.width;
375 1.11.8.2 nathanw ip->rows = view->display.height / ip->font.height;
376 1.11.8.2 nathanw
377 1.11.8.2 nathanw /*
378 1.11.8.2 nathanw * save new values so that future opens use them
379 1.11.8.2 nathanw * this may not be correct when we implement Virtual Consoles
380 1.11.8.2 nathanw */
381 1.11.8.2 nathanw ite_default_height = view->display.height;
382 1.11.8.2 nathanw ite_default_width = view->display.width;
383 1.11.8.2 nathanw ite_default_x = view->display.x;
384 1.11.8.2 nathanw ite_default_y = view->display.y;
385 1.11.8.2 nathanw ite_default_depth = view->bitmap->depth;
386 1.11.8.2 nathanw
387 1.11.8.2 nathanw et_save = (save_area_t *)view->save_area;
388 1.11.8.2 nathanw if (et_save == NULL)
389 1.11.8.2 nathanw et_inittextmode(ip, NULL, view->flags & VF_DISPLAY);
390 1.11.8.2 nathanw else {
391 1.11.8.2 nathanw et_inittextmode(ip, &et_save->sv_regs, view->flags & VF_DISPLAY);
392 1.11.8.2 nathanw et_save->fb_size = ip->cols * ip->rows;
393 1.11.8.2 nathanw }
394 1.11.8.2 nathanw et_clear(ip, 0, 0, ip->rows, ip->cols);
395 1.11.8.2 nathanw
396 1.11.8.2 nathanw return(error);
397 1.11.8.2 nathanw }
398 1.11.8.2 nathanw
399 1.11.8.2 nathanw int
400 1.11.8.2 nathanw iteet_ioctl(ip, cmd, addr, flag, p)
401 1.11.8.2 nathanw struct ite_softc *ip;
402 1.11.8.2 nathanw u_long cmd;
403 1.11.8.2 nathanw caddr_t addr;
404 1.11.8.2 nathanw int flag;
405 1.11.8.2 nathanw struct proc *p;
406 1.11.8.2 nathanw {
407 1.11.8.2 nathanw struct winsize ws;
408 1.11.8.2 nathanw struct itewinsize *is;
409 1.11.8.2 nathanw int error = 0;
410 1.11.8.2 nathanw view_t *view = viewview(ip->grf->g_viewdev);
411 1.11.8.2 nathanw
412 1.11.8.2 nathanw switch (cmd) {
413 1.11.8.2 nathanw case ITEIOCSWINSZ:
414 1.11.8.2 nathanw is = (struct itewinsize *)addr;
415 1.11.8.2 nathanw
416 1.11.8.2 nathanw if(ite_newsize(ip, is))
417 1.11.8.2 nathanw error = ENOMEM;
418 1.11.8.2 nathanw else {
419 1.11.8.2 nathanw view = viewview(ip->grf->g_viewdev);
420 1.11.8.2 nathanw ws.ws_row = ip->rows;
421 1.11.8.2 nathanw ws.ws_col = ip->cols;
422 1.11.8.2 nathanw ws.ws_xpixel = view->display.width;
423 1.11.8.2 nathanw ws.ws_ypixel = view->display.height;
424 1.11.8.2 nathanw ite_reset(ip);
425 1.11.8.2 nathanw /*
426 1.11.8.2 nathanw * XXX tell tty about the change
427 1.11.8.2 nathanw * XXX this is messy, but works
428 1.11.8.2 nathanw */
429 1.11.8.2 nathanw iteioctl(ip->grf->g_itedev,TIOCSWINSZ,(caddr_t)&ws,0,p);
430 1.11.8.2 nathanw }
431 1.11.8.2 nathanw break;
432 1.11.8.2 nathanw case VIOCSCMAP:
433 1.11.8.2 nathanw case VIOCGCMAP:
434 1.11.8.2 nathanw /*
435 1.11.8.2 nathanw * XXX watchout for that NOPROC. its not really the kernel
436 1.11.8.2 nathanw * XXX talking these two commands don't use the proc pointer
437 1.11.8.2 nathanw * XXX though.
438 1.11.8.2 nathanw */
439 1.11.8.2 nathanw error = viewioctl(ip->grf->g_viewdev, cmd, addr, flag, NOPROC);
440 1.11.8.2 nathanw break;
441 1.11.8.2 nathanw default:
442 1.11.8.2 nathanw error = EPASSTHROUGH;
443 1.11.8.2 nathanw break;
444 1.11.8.2 nathanw }
445 1.11.8.2 nathanw return (error);
446 1.11.8.2 nathanw }
447 1.11.8.2 nathanw
448 1.11.8.2 nathanw void
449 1.11.8.2 nathanw et_cursor(ip, flag)
450 1.11.8.2 nathanw struct ite_softc *ip;
451 1.11.8.2 nathanw int flag;
452 1.11.8.2 nathanw {
453 1.11.8.2 nathanw volatile u_char *ba;
454 1.11.8.2 nathanw view_t *v;
455 1.11.8.2 nathanw u_long cpos;
456 1.11.8.2 nathanw
457 1.11.8.2 nathanw ba = ((ipriv_t*)ip->priv)->regkva;
458 1.11.8.2 nathanw v = viewview(ip->grf->g_viewdev);
459 1.11.8.2 nathanw
460 1.11.8.2 nathanw /*
461 1.11.8.2 nathanw * Don't update the cursor when not on display
462 1.11.8.2 nathanw */
463 1.11.8.2 nathanw if (!(v->flags & VF_DISPLAY))
464 1.11.8.2 nathanw return;
465 1.11.8.2 nathanw
466 1.11.8.2 nathanw switch (flag) {
467 1.11.8.2 nathanw case DRAW_CURSOR:
468 1.11.8.2 nathanw /*WCrt(ba, CRT_ID_CURSOR_START, & ~0x20); */
469 1.11.8.2 nathanw case MOVE_CURSOR:
470 1.11.8.2 nathanw cpos = RCrt(ba, CRT_ID_START_ADDR_LOW) & 0xff;
471 1.11.8.2 nathanw cpos |= (RCrt(ba, CRT_ID_START_ADDR_HIGH) & 0xff) << 8;
472 1.11.8.2 nathanw cpos += ip->curx + ip->cury * ip->cols;
473 1.11.8.2 nathanw WCrt(ba, CRT_ID_CURSOR_LOC_LOW, cpos & 0xff);
474 1.11.8.2 nathanw WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, (cpos >> 8) & 0xff);
475 1.11.8.2 nathanw WCrt(ba, CTR_ID_EXT_START, (cpos >> (16-2)) & 0x0c);
476 1.11.8.2 nathanw
477 1.11.8.2 nathanw ip->cursorx = ip->curx;
478 1.11.8.2 nathanw ip->cursory = ip->cury;
479 1.11.8.2 nathanw break;
480 1.11.8.2 nathanw case ERASE_CURSOR:
481 1.11.8.2 nathanw /*WCrt(ba, CRT_ID_CURSOR_START, | 0x20); */
482 1.11.8.2 nathanw case START_CURSOROPT:
483 1.11.8.2 nathanw case END_CURSOROPT:
484 1.11.8.2 nathanw default:
485 1.11.8.2 nathanw break;
486 1.11.8.2 nathanw }
487 1.11.8.2 nathanw }
488 1.11.8.2 nathanw
489 1.11.8.2 nathanw void
490 1.11.8.2 nathanw et_putc(ip, c, dy, dx, mode)
491 1.11.8.2 nathanw struct ite_softc *ip;
492 1.11.8.2 nathanw int c;
493 1.11.8.2 nathanw int dy;
494 1.11.8.2 nathanw int dx;
495 1.11.8.2 nathanw int mode;
496 1.11.8.2 nathanw {
497 1.11.8.2 nathanw view_t *v = viewview(ip->grf->g_viewdev);
498 1.11.8.2 nathanw u_char attr;
499 1.11.8.2 nathanw u_short *cp;
500 1.11.8.2 nathanw
501 1.11.8.2 nathanw attr = (unsigned char) ((mode & ATTR_INV) ? (0x70) : (0x07));
502 1.11.8.2 nathanw if (mode & ATTR_UL) attr |= 0x01;
503 1.11.8.2 nathanw if (mode & ATTR_BOLD) attr |= 0x08;
504 1.11.8.2 nathanw if (mode & ATTR_BLINK) attr |= 0x80;
505 1.11.8.2 nathanw
506 1.11.8.2 nathanw cp = (u_short*)v->bitmap->plane;
507 1.11.8.2 nathanw cp[(dy * ip->cols) + dx] = (c << 8) | attr;
508 1.11.8.2 nathanw }
509 1.11.8.2 nathanw
510 1.11.8.2 nathanw void
511 1.11.8.2 nathanw et_clear(ip, sy, sx, h, w)
512 1.11.8.2 nathanw struct ite_softc *ip;
513 1.11.8.2 nathanw int sy;
514 1.11.8.2 nathanw int sx;
515 1.11.8.2 nathanw int h;
516 1.11.8.2 nathanw int w;
517 1.11.8.2 nathanw {
518 1.11.8.2 nathanw /* et_clear and et_scroll both rely on ite passing arguments
519 1.11.8.2 nathanw * which describe continuous regions. For a VT200 terminal,
520 1.11.8.2 nathanw * this is safe behavior.
521 1.11.8.2 nathanw */
522 1.11.8.2 nathanw view_t *v = viewview(ip->grf->g_viewdev);
523 1.11.8.2 nathanw u_short *dest;
524 1.11.8.2 nathanw int len;
525 1.11.8.2 nathanw
526 1.11.8.2 nathanw dest = (u_short *)v->bitmap->plane + (sy * ip->cols) + sx;
527 1.11.8.2 nathanw for(len = w * h; len-- ;)
528 1.11.8.2 nathanw *dest++ = 0x2007;
529 1.11.8.2 nathanw }
530 1.11.8.2 nathanw
531 1.11.8.2 nathanw void
532 1.11.8.2 nathanw et_scroll(ip, sy, sx, count, dir)
533 1.11.8.2 nathanw struct ite_softc *ip;
534 1.11.8.2 nathanw int sy;
535 1.11.8.2 nathanw int sx;
536 1.11.8.2 nathanw int count;
537 1.11.8.2 nathanw int dir;
538 1.11.8.2 nathanw {
539 1.11.8.2 nathanw view_t *v = viewview(ip->grf->g_viewdev);
540 1.11.8.2 nathanw u_short *fb;
541 1.11.8.2 nathanw u_short *src, *dst;
542 1.11.8.2 nathanw int len;
543 1.11.8.2 nathanw
544 1.11.8.2 nathanw fb = (u_short*)v->bitmap->plane + sy * ip->cols;
545 1.11.8.2 nathanw switch (dir) {
546 1.11.8.2 nathanw case SCROLL_UP:
547 1.11.8.2 nathanw src = fb;
548 1.11.8.2 nathanw dst = fb - count * ip->cols;
549 1.11.8.2 nathanw len = (ip->bottom_margin + 1 - sy) * ip->cols;
550 1.11.8.2 nathanw break;
551 1.11.8.2 nathanw case SCROLL_DOWN:
552 1.11.8.2 nathanw src = fb;
553 1.11.8.2 nathanw dst = fb + count * ip->cols;
554 1.11.8.2 nathanw len = (ip->bottom_margin + 1 - (sy + count)) * ip->cols;
555 1.11.8.2 nathanw break;
556 1.11.8.2 nathanw case SCROLL_RIGHT:
557 1.11.8.2 nathanw src = fb + sx;
558 1.11.8.2 nathanw dst = fb + sx + count;
559 1.11.8.2 nathanw len = ip->cols - sx + count;
560 1.11.8.2 nathanw break;
561 1.11.8.2 nathanw case SCROLL_LEFT:
562 1.11.8.2 nathanw src = fb + sx;
563 1.11.8.2 nathanw dst = fb + sx - count;
564 1.11.8.2 nathanw len = ip->cols - sx;
565 1.11.8.2 nathanw break;
566 1.11.8.2 nathanw default:
567 1.11.8.2 nathanw return;
568 1.11.8.2 nathanw }
569 1.11.8.2 nathanw if (src > dst) {
570 1.11.8.2 nathanw while (len--)
571 1.11.8.2 nathanw *dst++ = *src++;
572 1.11.8.2 nathanw }
573 1.11.8.2 nathanw else {
574 1.11.8.2 nathanw src = &src[len];
575 1.11.8.2 nathanw dst = &dst[len];
576 1.11.8.2 nathanw while (len--)
577 1.11.8.2 nathanw *--dst = *--src;
578 1.11.8.2 nathanw }
579 1.11.8.2 nathanw }
580 1.11.8.2 nathanw
581 1.11.8.2 nathanw static void
582 1.11.8.2 nathanw et_inittextmode(ip, etregs, loadfont)
583 1.11.8.2 nathanw struct ite_softc *ip;
584 1.11.8.2 nathanw et_sv_reg_t *etregs;
585 1.11.8.2 nathanw int loadfont;
586 1.11.8.2 nathanw {
587 1.11.8.2 nathanw volatile u_char *ba;
588 1.11.8.2 nathanw font_info *fd;
589 1.11.8.2 nathanw u_char *fb;
590 1.11.8.2 nathanw u_char *c, *f, tmp;
591 1.11.8.2 nathanw u_short z, y;
592 1.11.8.2 nathanw int s;
593 1.11.8.2 nathanw view_t *v = viewview(ip->grf->g_viewdev);
594 1.11.8.2 nathanw et_sv_reg_t loc_regs;
595 1.11.8.2 nathanw
596 1.11.8.2 nathanw if (etregs == NULL) {
597 1.11.8.2 nathanw etregs = &loc_regs;
598 1.11.8.2 nathanw et_hwsave(etregs);
599 1.11.8.2 nathanw }
600 1.11.8.2 nathanw
601 1.11.8.2 nathanw ba = ((ipriv_t*)ip->priv)->regkva;
602 1.11.8.2 nathanw fb = v->bitmap->plane;
603 1.11.8.2 nathanw
604 1.11.8.2 nathanw #if defined(KFONT_8X8)
605 1.11.8.2 nathanw fd = &font_info_8x8;
606 1.11.8.2 nathanw #else
607 1.11.8.2 nathanw fd = &font_info_8x16;
608 1.11.8.2 nathanw #endif
609 1.11.8.2 nathanw
610 1.11.8.2 nathanw if (loadfont) { /* XXX: We should set the colormap */
611 1.11.8.2 nathanw /*
612 1.11.8.2 nathanw * set colors (B&W)
613 1.11.8.2 nathanw */
614 1.11.8.2 nathanw vgaw(ba, VDAC_ADDRESS_W, 0);
615 1.11.8.2 nathanw for (z = 0; z < 256; z++) {
616 1.11.8.2 nathanw y = (z & 1) ? ((z > 7) ? 2 : 1) : 0;
617 1.11.8.2 nathanw
618 1.11.8.2 nathanw vgaw(ba, VDAC_DATA, etconscolors[y][0]);
619 1.11.8.2 nathanw vgaw(ba, VDAC_DATA, etconscolors[y][1]);
620 1.11.8.2 nathanw vgaw(ba, VDAC_DATA, etconscolors[y][2]);
621 1.11.8.2 nathanw }
622 1.11.8.2 nathanw
623 1.11.8.2 nathanw /*
624 1.11.8.2 nathanw * Enter a suitable mode to download the font. This
625 1.11.8.2 nathanw * basically means sequential addressing mode
626 1.11.8.2 nathanw */
627 1.11.8.2 nathanw s = splhigh();
628 1.11.8.2 nathanw
629 1.11.8.2 nathanw WAttr(ba, 0x20 | ACT_ID_ATTR_MODE_CNTL, 0x0a);
630 1.11.8.2 nathanw WSeq(ba, SEQ_ID_MAP_MASK, 0x04);
631 1.11.8.2 nathanw WSeq(ba, SEQ_ID_MEMORY_MODE, 0x06);
632 1.11.8.2 nathanw WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x02);
633 1.11.8.2 nathanw WGfx(ba, GCT_ID_GRAPHICS_MODE, 0x00);
634 1.11.8.2 nathanw WGfx(ba, GCT_ID_MISC, 0x04);
635 1.11.8.2 nathanw splx(s);
636 1.11.8.2 nathanw
637 1.11.8.2 nathanw /*
638 1.11.8.2 nathanw * load text font into beginning of display memory. Each
639 1.11.8.2 nathanw * character cell is 32 bytes long (enough for 4 planes)
640 1.11.8.2 nathanw */
641 1.11.8.2 nathanw for (z = 0, c = fb; z < 256 * 32; z++)
642 1.11.8.2 nathanw *c++ = 0;
643 1.11.8.2 nathanw
644 1.11.8.2 nathanw c = (unsigned char *) (fb) + (32 * fd->font_lo);
645 1.11.8.2 nathanw f = fd->font_p;
646 1.11.8.2 nathanw z = fd->font_lo;
647 1.11.8.2 nathanw for (; z <= fd->font_hi; z++, c += (32 - fd->height))
648 1.11.8.2 nathanw for (y = 0; y < fd->height; y++) {
649 1.11.8.2 nathanw *c++ = *f++;
650 1.11.8.2 nathanw }
651 1.11.8.2 nathanw }
652 1.11.8.2 nathanw
653 1.11.8.2 nathanw /*
654 1.11.8.2 nathanw * Odd/Even addressing
655 1.11.8.2 nathanw */
656 1.11.8.2 nathanw etregs->seq[SEQ_ID_MAP_MASK] = 0x03;
657 1.11.8.2 nathanw etregs->seq[SEQ_ID_MEMORY_MODE] = 0x03;
658 1.11.8.2 nathanw etregs->grf[GCT_ID_READ_MAP_SELECT] = 0x00;
659 1.11.8.2 nathanw etregs->grf[GCT_ID_GRAPHICS_MODE] = 0x10;
660 1.11.8.2 nathanw etregs->grf[GCT_ID_MISC] = 0x06;
661 1.11.8.2 nathanw
662 1.11.8.2 nathanw /*
663 1.11.8.2 nathanw * Font height + underline location
664 1.11.8.2 nathanw */
665 1.11.8.2 nathanw tmp = etregs->crt[CRT_ID_MAX_ROW_ADDRESS] & 0xe0;
666 1.11.8.2 nathanw etregs->crt[CRT_ID_MAX_ROW_ADDRESS] = tmp | (fd->height - 1);
667 1.11.8.2 nathanw tmp = etregs->crt[CRT_ID_UNDERLINE_LOC] & 0xe0;
668 1.11.8.2 nathanw etregs->crt[CRT_ID_UNDERLINE_LOC] = tmp | (fd->height - 1);
669 1.11.8.2 nathanw
670 1.11.8.2 nathanw /*
671 1.11.8.2 nathanw * Cursor setup
672 1.11.8.2 nathanw */
673 1.11.8.2 nathanw etregs->crt[CRT_ID_CURSOR_START] = 0x00;
674 1.11.8.2 nathanw etregs->crt[CRT_ID_CURSOR_END] = fd->height - 1;
675 1.11.8.2 nathanw etregs->crt[CRT_ID_CURSOR_LOC_HIGH] = 0x00;
676 1.11.8.2 nathanw etregs->crt[CRT_ID_CURSOR_LOC_LOW] = 0x00;
677 1.11.8.2 nathanw
678 1.11.8.2 nathanw /*
679 1.11.8.2 nathanw * Enter text mode
680 1.11.8.2 nathanw */
681 1.11.8.2 nathanw etregs->crt[CRT_ID_MODE_CONTROL] = 0xa3;
682 1.11.8.2 nathanw etregs->attr[ACT_ID_ATTR_MODE_CNTL] = 0x0a;
683 1.11.8.2 nathanw
684 1.11.8.2 nathanw #if 1
685 1.11.8.2 nathanw if (loadfont || (etregs == &loc_regs))
686 1.11.8.2 nathanw #else
687 1.11.8.2 nathanw if (etregs == &loc_regs)
688 1.11.8.2 nathanw #endif
689 1.11.8.2 nathanw et_hwrest(etregs);
690 1.11.8.2 nathanw }
691