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