Home | History | Annotate | Line # | Download | only in dev
ite_ul.c revision 1.1
      1 /*	$NetBSD: ite_ul.c,v 1.1 1995/08/18 16:15:48 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 	int pos;
    230 
    231 	ba = (struct gspregs *)ip->grf->g_regkva;
    232 
    233 	if (flag == END_CURSOROPT)
    234 		--ip->cursor_opt;
    235 	else if (flag == START_CURSOROPT) {
    236 		if (!ip->cursor_opt)
    237 			ulowell_cursor(ip, ERASE_CURSOR);
    238 		++ip->cursor_opt;
    239 		return;		/* if we are already opted */
    240 	}
    241 
    242 	if (ip->cursor_opt)
    243 		return;		/* if we are still nested. */
    244 
    245 	/* else we draw the cursor */
    246 
    247 	if (flag != DRAW_CURSOR && flag != END_CURSOROPT) {
    248 		/* erase cursor */
    249 #if 0
    250 		cmd[0] = GCMD_PIXBLT;
    251 		cmd[1] = 1024 - ip->ftwidth;
    252 		cmd[2] = 1024 - ip->ftheight;
    253 		cmd[3] = ip->ftwidth;
    254 		cmd[4] = ip->ftheight;
    255 		cmd[5] = ip->cursorx * ip->ftwidth;
    256 		cmd[6] = ip->cursory * ip->ftheight;
    257 		gsp_out(ba, cmd, 7);
    258 #endif
    259 		cmd[0] = GCMD_FILL;
    260 		cmd[1] = UL_FG(ip);
    261 		cmd[2] = ip->cursorx * ip->ftwidth;
    262 		cmd[3] = ip->cursory * ip->ftheight;
    263 		cmd[4] = ip->ftwidth;
    264 		cmd[5] = ip->ftheight;
    265 		cmd[6] = 10;	/* thats src xor dst */
    266 		gsp_out(ba, cmd, 7);
    267 	}
    268 
    269 	if (flag != DRAW_CURSOR && flag != MOVE_CURSOR &&
    270 	    flag != END_CURSOROPT)
    271 		return;
    272 
    273 	/* draw cursor */
    274 
    275 	ip->cursorx = min(ip->curx, ip->cols-1);
    276 	ip->cursory = ip->cury;
    277 #if 0
    278 	cmd[0] = GCMD_PIXBLT;
    279 	cmd[1] = ip->cursorx * ip->ftwidth;
    280 	cmd[2] = ip->cursory * ip->ftheight;
    281 	cmd[3] = ip->ftwidth;
    282 	cmd[4] = ip->ftheight;
    283 	cmd[5] = 1024 - ip->ftwidth;
    284 	cmd[6] = 1024 - ip->ftheight;
    285 	gsp_out(ba, cmd, 7);
    286 #endif
    287 	cmd[0] = GCMD_FILL;
    288 	cmd[1] = UL_FG(ip);
    289 	cmd[2] = ip->cursorx * ip->ftwidth;
    290 	cmd[3] = ip->cursory * ip->ftheight;
    291 	cmd[4] = ip->ftwidth;
    292 	cmd[5] = ip->ftheight;
    293 	cmd[6] = 10;	/* thats src xor dst */
    294 	gsp_out(ba, cmd, 7);
    295 
    296 }
    297 
    298 
    299 
    300 static void screen_up (struct ite_softc *ip, int top, int bottom, int lines)
    301 {
    302 	struct gspregs *ba;
    303 
    304 	u_int16_t cmd[7];
    305 
    306 	ba = (struct gspregs *)ip->grf->g_regkva;
    307 
    308 #ifdef DEBUG_UL
    309 	printf("screen_up %d %d %d ->",top,bottom,lines);
    310 #endif
    311 	/* do some bounds-checking here.. */
    312 
    313 	if (top >= bottom)
    314 		return;
    315 
    316 	if (top + lines >= bottom)
    317 	{
    318 		ulowell_clear (ip, top, 0, bottom - top, ip->cols);
    319 		return;
    320 	}
    321 
    322 	cmd[0] = GCMD_PIXBLT;
    323 	cmd[1] = 0;					/* x */
    324 	cmd[2] = top			* ip->ftheight;	/* y */
    325 	cmd[3] = ip->cols		* ip->ftwidth;	/* w */
    326 	cmd[4] = (bottom-top+1)		* ip->ftheight;	/* h */
    327 	cmd[5] = 0;					/* dst x */
    328 	cmd[6] = (top-lines)  		* ip->ftheight;	/* dst y */
    329 	gsp_out(ba, cmd, 7);
    330 
    331 	ulowell_clear(ip, bottom-lines+1, 0, lines-1, ip->cols);
    332 };
    333 
    334 static void screen_down (struct ite_softc *ip, int top, int bottom, int lines)
    335 {
    336 	struct gspregs *ba;
    337 
    338 	u_int16_t cmd[7];
    339 
    340 	ba = (struct gspregs *)ip->grf->g_regkva;
    341 
    342 #ifdef DEBUG_UL
    343 	printf("screen_down %d %d %d ->",top,bottom,lines);
    344 #endif
    345 
    346 	/* do some bounds-checking here.. */
    347 
    348 	if (top >= bottom)
    349 		return;
    350 
    351 	if (top + lines >= bottom)
    352 	{
    353 	    ulowell_clear (ip, top, 0, bottom - top, ip->cols);
    354 	    return;
    355 	}
    356 
    357 	cmd[0] = GCMD_PIXBLT;
    358 	cmd[1] = 0;					/* x */
    359 	cmd[2] = top			* ip->ftheight;	/* y */
    360 	cmd[3] = ip->cols		* ip->ftwidth;	/* w */
    361 	cmd[4] = (bottom - top - lines)	* ip->ftheight;	/* h */
    362 	cmd[5] = 0;					/* dst x */
    363 	cmd[6] = (top + lines)		* ip->ftheight;	/* dst y */
    364 	gsp_out(ba, cmd, 7);
    365 
    366 	ulowell_clear(ip, top, 0, lines, ip->cols);
    367 };
    368 
    369 void ulowell_deinit(struct ite_softc *ip)
    370 {
    371 	ip->flags &= ~ITE_INITED;
    372 }
    373 
    374 
    375 void ulowell_putc(struct ite_softc *ip, int c, int dy, int dx, int mode)
    376 {
    377 	struct gspregs *ba;
    378 	register u_int8_t attr;
    379 	u_int16_t cmd[8];
    380 
    381 	ba = (struct gspregs *)ip->grf->g_regkva;
    382 
    383 	cmd[0] = GCMD_CHAR;
    384 	cmd[1] = c & 0xff;
    385 	cmd[2] = 0x0;
    386 	cmd[3] = UL_FG(ip);
    387 	cmd[4] = dx * ip->ftwidth;
    388 	cmd[5] = dy * ip->ftheight;
    389 	cmd[6] = mode;
    390 	gsp_write(ba, cmd, 7);
    391 }
    392 
    393 void ulowell_clear(struct ite_softc *ip, int sy, int sx, int h, int w)
    394 {
    395 	/* XXX TBD */
    396 	struct gspregs * ba;
    397 
    398 	u_int16_t cmd[7];
    399 
    400 #ifdef	DEBUG_UL
    401 	printf("ulowell_clear %d %d %d %d ->",sy,sx,h,w);
    402 #endif
    403 	ba = (struct gspregs *)ip->grf->g_regkva;
    404 
    405 	cmd[0] = GCMD_FILL;
    406 	cmd[1] = 0x0; /* XXX */
    407 	cmd[2] = sx * ip->ftwidth;
    408 	cmd[3] = sy * ip->ftheight;
    409 	cmd[4] = w * ip->ftwidth;
    410 	cmd[5] = h * ip->ftheight;
    411 	cmd[6] = 0;
    412 
    413 	gsp_out(ba, cmd, 7);
    414 }
    415 
    416 void ulowell_scroll(struct ite_softc *ip, int sy, int sx, int count, int dir)
    417 {
    418 	struct gspregs *ba;
    419 
    420 	register int height, dy, i;
    421 	u_int16_t cmd[7];
    422 
    423 	ba = (struct gspregs *)ip->grf->g_regkva;
    424 
    425 #ifdef DEBUG_UL
    426 	printf("ulowell_scroll %d %d %d %d ->",sy,sx,count,dir);
    427 #endif
    428 
    429 	ulowell_cursor(ip, ERASE_CURSOR);
    430 
    431 	if (dir == SCROLL_UP) {
    432 		screen_up (ip, sy, ip->bottom_margin, count);
    433 	} else if (dir == SCROLL_DOWN) {
    434 		screen_down (ip, sy, ip->bottom_margin, count);
    435 	} else if (dir == SCROLL_RIGHT) {
    436 		cmd[0] = GCMD_PIXBLT;
    437 		cmd[1] = sx * ip->ftwidth;
    438 		cmd[2] = sy * ip->ftheight;
    439 		cmd[3] = (ip->cols - sx - count) * ip->ftwidth;
    440 		cmd[4] = ip->ftheight;
    441 		cmd[5] = (sx + count) * ip->ftwidth;
    442 		cmd[6] = sy * ip->ftheight;
    443 		gsp_out(ba,cmd,7);
    444 		ulowell_clear (ip, sy, sx, 1, count);
    445 	} else {
    446 		cmd[0] = GCMD_PIXBLT;
    447 		cmd[1] = sx * ip->ftwidth;
    448 		cmd[2] = sy * ip->ftheight;
    449 		cmd[3] = (ip->cols - sx) * ip->ftwidth;
    450 		cmd[4] = ip->ftheight;
    451 		cmd[5] = (sx - count) * ip->ftwidth;
    452 		cmd[6] = sy * ip->ftheight;
    453 		gsp_out(ba,cmd,7);
    454 		ulowell_clear (ip, sy, ip->cols - count, 1, count);
    455 	}
    456 }
    457 
    458 #ifdef DEBUG_UL
    459 void
    460 gsp_dump(cmd,len)
    461 	u_int16_t *cmd;
    462 	int len;
    463 {
    464 	printf("gsp");
    465 	while (len-- > 0)
    466 		printf(" %lx",*cmd++);
    467 	printf("\n");
    468 }
    469 #endif
    470 #endif /* NGRFUL */
    471