📄 rndr_gu1.c
字号:
/*---------------------------------------------------------------------------
* RNDR_GU1.C
*
* Version 2.1 - March 3, 2000
*
* This file contains routines to program the 2D acceleration hardware for
* the first generation graphics unit (GXLV, SC1200).
*
* gfx_set_bpp
* gfx_set_blt_buffers
* gfx_set_solid_pattern
* gfx_set_mono_pattern
* gfx_set_color_pattern
* gfx_set_solid_source
* gfx_set_mono_source
* gfx_set_raster_operation
* gfx_pattern_fill
* gfx_screen_to_screen_blt
* gfx_screen_to_screen_xblt
* gfx_color_bitmap_to_screen_blt
* gfx_color_bitmap_to_screen_xblt
* gfx_mono_bitmap_to_screen_blt
* gfx_bresenham_line
* gfx_wait_until_idle
*
* History:
* Versions 0.1 through 2.1 by Brian Falardeau.
*
* Copyright (c) 1999-2000 National Semiconductor.
*---------------------------------------------------------------------------
*/
#define DUROPTI 1
#define GFX_WAIT_PENDING while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_PENDING) { INB(0x80); }
#define GFX_WAIT_BUSY while(READ_REG16(GP_BLIT_STATUS) & BS_BLIT_BUSY) { INB(0x80); }
void gu1_detect_blt_buffer_base(void);
/*---------------------------------------------------------------------------
* GFX_SET_BPP
*
* This routine sets the bits per pixel value in the graphics engine.
* It is also stored in a static variable to use in the future calls to
* the rendering routines.
*---------------------------------------------------------------------------
*/
#if GFX_2DACCEL_DYNAMIC
void gu1_set_bpp(unsigned short bpp)
#else
void gfx_set_bpp(unsigned short bpp)
#endif
{
int control = 0;
GFXbpp = bpp;
/* DETECT BASE ADDRESSES FOR BLT BUFFERS */
/* Different for 2K or 3K of scratchpad. Also need to calculate */
/* the number of pixels that can fit in a BLT buffer - need to */
/* subtract 16 for alignment considerations. The 2K case, for */
/* example, is 816 bytes wide, allowing 800 pixels in 8 BPP, which */
/* means rendering operations won't be split for 800x600. */
gu1_detect_blt_buffer_base();
GFXbufferWidthPixels = GFXbb1Base - GFXbb0Base - 16;
if (bpp > 8) GFXbufferWidthPixels >>= 1;
/* SET THE GRAPHICS CONTROLLER BPP AND PITCH */
if (bpp > 8) control = BC_16BPP;
if (gfx_get_display_pitch() > 1024)
control |= BC_FB_WIDTH_2048;
GFX_WAIT_BUSY;
WRITE_REG32(GP_BLIT_STATUS, control);
}
/*
//---------------------------------------------------------------------------
// GFX_SET_BLT_BUFFERS
//
// This routine is used to specifly the BLT buffer parameters to this
// module.
//---------------------------------------------------------------------------
*/
void gfx_set_blt_buffers(unsigned short BB0base, unsigned short BB1base,
unsigned short BBwidthPixels)
{
GFXbb0Base = BB0base;
GFXbb1Base = BB1base;
GFXbufferWidthPixels = BBwidthPixels;
}
void gfx_set_pattern_flags(unsigned short flags)
{
GFXpatternFlags |= flags;
}
/*
//---------------------------------------------------------------------------
// GFX_SET_SOLID_SOURCE
//
// This routine is used to specify a solid source color. For the Xfree96
// display driver, the source color is used to specify a planemask and the
// ROP is adjusted accordingly.
//---------------------------------------------------------------------------
*/
#if GFX_2DACCEL_DYNAMIC
void gu1_set_solid_source(unsigned long color)
#else
void gfx_set_solid_source(unsigned long color)
#endif
{
/* CLEAR TRANSPARENCY FLAG */
GFXsourceFlags = 0;
/* FORMAT 8 BPP COLOR */
/* GX requires 8BPP color data be duplicated into bits [15:8]. */
if (GFXbpp == 8)
{
color &= 0x00FF;
color |= (color << 8);
}
/* POLL UNTIL ABLE TO WRITE THE SOURCE COLOR */
GFX_WAIT_PENDING;
WRITE_REG16(GP_SRC_COLOR_0, (unsigned short) color);
WRITE_REG16(GP_SRC_COLOR_1, (unsigned short) color);
}
/*
//---------------------------------------------------------------------------
// GFX_SET_MONO_SOURCE
//
// This routine is used to specify the monochrome source colors.
// It must be called *after* loading any pattern data (those routines
// clear the source flags).
//---------------------------------------------------------------------------
*/
#if GFX_2DACCEL_DYNAMIC
void gu1_set_mono_source(unsigned long bgcolor, unsigned long fgcolor,
unsigned short transparent)
#else
void gfx_set_mono_source(unsigned long bgcolor, unsigned long fgcolor,
unsigned short transparent)
#endif
{
/* SET TRANSPARENCY FLAG */
GFXsourceFlags = transparent ? RM_SRC_TRANSPARENT : 0;
/* FORMAT 8 BPP COLOR */
/* GX requires 8BPP color data be duplicated into bits [15:8]. */
if (GFXbpp == 8)
{
bgcolor &= 0x00FF;
bgcolor |= (bgcolor << 8);
fgcolor &= 0x00FF;
fgcolor |= (fgcolor << 8);
}
/* POLL UNTIL ABLE TO WRITE THE SOURCE COLOR */
GFX_WAIT_PENDING;
WRITE_REG16(GP_SRC_COLOR_0, (unsigned short) bgcolor);
WRITE_REG16(GP_SRC_COLOR_1, (unsigned short) fgcolor);
}
/*
//---------------------------------------------------------------------------
// GFX_SET_SOLID_PATTERN
//
// This routine is used to specify a solid pattern color. It is called
// before performing solid rectangle fills or more complicated BLTs that
// use a solid pattern color.
//
// The driver should always call "gfx_load_raster_operation" after a call
// to this routine to make sure that the pattern flags are set appropriately.
//---------------------------------------------------------------------------
*/
#if GFX_2DACCEL_DYNAMIC
void gu1_set_solid_pattern(unsigned long color)
#else
void gfx_set_solid_pattern(unsigned long color)
#endif
{
/* CLEAR TRANSPARENCY FLAG */
GFXsourceFlags = 0;
/* SET PATTERN FLAGS */
GFXpatternFlags = 0;
/* FORMAT 8 BPP COLOR */
/* GX requires 8BPP color data be duplicated into bits [15:8]. */
if (GFXbpp == 8)
{
color &= 0x00FF;
color |= (color << 8);
}
/* SAVE THE REFORMATTED COLOR FOR LATER */
/* Used to call the "GFX_solid_fill" routine for special cases. */
GFXsavedColor = color;
/* POLL UNTIL ABLE TO WRITE THE PATTERN COLOR */
GFX_WAIT_PENDING;
WRITE_REG16(GP_PAT_COLOR_0, (unsigned short) color);
}
/*
//---------------------------------------------------------------------------
// GFX_SET_MONO_PATTERN
//
// This routine is used to specify a monochrome pattern.
//---------------------------------------------------------------------------
*/
#if GFX_2DACCEL_DYNAMIC
void gu1_set_mono_pattern(unsigned long bgcolor, unsigned long fgcolor,
unsigned long data0, unsigned long data1, unsigned char transparent)
#else
void gfx_set_mono_pattern(unsigned long bgcolor, unsigned long fgcolor,
unsigned long data0, unsigned long data1, unsigned char transparent)
#endif
{
/* CLEAR TRANSPARENCY FLAG */
GFXsourceFlags = 0;
/* SET PATTERN FLAGS */
GFXpatternFlags = transparent ? RM_PAT_MONO | RM_PAT_TRANSPARENT :
RM_PAT_MONO;
/* FORMAT 8 BPP COLOR */
/* GXm requires 8BPP color data be duplicated into bits [15:8]. */
if (GFXbpp == 8)
{
bgcolor &= 0x00FF;
bgcolor |= (bgcolor << 8);
fgcolor &= 0x00FF;
fgcolor |= (fgcolor << 8);
}
/* POLL UNTIL ABLE TO WRITE THE PATTERN COLORS AND DATA */
GFX_WAIT_PENDING;
WRITE_REG16(GP_PAT_COLOR_0, (unsigned short) bgcolor);
WRITE_REG16(GP_PAT_COLOR_1, (unsigned short) fgcolor);
WRITE_REG32(GP_PAT_DATA_0, data0);
WRITE_REG32(GP_PAT_DATA_1, data1);
}
/*
//---------------------------------------------------------------------------
// GFX_SET_COLOR_PATTERN
//
// This routine is used to specify a color pattern.
//---------------------------------------------------------------------------
*/
#if GFX_2DACCEL_DYNAMIC
void gu1_set_color_pattern(unsigned long bgcolor, unsigned long fgcolor,
unsigned long data0, unsigned long data1,unsigned long data2,unsigned long data3, unsigned char transparent)
#else
void gfx_set_color_pattern(unsigned long bgcolor, unsigned long fgcolor,
unsigned long data0, unsigned long data1, unsigned long data2,unsigned long data3,unsigned char transparent)
#endif
{
/* CLEAR TRANSPARENCY FLAG */
GFXsourceFlags = 0;
/* SET PATTERN FLAGS */
GFXpatternFlags = transparent ? RM_PAT_MONO | RM_PAT_TRANSPARENT :
RM_PAT_MONO;
GFXpatternFlags |= RM_PAT_COLOR;
/* FORMAT 8 BPP COLOR */
/* GXm requires 8BPP color data be duplicated into bits [15:8]. */
if (GFXbpp == 8)
{
bgcolor &= 0x00FF;
bgcolor |= (bgcolor << 8);
fgcolor &= 0x00FF;
fgcolor |= (fgcolor << 8);
}
/* POLL UNTIL ABLE TO WRITE THE PATTERN COLORS AND DATA */
GFX_WAIT_PENDING;
WRITE_REG16(GP_PAT_COLOR_0, (unsigned short) bgcolor);
WRITE_REG16(GP_PAT_COLOR_1, (unsigned short) fgcolor);
WRITE_REG32(GP_PAT_DATA_0, data0);
WRITE_REG32(GP_PAT_DATA_1, data1);
if (GFXbpp > 8)
{
WRITE_REG32(GP_PAT_DATA_2, data2);
WRITE_REG32(GP_PAT_DATA_3, data3);
}
}
/*
//---------------------------------------------------------------------------
// GFX_SET_RASTER_OPERATION
//
// This routine loads the specified raster operation. It sets the pattern
// flags appropriately.
//---------------------------------------------------------------------------
*/
#if GFX_2DACCEL_DYNAMIC
void gu1_set_raster_operation(unsigned char rop)
#else
void gfx_set_raster_operation(unsigned char rop)
#endif
{
unsigned short rop16;
/* GENERATE 16-BIT VERSION OF ROP WITH PATTERN FLAGS */
rop16 = (unsigned short) rop | GFXpatternFlags;
if ((rop & 0x33) ^ ((rop >> 2) & 0x33))
rop16 |= GFXsourceFlags;
/* SAVE ROP FOR LATER COMPARISONS */
/* Need to have the pattern flags included */
GFXsavedRop = rop16;
/* SET FLAG INDICATING ROP REQUIRES DESTINATION DATA */
/* True if even bits (0:2:4:6) do not equal the correspinding */
/* even bits (1:3:5:7). */
GFXusesDstData = ((rop & 0x55) ^ ((rop >> 1) & 0x55));
/* POLL UNTIL ABLE TO WRITE THE PATTERN COLOR */
/* Only one operation can be pending at a time. */
GFX_WAIT_PENDING;
WRITE_REG16(GP_RASTER_MODE, rop16);
}
/*
//---------------------------------------------------------------------------
// GFX_SOLID_FILL
//
// This routine MUST be used when performing a solid rectangle fill with
// the ROPs of PATCOPY (0xF0), BLACKNESS (0x00), WHITENESS (0xFF), or
// PATINVERT (0x0F). There is a bug in GXm for these cases that requires a
// workaround.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -