ite_cc.c revision 1.13 1 1.9 chopps /*
2 1.13 chopps * $Id: ite_cc.c,v 1.13 1994/04/10 00:43:34 chopps Exp $
3 1.9 chopps */
4 1.9 chopps
5 1.1 mw #include "ite.h"
6 1.6 mw #if ! defined (NITE)
7 1.6 mw #define NITE 1
8 1.6 mw #endif
9 1.1 mw #if NITE > 0
10 1.1 mw
11 1.10 chopps #include <sys/param.h>
12 1.10 chopps #include <sys/conf.h>
13 1.10 chopps #include <sys/proc.h>
14 1.10 chopps #include <sys/ioctl.h>
15 1.10 chopps #include <sys/tty.h>
16 1.10 chopps #include <sys/systm.h>
17 1.12 chopps #include <sys/queue.h>
18 1.11 chopps #include <dev/cons.h>
19 1.1 mw
20 1.3 mw #include "ite.h"
21 1.10 chopps #include <amiga/dev/itevar.h>
22 1.10 chopps #include <amiga/dev/iteioctl.h>
23 1.10 chopps #include <machine/cpu.h>
24 1.10 chopps
25 1.10 chopps #include <amiga/amiga/cc.h>
26 1.10 chopps #include <amiga/dev/grfabs_reg.h>
27 1.10 chopps #include <amiga/dev/viewioctl.h>
28 1.10 chopps #include <amiga/dev/viewvar.h>
29 1.10 chopps
30 1.10 chopps #include <sys/termios.h>
31 1.3 mw
32 1.13 chopps extern u_char kernel_font_width, kernel_font_height, kernel_font_baseline;
33 1.13 chopps extern short kernel_font_boldsmear;
34 1.13 chopps extern u_char kernel_font_lo, kernel_font_hi;
35 1.13 chopps extern u_char kernel_font[], kernel_cursor[];
36 1.1 mw
37 1.3 mw /*
38 1.3 mw * This is what ip->priv points to;
39 1.3 mw * it contains local variables for custom-chip ites.
40 1.3 mw */
41 1.13 chopps struct ite_priv {
42 1.13 chopps view_t *view; /* the view for this ite. */
43 1.13 chopps u_char **row_ptr; /* array of pointers into the bitmap */
44 1.13 chopps u_long row_bytes;
45 1.13 chopps u_long cursor_opt;
46 1.13 chopps u_int *column_offset; /* array of offsets for columns */
47 1.13 chopps u_int row_offset; /* the row offset */
48 1.13 chopps u_short width; /* the bitmap width */
49 1.13 chopps u_short underline; /* where the underline goes */
50 1.13 chopps u_short ft_x; /* the font width */
51 1.13 chopps u_short ft_y; /* the font height */
52 1.13 chopps u_char *font_cell[256]; /* the font pointer */
53 1.13 chopps };
54 1.13 chopps typedef struct ite_priv ipriv_t;
55 1.3 mw
56 1.3 mw extern struct itesw itesw[];
57 1.13 chopps extern struct ite_softc ite_softc[];
58 1.13 chopps #define IPUNIT(ip) (((u_long)ip-(u_long)ite_softc)/sizeof(struct ite_softc))
59 1.3 mw
60 1.13 chopps static void putc8 __P((struct ite_softc *, int, int, int, int));
61 1.13 chopps static void clear8 __P((struct ite_softc *, int, int, int, int));
62 1.13 chopps static void scroll8 __P((struct ite_softc *, int, int, int, int));
63 1.13 chopps static void cursor32 __P((struct ite_softc *, int));
64 1.13 chopps static void scrollbmap __P((bmap_t *, u_short, u_short, u_short, u_short,
65 1.13 chopps short, short, u_char));
66 1.13 chopps
67 1.13 chopps /* patchable */
68 1.13 chopps int ite_default_x = 0; /* def leftedge offset */
69 1.13 chopps int ite_default_y = 0; /* def topedge offset */
70 1.13 chopps int ite_default_width = 640; /* def width */
71 1.13 chopps int ite_default_depth = 2; /* def depth */
72 1.6 mw #if defined (GRF_NTSC)
73 1.13 chopps int ite_default_height = 400; /* def NTSC height */
74 1.6 mw #elif defined (GRF_PAL)
75 1.13 chopps int ite_default_height = 512; /* def PAL height */
76 1.6 mw #else
77 1.13 chopps int ite_default_height = 400; /* def NON-PAL/NTSC height (?) */
78 1.6 mw #endif
79 1.3 mw
80 1.6 mw /* audio bell stuff */
81 1.13 chopps u_int bvolume = 10;
82 1.13 chopps u_int bpitch = 660;
83 1.13 chopps u_int bmsec = 75;
84 1.13 chopps
85 1.13 chopps static char *bsamplep;
86 1.13 chopps static char sample[20] = {
87 1.13 chopps 0,39,75,103,121,127,121,103,75,39,0,
88 1.13 chopps -39,-75,-103,-121,-127,-121,-103,-75,-39
89 1.13 chopps };
90 1.3 mw
91 1.6 mw cc_unblank ()
92 1.1 mw {
93 1.1 mw }
94 1.1 mw
95 1.13 chopps void
96 1.13 chopps init_bell()
97 1.1 mw {
98 1.13 chopps short i;
99 1.6 mw
100 1.13 chopps if (bsamplep != NULL)
101 1.13 chopps return;
102 1.13 chopps bsamplep = alloc_chipmem(20);
103 1.13 chopps if (bsamplep == NULL)
104 1.13 chopps panic("no chipmem for ccbell");
105 1.3 mw
106 1.13 chopps bcopy(sample, bsamplep, 20);
107 1.3 mw }
108 1.3 mw
109 1.13 chopps void
110 1.13 chopps cc_bell()
111 1.3 mw {
112 1.13 chopps u_int clock;
113 1.13 chopps u_int period;
114 1.13 chopps u_int count;
115 1.13 chopps
116 1.13 chopps clock = 3579545; /* PAL 3546895 */
117 1.13 chopps
118 1.13 chopps /*
119 1.13 chopps * the number of clock ticks per sample byte must be > 124
120 1.13 chopps * ergo bpitch must be < clock / 124*20
121 1.13 chopps * i.e. ~1443, 1300 to be safe (PAL etc.). also not zero obviously
122 1.13 chopps */
123 1.13 chopps period = clock / (bpitch * 20);
124 1.13 chopps count = bmsec * bpitch / 1000;
125 1.13 chopps
126 1.13 chopps play_sample(10, PREP_DMA_MEM(bsamplep), period, bvolume, 0x3, count);
127 1.1 mw }
128 1.1 mw
129 1.1 mw
130 1.6 mw int
131 1.13 chopps ite_newsize(ip, winsz)
132 1.13 chopps struct ite_softc *ip;
133 1.13 chopps struct itewinsize *winsz;
134 1.1 mw {
135 1.13 chopps extern struct view_softc views[];
136 1.13 chopps struct view_size vs;
137 1.13 chopps ipriv_t *cci = ip->priv;
138 1.13 chopps u_long fbp, i;
139 1.13 chopps int error;
140 1.13 chopps
141 1.13 chopps vs.x = winsz->x;
142 1.13 chopps vs.y = winsz->y;
143 1.13 chopps vs.width = winsz->width;
144 1.13 chopps vs.height = winsz->height;
145 1.13 chopps vs.depth = winsz->depth;
146 1.13 chopps error = viewioctl(IPUNIT(ip), VIOCSSIZE, &vs, 0, -1);
147 1.13 chopps
148 1.13 chopps /*
149 1.13 chopps * Reinitialize our structs
150 1.13 chopps */
151 1.13 chopps cci->view = views[IPUNIT(ip)].view;
152 1.13 chopps
153 1.13 chopps /* -1 for bold. */
154 1.13 chopps ip->cols = (cci->view->display.width - 1) / ip->ftwidth;
155 1.13 chopps ip->rows = cci->view->display.height / ip->ftheight;
156 1.13 chopps
157 1.13 chopps /*
158 1.13 chopps * save new values so that future opens use them
159 1.13 chopps * this may not be correct when we implement Virtual Consoles
160 1.13 chopps */
161 1.13 chopps ite_default_height = cci->view->display.height;
162 1.13 chopps ite_default_width = cci->view->display.width;
163 1.13 chopps ite_default_x = cci->view->display.x;
164 1.13 chopps ite_default_y = cci->view->display.y;
165 1.13 chopps ite_default_depth = cci->view->bitmap->depth;
166 1.13 chopps
167 1.13 chopps if (cci->row_ptr)
168 1.13 chopps free_chipmem(cci->row_ptr);
169 1.13 chopps if (cci->column_offset)
170 1.13 chopps free_chipmem(cci->column_offset);
171 1.3 mw
172 1.13 chopps cci->row_ptr = alloc_chipmem(sizeof(u_char *) * ip->rows);
173 1.13 chopps cci->column_offset = alloc_chipmem(sizeof(u_int) * ip->cols);
174 1.6 mw
175 1.13 chopps if (cci->row_ptr == NULL || cci->column_offset == NULL)
176 1.13 chopps panic("no chipmem for itecc data");
177 1.13 chopps
178 1.6 mw
179 1.13 chopps cci->width = cci->view->bitmap->bytes_per_row << 3;
180 1.13 chopps cci->underline = ip->ftbaseline + 1;
181 1.13 chopps cci->row_offset = cci->view->bitmap->bytes_per_row
182 1.13 chopps + cci->view->bitmap->row_mod;
183 1.13 chopps cci->ft_x = ip->ftwidth;
184 1.13 chopps cci->ft_y = ip->ftheight;
185 1.6 mw
186 1.13 chopps cci->row_bytes = cci->row_offset * ip->ftheight;
187 1.6 mw
188 1.13 chopps cci->row_ptr[0] = VDISPLAY_LINE (cci->view, 0, 0);
189 1.13 chopps for (i = 1; i < ip->rows; i++)
190 1.13 chopps cci->row_ptr[i] = cci->row_ptr[i-1] + cci->row_bytes;
191 1.13 chopps
192 1.13 chopps /* initialize the column offsets */
193 1.13 chopps cci->column_offset[0] = 0;
194 1.13 chopps for (i = 1; i < ip->cols; i++)
195 1.13 chopps cci->column_offset[i] = cci->column_offset[i - 1] + cci->ft_x;
196 1.13 chopps
197 1.13 chopps /* initialize the font cell pointers */
198 1.13 chopps cci->font_cell[ip->font_lo] = ip->font;
199 1.13 chopps for (i=ip->font_lo+1; i<=ip->font_hi; i++)
200 1.13 chopps cci->font_cell[i] = cci->font_cell[i-1] + ip->ftheight;
201 1.6 mw
202 1.13 chopps return (error);
203 1.3 mw }
204 1.3 mw
205 1.11 chopps /*
206 1.11 chopps * view_cnprobe is called when the console is being initialized
207 1.11 chopps * i.e. very early. grfconfig() has been called, so this implies
208 1.11 chopps * that grfcc_probe() was called as well as view_config() (in view.c)
209 1.11 chopps * if we are functioning view_inited will be true.
210 1.11 chopps */
211 1.11 chopps
212 1.11 chopps int
213 1.11 chopps view_cnprobe(min)
214 1.11 chopps int min;
215 1.11 chopps {
216 1.11 chopps extern int view_inited; /* in view.c */
217 1.11 chopps return (view_inited ? CN_INTERNAL : CN_DEAD);
218 1.11 chopps }
219 1.3 mw
220 1.11 chopps void
221 1.11 chopps view_init(ip)
222 1.3 mw register struct ite_softc *ip;
223 1.3 mw {
224 1.13 chopps struct itewinsize wsz;
225 1.13 chopps struct itesw *sp;
226 1.13 chopps ipriv_t *cci;
227 1.13 chopps
228 1.13 chopps sp = itesw;
229 1.13 chopps cci = ip->priv;
230 1.6 mw
231 1.13 chopps if (cci)
232 1.13 chopps return;
233 1.13 chopps
234 1.13 chopps init_bell();
235 1.6 mw
236 1.6 mw ip->font = kernel_font;
237 1.6 mw ip->font_lo = kernel_font_lo;
238 1.6 mw ip->font_hi = kernel_font_hi;
239 1.6 mw ip->ftwidth = kernel_font_width;
240 1.6 mw ip->ftheight = kernel_font_height;
241 1.6 mw ip->ftbaseline = kernel_font_baseline;
242 1.6 mw ip->ftboldsmear = kernel_font_boldsmear;
243 1.6 mw
244 1.6 mw /* Find the correct set of rendering routines for this font. */
245 1.13 chopps if (ip->ftwidth > 8)
246 1.6 mw panic("kernel font size not supported");
247 1.13 chopps else {
248 1.13 chopps sp->ite_cursor = (void *)cursor32;
249 1.13 chopps sp->ite_putc = (void *)putc8;
250 1.13 chopps sp->ite_clear = (void *)clear8;
251 1.13 chopps sp->ite_scroll = (void *)scroll8;
252 1.6 mw }
253 1.3 mw
254 1.13 chopps cci = alloc_chipmem(sizeof (*cci));
255 1.13 chopps if (cci == NULL)
256 1.13 chopps panic("no memory for console device.");
257 1.1 mw
258 1.6 mw ip->priv = cci;
259 1.6 mw cci->cursor_opt = 0;
260 1.6 mw cci->view = NULL;
261 1.6 mw cci->row_ptr = NULL;
262 1.6 mw cci->column_offset = NULL;
263 1.1 mw
264 1.6 mw #if 0
265 1.6 mw /* currently the view is permanently open due to grf driver */
266 1.13 chopps if (viewopen(IPUNIT(ip), 0))
267 1.13 chopps panic("cannot get ahold of our view");
268 1.6 mw #endif
269 1.13 chopps wsz.x = ite_default_x;
270 1.13 chopps wsz.y = ite_default_y;
271 1.13 chopps wsz.width = ite_default_width;
272 1.13 chopps wsz.height = ite_default_height;
273 1.13 chopps wsz.depth = ite_default_depth;
274 1.13 chopps
275 1.13 chopps ite_newsize (ip, &wsz);
276 1.13 chopps XXX_grf_cc_on(IPUNIT(ip));
277 1.13 chopps /* viewioctl(IPUNIT(ip), VIOCDISPLAY, NULL, 0, -1); */
278 1.6 mw }
279 1.6 mw
280 1.6 mw int
281 1.8 chopps ite_grf_ioctl (ip, cmd, addr, flag, p)
282 1.8 chopps struct ite_softc *ip;
283 1.8 chopps caddr_t addr;
284 1.8 chopps struct proc *p;
285 1.6 mw {
286 1.13 chopps struct winsize ws;
287 1.13 chopps struct itewinsize *is;
288 1.13 chopps struct itebell *ib;
289 1.13 chopps ipriv_t *cci;
290 1.13 chopps int error;
291 1.13 chopps
292 1.13 chopps cci = ip->priv;
293 1.13 chopps error = 0;
294 1.13 chopps
295 1.13 chopps switch (cmd) {
296 1.13 chopps case ITEIOCGWINSZ:
297 1.13 chopps is = (struct itewinsize *)addr;
298 1.13 chopps is->x = cci->view->display.x;
299 1.13 chopps is->y = cci->view->display.y;
300 1.13 chopps is->width = cci->view->display.width;
301 1.13 chopps is->height = cci->view->display.height;
302 1.13 chopps is->depth = cci->view->bitmap->depth;
303 1.13 chopps break;
304 1.13 chopps case ITEIOCSWINSZ:
305 1.13 chopps is = (struct itewinsize *)addr;
306 1.13 chopps
307 1.13 chopps if (ite_newsize(ip, is))
308 1.13 chopps error = ENOMEM;
309 1.13 chopps else {
310 1.13 chopps ws.ws_row = ip->rows;
311 1.13 chopps ws.ws_col = ip->cols;
312 1.13 chopps ws.ws_xpixel = cci->view->display.width;
313 1.13 chopps ws.ws_ypixel = cci->view->display.height;
314 1.13 chopps ite_reset (ip);
315 1.13 chopps /*
316 1.13 chopps * XXX tell tty about the change
317 1.13 chopps * XXX this is messy, but works
318 1.13 chopps */
319 1.13 chopps iteioctl(0, TIOCSWINSZ, (caddr_t)&ws, 0, p);
320 1.13 chopps }
321 1.13 chopps break;
322 1.13 chopps case ITEIOCDSPWIN:
323 1.13 chopps XXX_grf_cc_on(IPUNIT(ip));
324 1.13 chopps break;
325 1.13 chopps case ITEIOCREMWIN:
326 1.13 chopps XXX_grf_cc_off(IPUNIT(ip));
327 1.13 chopps break;
328 1.13 chopps case ITEIOCGBELL:
329 1.13 chopps ib = (struct itebell *)addr;
330 1.13 chopps ib->volume = bvolume;
331 1.13 chopps ib->pitch = bpitch;
332 1.13 chopps ib->msec = bmsec;
333 1.13 chopps break;
334 1.13 chopps case ITEIOCSBELL:
335 1.13 chopps ib = (struct itebell *)addr;
336 1.13 chopps /* bounds check */
337 1.13 chopps if (ib->pitch > MAXBPITCH || ib->pitch < MINBPITCH ||
338 1.13 chopps ib->volume > MAXBVOLUME || ib->msec > MAXBTIME)
339 1.13 chopps error = EINVAL;
340 1.13 chopps else {
341 1.13 chopps bvolume = ib->volume;
342 1.13 chopps bpitch = ib->pitch;
343 1.13 chopps bmsec = ib->msec;
344 1.13 chopps }
345 1.13 chopps break;
346 1.13 chopps case VIOCSCMAP:
347 1.13 chopps case VIOCGCMAP:
348 1.13 chopps /*
349 1.13 chopps * XXX needs to be fixed when multiple console implemented
350 1.13 chopps * XXX watchout for that -1 its not really the kernel talking
351 1.13 chopps * XXX these two commands don't use the proc pointer though
352 1.13 chopps */
353 1.13 chopps error = viewioctl(0, cmd, addr, flag, -1);
354 1.13 chopps break;
355 1.13 chopps default:
356 1.13 chopps error = -1;
357 1.13 chopps break;
358 1.13 chopps }
359 1.13 chopps return (error);
360 1.1 mw }
361 1.1 mw
362 1.11 chopps void
363 1.11 chopps view_deinit(ip)
364 1.6 mw struct ite_softc *ip;
365 1.1 mw {
366 1.13 chopps ip->flags &= ~ITE_INITED;
367 1.1 mw }
368 1.1 mw
369 1.6 mw /*** (M<8)-by-N routines ***/
370 1.6 mw
371 1.3 mw static void
372 1.13 chopps cursor32(struct ite_softc *ip, int flag)
373 1.3 mw {
374 1.13 chopps int cend, ofs, h, cstart, dr_plane;
375 1.13 chopps u_char *pl, opclr, opset;
376 1.13 chopps ipriv_t *cci;
377 1.13 chopps bmap_t *bm;
378 1.13 chopps view_t *v;
379 1.13 chopps
380 1.13 chopps cci = ip->priv;
381 1.13 chopps v = cci->view;
382 1.13 chopps bm = v->bitmap;
383 1.13 chopps dr_plane = (bm->depth > 1 ? bm->depth-1 : 0);
384 1.13 chopps
385 1.13 chopps if (flag == END_CURSOROPT)
386 1.13 chopps cci->cursor_opt--;
387 1.13 chopps else if (flag == START_CURSOROPT) {
388 1.13 chopps if (!cci->cursor_opt)
389 1.13 chopps cursor32 (ip, ERASE_CURSOR);
390 1.13 chopps cci->cursor_opt++;
391 1.13 chopps return; /* if we are already opted. */
392 1.6 mw }
393 1.6 mw
394 1.13 chopps if (cci->cursor_opt)
395 1.13 chopps return; /* if we are still nested. */
396 1.13 chopps /* else we draw the cursor. */
397 1.13 chopps cstart = 0;
398 1.13 chopps cend = ip->ftheight-1;
399 1.13 chopps pl = VDISPLAY_LINE(v, dr_plane, (ip->cursory * ip->ftheight + cstart));
400 1.13 chopps ofs = (ip->cursorx * ip->ftwidth);
401 1.6 mw
402 1.13 chopps if (flag != DRAW_CURSOR && flag != END_CURSOROPT) {
403 1.13 chopps /*
404 1.13 chopps * erase the cursor
405 1.13 chopps */
406 1.13 chopps int h;
407 1.13 chopps
408 1.13 chopps if (dr_plane) {
409 1.13 chopps for (h = cend; h >= 0; h--) {
410 1.13 chopps asm("bfclr %0@{%1:%2}" : : "a" (pl),
411 1.13 chopps "d" (ofs), "d" (ip->ftwidth));
412 1.13 chopps pl += cci->row_offset;
413 1.13 chopps }
414 1.13 chopps } else {
415 1.13 chopps for (h = cend; h >= 0; h--) {
416 1.13 chopps asm("bfchg %0@{%1:%2}" : : "a" (pl),
417 1.13 chopps "d" (ofs), "d" (ip->ftwidth));
418 1.13 chopps pl += cci->row_offset;
419 1.13 chopps }
420 1.13 chopps }
421 1.6 mw }
422 1.6 mw
423 1.13 chopps if (flag != DRAW_CURSOR && flag != MOVE_CURSOR &&
424 1.13 chopps flag != END_CURSOROPT)
425 1.13 chopps return;
426 1.6 mw
427 1.13 chopps /*
428 1.13 chopps * draw the cursor
429 1.13 chopps */
430 1.13 chopps
431 1.6 mw ip->cursorx = MIN(ip->curx, ip->cols-1);
432 1.6 mw ip->cursory = ip->cury;
433 1.6 mw cstart = 0;
434 1.6 mw cend = ip->ftheight-1;
435 1.13 chopps pl = VDISPLAY_LINE(v, dr_plane, ip->cursory * ip->ftheight + cstart);
436 1.13 chopps ofs = ip->cursorx * ip->ftwidth;
437 1.13 chopps
438 1.6 mw if (dr_plane) {
439 1.13 chopps for (h = cend; h >= 0; h--) {
440 1.13 chopps asm("bfset %0@{%1:%2}" : : "a" (pl),
441 1.13 chopps "d" (ofs), "d" (ip->ftwidth));
442 1.13 chopps pl += cci->row_offset;
443 1.13 chopps }
444 1.6 mw } else {
445 1.13 chopps for (h = cend; h >= 0; h--) {
446 1.13 chopps asm("bfchg %0@{%1:%2}" : : "a" (pl),
447 1.13 chopps "d" (ofs), "d" (ip->ftwidth));
448 1.13 chopps pl += cci->row_offset;
449 1.13 chopps }
450 1.6 mw }
451 1.3 mw }
452 1.3 mw
453 1.6 mw
454 1.6 mw static inline
455 1.6 mw int expbits (int data)
456 1.3 mw {
457 1.13 chopps int i, nd = 0;
458 1.13 chopps
459 1.13 chopps if (data & 1)
460 1.13 chopps nd |= 0x02;
461 1.13 chopps for (i=1; i < 32; i++) {
462 1.13 chopps if (data & (1 << i))
463 1.13 chopps nd |= 0x5 << (i-1);
464 1.6 mw }
465 1.13 chopps nd &= ~data;
466 1.13 chopps return(~nd);
467 1.6 mw }
468 1.3 mw
469 1.3 mw
470 1.6 mw /* Notes: optimizations given the kernel_font_(width|height) #define'd.
471 1.6 mw * the dbra loops could be elminated and unrolled using height,
472 1.6 mw * the :width in the bfxxx instruction could be made immediate instead
473 1.6 mw * of a data register as it now is.
474 1.6 mw * the underline could be added when the loop is unrolled
475 1.6 mw *
476 1.6 mw * It would look like hell but be very fast.*/
477 1.6 mw
478 1.6 mw static void
479 1.6 mw putc_nm (cci,p,f,co,ro,fw,fh)
480 1.6 mw register ipriv_t *cci;
481 1.6 mw register u_char *p;
482 1.6 mw register u_char *f;
483 1.6 mw register u_int co;
484 1.6 mw register u_int ro;
485 1.6 mw register u_int fw;
486 1.6 mw register u_int fh;
487 1.6 mw {
488 1.6 mw while (fh--) {
489 1.6 mw asm ("bfins %0,%1@{%2:%3}" : /* no output */ :
490 1.6 mw "d" (*f++), "a" (p), "d" (co), "d" (fw));
491 1.6 mw p += ro;
492 1.6 mw }
493 1.6 mw }
494 1.6 mw
495 1.6 mw static void
496 1.6 mw putc_in (cci,p,f,co,ro,fw,fh)
497 1.6 mw register ipriv_t *cci;
498 1.6 mw register u_char *p;
499 1.6 mw register u_char *f;
500 1.6 mw register u_int co;
501 1.6 mw register u_int ro;
502 1.6 mw register u_int fw;
503 1.6 mw register u_int fh;
504 1.6 mw {
505 1.6 mw while (fh--) {
506 1.6 mw asm ("bfins %0,%1@{%2:%3}" : /* no output */ :
507 1.6 mw "d" (~(*f++)), "a" (p), "d" (co), "d" (fw));
508 1.6 mw p += ro;
509 1.6 mw }
510 1.6 mw }
511 1.6 mw
512 1.6 mw
513 1.6 mw static void
514 1.6 mw putc_ul (cci,p,f,co,ro,fw,fh)
515 1.6 mw register ipriv_t *cci;
516 1.6 mw register u_char *p;
517 1.6 mw register u_char *f;
518 1.6 mw register u_int co;
519 1.6 mw register u_int ro;
520 1.6 mw register u_int fw;
521 1.6 mw register u_int fh;
522 1.6 mw {
523 1.6 mw int underline = cci->underline;
524 1.6 mw while (underline--) {
525 1.6 mw asm ("bfins %0,%1@{%2:%3}" : /* no output */ :
526 1.6 mw "d" (*f++), "a" (p), "d" (co), "d" (fw));
527 1.6 mw p += ro;
528 1.6 mw }
529 1.6 mw
530 1.6 mw asm ("bfins %0,%1@{%2:%3}" : /* no output */ :
531 1.6 mw "d" (expbits(*f++)), "a" (p), "d" (co), "d" (fw));
532 1.6 mw p += ro;
533 1.6 mw
534 1.6 mw underline = fh - cci->underline - 1;
535 1.6 mw while (underline--) {
536 1.6 mw asm ("bfins %0,%1@{%2:%3}" : /* no output */ :
537 1.6 mw "d" (*f++), "a" (p), "d" (co), "d" (fw));
538 1.6 mw p += ro;
539 1.6 mw }
540 1.6 mw }
541 1.6 mw
542 1.6 mw
543 1.6 mw static void
544 1.6 mw putc_ul_in (cci,p,f,co,ro,fw,fh)
545 1.6 mw register ipriv_t *cci;
546 1.6 mw register u_char *p;
547 1.6 mw register u_char *f;
548 1.6 mw register u_int co;
549 1.6 mw register u_int ro;
550 1.6 mw register u_int fw;
551 1.6 mw register u_int fh;
552 1.6 mw {
553 1.6 mw int underline = cci->underline;
554 1.6 mw while (underline--) {
555 1.6 mw asm ("bfins %0,%1@{%2:%3}" : /* no output */ :
556 1.6 mw "d" (~(*f++)), "a" (p), "d" (co), "d" (fw));
557 1.6 mw p += ro;
558 1.6 mw }
559 1.6 mw
560 1.6 mw asm ("bfins %0,%1@{%2:%3}" : /* no output */ :
561 1.6 mw "d" (~expbits(*f++)), "a" (p), "d" (co), "d" (fw));
562 1.6 mw p += ro;
563 1.6 mw
564 1.6 mw underline = fh - cci->underline - 1;
565 1.6 mw while (underline--) {
566 1.6 mw asm ("bfins %0,%1@{%2:%3}" : /* no output */ :
567 1.6 mw "d" (~(*f++)), "a" (p), "d" (co), "d" (fw));
568 1.6 mw p += ro;
569 1.6 mw }
570 1.6 mw }
571 1.6 mw
572 1.6 mw /* bold */
573 1.6 mw static void
574 1.6 mw putc_bd (cci,p,f,co,ro,fw,fh)
575 1.6 mw register ipriv_t *cci;
576 1.6 mw register u_char *p;
577 1.6 mw register u_char *f;
578 1.6 mw register u_int co;
579 1.6 mw register u_int ro;
580 1.6 mw register u_int fw;
581 1.6 mw register u_int fh;
582 1.6 mw {
583 1.10 chopps u_short ch;
584 1.6 mw
585 1.6 mw while (fh--) {
586 1.6 mw ch = *f++;
587 1.6 mw ch |= ch << 1;
588 1.6 mw asm ("bfins %0,%1@{%2:%3}" : /* no output */ :
589 1.6 mw "d" (ch), "a" (p), "d" (co), "d" (fw+1));
590 1.6 mw p += ro;
591 1.3 mw }
592 1.6 mw }
593 1.3 mw
594 1.6 mw static void
595 1.6 mw putc_bd_in (cci,p,f,co,ro,fw,fh)
596 1.6 mw register ipriv_t *cci;
597 1.6 mw register u_char *p;
598 1.6 mw register u_char *f;
599 1.6 mw register u_int co;
600 1.6 mw register u_int ro;
601 1.6 mw register u_int fw;
602 1.6 mw register u_int fh;
603 1.6 mw {
604 1.10 chopps u_short ch;
605 1.6 mw
606 1.6 mw while (fh--) {
607 1.6 mw ch = *f++;
608 1.6 mw ch |= ch << 1;
609 1.6 mw asm ("bfins %0,%1@{%2:%3}" : /* no output */ :
610 1.6 mw "d" (~(ch)), "a" (p), "d" (co), "d" (fw+1));
611 1.6 mw p += ro;
612 1.3 mw }
613 1.6 mw }
614 1.6 mw
615 1.3 mw
616 1.6 mw static void
617 1.6 mw putc_bd_ul (cci,p,f,co,ro,fw,fh)
618 1.6 mw register ipriv_t *cci;
619 1.6 mw register u_char *p;
620 1.6 mw register u_char *f;
621 1.6 mw register u_int co;
622 1.6 mw register u_int ro;
623 1.6 mw register u_int fw;
624 1.6 mw register u_int fh;
625 1.6 mw {
626 1.6 mw int underline = cci->underline;
627 1.10 chopps u_short ch;
628 1.6 mw
629 1.6 mw while (underline--) {
630 1.6 mw ch = *f++;
631 1.6 mw ch |= ch << 1;
632 1.6 mw asm ("bfins %0,%1@{%2:%3}" : /* no output */ :
633 1.6 mw "d" (ch), "a" (p), "d" (co), "d" (fw+1));
634 1.6 mw p += ro;
635 1.6 mw }
636 1.6 mw
637 1.6 mw ch = *f++;
638 1.6 mw ch |= ch << 1;
639 1.6 mw asm ("bfins %0,%1@{%2:%3}" : /* no output */ :
640 1.6 mw "d" (expbits(ch)), "a" (p), "d" (co), "d" (fw+1));
641 1.6 mw p += ro;
642 1.6 mw
643 1.6 mw underline = fh - cci->underline - 1;
644 1.6 mw while (underline--) {
645 1.6 mw ch = *f++;
646 1.6 mw ch |= ch << 1;
647 1.6 mw asm ("bfins %0,%1@{%2:%3}" : /* no output */ :
648 1.6 mw "d" (ch), "a" (p), "d" (co), "d" (fw+1));
649 1.6 mw p += ro;
650 1.3 mw }
651 1.3 mw }
652 1.3 mw
653 1.3 mw
654 1.6 mw static void
655 1.6 mw putc_bd_ul_in (cci,p,f,co,ro,fw,fh)
656 1.6 mw register ipriv_t *cci;
657 1.6 mw register u_char *p;
658 1.6 mw register u_char *f;
659 1.6 mw register u_int co;
660 1.6 mw register u_int ro;
661 1.6 mw register u_int fw;
662 1.6 mw register u_int fh;
663 1.1 mw {
664 1.6 mw int underline = cci->underline;
665 1.10 chopps u_short ch;
666 1.6 mw
667 1.6 mw while (underline--) {
668 1.6 mw ch = *f++;
669 1.6 mw ch |= ch << 1;
670 1.6 mw asm ("bfins %0,%1@{%2:%3}" : /* no output */ :
671 1.6 mw "d" (~(ch)), "a" (p), "d" (co), "d" (fw+1));
672 1.6 mw p += ro;
673 1.6 mw }
674 1.6 mw
675 1.6 mw ch = *f++;
676 1.6 mw ch |= ch << 1;
677 1.6 mw asm ("bfins %0,%1@{%2:%3}" : /* no output */ :
678 1.6 mw "d" (~expbits(ch)), "a" (p), "d" (co), "d" (fw+1));
679 1.6 mw p += ro;
680 1.6 mw
681 1.6 mw underline = fh - cci->underline - 1;
682 1.6 mw while (underline--) {
683 1.6 mw ch = *f++;
684 1.6 mw ch |= ch << 1;
685 1.6 mw asm ("bfins %0,%1@{%2:%3}" : /* no output */ :
686 1.6 mw "d" (~(ch)), "a" (p), "d" (co), "d" (fw+1));
687 1.6 mw p += ro;
688 1.6 mw }
689 1.6 mw }
690 1.1 mw
691 1.3 mw
692 1.6 mw typedef void cc_putc_func ();
693 1.6 mw
694 1.6 mw cc_putc_func *put_func[ATTR_ALL+1] = {
695 1.6 mw putc_nm,
696 1.6 mw putc_in,
697 1.6 mw putc_ul,
698 1.6 mw putc_ul_in,
699 1.6 mw putc_bd,
700 1.6 mw putc_bd_in,
701 1.6 mw putc_bd_ul,
702 1.6 mw putc_bd_ul_in,
703 1.6 mw /* no support for blink */
704 1.6 mw putc_nm,
705 1.6 mw putc_in,
706 1.6 mw putc_ul,
707 1.6 mw putc_ul_in,
708 1.6 mw putc_bd,
709 1.6 mw putc_bd_in,
710 1.6 mw putc_bd_ul,
711 1.6 mw putc_bd_ul_in
712 1.6 mw };
713 1.3 mw
714 1.3 mw
715 1.6 mw /* FIX: shouldn't this advance the cursor even if the character to
716 1.6 mw be output is not available in the font? -ch */
717 1.1 mw
718 1.3 mw static void
719 1.13 chopps putc8(struct ite_softc *ip, int c, int dy, int dx, int mode)
720 1.1 mw {
721 1.6 mw register ipriv_t *cci = (ipriv_t *) ip->priv;
722 1.6 mw if (c < ip->font_lo || c > ip->font_hi)
723 1.6 mw return;
724 1.6 mw
725 1.6 mw put_func[mode](cci,
726 1.6 mw cci->row_ptr[dy],
727 1.6 mw cci->font_cell[c],
728 1.6 mw cci->column_offset[dx],
729 1.6 mw cci->row_offset,
730 1.6 mw cci->ft_x,
731 1.6 mw cci->ft_y);
732 1.1 mw }
733 1.1 mw
734 1.3 mw static void
735 1.13 chopps clear8(struct ite_softc *ip, int sy, int sx, int h, int w)
736 1.1 mw {
737 1.6 mw ipriv_t *cci = (ipriv_t *) ip->priv;
738 1.6 mw view_t *v = cci->view;
739 1.6 mw bmap_t *bm = cci->view->bitmap;
740 1.1 mw
741 1.3 mw if ((sx == 0) && (w == ip->cols))
742 1.3 mw {
743 1.3 mw /* common case: clearing whole lines */
744 1.3 mw while (h--)
745 1.3 mw {
746 1.6 mw int i;
747 1.6 mw u_char *ptr = cci->row_ptr[sy];
748 1.6 mw for (i=0; i < ip->ftheight; i++) {
749 1.6 mw bzero(ptr, bm->bytes_per_row);
750 1.6 mw ptr += bm->bytes_per_row + bm->row_mod; /* don't get any smart
751 1.6 mw ideas, becuase this is for
752 1.6 mw interleaved bitmaps */
753 1.6 mw }
754 1.3 mw sy++;
755 1.3 mw }
756 1.3 mw }
757 1.3 mw else
758 1.3 mw {
759 1.3 mw /* clearing only part of a line */
760 1.3 mw /* XXX could be optimized MUCH better, but is it worth the trouble? */
761 1.3 mw while (h--)
762 1.3 mw {
763 1.6 mw u_char *pl = cci->row_ptr[sy];
764 1.3 mw int ofs = sx * ip->ftwidth;
765 1.3 mw int i, j;
766 1.3 mw for (i = w-1; i >= 0; i--)
767 1.3 mw {
768 1.3 mw u_char *ppl = pl;
769 1.3 mw for (j = ip->ftheight-1; j >= 0; j--)
770 1.3 mw {
771 1.3 mw asm("bfclr %0@{%1:%2}"
772 1.3 mw : : "a" (ppl), "d" (ofs), "d" (ip->ftwidth));
773 1.6 mw ppl += bm->row_mod + bm->bytes_per_row;
774 1.3 mw }
775 1.3 mw ofs += ip->ftwidth;
776 1.3 mw }
777 1.3 mw sy++;
778 1.3 mw }
779 1.3 mw }
780 1.1 mw }
781 1.1 mw
782 1.3 mw /* Note: sx is only relevant for SCROLL_LEFT or SCROLL_RIGHT. */
783 1.3 mw static void
784 1.13 chopps scroll8(ip, sy, sx, count, dir)
785 1.1 mw register struct ite_softc *ip;
786 1.1 mw register int sy;
787 1.1 mw int dir, sx, count;
788 1.1 mw {
789 1.6 mw bmap_t *bm = ((ipriv_t *)ip->priv)->view->bitmap;
790 1.6 mw u_char *pl = ((ipriv_t *)ip->priv)->row_ptr[sy];
791 1.6 mw
792 1.1 mw if (dir == SCROLL_UP)
793 1.1 mw {
794 1.3 mw int dy = sy - count;
795 1.6 mw int height = ip->bottom_margin - sy + 1;
796 1.3 mw int i;
797 1.3 mw
798 1.6 mw /*FIX: add scroll bitmap call */
799 1.13 chopps cursor32(ip, ERASE_CURSOR);
800 1.13 chopps scrollbmap (bm, 0, dy*ip->ftheight,
801 1.6 mw bm->bytes_per_row >> 3, (ip->bottom_margin-dy+1)*ip->ftheight,
802 1.6 mw 0, -(count*ip->ftheight), 0x1);
803 1.6 mw /* if (ip->cursory <= bot || ip->cursory >= dy) {
804 1.6 mw ip->cursory -= count;
805 1.6 mw } */
806 1.1 mw }
807 1.1 mw else if (dir == SCROLL_DOWN)
808 1.1 mw {
809 1.3 mw int dy = sy + count;
810 1.6 mw int height = ip->bottom_margin - dy + 1;
811 1.3 mw int i;
812 1.3 mw
813 1.6 mw /* FIX: add scroll bitmap call */
814 1.13 chopps cursor32(ip, ERASE_CURSOR);
815 1.13 chopps scrollbmap (bm, 0, sy*ip->ftheight,
816 1.6 mw bm->bytes_per_row >> 3, (ip->bottom_margin-sy+1)*ip->ftheight,
817 1.6 mw 0, count*ip->ftheight, 0x1);
818 1.6 mw /* if (ip->cursory <= bot || ip->cursory >= sy) {
819 1.6 mw ip->cursory += count;
820 1.6 mw } */
821 1.1 mw }
822 1.1 mw else if (dir == SCROLL_RIGHT)
823 1.1 mw {
824 1.3 mw int sofs = (ip->cols - count) * ip->ftwidth;
825 1.3 mw int dofs = (ip->cols) * ip->ftwidth;
826 1.3 mw int i, j;
827 1.3 mw
828 1.13 chopps cursor32(ip, ERASE_CURSOR);
829 1.3 mw for (j = ip->ftheight-1; j >= 0; j--)
830 1.3 mw {
831 1.3 mw int sofs2 = sofs, dofs2 = dofs;
832 1.3 mw for (i = (ip->cols - (sx + count))-1; i >= 0; i--)
833 1.3 mw {
834 1.3 mw int t;
835 1.3 mw sofs2 -= ip->ftwidth;
836 1.3 mw dofs2 -= ip->ftwidth;
837 1.3 mw asm("bfextu %1@{%2:%3},%0"
838 1.3 mw : "=d" (t)
839 1.3 mw : "a" (pl), "d" (sofs2), "d" (ip->ftwidth));
840 1.3 mw asm("bfins %3,%0@{%1:%2}"
841 1.3 mw : : "a" (pl), "d" (dofs2), "d" (ip->ftwidth), "d" (t));
842 1.3 mw }
843 1.6 mw pl += bm->row_mod + bm->bytes_per_row;
844 1.3 mw }
845 1.1 mw }
846 1.3 mw else /* SCROLL_LEFT */
847 1.1 mw {
848 1.3 mw int sofs = (sx) * ip->ftwidth;
849 1.3 mw int dofs = (sx - count) * ip->ftwidth;
850 1.3 mw int i, j;
851 1.3 mw
852 1.13 chopps cursor32(ip, ERASE_CURSOR);
853 1.3 mw for (j = ip->ftheight-1; j >= 0; j--)
854 1.3 mw {
855 1.3 mw int sofs2 = sofs, dofs2 = dofs;
856 1.3 mw for (i = (ip->cols - sx)-1; i >= 0; i--)
857 1.3 mw {
858 1.3 mw int t;
859 1.3 mw asm("bfextu %1@{%2:%3},%0"
860 1.3 mw : "=d" (t)
861 1.3 mw : "a" (pl), "d" (sofs2), "d" (ip->ftwidth));
862 1.3 mw asm("bfins %3,%0@{%1:%2}"
863 1.3 mw : : "a" (pl), "d" (dofs2), "d" (ip->ftwidth), "d" (t));
864 1.3 mw sofs2 += ip->ftwidth;
865 1.3 mw dofs2 += ip->ftwidth;
866 1.3 mw }
867 1.6 mw pl += bm->row_mod + bm->bytes_per_row;
868 1.3 mw }
869 1.1 mw }
870 1.1 mw }
871 1.1 mw
872 1.6 mw void
873 1.13 chopps scrollbmap (bmap_t *bm, u_short x, u_short y, u_short width, u_short height, short dx, short dy, u_char mask)
874 1.6 mw {
875 1.10 chopps u_short depth = bm->depth;
876 1.10 chopps u_short lwpr = bm->bytes_per_row >> 2;
877 1.6 mw if (dx) {
878 1.6 mw /* FIX: */ panic ("delta x not supported in scroll bitmap yet.");
879 1.6 mw }
880 1.6 mw if (bm->flags & BMF_INTERLEAVED) {
881 1.6 mw height *= depth;
882 1.6 mw depth = 1;
883 1.6 mw }
884 1.6 mw if (dy == 0) {
885 1.6 mw return;
886 1.6 mw }
887 1.6 mw if (dy > 0) {
888 1.6 mw int i;
889 1.6 mw for (i=0; i < depth && mask; i++, mask >>= 1) {
890 1.6 mw if (0x1 & mask) {
891 1.6 mw u_long *pl = (u_long *)bm->plane[i];
892 1.6 mw u_long *src_y = pl + (lwpr*y);
893 1.6 mw u_long *dest_y = pl + (lwpr*(y+dy));
894 1.6 mw u_long count = lwpr*(height-dy);
895 1.6 mw u_long *clr_y = src_y;
896 1.6 mw u_long clr_count = dest_y - src_y;
897 1.6 mw u_long bc, cbc;
898 1.6 mw
899 1.6 mw src_y += count - 1;
900 1.6 mw dest_y += count - 1;
901 1.6 mw
902 1.6 mw bc = count >> 4;
903 1.6 mw count &= 0xf;
904 1.6 mw
905 1.6 mw while (bc--) {
906 1.6 mw *dest_y-- = *src_y--; *dest_y-- = *src_y--;
907 1.6 mw *dest_y-- = *src_y--; *dest_y-- = *src_y--;
908 1.6 mw *dest_y-- = *src_y--; *dest_y-- = *src_y--;
909 1.6 mw *dest_y-- = *src_y--; *dest_y-- = *src_y--;
910 1.6 mw *dest_y-- = *src_y--; *dest_y-- = *src_y--;
911 1.6 mw *dest_y-- = *src_y--; *dest_y-- = *src_y--;
912 1.6 mw *dest_y-- = *src_y--; *dest_y-- = *src_y--;
913 1.6 mw *dest_y-- = *src_y--; *dest_y-- = *src_y--;
914 1.6 mw }
915 1.6 mw while (count--) {
916 1.6 mw *dest_y-- = *src_y--;
917 1.6 mw }
918 1.6 mw
919 1.6 mw cbc = clr_count >> 4;
920 1.6 mw clr_count &= 0xf;
921 1.6 mw
922 1.6 mw while (cbc--) {
923 1.6 mw *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
924 1.6 mw *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
925 1.6 mw *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
926 1.6 mw *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
927 1.6 mw }
928 1.6 mw while (clr_count--) {
929 1.6 mw *clr_y++ = 0;
930 1.6 mw }
931 1.6 mw }
932 1.6 mw }
933 1.6 mw } else if (dy < 0) {
934 1.6 mw int i;
935 1.6 mw for (i=0; i < depth && mask; i++, mask >>= 1) {
936 1.6 mw if (0x1 & mask) {
937 1.6 mw u_long *pl = (u_long *)bm->plane[i];
938 1.6 mw u_long *src_y = pl + (lwpr*(y-dy));
939 1.6 mw u_long *dest_y = pl + (lwpr*y);
940 1.6 mw long count = lwpr*(height + dy);
941 1.6 mw u_long *clr_y = dest_y + count;
942 1.6 mw u_long clr_count = src_y - dest_y;
943 1.6 mw u_long bc, cbc;
944 1.6 mw
945 1.6 mw bc = count >> 4;
946 1.6 mw count &= 0xf;
947 1.6 mw
948 1.6 mw while (bc--) {
949 1.6 mw *dest_y++ = *src_y++; *dest_y++ = *src_y++;
950 1.6 mw *dest_y++ = *src_y++; *dest_y++ = *src_y++;
951 1.6 mw *dest_y++ = *src_y++; *dest_y++ = *src_y++;
952 1.6 mw *dest_y++ = *src_y++; *dest_y++ = *src_y++;
953 1.6 mw *dest_y++ = *src_y++; *dest_y++ = *src_y++;
954 1.6 mw *dest_y++ = *src_y++; *dest_y++ = *src_y++;
955 1.6 mw *dest_y++ = *src_y++; *dest_y++ = *src_y++;
956 1.6 mw *dest_y++ = *src_y++; *dest_y++ = *src_y++;
957 1.6 mw }
958 1.6 mw while (count--) {
959 1.6 mw *dest_y++ = *src_y++;
960 1.6 mw }
961 1.6 mw
962 1.6 mw cbc = clr_count >> 4;
963 1.6 mw clr_count &= 0xf;
964 1.6 mw
965 1.6 mw while (cbc--) {
966 1.6 mw *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
967 1.6 mw *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
968 1.6 mw *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
969 1.6 mw *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0; *clr_y++ = 0;
970 1.6 mw }
971 1.6 mw while (clr_count--) {
972 1.6 mw *clr_y++ = 0;
973 1.6 mw }
974 1.6 mw }
975 1.6 mw }
976 1.6 mw }
977 1.6 mw }
978 1.1 mw #endif
979