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