📄 halgxm.cpp
字号:
/*
* $Workfile: halgxm.cpp $
* $Revision: 6 $
* $Date: 4/07/00 9:12a $
* $Modtime: 4/07/00 8:59a $
* $Author: Sarma $
*
* Copyright (c) 1998 National Semiconductor Corporation.
* All Rights Reserved.
*
* This software is the confidential and proprietary information of National
* Semiconductor Corporation. ("Confidential Information").
* You shall not disclose such Confidential Information and shall use it only
* in accordance with the terms of the license agreement you entered into
* with National Semiconductor Corporation.
* This code is supplied as is.
*
*/
/*
*$Log: /CE/Platform/Nsc/Drivers/Video/gxvideo/ddraw/halgxm.cpp $
*
* 6 4/07/00 9:12a Sarma
* Removed Cyrix Corporation from the legal/confidentail information. Also
* added for files not containing this info.
*
*$History: halgxm.cpp $
*
* ***************** Version 6 *****************
* User: Sarma Date: 4/07/00 Time: 9:12a
* Updated in $/CE/Platform/Nsc/Drivers/Video/gxvideo/ddraw
* Removed Cyrix Corporation from the legal/confidentail information. Also
* added for files not containing this info.
*
*/
#include "precomp.h"
#ifdef DURANGO
#include "gfx_rtns.h" //Durango includes
#endif
#ifdef DD_SUPPORT
#include "gpevga.h"
/* this structure will be initialized by buildHalInfo */
extern DDRAWDATA *pDriverData;
extern OVERLAYDATA OverlayData;
WORD GetScanline() {
// DEBUGENTER( GetScanline );
// BYTE lo=0xFF;
// WORD hi=0;
//
// while (lo==0xFF) {
// lo = reg_CURRENT_VLINE_LO;
// }
// hi = reg_CURRENT_VLINE_HI;
// hi = (hi<<8)+lo;
// return (hi&0x7FF);
//
WORD count1, count2;
do {
count1 = READ_REG16(pDriverData->RegLinear, DC_V_LINE_CNT) & 0x3FF;
count2 = READ_REG16(pDriverData->RegLinear, DC_V_LINE_CNT) & 0x3FF;
}
while(count1 != count2);
return(count2);
}
/****
NAME: InVBlank
RETURN VALUE
TRUE if in vertical blank period, else FALSE.
****/
BOOL InVBlank(void)
{
//DEBUGENTER( InVBlank );
if (MEM_READ_32(pDriverData->RegLinear, DC_TIMING_CFG) & DC_TCFG_VNA) {
//DEBUGMSG(1,(TEXT("returned true\r\n")));
return(TRUE);
} else {
//DEBUGMSG(1,(TEXT("returned false\r\n")));
return(FALSE);
}
}
/****
NAME: DrawEngineBusy
RETURN VALUE
TRUE if draw engine busy, else FALSE.
****/
BOOL DrawEngineBusy(void)
{
// DEBUGENTER( DrawEngineBusy );
if (MEM_READ_16(pDriverData->RegLinear, GP_BLIT_STATUS) & BS_BLIT_BUSY)
return(TRUE);
else
return(FALSE);
}
/****
NAME: CommandBufferEmpty
RETURN VALUE
TRUE if command buffer is empty, else FALSE.
****/
BOOL CommandBufferEmpty(void)
{
// DEBUGENTER( CommandBufferEmpty );
if (MEM_READ_16(pDriverData->RegLinear, GP_BLIT_STATUS) & BS_BLIT_PENDING)
return(FALSE);
else
return(TRUE);
}
/****
NAME: SetVideoOffset
DESCRIPTION
Set the offset into the framebuffer where GXi is to fetch video data from
RETURN VALUE
TRUE if successful, else FALSE.
****/
BOOL SetVideoOffset(DWORD Offset)
{
// DEBUGENTER( SetVideoOffset );
DWORD YSteps;
DWORD CfgData;
// DWORD VPStatus;
pDriverData->Video.Offset = Offset;
if (OverlayData.VidFormat == EMMA)
return (TRUE);
if(pDriverData->wPanY > pDriverData->Video.YPos)
{
YSteps = ((pDriverData->wPanY - pDriverData->Video.YPos) * pDriverData->Video.YScale) / 0x1FFF;
Offset += pDriverData->Video.Pitch * YSteps;
}
// This is done to fix a bug when we are using videoport. If videoport is active, then
// then we add pitch * steps to the offset. This is to get rid of
/* if (OverlayData.VidFormat != EMMA ) {
VPStatus = MEM_READ_32(pDriverData->VIPLinear, 0x00000008);
VPStatus &= 0x00000001;
if(VPStatus == 1 ) {
// 30 is for the first 30 lines of video data.
Offset += 30 * pDriverData->Video.Pitch;
}
}
*/
#ifdef DURANGO
gfx_set_video_offset(Offset);
#else
MEM_WRITE_32(pDriverData->RegLinear, DC_UNLOCK, 0x4758);
MEM_WRITE_32(pDriverData->RegLinear, DC_VID_ST_OFFSET, Offset);
MEM_WRITE_32(pDriverData->RegLinear, DC_UNLOCK, 0x0);
#endif
// RESET 5530 CRC VALUE TO INDICATE FLIP STATUS LATER
//if(pDriverData->SysInfo1.CoreLogic >= SYSINFO1_CORE_5530)
//{
CfgData = MEM_READ_32(pDriverData->RegLinear, VC_CRCSIG_TFT_TV);
CfgData &= ~0x1;
MEM_WRITE_32(pDriverData->RegLinear, VC_CRCSIG_TFT_TV, CfgData);
// jp 5 enables subpicture u need to disable subpicture.
// right here we are enabling subpicture and graphics and video bypass gamma correction RAM
// subpicture is later disabled.
CfgData |= 0x5;
// this was added because when u moved the window sometime the window would get corrupted.
// Changing this fixes the corruption.
MEM_WRITE_32(pDriverData->RegLinear, VC_CRCSIG_TFT_TV, CfgData);
CfgData &= ~0x4;
// right here we are disabling subpicture
MEM_WRITE_32(pDriverData->RegLinear, VC_CRCSIG_TFT_TV, CfgData);
//}
return(TRUE);
}
/****
NAME: FlipDisplay
PARAMETERS
Offset
Offset in bytes to start address of screen.
RETURN VALUE
DD_OK
****/
BOOL FlipDisplay(DWORD Offset)
{
// DEBUGENTER( FlipDisplay );
//DWORD ScreenOffset;
DWORD lock;
DWORD CfgData;
//if(pDriverData->SysInfo1.CoreLogic >= SYSINFO1_CORE_5530)
//{
lock = MEM_READ_32(pDriverData->RegLinear, DC_UNLOCK);
MEM_WRITE_32(pDriverData->RegLinear, DC_UNLOCK, DC_UNLOCK_VALUE);
CfgData = MEM_READ_32(pDriverData->RegLinear, DC_GENERAL_CFG);
CfgData &= ~DC_GCFG_CMPE;
CfgData &= ~DC_GCFG_DECE;
MEM_WRITE_32(pDriverData->RegLinear, DC_GENERAL_CFG, CfgData);
MEM_WRITE_32(pDriverData->RegLinear, DC_FB_ST_OFFSET, Offset);
MEM_WRITE_32(pDriverData->RegLinear, DC_UNLOCK, lock);
CfgData = MEM_READ_32(pDriverData->RegLinear, VC_CRCSIG_TFT_TV);
CfgData &= ~0x1;
MEM_WRITE_32(pDriverData->RegLinear, VC_CRCSIG_TFT_TV, CfgData);
CfgData |= 0x5;
MEM_WRITE_32(pDriverData->RegLinear, VC_CRCSIG_TFT_TV, CfgData);
//}
//else
//{
// // Bytes to Dwords
// ScreenOffset = Offset >> 2;
//
// IO_WRITE_16(CRTC_INDEX, (WORD)0x57 << 8 | SOFTVGA_EXT_REG_LOCK);
// IO_WRITE_16(CRTC_INDEX, (WORD)0x4C << 8 | SOFTVGA_EXT_REG_LOCK);
// IO_WRITE_16(CRTC_INDEX, (WORD)0x80 << 8 | EXTENDED_START_ADDRESS);
// IO_WRITE_16(CRTC_INDEX, (WORD)(ScreenOffset) << 8 | CRTC_START_ADDR_LOW);
// IO_WRITE_16(CRTC_INDEX, (WORD)(ScreenOffset >> 8) << 8 | CRTC_START_ADDR_HIGH);
// IO_WRITE_16(CRTC_INDEX, (WORD)((ScreenOffset >> 16) & 0x1f) << 8 | EXTENDED_START_ADDRESS);
// IO_WRITE_16(CRTC_INDEX, (WORD)0x00 << 8 | SOFTVGA_EXT_REG_LOCK);
//}
return DD_OK;
}
/****
NAME: SetChromaKey
DESCRIPTION
Loads the chroma key color into COGNAC
Key should be in Bpp specified
If Key and Bpp are 0 then don't
chroma key (video always shown)
RETURN VALUE
TRUE if successful, else FALSE.
****/
BOOL SetChromaKey(DWORD Key, DWORD Bpp)
{
// DEBUGENTER( SetChromaKey );
DWORD R,G,B;
DWORD data18;
if((Key == 0) && (Bpp == 0))
{
#ifdef DURANGO
RETAILMSG( 0, ( TEXT("Durango Set_Color_Key 0\n") ) );
gfx_set_video_color_key(0,0,0);
#else
MEM_WRITE_32(pDriverData->RegLinear, VC_COLOR_KEY, 0);
MEM_WRITE_32(pDriverData->RegLinear, VC_COLOR_MASK, 0);
#endif
}
else
{
if(Bpp == 16)
{
B = (Key & 0x1f) << 3;
G = ((Key >> 5) & 0x3f) << 2;
R = ((Key >> 11) & 0x1f) << 3;
}
else // 8bpp indexed
{
// Read Internal Palette
MEM_WRITE_32(pDriverData->RegLinear, DC_PAL_ADDRESS, Key);
data18 = MEM_READ_32(pDriverData->RegLinear, DC_PAL_DATA);
R = (data18 >> 12) & 0x3F;
G = (data18 >> 6) & 0x3F;
B = data18 & 0x3F;
R = (R & 0x3F) << 2;
G = (G & 0x3F) << 2;
B = (B & 0x3F) << 2;
}
#ifdef DURANGO
RETAILMSG( 0, ( TEXT("Durango Set_Color_Key 1\n") ) );
gfx_set_video_color_key( (B | (G << 8) | (R << 16)), 0x00FCFCFC,0);
#else
MEM_WRITE_32(pDriverData->RegLinear, VC_COLOR_KEY, (B | (G << 8) | (R << 16)));
MEM_WRITE_32(pDriverData->RegLinear, VC_COLOR_MASK, 0x00FCFCFC);
#endif
}
return(TRUE);
}
/********************************************************************
* BytesToPixels
*
*/
void BytesToPixels(DWORD Bpp, LONG Pitch, DWORD Offset, DWORD *OffsetX, DWORD *OffsetY)
{
// DEBUGENTER( BytesToPixels );
*OffsetX = (Offset & (Pitch - 1)) / (Bpp >> 3);
*OffsetY = Offset / Pitch;
}
/****
NAME: ScrToScrBlt
DESCRIPTION
Screen to screen bitblt.
RETURN VALUE
TRUE if successful, else FALSE.
****/
BOOL ScrToScrBlt(DWORD SrcX, DWORD SrcY, DWORD DstX, DWORD DstY, DWORD Width, DWORD Height)
{
// DEBUGENTER( ScrToScrBlt );
WORD BlitMode = BM_WRITE_FB | BM_READ_SRC_FB;
BOOL ReverseX = FALSE;
DWORD PixelsRemain;
// Check for Y reverse direction.
if (SrcY < DstY)
{
SrcY += Height - 1;
DstY += Height - 1;
BlitMode |= BM_REVERSE_Y;
}
// Check to see if enough room in blt buffer for each scan line.
if (Width <= pDriverData->MaxBufferPixels)
{
// There's enough room in the blt buffer so do
// the blt in one shot.
// SET BUSY FLAG
// This is used to prevent save to disk from happening during GP setup.
MEM_WRITE_8(pDriverData->RegLinear, SPAD_BUSY_FLAG, 1);
// Load GX command registers.
WAIT_PENDING(pDriverData->RegLinear);
MEM_WRITE_32(pDriverData->RegLinear, GP_SRC_XCOOR, (SrcY << 16) | SrcX);
MEM_WRITE_32(pDriverData->RegLinear, GP_DST_XCOOR, (DstY << 16) | DstX);
MEM_WRITE_32(pDriverData->RegLinear, GP_WIDTH, (Height << 16) | Width);
MEM_WRITE_16(pDriverData->RegLinear, GP_RASTER_MODE, GX_SRCCOPY);
// Do the blt.
MEM_WRITE_16(pDriverData->RegLinear, GP_BLIT_MODE, BlitMode);
}
else
{
// There's not enough room in the blt buffer so do
// the blt one line at a time.
// Check for X reverse direction.
if (SrcX < DstX)
{
SrcX += Width;
DstX += Width;
ReverseX = TRUE;
}
// SET BUSY FLAG
// This is used to prevent save to disk from happening during GP setup.
MEM_WRITE_8(pDriverData->RegLinear, SPAD_BUSY_FLAG, 1);
// Blt MaxBufferPixels at a time.
PixelsRemain = Width;
do {
Width = PixelsRemain;
if (Width > (DWORD)pDriverData->MaxBufferPixels)
{
Width = pDriverData->MaxBufferPixels;
}
PixelsRemain -= Width;
// Adjust for X reverse direction.
if (ReverseX)
{
SrcX -= Width;
DstX -= Width;
}
// Load GX command registers
WAIT_PENDING(pDriverData->RegLinear);
MEM_WRITE_32(pDriverData->RegLinear, GP_SRC_XCOOR, (SrcY << 16) | SrcX);
MEM_WRITE_32(pDriverData->RegLinear, GP_DST_XCOOR, (DstY << 16) | DstX);
MEM_WRITE_32(pDriverData->RegLinear, GP_WIDTH, (Height << 16) | Width);
MEM_WRITE_16(pDriverData->RegLinear, GP_RASTER_MODE, GX_SRCCOPY);
// Do the blt.
MEM_WRITE_16(pDriverData->RegLinear, GP_BLIT_MODE, BlitMode);
// Adjust for NOT X reverse direction.
if (!ReverseX)
{
SrcX += Width;
DstX += Width;
}
} while (PixelsRemain > 0);
}
MEM_WRITE_8(pDriverData->RegLinear, SPAD_BUSY_FLAG, 0);
return(TRUE);
}
/****
NAME: ScrToScrXBlt
DESCRIPTION
Screen to screen transparent bitblt. Every occurence of ColorKey in the source data
will result in the destination data remaining unchanged (eg. transparent source).
RETURN VALUE
TRUE if successful, else FALSE.
****/
BOOL ScrToScrXBlt(DWORD SrcX, DWORD SrcY, DWORD DstX, DWORD DstY,
DWORD Width, DWORD Height, DWORD ColorKey)
{
// DEBUGENTER( ScrToScrXBlt );
WORD BlitMode = BM_WRITE_FB | BM_READ_SRC_FB | BM_READ_DST_BB1;
BOOL ReverseX = FALSE;
DWORD PixelsRemain;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -