Home | History | Annotate | Line # | Download | only in dev
ite_ul.c revision 1.8
      1 /*	$NetBSD: ite_ul.c,v 1.8 1999/02/16 22:46:57 is Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1999 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 __P((struct ite_softc *,int));
     95 void ulowell_scroll __P((struct ite_softc *,int,int,int,int));
     96 void ulowell_deinit __P((struct ite_softc *));
     97 void ulowell_clear __P((struct ite_softc *,int,int,int,int));
     98 void ulowell_putc __P((struct ite_softc *,int,int,int,int));
     99 void ulowell_init __P((struct ite_softc *));
    100 
    101 #ifdef DEBUG_UL
    102 void gsp_dump __P((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()
    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(gp)
    134 	struct grf_softc *gp;
    135 {
    136 	gp->g_iteinit = ulowell_init;
    137 	gp->g_itedeinit = ulowell_deinit;
    138 	gp->g_iteclear = ulowell_clear;
    139 	gp->g_iteputc = ulowell_putc;
    140 	gp->g_itescroll = ulowell_scroll;
    141 	gp->g_itecursor = ulowell_cursor;
    142 }
    143 
    144 void
    145 ulowell_init(ip)
    146 	struct ite_softc *ip;
    147 {
    148 	struct gspregs *ba;
    149 
    150 	u_int16_t *sp;
    151 	u_int16_t cmd[8];
    152 
    153 	int i;
    154 
    155 	ba = (struct gspregs *) ip->grf->g_regkva;
    156 
    157 	ip->font     = kernel_font;
    158 	ip->font_lo  = kernel_font_lo;
    159 	ip->font_hi  = kernel_font_hi;
    160 	ip->ftwidth  = kernel_font_width;
    161 	ip->ftheight = kernel_font_height;
    162 	ip->ftbaseline = kernel_font_baseline;
    163 	ip->ftboldsmear = kernel_font_boldsmear;
    164 
    165 	/* upload font data */
    166 
    167 	ba->ctrl = LBL|INCW;
    168 	ba->hstadrh = 0xFFA2;
    169 	ba->hstadrl = 0x0200;
    170 
    171 	ba->data = 0x0000;
    172 	ba->data = 0xFFA3;
    173 	ba->data = ip->ftwidth;
    174 	ba->data = ip->ftheight;
    175 	ba->data = ip->ftbaseline;
    176 	ba->data = 1;
    177 	ba->data = ip->font_lo;
    178 	ba->data = ip->font_hi;
    179 	ba->data = ip->ftboldsmear;
    180 
    181 	ba->hstadrh = 0xFFA3;
    182 	ba->hstadrl = 0x0000;
    183 
    184 	/*
    185 	 * font has to be word aligned and padded to word boundary.
    186 	 * 8 bit wide fonts will be byte swapped in the bit swap
    187 	 * routine.
    188 	 */
    189 
    190 	i = (ip->font_hi - ip->font_lo + 1) * ip->ftheight;
    191 	if (ip->ftwidth <= 8)
    192 		i /= 2;
    193 	for (sp = (u_int16_t *)ip->font; i>0; --i,++sp) {
    194 		ba->data = *sp;
    195 	}
    196 
    197 	/* bitwise mirror the font: */
    198 
    199 	cmd[0] = GCMD_FNTMIR;
    200 	gsp_out(ba, cmd, 1);
    201 
    202 	ip->priv = NULL;
    203 	ip->cursor_opt = 0;
    204 
    205 	if (ip->ftwidth >0 && ip->ftheight > 0) {
    206 		ip->cols = ip->grf->g_display.gd_dwidth  / ip->ftwidth;
    207 		ip->rows = ip->grf->g_display.gd_dheight / ip->ftheight;
    208 	}
    209 
    210 	ulowell_clear(ip, 0, 0, ip->rows, ip->cols);
    211 
    212 	/*
    213 	 * switch overlay plane 0 on again, in case s.b. did a GM_GRFOVOFF
    214 	 * XXX maybe this should be done on each output, by the TMS code?
    215 	 * what happens on panic?
    216 
    217 	ba->ctrl = LBL;
    218 	GSPSETHADRS(ba, 0xFE800000);
    219 	ba->data = 0;
    220 	ba->hstadrl = 0x0020;
    221 	gup->gus_ovslct |= 1;
    222 	ba->data = gup->gus_ovslct;
    223 	 */
    224 
    225 #ifdef UL_DEBUG
    226 	printf("ulowell_init: %d %d %d %d %d %d\n", ip->ftwidth, ip->ftheight,
    227 		ip->ftbaseline, ip->font_lo, ip->font_hi, ip->ftboldsmear);
    228 #endif
    229 }
    230 
    231 
    232 void ulowell_cursor(struct ite_softc *ip, int flag)
    233 {
    234 	struct gspregs *ba;
    235 	u_int16_t cmd[7];
    236 
    237 	ba = (struct gspregs *)ip->grf->g_regkva;
    238 
    239 	if (flag == END_CURSOROPT)
    240 		--ip->cursor_opt;
    241 	else if (flag == START_CURSOROPT) {
    242 		if (!ip->cursor_opt)
    243 			ulowell_cursor(ip, ERASE_CURSOR);
    244 		++ip->cursor_opt;
    245 		return;		/* if we are already opted */
    246 	}
    247 
    248 	if (ip->cursor_opt)
    249 		return;		/* if we are still nested. */
    250 
    251 	/* else we draw the cursor */
    252 
    253 	if (flag != DRAW_CURSOR && flag != END_CURSOROPT) {
    254 		/* erase cursor */
    255 #if 0
    256 		cmd[0] = GCMD_PIXBLT;
    257 		cmd[1] = 1024 - ip->ftwidth;
    258 		cmd[2] = 1024 - ip->ftheight;
    259 		cmd[3] = ip->ftwidth;
    260 		cmd[4] = ip->ftheight;
    261 		cmd[5] = ip->cursorx * ip->ftwidth;
    262 		cmd[6] = ip->cursory * ip->ftheight;
    263 		gsp_out(ba, cmd, 7);
    264 #endif
    265 		cmd[0] = GCMD_FILL;
    266 		cmd[1] = UL_FG(ip);
    267 		cmd[2] = ip->cursorx * ip->ftwidth;
    268 		cmd[3] = ip->cursory * ip->ftheight;
    269 		cmd[4] = ip->ftwidth;
    270 		cmd[5] = ip->ftheight;
    271 		cmd[6] = 10;	/* thats src xor dst */
    272 		gsp_out(ba, cmd, 7);
    273 	}
    274 
    275 	if (flag != DRAW_CURSOR && flag != MOVE_CURSOR &&
    276 	    flag != END_CURSOROPT)
    277 		return;
    278 
    279 	/* draw cursor */
    280 
    281 	ip->cursorx = min(ip->curx, ip->cols-1);
    282 	ip->cursory = ip->cury;
    283 #if 0
    284 	cmd[0] = GCMD_PIXBLT;
    285 	cmd[1] = ip->cursorx * ip->ftwidth;
    286 	cmd[2] = ip->cursory * ip->ftheight;
    287 	cmd[3] = ip->ftwidth;
    288 	cmd[4] = ip->ftheight;
    289 	cmd[5] = 1024 - ip->ftwidth;
    290 	cmd[6] = 1024 - ip->ftheight;
    291 	gsp_out(ba, cmd, 7);
    292 #endif
    293 	cmd[0] = GCMD_FILL;
    294 	cmd[1] = UL_FG(ip);
    295 	cmd[2] = ip->cursorx * ip->ftwidth;
    296 	cmd[3] = ip->cursory * ip->ftheight;
    297 	cmd[4] = ip->ftwidth;
    298 	cmd[5] = ip->ftheight;
    299 	cmd[6] = 10;	/* thats src xor dst */
    300 	gsp_out(ba, cmd, 7);
    301 
    302 }
    303 
    304 
    305 
    306 static void screen_up (struct ite_softc *ip, int top, int bottom, int lines)
    307 {
    308 	struct gspregs *ba;
    309 
    310 	u_int16_t cmd[7];
    311 
    312 	ba = (struct gspregs *)ip->grf->g_regkva;
    313 
    314 #ifdef DEBUG_UL
    315 	printf("screen_up %d %d %d ->",top,bottom,lines);
    316 #endif
    317 	/* do some bounds-checking here.. */
    318 
    319 	if (top >= bottom)
    320 		return;
    321 
    322 	if (top + lines >= bottom)
    323 	{
    324 		ulowell_clear (ip, top, 0, bottom - top, ip->cols);
    325 		return;
    326 	}
    327 
    328 	cmd[0] = GCMD_PIXBLT;
    329 	cmd[1] = 0;					/* x */
    330 	cmd[2] = top			* ip->ftheight;	/* y */
    331 	cmd[3] = ip->cols		* ip->ftwidth;	/* w */
    332 	cmd[4] = (bottom-top+1)		* ip->ftheight;	/* h */
    333 	cmd[5] = 0;					/* dst x */
    334 	cmd[6] = (top-lines)  		* ip->ftheight;	/* dst y */
    335 	gsp_out(ba, cmd, 7);
    336 
    337 	ulowell_clear(ip, bottom-lines+1, 0, lines-1, ip->cols);
    338 };
    339 
    340 static void screen_down (struct ite_softc *ip, int top, int bottom, int lines)
    341 {
    342 	struct gspregs *ba;
    343 
    344 	u_int16_t cmd[7];
    345 
    346 	ba = (struct gspregs *)ip->grf->g_regkva;
    347 
    348 #ifdef DEBUG_UL
    349 	printf("screen_down %d %d %d ->",top,bottom,lines);
    350 #endif
    351 
    352 	/* do some bounds-checking here.. */
    353 
    354 	if (top >= bottom)
    355 		return;
    356 
    357 	if (top + lines >= bottom)
    358 	{
    359 	    ulowell_clear (ip, top, 0, bottom - top, ip->cols);
    360 	    return;
    361 	}
    362 
    363 	cmd[0] = GCMD_PIXBLT;
    364 	cmd[1] = 0;					/* x */
    365 	cmd[2] = top			* ip->ftheight;	/* y */
    366 	cmd[3] = ip->cols		* ip->ftwidth;	/* w */
    367 	cmd[4] = (bottom - top - lines)	* ip->ftheight;	/* h */
    368 	cmd[5] = 0;					/* dst x */
    369 	cmd[6] = (top + lines)		* ip->ftheight;	/* dst y */
    370 	gsp_out(ba, cmd, 7);
    371 
    372 	ulowell_clear(ip, top, 0, lines, ip->cols);
    373 };
    374 
    375 void ulowell_deinit(struct ite_softc *ip)
    376 {
    377 	ip->flags &= ~ITE_INITED;
    378 }
    379 
    380 
    381 void ulowell_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
    382 {
    383 	struct gspregs *ba;
    384 	u_int16_t cmd[8];
    385 
    386 	ba = (struct gspregs *)ip->grf->g_regkva;
    387 
    388 	cmd[0] = GCMD_CHAR;
    389 	cmd[1] = c & 0xff;
    390 	cmd[2] = 0x0;
    391 	cmd[3] = UL_FG(ip);
    392 	cmd[4] = dx * ip->ftwidth;
    393 	cmd[5] = dy * ip->ftheight;
    394 	cmd[6] = mode;
    395 	gsp_write(ba, cmd, 7);
    396 }
    397 
    398 void ulowell_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
    399 {
    400 	/* XXX TBD */
    401 	struct gspregs * ba;
    402 
    403 	u_int16_t cmd[7];
    404 
    405 #ifdef	DEBUG_UL
    406 	printf("ulowell_clear %d %d %d %d ->",sy,sx,h,w);
    407 #endif
    408 	ba = (struct gspregs *)ip->grf->g_regkva;
    409 
    410 	cmd[0] = GCMD_FILL;
    411 	cmd[1] = 0x0; /* XXX */
    412 	cmd[2] = sx * ip->ftwidth;
    413 	cmd[3] = sy * ip->ftheight;
    414 	cmd[4] = w * ip->ftwidth;
    415 	cmd[5] = h * ip->ftheight;
    416 	cmd[6] = 0;
    417 
    418 	gsp_out(ba, cmd, 7);
    419 }
    420 
    421 void ulowell_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
    422 {
    423 	struct gspregs *ba;
    424 	u_int16_t cmd[7];
    425 
    426 	ba = (struct gspregs *)ip->grf->g_regkva;
    427 
    428 #ifdef DEBUG_UL
    429 	printf("ulowell_scroll %d %d %d %d ->",sy,sx,count,dir);
    430 #endif
    431 
    432 	ulowell_cursor(ip, ERASE_CURSOR);
    433 
    434 	if (dir == SCROLL_UP) {
    435 		screen_up (ip, sy, ip->bottom_margin, count);
    436 	} else if (dir == SCROLL_DOWN) {
    437 		screen_down (ip, sy, ip->bottom_margin, count);
    438 	} else if (dir == SCROLL_RIGHT) {
    439 		cmd[0] = GCMD_PIXBLT;
    440 		cmd[1] = sx * ip->ftwidth;
    441 		cmd[2] = sy * ip->ftheight;
    442 		cmd[3] = (ip->cols - sx - count) * ip->ftwidth;
    443 		cmd[4] = ip->ftheight;
    444 		cmd[5] = (sx + count) * ip->ftwidth;
    445 		cmd[6] = sy * ip->ftheight;
    446 		gsp_out(ba,cmd,7);
    447 		ulowell_clear (ip, sy, sx, 1, count);
    448 	} else {
    449 		cmd[0] = GCMD_PIXBLT;
    450 		cmd[1] = sx * ip->ftwidth;
    451 		cmd[2] = sy * ip->ftheight;
    452 		cmd[3] = (ip->cols - sx) * ip->ftwidth;
    453 		cmd[4] = ip->ftheight;
    454 		cmd[5] = (sx - count) * ip->ftwidth;
    455 		cmd[6] = sy * ip->ftheight;
    456 		gsp_out(ba,cmd,7);
    457 		ulowell_clear (ip, sy, ip->cols - count, 1, count);
    458 	}
    459 }
    460 
    461 #ifdef DEBUG_UL
    462 void
    463 gsp_dump(cmd,len)
    464 	u_int16_t *cmd;
    465 	int len;
    466 {
    467 	printf("gsp");
    468 	while (len-- > 0)
    469 		printf(" %lx",*cmd++);
    470 	printf("\n");
    471 }
    472 #endif
    473 #endif /* NGRFUL */
    474