ite_ul.c revision 1.10 1 /* $NetBSD: ite_ul.c,v 1.10 2002/01/26 13:40:58 aymeric Exp $ */
2
3 /*-
4 * Copyright (c) 1995 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Ignatios Souvatzis.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include "grful.h"
40 #if NGRFUL > 0
41
42 #include <sys/param.h>
43 #include <sys/conf.h>
44 #include <sys/proc.h>
45 #include <sys/device.h>
46 #include <sys/ioctl.h>
47 #include <sys/tty.h>
48 #include <sys/systm.h>
49 #include <dev/cons.h>
50 #include <machine/cpu.h>
51 #include <amiga/amiga/device.h>
52 #include <amiga/amiga/isr.h>
53 #include <amiga/dev/itevar.h>
54 #include <amiga/dev/grfioctl.h>
55 #include <amiga/dev/grfvar.h>
56 #include <amiga/dev/grf_ulreg.h>
57
58 #ifndef KFONT_CUSTOM
59 #ifdef KFONT_8X11
60 #define kernel_font_width kernel_font_width_8x11
61 #define kernel_font_height kernel_font_height_8x11
62 #define kernel_font_baseline kernel_font_baseline_8x11
63 #define kernel_font_boldsmear kernel_font_boldsmear_8x11
64 #define kernel_font_lo kernel_font_lo_8x11
65 #define kernel_font_hi kernel_font_hi_8x11
66 #define kernel_font kernel_font_8x11
67 #define kernel_cursor kernel_cursor_8x11
68 #else
69 #define kernel_font_width kernel_font_width_8x8
70 #define kernel_font_height kernel_font_height_8x8
71 #define kernel_font_baseline kernel_font_baseline_8x8
72 #define kernel_font_boldsmear kernel_font_boldsmear_8x8
73 #define kernel_font_lo kernel_font_lo_8x8
74 #define kernel_font_hi kernel_font_hi_8x8
75 #define kernel_font kernel_font_8x8
76 #define kernel_cursor kernel_cursor_8x8
77 #endif
78 #endif
79
80 extern u_int8_t kernel_font_width, kernel_font_height, kernel_font_baseline;
81 extern short kernel_font_boldsmear;
82 extern u_int8_t kernel_font_lo, kernel_font_hi;
83 extern u_int8_t kernel_font[], kernel_cursor[];
84
85
86 #ifdef DEBUG_UL
87 #define gsp_out(ba,cmd,len) gsp_dump(cmd,len); gsp_write(ba,cmd,len)
88 #else
89 #define gsp_out(ba,cmd,len) gsp_write(ba,cmd,len)
90 #endif
91
92 int ulowell_console = 1;
93
94 void ulowell_cursor(struct ite_softc *, int);
95 void ulowell_scroll(struct ite_softc *, int, int, int, int);
96 void ulowell_deinit(struct ite_softc *);
97 void ulowell_clear(struct ite_softc *, int, int, int, int);
98 void ulowell_putc(struct ite_softc *, int, int, int, int);
99 void ulowell_init(struct ite_softc *);
100
101 #ifdef DEBUG_UL
102 void gsp_dump(u_int16_t *, int);
103 #endif
104
105 /* Text always on overlay plane, so: */
106
107 #define UL_FG(ip) 0xFFFF
108 #define UL_BG(ip) 0x0000
109
110 /*
111 * this function is called from grf_ul to init the grf_softc->g_conpri
112 * field each time a ulowell board is attached.
113 */
114 int
115 grful_cnprobe(void)
116 {
117 static int done;
118 int uv;
119
120 if (ulowell_console && done == 0)
121 uv = CN_INTERNAL;
122 else
123 uv = CN_NORMAL;
124 done = 1;
125 return(uv);
126 }
127
128 /*
129 * init the required fields in the grf_softc struct for a
130 * grf to function as an ite.
131 */
132 void
133 grful_iteinit(struct grf_softc *gp)
134 {
135 gp->g_iteinit = ulowell_init;
136 gp->g_itedeinit = ulowell_deinit;
137 gp->g_iteclear = ulowell_clear;
138 gp->g_iteputc = ulowell_putc;
139 gp->g_itescroll = ulowell_scroll;
140 gp->g_itecursor = ulowell_cursor;
141 }
142
143 void
144 ulowell_init(struct ite_softc *ip)
145 {
146 struct gspregs *ba;
147
148 u_int16_t *sp;
149 u_int16_t cmd[8];
150
151 int i;
152
153 ba = (struct gspregs *) ip->grf->g_regkva;
154
155 ip->font = kernel_font;
156 ip->font_lo = kernel_font_lo;
157 ip->font_hi = kernel_font_hi;
158 ip->ftwidth = kernel_font_width;
159 ip->ftheight = kernel_font_height;
160 ip->ftbaseline = kernel_font_baseline;
161 ip->ftboldsmear = kernel_font_boldsmear;
162
163 /* upload font data */
164
165 ba->ctrl = LBL|INCW;
166 ba->hstadrh = 0xFFA2;
167 ba->hstadrl = 0x0200;
168
169 ba->data = 0x0000;
170 ba->data = 0xFFA3;
171 ba->data = ip->ftwidth;
172 ba->data = ip->ftheight;
173 ba->data = ip->ftbaseline;
174 ba->data = 1;
175 ba->data = ip->font_lo;
176 ba->data = ip->font_hi;
177 ba->data = ip->ftboldsmear;
178
179 ba->hstadrh = 0xFFA3;
180 ba->hstadrl = 0x0000;
181
182 /*
183 * font has to be word aligned and padded to word boundary.
184 * 8 bit wide fonts will be byte swapped in the bit swap
185 * routine.
186 */
187
188 i = (ip->font_hi - ip->font_lo + 1) * ip->ftheight;
189 if (ip->ftwidth <= 8)
190 i /= 2;
191 for (sp = (u_int16_t *)ip->font; i>0; --i,++sp) {
192 ba->data = *sp;
193 }
194
195 /* bitwise mirror the font: */
196
197 cmd[0] = GCMD_FNTMIR;
198 gsp_out(ba, cmd, 1);
199
200 ip->priv = NULL;
201 ip->cursor_opt = 0;
202
203 if (ip->ftwidth >0 && ip->ftheight > 0) {
204 ip->cols = ip->grf->g_display.gd_dwidth / ip->ftwidth;
205 ip->rows = ip->grf->g_display.gd_dheight / ip->ftheight;
206 }
207
208 ulowell_clear(ip, 0, 0, ip->rows, ip->cols);
209
210 /*
211 * switch overlay plane 0 on again, in case s.b. did a GM_GRFOVOFF
212 * XXX maybe this should be done on each output, by the TMS code?
213 * what happens on panic?
214
215 ba->ctrl = LBL;
216 GSPSETHADRS(ba, 0xFE800000);
217 ba->data = 0;
218 ba->hstadrl = 0x0020;
219 gup->gus_ovslct |= 1;
220 ba->data = gup->gus_ovslct;
221 */
222
223 #ifdef UL_DEBUG
224 printf("ulowell_init: %d %d %d %d %d %d\n", ip->ftwidth, ip->ftheight,
225 ip->ftbaseline, ip->font_lo, ip->font_hi, ip->ftboldsmear);
226 #endif
227 }
228
229
230 void ulowell_cursor(struct ite_softc *ip, int flag)
231 {
232 struct gspregs *ba;
233 u_int16_t cmd[7];
234
235 ba = (struct gspregs *)ip->grf->g_regkva;
236
237 if (flag == END_CURSOROPT)
238 --ip->cursor_opt;
239 else if (flag == START_CURSOROPT) {
240 if (!ip->cursor_opt)
241 ulowell_cursor(ip, ERASE_CURSOR);
242 ++ip->cursor_opt;
243 return; /* if we are already opted */
244 }
245
246 if (ip->cursor_opt)
247 return; /* if we are still nested. */
248
249 /* else we draw the cursor */
250
251 if (flag != DRAW_CURSOR && flag != END_CURSOROPT) {
252 /* erase cursor */
253 #if 0
254 cmd[0] = GCMD_PIXBLT;
255 cmd[1] = 1024 - ip->ftwidth;
256 cmd[2] = 1024 - ip->ftheight;
257 cmd[3] = ip->ftwidth;
258 cmd[4] = ip->ftheight;
259 cmd[5] = ip->cursorx * ip->ftwidth;
260 cmd[6] = ip->cursory * ip->ftheight;
261 gsp_out(ba, cmd, 7);
262 #endif
263 cmd[0] = GCMD_FILL;
264 cmd[1] = UL_FG(ip);
265 cmd[2] = ip->cursorx * ip->ftwidth;
266 cmd[3] = ip->cursory * ip->ftheight;
267 cmd[4] = ip->ftwidth;
268 cmd[5] = ip->ftheight;
269 cmd[6] = 10; /* thats src xor dst */
270 gsp_out(ba, cmd, 7);
271 }
272
273 if (flag != DRAW_CURSOR && flag != MOVE_CURSOR &&
274 flag != END_CURSOROPT)
275 return;
276
277 /* draw cursor */
278
279 ip->cursorx = min(ip->curx, ip->cols-1);
280 ip->cursory = ip->cury;
281 #if 0
282 cmd[0] = GCMD_PIXBLT;
283 cmd[1] = ip->cursorx * ip->ftwidth;
284 cmd[2] = ip->cursory * ip->ftheight;
285 cmd[3] = ip->ftwidth;
286 cmd[4] = ip->ftheight;
287 cmd[5] = 1024 - ip->ftwidth;
288 cmd[6] = 1024 - ip->ftheight;
289 gsp_out(ba, cmd, 7);
290 #endif
291 cmd[0] = GCMD_FILL;
292 cmd[1] = UL_FG(ip);
293 cmd[2] = ip->cursorx * ip->ftwidth;
294 cmd[3] = ip->cursory * ip->ftheight;
295 cmd[4] = ip->ftwidth;
296 cmd[5] = ip->ftheight;
297 cmd[6] = 10; /* thats src xor dst */
298 gsp_out(ba, cmd, 7);
299
300 }
301
302
303
304 static void screen_up(struct ite_softc *ip, int top, int bottom, int lines)
305 {
306 struct gspregs *ba;
307
308 u_int16_t cmd[7];
309
310 ba = (struct gspregs *)ip->grf->g_regkva;
311
312 #ifdef DEBUG_UL
313 printf("screen_up %d %d %d ->",top,bottom,lines);
314 #endif
315 /* do some bounds-checking here.. */
316
317 if (top >= bottom)
318 return;
319
320 if (top + lines >= bottom)
321 {
322 ulowell_clear (ip, top, 0, bottom - top, ip->cols);
323 return;
324 }
325
326 cmd[0] = GCMD_PIXBLT;
327 cmd[1] = 0; /* x */
328 cmd[2] = top * ip->ftheight; /* y */
329 cmd[3] = ip->cols * ip->ftwidth; /* w */
330 cmd[4] = (bottom-top+1) * ip->ftheight; /* h */
331 cmd[5] = 0; /* dst x */
332 cmd[6] = (top-lines) * ip->ftheight; /* dst y */
333 gsp_out(ba, cmd, 7);
334
335 ulowell_clear(ip, bottom-lines+1, 0, lines-1, ip->cols);
336 };
337
338 static void screen_down(struct ite_softc *ip, int top, int bottom, int lines)
339 {
340 struct gspregs *ba;
341
342 u_int16_t cmd[7];
343
344 ba = (struct gspregs *)ip->grf->g_regkva;
345
346 #ifdef DEBUG_UL
347 printf("screen_down %d %d %d ->",top,bottom,lines);
348 #endif
349
350 /* do some bounds-checking here.. */
351
352 if (top >= bottom)
353 return;
354
355 if (top + lines >= bottom)
356 {
357 ulowell_clear (ip, top, 0, bottom - top, ip->cols);
358 return;
359 }
360
361 cmd[0] = GCMD_PIXBLT;
362 cmd[1] = 0; /* x */
363 cmd[2] = top * ip->ftheight; /* y */
364 cmd[3] = ip->cols * ip->ftwidth; /* w */
365 cmd[4] = (bottom - top - lines) * ip->ftheight; /* h */
366 cmd[5] = 0; /* dst x */
367 cmd[6] = (top + lines) * ip->ftheight; /* dst y */
368 gsp_out(ba, cmd, 7);
369
370 ulowell_clear(ip, top, 0, lines, ip->cols);
371 };
372
373 void ulowell_deinit(struct ite_softc *ip)
374 {
375 ip->flags &= ~ITE_INITED;
376 }
377
378
379 void ulowell_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
380 {
381 struct gspregs *ba;
382 u_int16_t cmd[8];
383
384 ba = (struct gspregs *)ip->grf->g_regkva;
385
386 cmd[0] = GCMD_CHAR;
387 cmd[1] = c & 0xff;
388 cmd[2] = 0x0;
389 cmd[3] = UL_FG(ip);
390 cmd[4] = dx * ip->ftwidth;
391 cmd[5] = dy * ip->ftheight;
392 cmd[6] = mode;
393 gsp_write(ba, cmd, 7);
394 }
395
396 void ulowell_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
397 {
398 /* XXX TBD */
399 struct gspregs * ba;
400
401 u_int16_t cmd[7];
402
403 #ifdef DEBUG_UL
404 printf("ulowell_clear %d %d %d %d ->",sy,sx,h,w);
405 #endif
406 ba = (struct gspregs *)ip->grf->g_regkva;
407
408 cmd[0] = GCMD_FILL;
409 cmd[1] = 0x0; /* XXX */
410 cmd[2] = sx * ip->ftwidth;
411 cmd[3] = sy * ip->ftheight;
412 cmd[4] = w * ip->ftwidth;
413 cmd[5] = h * ip->ftheight;
414 cmd[6] = 0;
415
416 gsp_out(ba, cmd, 7);
417 }
418
419 void ulowell_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
420 {
421 struct gspregs *ba;
422 u_int16_t cmd[7];
423
424 ba = (struct gspregs *)ip->grf->g_regkva;
425
426 #ifdef DEBUG_UL
427 printf("ulowell_scroll %d %d %d %d ->",sy,sx,count,dir);
428 #endif
429
430 ulowell_cursor(ip, ERASE_CURSOR);
431
432 if (dir == SCROLL_UP) {
433 screen_up (ip, sy, ip->bottom_margin, count);
434 } else if (dir == SCROLL_DOWN) {
435 screen_down (ip, sy, ip->bottom_margin, count);
436 } else if (dir == SCROLL_RIGHT) {
437 cmd[0] = GCMD_PIXBLT;
438 cmd[1] = sx * ip->ftwidth;
439 cmd[2] = sy * ip->ftheight;
440 cmd[3] = (ip->cols - sx - count) * ip->ftwidth;
441 cmd[4] = ip->ftheight;
442 cmd[5] = (sx + count) * ip->ftwidth;
443 cmd[6] = sy * ip->ftheight;
444 gsp_out(ba,cmd,7);
445 ulowell_clear (ip, sy, sx, 1, count);
446 } else {
447 cmd[0] = GCMD_PIXBLT;
448 cmd[1] = sx * ip->ftwidth;
449 cmd[2] = sy * ip->ftheight;
450 cmd[3] = (ip->cols - sx) * ip->ftwidth;
451 cmd[4] = ip->ftheight;
452 cmd[5] = (sx - count) * ip->ftwidth;
453 cmd[6] = sy * ip->ftheight;
454 gsp_out(ba,cmd,7);
455 ulowell_clear (ip, sy, ip->cols - count, 1, count);
456 }
457 }
458
459 #ifdef DEBUG_UL
460 void
461 gsp_dump(cmd,len)
462 u_int16_t *cmd;
463 int len;
464 {
465 printf("gsp");
466 while (len-- > 0)
467 printf(" %lx",*cmd++);
468 printf("\n");
469 }
470 #endif
471 #endif /* NGRFUL */
472