graphics.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "graphics.h"
#include "biosint.h"
#include "vga.h"
#include "util.h"
#include "multiboot.h"
#include "console.h"
#include "standalloc.h"
#include "debug.h"
typedef int (*func_t)();
extern int openfile(char *, char *);
extern int close(int);
extern int console;
int saved_videomode;
unsigned char *font8x16;
int graphics_inited = 0;
static char splashimage[64];
unsigned char VSHADOW1[38400];
unsigned char VSHADOW2[38400];
unsigned char VSHADOW4[38400];
unsigned char VSHADOW8[38400];
/*
* constants to define the viewable area
*/
const int x0 = 0;
const int x1 = 80;
const int y0 = 0;
const int y1 = 30;
/*
* text buffer has to be kept around so that we can write things as we
* scroll and the like
*/
/*
* why do these have to be kept here?
*/
/*
* current position
*/
static int fontx = 0;
static int fonty = 10;
/*
* global state so that we don't try to recursively scroll or cursor
*/
static int no_scroll = 0;
/*
* color state
*/
static int graphics_standard_color = A_NORMAL;
static int graphics_normal_color = A_NORMAL;
static int graphics_highlight_color = A_REVERSE;
static int graphics_current_color = A_NORMAL;
/*
* graphics local functions
*/
static void graphics_scroll();
static int read_image(char *s);
static int hex(int v);
}
/* bit mask register */
}
/* Set the splash image */
int graphics_set_splash(char *splashfile) {
/* filename can only be 64 characters due to our buffer size */
return (0);
return (1);
}
/* Get the current splash image */
char *
graphics_get_splash(void)
{
return (splashimage);
}
/*
* Initialize a vga16 graphics display with the palette based off of
* the image in splashimage. If the image doesn't exist, leave graphics
* mode.
*/
int
{
int fail_n = 0;
if (!graphics_inited) {
if (saved_videomode == -1) {
fail_n = 1;
goto fail;
}
}
if (!graphics_set_splash("boot/solaris.xpm")) {
fail_n = 2;
goto fail;
}
if (!read_image(splashimage)) {
fail_n = 3;
goto fail;
}
font8x16 = (unsigned char *)graphics_get_font();
if (!font8x16) {
fail_n = 4;
goto fail;
}
graphics_inited = 1;
/* make sure that the highlight color is set correctly */
graphics_cursor(0);
graphics_cursor(1);
graphics_cls();
return (1);
fail :
text_init();
switch (fail_n) {
case 1:
printf("Failed to set graphics video mode\n");
break;
case 2:
printf("Splash image file name is too long\n");
break;
case 3:
printf("Failed to read splash image\n");
break;
case 4:
printf("Failed to get font address\n");
}
return (0);
}
/*
* int set_videomode(mode)
* BIOS call "INT 10H Function 0h" to set video mode
* Call with %ah = 0x0
* %al = video mode
* Return correct : old videomode
* error : -1
*/
int
set_videomode(int mode)
{
int ret;
return (-1);
}
return (-1);
} /* Set Video mode */
return (ret);
}
/*
* unsigned char * graphics_get_font()
* BIOS call "INT 10H Function 11h" to set font
* Call with %ah = 0x11
* Return correct : font address
* error : 0
*/
unsigned char *
{
int ret;
return (0);
}
return ((unsigned char *) ret);
}
/*
* int graphics_set_palette(unsigned index, unsigned red,
* unsigned green,unsigned blue)
* BIOS call "INT 10H Function 10h" to set individual dac register
* Call with %ah = 0x10
* %bx = register number
* %ch = new value for green (0-63)
* %cl = new value for blue (0-63)
* %dh = new value for red (0-63)
* Return correct : 1
* error : 0
*/
int
{
int ret;
/* wait vertical active display */
/* wait vertical retrace */
return (0);
} else
return (1);
}
/* Leave graphics mode */
void
graphics_end(void)
{
if (graphics_inited) {
graphics_inited = 0;
}
}
/* Print ch on the screen. Handle any needed scrolling or the like */
void
graphics_putchar(int ch)
{
ch &= 0xff;
graphics_cursor(0);
if (ch == '\n') {
else
graphics_cursor(1);
return;
} else if (ch == '\r') {
graphics_cursor(1);
return;
}
graphics_cursor(0);
if (graphics_current_color & 0xf0)
graphics_cursor(0);
else
} else {
}
graphics_cursor(1);
}
/* get the current location of the cursor */
int
graphics_getxy(void)
{
}
void
graphics_gotoxy(int x, int y)
{
graphics_cursor(0);
graphics_setxy(x, y);
graphics_cursor(1);
}
void
graphics_cls(void)
{
int i;
graphics_cursor(0);
for (i = 0; i < 80 * 30; i++)
text[i] = ' ';
graphics_cursor(1);
BitMask(0xff);
/* plano 1 */
MapMask(1);
/* plano 2 */
MapMask(2);
/* plano 3 */
MapMask(4);
/* plano 4 */
MapMask(8);
MapMask(15);
}
void
{
switch (state) {
case COLOR_STATE_STANDARD:
break;
case COLOR_STATE_NORMAL:
break;
case COLOR_STATE_HIGHLIGHT:
break;
default:
break;
}
}
void
{
}
void
graphics_setcursor(int on)
{
/* FIXME: we don't have a cursor in graphics */
}
/*
* Read in the splashscreen image and set the palette up appropriately.
* Format of splashscreen is an xpm (can be gzipped) with 16 colors and
* 640x480.
*/
static int
read_image(char *s)
{
int fd;
if (fd == -1) {
dprintf("error opening %s\n", s);
return (0);
}
/* read header */
dprintf("read header error\n");
return (0);
}
/* parse info */
if (c == '"')
break;
}
;
i = 0;
width = c - '0';
if (c >= '0' && c <= '9')
else
break;
}
;
height = c - '0';
if (c >= '0' && c <= '9')
else
break;
}
;
colors = c - '0';
if (c >= '0' && c <= '9')
else
break;
}
base = 0;
;
/* palette */
len = 0;
;
base = c;
}
graphics_set_palette(idx, r, g, b);
++idx;
}
}
x = y = len = 0;
for (i = 0; i < 38400; i++)
/* parse xpm data */
while (y < height) {
while (1) {
return (0);
}
if (c == '"')
break;
}
for (i = 1; i < 15; i++)
if (pal[i] == c) {
c = i;
break;
}
if (c & 1)
if (c & 2)
if (c & 4)
if (c & 8)
if (++x >= 640) {
x = 0;
if (y < 480)
len += 80;
++y;
}
}
}
background & 63);
foreground & 63);
border & 63);
return (1);
}
/* Convert a character which is a hex digit to the appropriate integer */
static int
hex(int v)
{
if (v >= 'A' && v <= 'F')
return (v - 'A' + 10);
if (v >= 'a' && v <= 'f')
return (v - 'a' + 10);
return (v - '0');
}
/* move the graphics cursor location to col, row */
static void
{
}
}
}
static void
{
int i;
for (i = 0; i < len; i++)
d[i] = s[i];
}
static int
{
while (n) {
return (-1);
return (1);
s1++;
s2++;
n--;
}
return (0);
}
/* scroll the screen */
static void
{
int i, j;
/* we don't want to scroll recursively... that would be bad */
if (no_scroll)
return;
no_scroll = 1;
/* move everything up a line */
}
}
/* last line should be blank */
graphics_putchar(' ');
no_scroll = 0;
}
void graphics_cursor(int set) {
return;
if (set) {
MapMask(15);
}
return;
}
for (i = 0; i < 16; i++) {
if (!invert) {
offset += 80;
} else {
}
}
offset = 0;
int j;
MapMask(i);
}
MapMask(15);
}