ite_cc.c revision 1.8 1 1.8 leo /* $NetBSD: ite_cc.c,v 1.8 1996/10/04 07:27:58 leo Exp $ */
2 1.1 leo
3 1.1 leo /*
4 1.7 leo * Copyright (c) 1996 Leo Weppelman
5 1.1 leo * Copyright (c) 1994 Christian E. Hopps
6 1.1 leo * All rights reserved.
7 1.1 leo *
8 1.1 leo * Redistribution and use in source and binary forms, with or without
9 1.1 leo * modification, are permitted provided that the following conditions
10 1.1 leo * are met:
11 1.1 leo * 1. Redistributions of source code must retain the above copyright
12 1.1 leo * notice, this list of conditions and the following disclaimer.
13 1.1 leo * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 leo * notice, this list of conditions and the following disclaimer in the
15 1.1 leo * documentation and/or other materials provided with the distribution.
16 1.1 leo * 3. All advertising materials mentioning features or use of this software
17 1.1 leo * must display the following acknowledgement:
18 1.1 leo * This product includes software developed by Christian E. Hopps.
19 1.1 leo * 4. The name of the author may not be used to endorse or promote products
20 1.1 leo * derived from this software without specific prior written permission
21 1.1 leo *
22 1.1 leo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 leo * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 leo * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 leo * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 leo * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1 leo * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1 leo * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1 leo * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1 leo * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1 leo * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 leo */
33 1.1 leo
34 1.7 leo #include "grfcc.h"
35 1.7 leo #if NGRFCC > 0
36 1.1 leo
37 1.1 leo #include <sys/param.h>
38 1.1 leo #include <sys/conf.h>
39 1.1 leo #include <sys/proc.h>
40 1.1 leo #include <sys/ioctl.h>
41 1.1 leo #include <sys/tty.h>
42 1.1 leo #include <sys/systm.h>
43 1.1 leo #include <sys/queue.h>
44 1.1 leo #include <sys/termios.h>
45 1.1 leo #include <sys/malloc.h>
46 1.7 leo #include <sys/device.h>
47 1.1 leo #include <dev/cons.h>
48 1.1 leo #include <machine/cpu.h>
49 1.7 leo #include <atari/atari/device.h>
50 1.1 leo #include <atari/dev/itevar.h>
51 1.1 leo #include <atari/dev/iteioctl.h>
52 1.1 leo #include <atari/dev/grfioctl.h>
53 1.1 leo #include <atari/dev/grfabs_reg.h>
54 1.1 leo #include <atari/dev/grfvar.h>
55 1.1 leo #include <atari/dev/font.h>
56 1.1 leo #include <atari/dev/viewioctl.h>
57 1.1 leo #include <atari/dev/viewvar.h>
58 1.1 leo
59 1.1 leo /*
60 1.1 leo * This is what ip->priv points to;
61 1.1 leo * it contains local variables for custom-chip ites.
62 1.1 leo */
63 1.1 leo struct ite_priv {
64 1.1 leo u_char **row_ptr; /* array of pointers into the bitmap */
65 1.1 leo u_long row_bytes;
66 1.1 leo u_long cursor_opt;
67 1.1 leo u_short *column_offset; /* array of offsets for columns */
68 1.1 leo u_int row_offset; /* the row offset */
69 1.1 leo u_short width; /* the bitmap width */
70 1.1 leo u_short underline; /* where the underline goes */
71 1.1 leo u_short ft_x; /* the font width */
72 1.1 leo u_short ft_y; /* the font height */
73 1.1 leo u_char *font_cell[256];/* the font pointer */
74 1.1 leo };
75 1.1 leo typedef struct ite_priv ipriv_t;
76 1.1 leo
77 1.1 leo /*
78 1.1 leo * We need the following space to get an ite-console setup before
79 1.1 leo * the VM-system is brought up. We setup for a 1280x960 monitor with
80 1.1 leo * an 8x8 font.
81 1.1 leo */
82 1.1 leo #define CONS_MAXROW 120 /* Max. number of rows on console */
83 1.1 leo #define CONS_MAXCOL 160 /* Max. number of columns on console */
84 1.1 leo static u_short con_columns[CONS_MAXCOL];
85 1.1 leo static u_char *con_rows[CONS_MAXROW];
86 1.1 leo static ipriv_t con_ipriv;
87 1.1 leo
88 1.1 leo extern font_info font_info_8x8;
89 1.1 leo extern font_info font_info_8x16;
90 1.1 leo
91 1.1 leo static void view_init __P((struct ite_softc *));
92 1.1 leo static void view_deinit __P((struct ite_softc *));
93 1.1 leo static int ite_newsize __P((struct ite_softc *, struct itewinsize *));
94 1.1 leo static void cursor32 __P((struct ite_softc *, int));
95 1.1 leo static void putc8 __P((struct ite_softc *, int, int, int, int));
96 1.1 leo static void clear8 __P((struct ite_softc *, int, int, int, int));
97 1.1 leo static void scroll8 __P((struct ite_softc *, int, int, int, int));
98 1.1 leo static void scrollbmap __P((bmap_t *, u_short, u_short, u_short, u_short,
99 1.1 leo short, short));
100 1.1 leo
101 1.1 leo /*
102 1.1 leo * Patchable
103 1.1 leo */
104 1.1 leo int ite_default_x = 0; /* def leftedge offset */
105 1.1 leo int ite_default_y = 0; /* def topedge offset */
106 1.1 leo int ite_default_width = 640; /* def width */
107 1.1 leo int ite_default_depth = 1; /* def depth */
108 1.1 leo int ite_default_height = 400; /* def height */
109 1.1 leo
110 1.1 leo /*
111 1.7 leo * grfcc config stuff
112 1.7 leo */
113 1.7 leo void grfccattach __P((struct device *, struct device *, void *));
114 1.7 leo int grfccmatch __P((struct device *, void *, void *));
115 1.7 leo int grfccprint __P((void *, const char *));
116 1.7 leo
117 1.7 leo struct cfattach grfcc_ca = {
118 1.7 leo sizeof(struct grf_softc), grfccmatch, grfccattach
119 1.7 leo };
120 1.7 leo
121 1.7 leo struct cfdriver grfcc_cd = {
122 1.7 leo NULL, "grfcc", DV_DULL
123 1.7 leo };
124 1.7 leo
125 1.7 leo /*
126 1.7 leo * only used in console init.
127 1.7 leo */
128 1.7 leo static struct cfdata *cfdata_grf = NULL;
129 1.7 leo
130 1.7 leo /*
131 1.7 leo * Probe functions we can use:
132 1.7 leo */
133 1.7 leo #ifdef TT_VIDEO
134 1.7 leo void tt_probe_video __P((MODES *));
135 1.7 leo #endif /* TT_VIDEO */
136 1.7 leo #ifdef FALCON_VIDEO
137 1.7 leo void falcon_probe_video __P((MODES *));
138 1.7 leo #endif /* FALCON_VIDEO */
139 1.7 leo
140 1.7 leo int
141 1.7 leo grfccmatch(pdp, match, auxp)
142 1.7 leo struct device *pdp;
143 1.7 leo void *match, *auxp;
144 1.7 leo {
145 1.7 leo static int must_probe = 1;
146 1.7 leo grf_auxp_t *grf_auxp = auxp;
147 1.7 leo struct cfdata *cfp = match;
148 1.7 leo
149 1.7 leo if (must_probe) {
150 1.7 leo /*
151 1.7 leo * Check if the layers we depend on exist
152 1.7 leo */
153 1.7 leo if (!(machineid & (ATARI_TT|ATARI_FALCON)))
154 1.7 leo return (0);
155 1.7 leo #ifdef TT_VIDEO
156 1.7 leo if ((machineid & ATARI_TT) && !grfabs_probe(&tt_probe_video))
157 1.7 leo return (0);
158 1.7 leo #endif /* TT_VIDEO */
159 1.7 leo #ifdef FALCON_VIDEO
160 1.7 leo if ((machineid & ATARI_FALCON)
161 1.7 leo && !grfabs_probe(&falcon_probe_video))
162 1.7 leo return (0);
163 1.7 leo #endif /* FALCON_VIDEO */
164 1.7 leo
165 1.7 leo viewprobe();
166 1.7 leo must_probe = 0;
167 1.7 leo }
168 1.7 leo
169 1.7 leo if (atari_realconfig == 0) {
170 1.7 leo /*
171 1.7 leo * Early console init. Only match unit 0.
172 1.7 leo */
173 1.7 leo if (cfp->cf_unit != 0)
174 1.7 leo return(0);
175 1.7 leo if (viewopen(0, 0, 0, NULL))
176 1.7 leo return(0);
177 1.7 leo cfdata_grf = cfp;
178 1.7 leo return (1);
179 1.7 leo }
180 1.7 leo
181 1.7 leo /*
182 1.7 leo * Normal config. When we are called directly from the grfbus,
183 1.7 leo * we only match unit 0. The attach function will call us for
184 1.7 leo * the other configured units.
185 1.7 leo */
186 1.7 leo if (grf_auxp->from_bus_match && (cfp->cf_unit != 0))
187 1.7 leo return (0);
188 1.7 leo
189 1.7 leo if (!grf_auxp->from_bus_match && (grf_auxp->unit != cfp->cf_unit))
190 1.7 leo return (0);
191 1.7 leo
192 1.7 leo /*
193 1.7 leo * Final constraint: each grf needs a view....
194 1.7 leo */
195 1.7 leo if((cfdata_grf == NULL) || (cfp->cf_unit != 0)) {
196 1.7 leo if(viewopen(cfp->cf_unit, 0, 0, NULL))
197 1.7 leo return(0);
198 1.7 leo }
199 1.7 leo return(1);
200 1.7 leo }
201 1.7 leo
202 1.7 leo /*
203 1.7 leo * attach: initialize the grf-structure and try to attach an ite to us.
204 1.7 leo * note : dp is NULL during early console init.
205 1.7 leo */
206 1.7 leo void
207 1.7 leo grfccattach(pdp, dp, auxp)
208 1.7 leo struct device *pdp, *dp;
209 1.7 leo void *auxp;
210 1.7 leo {
211 1.7 leo static struct grf_softc congrf;
212 1.7 leo grf_auxp_t *grf_bus_auxp = auxp;
213 1.7 leo grf_auxp_t grf_auxp;
214 1.7 leo struct grf_softc *gp;
215 1.7 leo int maj;
216 1.7 leo
217 1.7 leo /*
218 1.7 leo * find our major device number
219 1.7 leo */
220 1.7 leo for(maj = 0; maj < nchrdev; maj++)
221 1.7 leo if (cdevsw[maj].d_open == grfopen)
222 1.7 leo break;
223 1.7 leo
224 1.7 leo /*
225 1.7 leo * Handle exeption case: early console init
226 1.7 leo */
227 1.7 leo if(dp == NULL) {
228 1.7 leo congrf.g_unit = 0;
229 1.7 leo congrf.g_itedev = (dev_t)-1;
230 1.7 leo congrf.g_grfdev = makedev(maj, 0);
231 1.7 leo congrf.g_flags = GF_ALIVE;
232 1.7 leo congrf.g_mode = grf_mode;
233 1.7 leo congrf.g_conpri = grfcc_cnprobe();
234 1.7 leo congrf.g_viewdev = congrf.g_unit;
235 1.7 leo grfcc_iteinit(&congrf);
236 1.7 leo grf_viewsync(&congrf);
237 1.7 leo
238 1.7 leo /* Attach console ite */
239 1.7 leo atari_config_found(cfdata_grf, NULL, &congrf, grfccprint);
240 1.7 leo return;
241 1.7 leo }
242 1.7 leo
243 1.7 leo gp = (struct grf_softc *)dp;
244 1.7 leo gp->g_unit = gp->g_device.dv_unit;
245 1.7 leo grfsp[gp->g_unit] = gp;
246 1.7 leo
247 1.7 leo if((cfdata_grf != NULL) && (gp->g_unit == 0)) {
248 1.7 leo /*
249 1.7 leo * We inited earlier just copy the info, take care
250 1.7 leo * not to copy the device struct though.
251 1.7 leo */
252 1.7 leo bcopy(&congrf.g_display, &gp->g_display,
253 1.7 leo (char *)&gp[1] - (char *)&gp->g_display);
254 1.7 leo }
255 1.7 leo else {
256 1.7 leo gp->g_grfdev = makedev(maj, gp->g_unit);
257 1.7 leo gp->g_itedev = (dev_t)-1;
258 1.7 leo gp->g_flags = GF_ALIVE;
259 1.7 leo gp->g_mode = grf_mode;
260 1.7 leo gp->g_conpri = 0;
261 1.7 leo gp->g_viewdev = gp->g_unit;
262 1.7 leo grfcc_iteinit(gp);
263 1.7 leo grf_viewsync(gp);
264 1.7 leo }
265 1.7 leo
266 1.7 leo printf(": width %d height %d", gp->g_display.gd_dwidth,
267 1.7 leo gp->g_display.gd_dheight);
268 1.7 leo if(gp->g_display.gd_colors == 2)
269 1.7 leo printf(" monochrome\n");
270 1.7 leo else printf(" colors %d\n", gp->g_display.gd_colors);
271 1.7 leo
272 1.7 leo /*
273 1.7 leo * try and attach an ite
274 1.7 leo */
275 1.7 leo config_found(dp, gp, grfccprint);
276 1.7 leo
277 1.7 leo /*
278 1.7 leo * If attaching unit 0, go ahead and 'find' the rest of us
279 1.7 leo */
280 1.7 leo if (gp->g_unit == 0) {
281 1.7 leo grf_auxp.from_bus_match = 0;
282 1.7 leo for (grf_auxp.unit=1; grf_auxp.unit < NGRFCC; grf_auxp.unit++) {
283 1.7 leo config_found(pdp, (void*)&grf_auxp, grf_bus_auxp->busprint);
284 1.7 leo }
285 1.7 leo }
286 1.7 leo }
287 1.7 leo
288 1.7 leo int
289 1.7 leo grfccprint(auxp, pnp)
290 1.7 leo void *auxp;
291 1.7 leo const char *pnp;
292 1.7 leo {
293 1.7 leo if(pnp)
294 1.7 leo printf("ite at %s", pnp);
295 1.7 leo return(UNCONF);
296 1.7 leo }
297 1.7 leo
298 1.7 leo /*
299 1.1 leo * called from grf_cc to return console priority
300 1.1 leo */
301 1.1 leo int
302 1.1 leo grfcc_cnprobe()
303 1.1 leo {
304 1.1 leo return(CN_INTERNAL);
305 1.1 leo }
306 1.1 leo /*
307 1.1 leo * called from grf_cc to init ite portion of
308 1.1 leo * grf_softc struct
309 1.1 leo */
310 1.1 leo void
311 1.1 leo grfcc_iteinit(gp)
312 1.1 leo struct grf_softc *gp;
313 1.1 leo {
314 1.1 leo
315 1.1 leo gp->g_itecursor = cursor32;
316 1.1 leo gp->g_iteputc = putc8;
317 1.1 leo gp->g_iteclear = clear8;
318 1.1 leo gp->g_itescroll = scroll8;
319 1.1 leo gp->g_iteinit = view_init;
320 1.1 leo gp->g_itedeinit = view_deinit;
321 1.1 leo }
322 1.1 leo
323 1.1 leo static void
324 1.1 leo view_deinit(ip)
325 1.1 leo struct ite_softc *ip;
326 1.1 leo {
327 1.1 leo ip->flags &= ~ITE_INITED;
328 1.1 leo }
329 1.1 leo
330 1.1 leo static void
331 1.1 leo view_init(ip)
332 1.1 leo register struct ite_softc *ip;
333 1.1 leo {
334 1.1 leo struct itewinsize wsz;
335 1.1 leo ipriv_t *cci;
336 1.1 leo
337 1.6 leo if((cci = ip->priv) != NULL)
338 1.1 leo return;
339 1.1 leo
340 1.1 leo #if defined(KFONT_8X8)
341 1.1 leo ip->font = font_info_8x8;
342 1.1 leo #else
343 1.1 leo ip->font = font_info_8x16;
344 1.1 leo #endif
345 1.1 leo
346 1.1 leo /* Find the correct set of rendering routines for this font. */
347 1.1 leo if(ip->font.width != 8)
348 1.1 leo panic("kernel font size not supported");
349 1.1 leo
350 1.1 leo if(!atari_realconfig)
351 1.1 leo ip->priv = cci = &con_ipriv;
352 1.1 leo else ip->priv = cci = (ipriv_t*)malloc(sizeof(*cci), M_DEVBUF,M_WAITOK);
353 1.1 leo if(cci == NULL)
354 1.1 leo panic("No memory for ite-view");
355 1.1 leo bzero(cci, sizeof(*cci));
356 1.1 leo
357 1.1 leo cci->cursor_opt = 0;
358 1.1 leo cci->row_ptr = NULL;
359 1.1 leo cci->column_offset = NULL;
360 1.1 leo
361 1.1 leo wsz.x = ite_default_x;
362 1.1 leo wsz.y = ite_default_y;
363 1.1 leo wsz.width = ite_default_width;
364 1.1 leo wsz.height = ite_default_height;
365 1.1 leo wsz.depth = ite_default_depth;
366 1.1 leo
367 1.1 leo ite_newsize (ip, &wsz);
368 1.1 leo
369 1.1 leo /*
370 1.1 leo * Only console will be turned on by default..
371 1.1 leo */
372 1.1 leo if(ip->flags & ITE_ISCONS)
373 1.1 leo ip->grf->g_mode(ip->grf, GM_GRFON, NULL, 0, 0);
374 1.1 leo }
375 1.1 leo
376 1.1 leo static int
377 1.1 leo ite_newsize(ip, winsz)
378 1.1 leo struct ite_softc *ip;
379 1.1 leo struct itewinsize *winsz;
380 1.1 leo {
381 1.4 leo struct view_size vs;
382 1.4 leo ipriv_t *cci = ip->priv;
383 1.5 leo u_long i, j;
384 1.4 leo int error = 0;
385 1.4 leo view_t *view;
386 1.1 leo
387 1.1 leo vs.x = winsz->x;
388 1.1 leo vs.y = winsz->y;
389 1.1 leo vs.width = winsz->width;
390 1.1 leo vs.height = winsz->height;
391 1.1 leo vs.depth = winsz->depth;
392 1.2 leo
393 1.6 leo error = viewioctl(ip->grf->g_viewdev, VIOCSSIZE, (caddr_t)&vs, 0,
394 1.6 leo NOPROC);
395 1.4 leo view = viewview(ip->grf->g_viewdev);
396 1.1 leo
397 1.1 leo /*
398 1.1 leo * Reinitialize our structs
399 1.1 leo */
400 1.1 leo ip->cols = view->display.width / ip->font.width;
401 1.1 leo ip->rows = view->display.height / ip->font.height;
402 1.1 leo
403 1.1 leo /*
404 1.1 leo * save new values so that future opens use them
405 1.1 leo * this may not be correct when we implement Virtual Consoles
406 1.1 leo */
407 1.1 leo ite_default_height = view->display.height;
408 1.1 leo ite_default_width = view->display.width;
409 1.1 leo ite_default_x = view->display.x;
410 1.1 leo ite_default_y = view->display.y;
411 1.1 leo ite_default_depth = view->bitmap->depth;
412 1.1 leo
413 1.1 leo if(cci->row_ptr && (cci->row_ptr != con_rows)) {
414 1.1 leo free(cci->row_ptr, M_DEVBUF);
415 1.1 leo cci->row_ptr = NULL;
416 1.1 leo }
417 1.1 leo if(cci->column_offset && (cci->column_offset != con_columns)) {
418 1.1 leo free(cci->column_offset, M_DEVBUF);
419 1.1 leo cci->column_offset = NULL;
420 1.1 leo }
421 1.1 leo
422 1.1 leo if(!atari_realconfig) {
423 1.1 leo cci->row_ptr = con_rows;
424 1.1 leo cci->column_offset = con_columns;
425 1.1 leo }
426 1.1 leo else {
427 1.2 leo cci->row_ptr = malloc(sizeof(u_char *) * ip->rows,M_DEVBUF,M_NOWAIT);
428 1.2 leo cci->column_offset = malloc(sizeof(u_int)*ip->cols,M_DEVBUF,M_NOWAIT);
429 1.1 leo }
430 1.1 leo
431 1.1 leo if(!cci->row_ptr || !cci->column_offset)
432 1.1 leo panic("No memory for ite-view");
433 1.1 leo
434 1.1 leo cci->width = view->bitmap->bytes_per_row << 3;
435 1.1 leo cci->underline = ip->font.baseline + 1;
436 1.1 leo cci->row_offset = view->bitmap->bytes_per_row;
437 1.1 leo cci->ft_x = ip->font.width;
438 1.1 leo cci->ft_y = ip->font.height;
439 1.1 leo cci->row_bytes = cci->row_offset * cci->ft_y;
440 1.1 leo cci->row_ptr[0] = view->bitmap->plane;
441 1.1 leo for(i = 1; i < ip->rows; i++)
442 1.1 leo cci->row_ptr[i] = cci->row_ptr[i-1] + cci->row_bytes;
443 1.1 leo
444 1.1 leo /*
445 1.1 leo * Initialize the column offsets to point at the correct location
446 1.1 leo * in the first plane. This definitely assumes a font width of 8!
447 1.1 leo */
448 1.1 leo j = view->bitmap->depth * 2;
449 1.1 leo cci->column_offset[0] = 0;
450 1.1 leo for(i = 1; i < ip->cols; i++)
451 1.1 leo cci->column_offset[i] = ((i >> 1) * j) + (i & 1);
452 1.1 leo
453 1.1 leo /* initialize the font cell pointers */
454 1.1 leo cci->font_cell[ip->font.font_lo] = ip->font.font_p;
455 1.1 leo for(i = ip->font.font_lo+1; i <= ip->font.font_hi; i++)
456 1.1 leo cci->font_cell[i] = cci->font_cell[i-1] + ip->font.height;
457 1.1 leo
458 1.1 leo return(error);
459 1.2 leo }
460 1.2 leo
461 1.2 leo int
462 1.2 leo ite_grf_ioctl(ip, cmd, addr, flag, p)
463 1.2 leo struct ite_softc *ip;
464 1.2 leo u_long cmd;
465 1.2 leo caddr_t addr;
466 1.2 leo int flag;
467 1.2 leo struct proc *p;
468 1.2 leo {
469 1.2 leo struct winsize ws;
470 1.2 leo struct itewinsize *is;
471 1.2 leo int error = 0;
472 1.4 leo view_t *view = viewview(ip->grf->g_viewdev);
473 1.5 leo #if 0 /* LWP: notyet */
474 1.5 leo struct itebell *ib;
475 1.5 leo #endif
476 1.2 leo
477 1.2 leo switch (cmd) {
478 1.2 leo case ITEIOCGWINSZ:
479 1.2 leo is = (struct itewinsize *)addr;
480 1.2 leo is->x = view->display.x;
481 1.2 leo is->y = view->display.y;
482 1.2 leo is->width = view->display.width;
483 1.2 leo is->height = view->display.height;
484 1.2 leo is->depth = view->bitmap->depth;
485 1.2 leo break;
486 1.2 leo case ITEIOCSWINSZ:
487 1.2 leo is = (struct itewinsize *)addr;
488 1.2 leo
489 1.2 leo if(ite_newsize(ip, is))
490 1.2 leo error = ENOMEM;
491 1.2 leo else {
492 1.4 leo view = viewview(ip->grf->g_viewdev);
493 1.2 leo ws.ws_row = ip->rows;
494 1.2 leo ws.ws_col = ip->cols;
495 1.2 leo ws.ws_xpixel = view->display.width;
496 1.2 leo ws.ws_ypixel = view->display.height;
497 1.2 leo ite_reset(ip);
498 1.2 leo /*
499 1.2 leo * XXX tell tty about the change
500 1.2 leo * XXX this is messy, but works
501 1.2 leo */
502 1.2 leo iteioctl(ip->grf->g_itedev,TIOCSWINSZ,(caddr_t)&ws,0,p);
503 1.2 leo }
504 1.2 leo break;
505 1.2 leo case ITEIOCDSPWIN:
506 1.2 leo ip->grf->g_mode(ip->grf, GM_GRFON, NULL, 0, 0);
507 1.2 leo break;
508 1.2 leo case ITEIOCREMWIN:
509 1.2 leo ip->grf->g_mode(ip->grf, GM_GRFOFF, NULL, 0, 0);
510 1.2 leo break;
511 1.2 leo case ITEIOCGBELL:
512 1.2 leo #if 0 /* LWP */
513 1.2 leo /* XXX This won't work now */
514 1.2 leo /* XXX Should the bell be device dependent? */
515 1.2 leo ib = (struct itebell *)addr;
516 1.2 leo ib->volume = bvolume;
517 1.2 leo ib->pitch = bpitch;
518 1.2 leo ib->msec = bmsec;
519 1.2 leo #endif
520 1.2 leo break;
521 1.2 leo case ITEIOCSBELL:
522 1.2 leo #if 0 /* LWP */
523 1.2 leo /* XXX See above */
524 1.2 leo ib = (struct itebell *)addr;
525 1.2 leo /* bounds check */
526 1.2 leo if(ib->pitch > MAXBPITCH || ib->pitch < MINBPITCH ||
527 1.2 leo ib->volume > MAXBVOLUME || ib->msec > MAXBTIME)
528 1.2 leo error = EINVAL;
529 1.2 leo else {
530 1.2 leo bvolume = ib->volume;
531 1.2 leo bpitch = ib->pitch;
532 1.2 leo bmsec = ib->msec;
533 1.2 leo }
534 1.2 leo #endif
535 1.2 leo break;
536 1.2 leo case VIOCSCMAP:
537 1.2 leo case VIOCGCMAP:
538 1.2 leo /*
539 1.6 leo * XXX watchout for that NOPROC. its not really the kernel
540 1.6 leo * XXX talking these two commands don't use the proc pointer
541 1.6 leo * XXX though.
542 1.2 leo */
543 1.6 leo error = viewioctl(ip->grf->g_viewdev, cmd, addr, flag, NOPROC);
544 1.2 leo break;
545 1.2 leo default:
546 1.2 leo error = -1;
547 1.2 leo break;
548 1.2 leo }
549 1.2 leo return (error);
550 1.1 leo }
551 1.1 leo
552 1.1 leo static void
553 1.1 leo cursor32(struct ite_softc *ip, int flag)
554 1.1 leo {
555 1.1 leo int cend;
556 1.1 leo u_char *pl;
557 1.1 leo ipriv_t *cci;
558 1.1 leo
559 1.1 leo cci = ip->priv;
560 1.1 leo
561 1.1 leo if(flag == END_CURSOROPT)
562 1.1 leo cci->cursor_opt--;
563 1.1 leo else if(flag == START_CURSOROPT) {
564 1.1 leo if(!cci->cursor_opt)
565 1.1 leo cursor32(ip, ERASE_CURSOR);
566 1.1 leo cci->cursor_opt++;
567 1.1 leo return; /* if we are already opted. */
568 1.1 leo }
569 1.1 leo
570 1.1 leo if(cci->cursor_opt)
571 1.1 leo return; /* if we are still nested. */
572 1.1 leo /* else we draw the cursor. */
573 1.1 leo
574 1.1 leo if(flag != DRAW_CURSOR && flag != END_CURSOROPT) {
575 1.1 leo /*
576 1.1 leo * erase the cursor
577 1.1 leo */
578 1.1 leo cend = ip->font.height-1;
579 1.1 leo pl = cci->column_offset[ip->cursorx]
580 1.1 leo + cci->row_ptr[ip->cursory];
581 1.1 leo __asm__ __volatile__
582 1.1 leo ("1: notb %0@ ; addaw %4,%0\n\t"
583 1.1 leo "dbra %1,1b"
584 1.1 leo : "=a" (pl), "=d" (cend)
585 1.1 leo : "0" (pl), "1" (cend),
586 1.1 leo "d" (cci->row_offset)
587 1.1 leo );
588 1.1 leo }
589 1.1 leo
590 1.1 leo if(flag != DRAW_CURSOR && flag != MOVE_CURSOR && flag != END_CURSOROPT)
591 1.1 leo return;
592 1.1 leo
593 1.1 leo /*
594 1.1 leo * draw the cursor
595 1.1 leo */
596 1.8 leo cend = min(ip->curx, ip->cols-1);
597 1.8 leo if (ip->cursorx == cend && ip->cursory == ip->cury)
598 1.8 leo return;
599 1.8 leo ip->cursorx = cend;
600 1.1 leo ip->cursory = ip->cury;
601 1.1 leo cend = ip->font.height-1;
602 1.1 leo pl = cci->column_offset[ip->cursorx]
603 1.1 leo + cci->row_ptr[ip->cursory];
604 1.1 leo
605 1.1 leo __asm__ __volatile__
606 1.1 leo ("1: notb %0@ ; addaw %4,%0\n\t"
607 1.1 leo "dbra %1,1b"
608 1.1 leo : "=a" (pl), "=d" (cend)
609 1.1 leo : "0" (pl), "1" (cend),
610 1.1 leo "d" (cci->row_offset)
611 1.1 leo );
612 1.1 leo }
613 1.1 leo
614 1.1 leo static void
615 1.1 leo putc8(struct ite_softc *ip, int c, int dy, int dx, int mode)
616 1.1 leo {
617 1.1 leo register ipriv_t *cci = (ipriv_t *)ip->priv;
618 1.1 leo register u_char *pl = cci->column_offset[dx] + cci->row_ptr[dy];
619 1.1 leo register u_int fh = cci->ft_y;
620 1.1 leo register u_int ro = cci->row_offset;
621 1.1 leo register u_char eor_mask;
622 1.1 leo register u_char bl, tmp, ul;
623 1.1 leo register u_char *ft;
624 1.1 leo
625 1.1 leo if(c < ip->font.font_lo || c > ip->font.font_hi)
626 1.1 leo return;
627 1.1 leo
628 1.1 leo ft = cci->font_cell[c];
629 1.1 leo
630 1.1 leo if(!mode) {
631 1.1 leo while(fh--) {
632 1.1 leo *pl = *ft++; pl += ro;
633 1.1 leo }
634 1.1 leo return;
635 1.1 leo }
636 1.1 leo
637 1.1 leo eor_mask = (mode & ATTR_INV) ? 0xff : 0x00;
638 1.1 leo bl = (mode & ATTR_BOLD) ? 1 : 0;
639 1.3 leo ul = (mode & ATTR_UL) ? fh - cci->underline : fh;
640 1.3 leo for(; fh--; pl += ro) {
641 1.3 leo if(fh != ul) {
642 1.3 leo tmp = *ft++;
643 1.3 leo if(bl)
644 1.3 leo tmp |= (tmp >> 1);
645 1.3 leo *pl = tmp ^ eor_mask;
646 1.3 leo }
647 1.3 leo else {
648 1.3 leo *pl = 0xff ^ eor_mask;
649 1.3 leo ft++;
650 1.3 leo }
651 1.1 leo }
652 1.1 leo }
653 1.1 leo
654 1.1 leo static void
655 1.1 leo clear8(struct ite_softc *ip, int sy, int sx, int h, int w)
656 1.1 leo {
657 1.1 leo ipriv_t *cci = (ipriv_t *) ip->priv;
658 1.4 leo view_t *v = viewview(ip->grf->g_viewdev);
659 1.1 leo bmap_t *bm = v->bitmap;
660 1.1 leo
661 1.1 leo if((sx == 0) && (w == ip->cols)) {
662 1.1 leo /* common case: clearing whole lines */
663 1.1 leo while (h--) {
664 1.1 leo int i;
665 1.1 leo u_char *ptr = cci->row_ptr[sy];
666 1.1 leo for(i = 0; i < ip->font.height; i++) {
667 1.1 leo bzero(ptr, bm->bytes_per_row);
668 1.1 leo ptr += bm->bytes_per_row;
669 1.1 leo }
670 1.1 leo sy++;
671 1.1 leo }
672 1.1 leo }
673 1.1 leo else {
674 1.1 leo /*
675 1.1 leo * clearing only part of a line
676 1.1 leo * XXX could be optimized MUCH better, but is it worth the
677 1.1 leo * trouble?
678 1.1 leo */
679 1.1 leo
680 1.1 leo int i;
681 1.1 leo u_char *pls, *ple;
682 1.1 leo
683 1.1 leo pls = cci->row_ptr[sy];
684 1.1 leo ple = pls + cci->column_offset[sx + w-1];
685 1.1 leo pls = pls + cci->column_offset[sx];
686 1.1 leo
687 1.1 leo for(i = ((ip->font.height) * h)-1; i >= 0; i--) {
688 1.1 leo u_char *p = pls;
689 1.1 leo while(p <= ple)
690 1.1 leo *p++ = 0;
691 1.1 leo pls += bm->bytes_per_row;
692 1.1 leo ple += bm->bytes_per_row;
693 1.1 leo }
694 1.1 leo }
695 1.1 leo }
696 1.1 leo
697 1.1 leo /* Note: sx is only relevant for SCROLL_LEFT or SCROLL_RIGHT. */
698 1.1 leo static void
699 1.1 leo scroll8(ip, sy, sx, count, dir)
700 1.1 leo register struct ite_softc *ip;
701 1.1 leo register int sy;
702 1.1 leo int dir, sx, count;
703 1.1 leo {
704 1.4 leo bmap_t *bm = viewview(ip->grf->g_viewdev)->bitmap;
705 1.1 leo u_char *pl = ((ipriv_t *)ip->priv)->row_ptr[sy];
706 1.1 leo
707 1.1 leo if(dir == SCROLL_UP) {
708 1.1 leo int dy = sy - count;
709 1.1 leo
710 1.1 leo cursor32(ip, ERASE_CURSOR);
711 1.1 leo scrollbmap(bm, 0, dy*ip->font.height, bm->bytes_per_row >> 3,
712 1.1 leo (ip->bottom_margin-dy+1)*ip->font.height,
713 1.1 leo 0, -(count*ip->font.height));
714 1.1 leo }
715 1.1 leo else if(dir == SCROLL_DOWN) {
716 1.5 leo cursor32(ip, ERASE_CURSOR);
717 1.1 leo scrollbmap(bm, 0, sy*ip->font.height, bm->bytes_per_row >> 3,
718 1.1 leo (ip->bottom_margin-sy+1)*ip->font.height,
719 1.1 leo 0, count*ip->font.height);
720 1.1 leo }
721 1.1 leo else if(dir == SCROLL_RIGHT) {
722 1.1 leo int sofs = (ip->cols - count) * ip->font.width;
723 1.1 leo int dofs = (ip->cols) * ip->font.width;
724 1.1 leo int i, j;
725 1.1 leo
726 1.1 leo cursor32(ip, ERASE_CURSOR);
727 1.1 leo for(j = ip->font.height-1; j >= 0; j--) {
728 1.1 leo int sofs2 = sofs, dofs2 = dofs;
729 1.1 leo for (i = (ip->cols - (sx + count))-1; i >= 0; i--) {
730 1.1 leo int t;
731 1.1 leo sofs2 -= ip->font.width;
732 1.1 leo dofs2 -= ip->font.width;
733 1.1 leo asm("bfextu %1@{%2:%3},%0" : "=d" (t)
734 1.1 leo : "a" (pl), "d" (sofs2), "d" (ip->font.width));
735 1.1 leo asm("bfins %3,%0@{%1:%2}" :
736 1.1 leo : "a" (pl), "d" (dofs2), "d" (ip->font.width),
737 1.1 leo "d" (t));
738 1.1 leo }
739 1.1 leo pl += bm->bytes_per_row;
740 1.1 leo }
741 1.1 leo }
742 1.1 leo else { /* SCROLL_LEFT */
743 1.1 leo int sofs = (sx) * ip->font.width;
744 1.1 leo int dofs = (sx - count) * ip->font.width;
745 1.1 leo int i, j;
746 1.1 leo
747 1.1 leo cursor32(ip, ERASE_CURSOR);
748 1.1 leo for(j = ip->font.height-1; j >= 0; j--) {
749 1.1 leo int sofs2 = sofs, dofs2 = dofs;
750 1.1 leo for(i = (ip->cols - sx)-1; i >= 0; i--) {
751 1.1 leo int t;
752 1.1 leo
753 1.1 leo asm("bfextu %1@{%2:%3},%0" : "=d" (t)
754 1.1 leo : "a" (pl), "d" (sofs2), "d" (ip->font.width));
755 1.1 leo asm("bfins %3,%0@{%1:%2}"
756 1.1 leo : : "a" (pl), "d" (dofs2),"d" (ip->font.width),
757 1.1 leo "d" (t));
758 1.1 leo sofs2 += ip->font.width;
759 1.1 leo dofs2 += ip->font.width;
760 1.1 leo }
761 1.1 leo pl += bm->bytes_per_row;
762 1.1 leo }
763 1.1 leo }
764 1.1 leo }
765 1.1 leo
766 1.1 leo static void
767 1.1 leo scrollbmap (bmap_t *bm, u_short x, u_short y, u_short width, u_short height, short dx, short dy)
768 1.1 leo {
769 1.1 leo u_short lwpr = bm->bytes_per_row >> 2;
770 1.1 leo
771 1.1 leo if(dx) {
772 1.1 leo /* FIX: */ panic ("delta x not supported in scroll bitmap yet.");
773 1.1 leo }
774 1.1 leo
775 1.1 leo if(dy == 0) {
776 1.1 leo return;
777 1.1 leo }
778 1.1 leo if(dy > 0) {
779 1.1 leo u_long *pl = (u_long *)bm->plane;
780 1.1 leo u_long *src_y = pl + (lwpr*y);
781 1.1 leo u_long *dest_y = pl + (lwpr*(y+dy));
782 1.1 leo u_long count = lwpr*(height-dy);
783 1.1 leo u_long *clr_y = src_y;
784 1.1 leo u_long clr_count = dest_y - src_y;
785 1.1 leo u_long bc, cbc;
786 1.1 leo
787 1.1 leo src_y += count - 1;
788 1.1 leo dest_y += count - 1;
789 1.1 leo
790 1.1 leo bc = count >> 4;
791 1.1 leo count &= 0xf;
792 1.1 leo
793 1.1 leo while (bc--) {
794 1.1 leo *dest_y-- = *src_y--; *dest_y-- = *src_y--;
795 1.1 leo *dest_y-- = *src_y--; *dest_y-- = *src_y--;
796 1.1 leo *dest_y-- = *src_y--; *dest_y-- = *src_y--;
797 1.1 leo *dest_y-- = *src_y--; *dest_y-- = *src_y--;
798 1.1 leo *dest_y-- = *src_y--; *dest_y-- = *src_y--;
799 1.1 leo *dest_y-- = *src_y--; *dest_y-- = *src_y--;
800 1.1 leo *dest_y-- = *src_y--; *dest_y-- = *src_y--;
801 1.1 leo *dest_y-- = *src_y--; *dest_y-- = *src_y--;
802 1.1 leo }
803 1.1 leo while (count--)
804 1.1 leo *dest_y-- = *src_y--;
805 1.1 leo
806 1.1 leo cbc = clr_count >> 4;
807 1.1 leo clr_count &= 0xf;
808 1.1 leo
809 1.1 leo while (cbc--) {
810 1.1 leo *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
811 1.1 leo *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
812 1.1 leo *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
813 1.1 leo *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
814 1.1 leo }
815 1.1 leo while(clr_count--)
816 1.1 leo *clr_y++ = 0;
817 1.1 leo }
818 1.1 leo else {
819 1.1 leo u_long *pl = (u_long *)bm->plane;
820 1.1 leo u_long *src_y = pl + (lwpr*(y-dy));
821 1.1 leo u_long *dest_y = pl + (lwpr*y);
822 1.1 leo long count = lwpr*(height + dy);
823 1.1 leo u_long *clr_y = dest_y + count;
824 1.1 leo u_long clr_count = src_y - dest_y;
825 1.1 leo u_long bc, cbc;
826 1.1 leo
827 1.1 leo bc = count >> 4;
828 1.1 leo count &= 0xf;
829 1.1 leo
830 1.1 leo while(bc--) {
831 1.1 leo *dest_y++ = *src_y++; *dest_y++ = *src_y++;
832 1.1 leo *dest_y++ = *src_y++; *dest_y++ = *src_y++;
833 1.1 leo *dest_y++ = *src_y++; *dest_y++ = *src_y++;
834 1.1 leo *dest_y++ = *src_y++; *dest_y++ = *src_y++;
835 1.1 leo *dest_y++ = *src_y++; *dest_y++ = *src_y++;
836 1.1 leo *dest_y++ = *src_y++; *dest_y++ = *src_y++;
837 1.1 leo *dest_y++ = *src_y++; *dest_y++ = *src_y++;
838 1.1 leo *dest_y++ = *src_y++; *dest_y++ = *src_y++;
839 1.1 leo }
840 1.1 leo while(count--)
841 1.1 leo *dest_y++ = *src_y++;
842 1.1 leo
843 1.1 leo cbc = clr_count >> 4;
844 1.1 leo clr_count &= 0xf;
845 1.1 leo
846 1.1 leo while (cbc--) {
847 1.1 leo *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
848 1.1 leo *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
849 1.1 leo *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
850 1.1 leo *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
851 1.1 leo }
852 1.1 leo while (clr_count--)
853 1.1 leo *clr_y++ = 0;
854 1.1 leo }
855 1.1 leo }
856 1.1 leo #else
857 1.1 leo #error Must be defined
858 1.7 leo #endif /* NGRFCC */
859