📄 screen.c
字号:
/******************************************************************************
**
** COPYRIGHT (C) 2000, 2001 Intel Corporation.
**
** This software as well as the software described in it is furnished under
** license and may only be used or copied in accordance with the terms of the
** license. The information in this file is furnished for informational use
** only, is subject to change without notice, and should not be construed as
** a commitment by Intel Corporation. Intel Corporation assumes no
** responsibility or liability for any errors or inaccuracies that may appear
** in this document or any software that may be provided in association with
** this document.
** Except as permitted by such license, no part of this document may be
** reproduced, stored in a retrieval system, or transmitted in any form or by
** any means without the express written consent of Intel Corporation.
**
** FILENAME: screen.c
**
** PURPOSE: API functions to support the Screen
**
** LAST MODIFIED: 01/12/2001
******************************************************************************/
/*
*******************************************************************************
* HEADER FILES
*******************************************************************************
*/
#include "systypes.h"
#include <string.h>
#include <stdlib.h>
#include "dm_struct.h"
#include "vgafont.h"
#include "xslcdcontroller.h"
#include "lubbockControl.h"
#include "cotulla.h"
#define SCREEN_GLOBALS 1
#include "screen.h"
//#include "assabetControl.h"
#include "dm.h"
/*
*******************************************************************************
* GLOBAL DEFINITIONS
*******************************************************************************
*/
/*
*******************************************************************************
* LOCAL DEFINITIONS
*******************************************************************************
*/
/*----------------------------------------------------------------------
* Current screen geometry and offsets in the frame buffer
*/
static int horizPixel;
static int vertPixel;
static int maxCharCol;
static int maxCharRow;
static int horizOffset;
static int vertOffset;
static int fieldOffset;
static int colorDepth;
// temp
// PVINT16 miscWrP = (PVINT16)0x08000080;
/*----------------------------------------------------------------------
* Our frame buffer (actually borrowed from the LCD driver)
*/
static DM_FrameBuffer_T* fbP;
/*----------------------------------------------------------------------
* Set a pixel in the frame buffer
*/
typedef void (*Screen_SetPixel_T)(int x, int y, unsigned fg, int w, void * p);
/*----------------------------------------------------------------------
* Write a character to the frame buffer (interlaced display)
*/
static
void drawCharX(char c, int row, int col,
unsigned fgColor, unsigned bgColor,
Screen_SetPixel_T setPixel)
{
unsigned char *font;
int r,i;
int x, y;
/* Get X/Y of upper left corner of cell
*/
x = col * (FONT_HORZ_PIX+1);
y = row * (FONT_VERT_PIX-2);
/* Get pointer to character generator
*/
font = &font9x16[((c&0xff)<<4)+2]; // skip first two blank lines in font
/* Scan the character and render
*/
for (r=0; r < FONT_VERT_PIX-2; r++) {
unsigned int f = *font++;
int ix = x;
/* Note this loop is hardcoded to a character width of 9 pixels
*/
setPixel(ix++,y+r,bgColor,1,fbP->pixelP);
for (i=7; i >= 0; i--)
setPixel(ix++,y+r,f&(1<<i)?fgColor:bgColor,1,fbP->pixelP);
}
}
/*----------------------------------------------------------------------
* Scroll rows in a region (interlaced)
*/
static
void scrollRowsInterleave(int nStartRow, int nEndRow, int nRows,
unsigned bg)
{
#ifdef DIVX
unsigned short * startPix = fbP->pixelP +
nStartRow*(FONT_VERT_PIX/2-2)*horizPixel;
unsigned short * copyPix = startPix +
nRows*(FONT_VERT_PIX/2-2)*horizPixel;
unsigned short * fillPix = startPix +
(maxCharRow-nRows)*(FONT_VERT_PIX/2-2)*horizPixel;
#else
unsigned short * startPix = fbP->pixelP +
nStartRow*(FONT_VERT_PIX-2)/2*horizPixel;
unsigned short * copyPix = startPix +
nRows*(FONT_VERT_PIX-2)/2*horizPixel;
unsigned short * fillPix = startPix +
(maxCharRow-nRows)*(FONT_VERT_PIX-2)/2*horizPixel;
#endif
int i;
if ((nRows < 0) || (nRows > maxCharRow))
return;
/* Check to see if were scrolling before init */
if (fbP == NULL)
return;
/* Copy from the first character of the new top line to the top of
* the screen buffer.
*/
memcpy(startPix,
copyPix,
#ifdef DIVX
((nEndRow+1)-nRows-nStartRow)*(FONT_VERT_PIX/2-2)*horizPixel*2);
#else
((nEndRow+1)-nRows-nStartRow)*(FONT_VERT_PIX-2)/2*horizPixel*2);
#endif
/* Fill the new region with background color
*/
#ifdef DIVX
for(i=0; i < (FONT_VERT_PIX/2-2)*horizPixel*nRows;) {
#else
for(i=0; i < ((FONT_VERT_PIX-2)/2)*horizPixel*nRows;) {
#endif
fillPix[i++] = bg >> 16;
fillPix[i++] = bg & 0xffff;
}
/* Point to the second field and copy it also
*/
startPix += fieldOffset;
copyPix += fieldOffset;
fillPix += fieldOffset;
memcpy(startPix,
copyPix,
#ifdef DIVX
((nEndRow+1)-nRows-nStartRow)*(FONT_VERT_PIX/2-2)*horizPixel*2);
#else
((nEndRow+1)-nRows-nStartRow)*(FONT_VERT_PIX-2)/2*horizPixel*2);
#endif
/* Fill the cleared region with background color
*/
#ifdef DIVX
for(i=0; i < (FONT_VERT_PIX/2-2)*horizPixel*nRows;) {
#else
for(i=0; i < ((FONT_VERT_PIX-2)/2)*horizPixel*nRows;) {
#endif
fillPix[i++] = bg >> 16;
fillPix[i++] = bg & 0xffff;
}
}
/*----------------------------------------------------------------------
* Scroll rows in a region (non interlaced, 16 bit)
*/
static
void scrollRowsNonInterleave(int nStartRow, int nEndRow, int nRows,
unsigned bg)
{
unsigned short * startPix = fbP->pixelP +
nStartRow * (FONT_VERT_PIX-2)*horizPixel;
unsigned short * copyPix = startPix +
nRows*(FONT_VERT_PIX-2)*horizPixel;
unsigned short * fillPix = startPix +
(maxCharRow-nRows)*(FONT_VERT_PIX-2)*horizPixel;
int i;
if ((nRows < 0) || (nRows+nStartRow > maxCharRow))
return;
/* Check to see if were scrolling before init */
if (fbP == NULL)
return;
/* Copy from the first character of the new top line to the top of
* the screen buffer. The data is 16 bit.
*/
for(i=0; i < ((nEndRow+1)-nRows-nStartRow)*(FONT_VERT_PIX-2)*horizPixel; i++)
startPix[i] = copyPix[i];
/* Fill the new region with background color
*/
for(i=0; i < (FONT_VERT_PIX-2)*nRows*horizPixel; ) {
fillPix[i++] = bg >> 16;
fillPix[i++] = bg & 0xffff;
}
}
/*----------------------------------------------------------------------
* Scroll rows in a region (non interlaced, 8 bit)
*/
static
void scrollRowsNonInterleave8(int nStartRow, int nEndRow, int nRows,
unsigned bg)
{
unsigned char * startPix = (unsigned char*)fbP->pixelP +
nStartRow * (FONT_VERT_PIX-2)*horizPixel;
unsigned char * copyPix = startPix +
nRows*(FONT_VERT_PIX-2)*horizPixel;
unsigned char * fillPix = startPix +
(maxCharRow-nRows)*(FONT_VERT_PIX-2)*horizPixel;
int i;
if ((nRows < 0) || (nRows+nStartRow > maxCharRow))
return;
/* Check to see if were scrolling before init */
if (fbP == NULL)
return;
/* Copy from the first character of the new top line to the top of
* the screen buffer. The data is 16 bit.
*/
for(i=0; i < ((nEndRow+1)-nRows-nStartRow)*(FONT_VERT_PIX-2)*horizPixel; i++)
startPix[i] = copyPix[i];
/* Fill the new region with background color
*/
for(i=0; i < (FONT_VERT_PIX-2)*nRows*horizPixel; ) {
fillPix[i++] = bg;
}
}
/*----------------------------------------------------------------------
* Draw a line on an arbitrary pixel plane
* Midpoint algorithm, Pitteway/VanAken
* Computer Graphics Principles and Practice
*/
void drawLineX(int from_x, int from_y,
int to_x, int to_y,
unsigned fg,
int width,
Screen_SetPixel_T setPixel)
{
unsigned short * pixelP = fbP->pixelP;
int dx = to_x - from_x;
int dy = to_y - from_y;
int abs_dx = dx;
int abs_dy = dy;
int x, y, d, end_x, rev, tmp;
int incrE, incrNE;
int xDelta, yDelta;
if (dy < 0)
abs_dy = -dy;
if (dx < 0)
abs_dx = -dx;
switch (((dy < 0) << 2) | ((dx < 0) << 1) | ((abs_dy > abs_dx) << 0)) {
case 0: /* First quadrant, no reflection, no rotation */
x = from_x; end_x = to_x;
y = from_y;
xDelta = 1; yDelta = 1;
rev = 0;
break;
case 1: /* First quadrant, no reflection, x/y rotation */
x = from_y; end_x = to_y;
y = from_x;
tmp = dy; dy = dx; dx = tmp;
xDelta = 1; yDelta = 1;
rev = 1;
break;
case 2: /* Second quadrant, x reflection, no rotation */
x = from_x; end_x = to_x;
y = from_y;
dx = -dx;
xDelta = -1; yDelta = 1;
rev = 0;
break;
case 3: /* Second quadrant, x reflection, x/y rotation */
x = from_y; end_x = to_y;
y = from_x;
tmp = dy; dy = -dx; dx = tmp;
xDelta = 1; yDelta = -1;
rev = 1;
break;
case 4: /* Mirror of case 2 */
x = from_x; end_x = to_x;
y = from_y;
dy = -dy;
xDelta = 1; yDelta = -1;
rev = 0;
break;
case 5: /* Mirror of case 3 */
x = from_y; end_x = to_y;
y = from_x;
tmp = -dy; dy = dx; dx = tmp;
xDelta = -1; yDelta = 1;
rev = 1;
break;
case 6: /* Mirror of case 0 */
x = from_x; end_x = to_x;
y = from_y;
dx = -dx;
dy = -dy;
xDelta = -1; yDelta = -1;
rev = 0;
break;
case 7: /* Mirror of case 1 */
x = from_y; end_x = to_y;
y = from_x;
tmp = -dy; dy = -dx; dx = tmp;
xDelta = -1; yDelta = -1;
rev = 1;
break;
}
d = 2 * dy - dx;
incrE = 2 * dy;
incrNE = 2 * (dy-dx);
if (rev)
setPixel(y,x,fg,width,pixelP);
else
setPixel(x,y,fg,width,pixelP);
while (x != end_x) {
if (d <= 0) {
d += incrE;
x += xDelta;
}
else {
d += incrNE;
x += xDelta;
y += yDelta;
}
if (rev)
setPixel(y,x,fg,width,pixelP);
else
setPixel(x,y,fg,width,pixelP);
}
}
/*----------------------------------------------------------------------
* Fill a rectangle, brute force
*/
void fillRectX(int x1, int y1,
int x2, int y2,
unsigned fg,
Screen_SetPixel_T setPixel)
{
int start_x, end_x, start_y, end_y;
int i, j;
if (x1 < x2) {
start_x = x1;
end_x = x2;
}
else {
start_x = x2;
end_x = x1;
}
if (y1 < y2) {
start_y = y1;
end_y = y2;
}
else {
start_y = y2;
end_y = y1;
}
for (i=start_x; i < end_x; i++)
for (j=start_y; j < end_y; j++)
setPixel(i,j,fg,1,fbP->pixelP);
}
/*----------------------------------------------------------------------
* Clear lines on the screen
*/
static
void clearLinesX(int start,
int num,
unsigned clearChar,
Screen_SetPixel_T setPixel)
{
int x, y;
for (x=horizPixel - 1; x >= 0; x--)
for(y=start+num -1; y >= start; y--)
setPixel(x,y,clearChar,1,fbP->pixelP);
}
/*----------------------------------------------------------------------
* Clear rows in a region
*/
static
void clearRowsX(int start,
int num,
unsigned clearChar,
Screen_SetPixel_T setPixel)
{
int x, y;
for (x=0; x < horizPixel; x++)
{
for(y=start*(FONT_VERT_PIX-2); y < (start+num) * (FONT_VERT_PIX-2); y++)
{
setPixel(x,y,clearChar,1,fbP->pixelP);
}
}
/* If the screen is not an even multiple of the font height clear the extra
* lines at the end of the display.
*/
if ((start+num == maxCharRow) &&
(maxCharRow*(FONT_VERT_PIX-2) != vertPixel))
{
y = maxCharRow*(FONT_VERT_PIX-2);
clearLinesX(y, vertPixel-y, clearChar, setPixel);
}
}
/*----------------------------------------------------------------------
* 16 bit interlaced pixel pen function, just use simple rectangle pen
* and brute force it.
*/
static
void setPixelTV(int x, int y, unsigned color, int width, void * p)
{
short * f1PixelP = (short*)p;
short * f2PixelP = (short*)p + fieldOffset;
int i, j;
if (width == 0)
width = 1;
for (i=0; i < width; i++) {
for (j=0; j < width; j++) {
if (((y+j) & 1) == 0)
f2PixelP[(y+j)/2*horizPixel+(x+i)] = color;
else
f1PixelP[(y+j)/2*horizPixel+(x+i)] = color;
}
}
}
/*----------------------------------------------------------------------
* 16 bit pixel pen function, just use simple rectangle pen and brute
* force it.
*/
static
void setPixel16(int x, int y, unsigned color, int width, void * p)
{
int i, j;
short * pixelP = (short*)p;
if (width == 0) width = 1;
for (i=0; i < width; i++)
{
for (j=0; j < width; j++)
{
pixelP[(y+j)*horizPixel+(x+i)] = color;
}
}
}
/*----------------------------------------------------------------------
* 8 bit pixel pen function, just use simple rectangle pen and brute
* force it.
*/
static
void setPixel8(int x, int y, unsigned color, int width, void * p)
{
char * pixelP = (char*)p;
int i, j;
if (width == 0)
width = 1;
for (i=0; i < width; i++)
for (j=0; j < width; j++)
pixelP[(y+j)*horizPixel+(x+i)] = color;
}
#if 0
/*----------------------------------------------------------------------
* Test color bars
*/
static
void colorBars(void * arg)
{
int i, j, k;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -