Home | History | Annotate | Line # | Download | only in boot
video.c revision 1.1
      1 /*	$Id: video.c,v 1.1 1998/10/26 00:45:47 sakamoto Exp $	*/
      2 
      3 /*-
      4  * Copyright (C) 1995-1997 Gary Thomas (gdt (at) linuxppc.org)
      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 Gary Thomas.
     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 
     33 #ifdef CONS_BE
     34 #include <stand.h>
     35 #include "iso_font.h"
     36 
     37 #define	FONT_WIDTH	8
     38 #define	FONT_HEIGHT	16
     39 #define	VRAM_WIDTH	640
     40 #define	VRAM_HEIGHT	480
     41 #define	VRAM_SIZE	(VRAM_WIDTH * VRAM_HEIGHT)
     42 #define	ROW	(VRAM_WIDTH / FONT_WIDTH)
     43 #define	COL	(VRAM_HEIGHT / FONT_HEIGHT)
     44 
     45 unsigned char *VramBase;
     46 unsigned char save_cursor[FONT_WIDTH];
     47 
     48 /*
     49  * The current state of virtual displays
     50  */
     51 struct screen {
     52 	enum state {
     53 		NORMAL,		/* no pending escape */
     54 		ESC,		/* saw ESC */
     55 		EBRAC,		/* saw ESC[ */
     56 		EBRACEQ		/* saw ESC[= */
     57 	} state;		/* command parser state */
     58 	int	cx;		/* the first escape seq argument */
     59 	int	cy;		/* the second escap seq argument */
     60 	int	*accp;		/* pointer to the current processed argument */
     61 	int	row;
     62 	int	col;
     63 	unsigned char fgcolor;
     64 	unsigned char bgcolor;
     65 } screen;
     66 
     67 
     68 void
     69 video_init(unsigned char *buffer)
     70 {
     71 	struct screen *d = &screen;
     72 
     73 	VramBase = buffer;
     74 	d->fgcolor = 0xff;
     75 	d->bgcolor = 0x00;
     76 	d->row = 0;
     77 	d->col = 0;
     78 	d->state = NORMAL;
     79 	memset(VramBase, d->bgcolor, VRAM_SIZE);
     80 	memset(save_cursor, d->bgcolor, FONT_WIDTH);
     81 }
     82 
     83 static void
     84 wrtchar(unsigned char c, struct screen *d)
     85 {
     86 	unsigned char *p = VramBase +
     87 		(d->col * VRAM_WIDTH * FONT_HEIGHT) + (d->row * FONT_WIDTH);
     88 	int fontbase = c * 16;
     89 	int x, y;
     90 
     91 	for (y = 0; y < FONT_HEIGHT; y++) {
     92 		for (x = 0; x < FONT_WIDTH; x++) {
     93 			if ((font[fontbase + y] >> (FONT_WIDTH - x)) & 1)
     94 				*(p + x + (y * VRAM_WIDTH)) = d->fgcolor;
     95 			else
     96 				*(p + x + (y * VRAM_WIDTH)) = d->bgcolor;
     97 		}
     98 	}
     99 	d->row++;
    100 }
    101 
    102 static void
    103 cursor(struct screen *d, int flag)
    104 {
    105 	int x;
    106 	int y = FONT_HEIGHT - 1;
    107 
    108 	unsigned char *p = VramBase +
    109 		(d->col * VRAM_WIDTH * FONT_HEIGHT) + (d->row * FONT_WIDTH);
    110 	for (x = 0; x < FONT_WIDTH - 1; x++) {
    111 		if (flag) {
    112 			save_cursor[x] = *(p + x + (y * VRAM_WIDTH));
    113 			*(p + x + (y * VRAM_WIDTH)) = d->fgcolor;
    114 		} else {
    115 			*(p + x + (y * VRAM_WIDTH)) = save_cursor[x];
    116 		}
    117 	}
    118 }
    119 
    120 /*
    121  * vga_putc (nee sput) has support for emulation of the 'ibmpc' termcap entry.
    122  * This is a bare-bones implementation of a bare-bones entry
    123  * One modification: Change li#24 to li#25 to reflect 25 lines
    124  * "ca" is the color/attributes value (left-shifted by 8)
    125  * or 0 if the current regular color for that screen is to be used.
    126  */
    127 void
    128 video_putc(u_char c)
    129 {
    130 	struct screen *d = &screen;
    131 	int i, j;
    132 	unsigned char *pp;
    133 
    134 	cursor(d, 0);
    135 
    136 	switch (d->state) {
    137 	case NORMAL:
    138 		switch (c) {
    139 		case 0x0:		/* Ignore pad characters */
    140 			return;
    141 
    142 		case 0x1B:
    143 			d->state = ESC;
    144 			break;
    145 
    146 		case '\t':
    147 			do {
    148 				wrtchar(' ', d);
    149 			} while (d->row % 8);
    150 			break;
    151 
    152 		case '\b':  /* non-destructive backspace */
    153 			d->row--;
    154 			if (d->row < 0) {
    155 				if (d->col > 0) {
    156 					d->col--;
    157 					d->row += ROW;	/* prev column */
    158 				} else {
    159 					d->row = 0;
    160 				}
    161 			}
    162 			break;
    163 
    164 		case '\n':
    165 			d->col++;
    166 		case '\r':
    167 			d->row = 0;
    168 			break;
    169 
    170 		case '\007':
    171 			break;
    172 
    173 		default:
    174 			wrtchar(c, d);
    175 			if (d->row >= ROW) {
    176 				d->row = 0;
    177 				d->col++;
    178 			}
    179 			break;
    180 		}
    181 		break;
    182 	}
    183 	if (d->col >= COL) {		/* scroll check */
    184 		memcpy(VramBase, VramBase + VRAM_WIDTH * FONT_HEIGHT,
    185 			VRAM_SIZE - VRAM_WIDTH * FONT_WIDTH);
    186 		memset(VramBase + VRAM_SIZE - VRAM_WIDTH * FONT_HEIGHT,
    187 			d->bgcolor, VRAM_WIDTH * FONT_HEIGHT);
    188 		d->col = COL - 1;
    189 	}
    190 	cursor(d, 1);
    191 }
    192 #endif
    193