/*
* Copyright (c) 1994 Christian E. Hopps
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Christian E. Hopps.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This is what ip->priv points to;
* it contains local variables for custom-chip ites.
*/
struct ite_priv {
view_t *view; /* the view for this ite. */
u_char **row_ptr; /* array of pointers into the bitmap */
u_long row_bytes;
u_long cursor_opt;
u_int *column_offset; /* array of offsets for columns */
u_int row_offset; /* the row offset */
u_short width; /* the bitmap width */
u_short underline; /* where the underline goes */
u_short ft_x; /* the font width */
u_short ft_y; /* the font height */
u_char *font_cell[256]; /* the font pointer */
};
typedef struct ite_priv ipriv_t;
/*
* save new values so that future opens use them
* this may not be correct when we implement Virtual Consoles
*/
ite_default_height = cci->view->display.height;
ite_default_width = cci->view->display.width;
ite_default_x = cci->view->display.x;
ite_default_y = cci->view->display.y;
ite_default_depth = cci->view->bitmap->depth;
if (cci->row_ptr)
free_chipmem(cci->row_ptr);
if (cci->column_offset)
free_chipmem(cci->column_offset);
/* Find the correct set of rendering routines for this font. */
if (ip->ftwidth > 8)
panic("kernel font size not supported");
cci = alloc_chipmem(sizeof (*cci));
if (cci == NULL)
panic("no memory for console device.");
switch (cmd) {
case ITEIOCGWINSZ:
is = (struct itewinsize *)addr;
is->x = cci->view->display.x;
is->y = cci->view->display.y;
is->width = cci->view->display.width;
is->height = cci->view->display.height;
is->depth = cci->view->bitmap->depth;
break;
case ITEIOCSWINSZ:
is = (struct itewinsize *)addr;
if (ite_newsize(ip, is))
error = ENOMEM;
else {
ws.ws_row = ip->rows;
ws.ws_col = ip->cols;
ws.ws_xpixel = cci->view->display.width;
ws.ws_ypixel = cci->view->display.height;
ite_reset (ip);
/*
* XXX tell tty about the change
* XXX this is messy, but works
*/
(*ite_cdevsw.d_ioctl)(0, TIOCSWINSZ,
(void *)&ws, 0, l);
}
break;
case ITEIOCDSPWIN:
cc_mode(ip->grf, GM_GRFON, NULL, 0, 0);
break;
case ITEIOCREMWIN:
cc_mode(ip->grf, GM_GRFOFF, NULL, 0, 0);
break;
case VIOCSCMAP:
case VIOCGCMAP:
/*
* XXX needs to be fixed when multiple console implemented
* XXX watchout for that -1 its not really the kernel talking
* XXX these two commands don't use the proc pointer though
*/
error = (*view_cdevsw.d_ioctl)(0, cmd, addr, -1, l);
break;
default:
error = EPASSTHROUGH;
break;
}
return (error);
}
cci = ip->priv;
v = cci->view;
bm = v->bitmap;
dr_plane = (bm->depth > 1 ? bm->depth-1 : 0);
if (flag == END_CURSOROPT)
cci->cursor_opt--;
else if (flag == START_CURSOROPT) {
if (!cci->cursor_opt)
cursor32 (ip, ERASE_CURSOR);
cci->cursor_opt++;
return; /* if we are already opted. */
}
if (cci->cursor_opt)
return; /* if we are still nested. */
/* else we draw the cursor. */
cstart = 0;
cend = ip->ftheight-1;
pl = VDISPLAY_LINE(v, dr_plane, (ip->cursory * ip->ftheight + cstart));
ofs = (ip->cursorx * ip->ftwidth);
if (flag != DRAW_CURSOR && flag != END_CURSOROPT) {
/*
* erase the cursor
*/
int hh;
if (dr_plane) {
for (h = cend; h >= 0; h--) {
BFSET(pl, ofs, ip->ftwidth);
pl += cci->row_offset;
}
} else {
for (h = cend; h >= 0; h--) {
BFCHG(pl, ofs, ip->ftwidth);
pl += cci->row_offset;
}
}
}
static inline
int expbits(int data)
{
int i, nd = 0;
if (data & 1)
nd |= 0x02;
for (i=1; i < 32; i++) {
if (data & (1 << i))
nd |= 0x5 << (i-1);
}
nd &= ~data;
return(~nd);
}
/* Notes: optimizations given the kernel_font_(width|height) #define'd.
* the dbra loops could be elminated and unrolled using height,
* the :width in the bfxxx instruction could be made immediate instead
* of a data register as it now is.
* the underline could be added when the loop is unrolled
*
* It would look like hell but be very fast.*/
cc_putc_func *put_func[ATTR_ALL+1] = {
putc_nm,
putc_in,
putc_ul,
putc_ul_in,
putc_bd,
putc_bd_in,
putc_bd_ul,
putc_bd_ul_in,
/* no support for blink */
putc_nm,
putc_in,
putc_ul,
putc_ul_in,
putc_bd,
putc_bd_in,
putc_bd_ul,
putc_bd_ul_in
};
/* FIX: shouldn't this advance the cursor even if the character to
be output is not available in the font? -ch */
static void
putc8(struct ite_softc *ip, int c, int dy, int dx, int mode)
{
ipriv_t *cci = (ipriv_t *) ip->priv;
/*
* if character is higher than font has glyphs, substitute
* highest glyph.
*/
c = (u_char)c;
if (c < ip->font_lo || c > ip->font_hi)
c = ip->font_hi;
put_func[mode](cci, cci->row_ptr[dy], cci->font_cell[c],
cci->column_offset[dx], cci->row_offset, cci->ft_x, cci->ft_y);
}
static void
clear8(struct ite_softc *ip, int sy, int sx, int h, int w)
{
ipriv_t *cci = (ipriv_t *) ip->priv;
bmap_t *bm = cci->view->bitmap;
if ((sx == 0) && (w == ip->cols))
{
/* common case: clearing whole lines */
while (h--)
{
int i;
u_char *ptr = cci->row_ptr[sy];
for (i=0; i < ip->ftheight; i++) {
memset(ptr, 0, bm->bytes_per_row);
ptr += bm->bytes_per_row + bm->row_mod; /* don't get any smart
ideas, because this is for
interleaved bitmaps */
}
sy++;
}
}
else
{
/* clearing only part of a line */
/* XXX could be optimized MUCH better, but is it worth the trouble? */
while (h--)
{
u_char *pl = cci->row_ptr[sy];
int ofs = sx * ip->ftwidth;
int i, j;
for (i = w-1; i >= 0; i--)
{
u_char *ppl = pl;
for (j = ip->ftheight-1; j >= 0; j--)
{
BFCLR(ppl, ofs, ip->ftwidth);
ppl += bm->row_mod + bm->bytes_per_row;
}
ofs += ip->ftwidth;
}
sy++;
}
}
}
/* Note: sx is only relevant for SCROLL_LEFT or SCROLL_RIGHT. */
static void
scroll8(register struct ite_softc *ip, register int sy, int sx, int count,
int dir)
{
bmap_t *bm = ((ipriv_t *)ip->priv)->view->bitmap;
u_char *pl = ((ipriv_t *)ip->priv)->row_ptr[sy];