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