📄 surf.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Module Name: surface allocation/manipulation/free routines
Abstract:
Functions:
Notes:
--*/
#include "precomp.h"
#include "XSLGPE.h"
static unsigned short bar[8] = {
0x7bef, 0x001f, 0x07e0, 0x7ff, 0xf800, 0xf81f, 0xffe0, 0xffff
};
void CleanFrameBuffer(PVOID buffer, unsigned sx, unsigned sy, unsigned bpp)
{
unsigned j;
/*
unsigned i, m;
unsigned k = sx>>3; // 8 bars
if (bpp==16) {
unsigned short *p2;
p2 = (unsigned short*)buffer;
for (j=0; j<sy; j++) {
for (i=0; i<8; i++) {
for (m=0; m<k; m++) *p2++ = bar[i];
}
for (i=8*k; i<sx; i++) *p2++ = bar[7];
}
}
else
if (bpp==8) {
PBYTE p2;
p2 = (PBYTE)buffer;
for (j=0; j<sy; j++) {
for (i=0; i<8; i++) {
for (m=0; m<k; m++) *p2++ = i+7;
}
for (i=8*k; i<sx; i++) *p2++ = 15;
}
}
else {
PBYTE p1;
p1 = (PBYTE)buffer;
for (i=0; i<sx*sy*2; i++) *p1++ = 0;
}
*/
//@#$ clear the right most data to zero
// default for bpp==16
sx = sx*sy >>1;
if (bpp==8) sx =sx>>1;
DWORD *p2 = (DWORD*)buffer;
for (j=0; j<sx; j++) {
*p2++=0;
}
}
SCODE
XSLGPE::AllocSurface(GPESurf **ppSurf, int width, int height, EGPEFormat format, int surfaceFlags)
{
#ifdef DD_ENABLE
DEBUGMSG (GPE_ZONE_INIT, (L"AllocSurface without pixelFormat\n"));
return AllocSurface ((DDGPESurf**)ppSurf,
width,
height,
format,
EGPEFormatToEDDGPEPixelFormat[format],
surfaceFlags);
}
SCODE
XSLGPE::AllocSurface(DDGPESurf **ppSurf, int width, int height, EGPEFormat format, EDDGPEPixelFormat pixelFormat, int surfaceFlags)
{
#endif // DD_ENABLE
if ((surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY) || (format == m_pMode->format) && (surfaceFlags & GPE_PREFER_VIDEO_MEMORY))
{
if (!(format == m_pMode->format))
{
RETAILMSG (1, (L"AllocSurface - Invalid format value\n"));
return E_INVALIDARG;
}
// Attempt to allocate from video memory
Node2D *pNode = m_p2DVideoMemory->Alloc(width, height);
if (pNode)
{
ULONG offset = (m_cbScanLineLength * pNode->Top()) + ((pNode->Left() * EGPEFormatToBpp[format]) / 8);
#ifdef DD_ENABLE
*ppSurf = new XSLGPESurf(width, height, offset, (PVOID)(m_VirtualFrameBuffer + offset), m_cbScanLineLength, format, pixelFormat, pNode);
#else // DD_ENABLE
*ppSurf = new XSLGPESurf(width, height, offset, (PVOID)(m_VirtualFrameBuffer + offset), m_cbScanLineLength, format, pNode);
#endif // DD_ENABLE
if (!(*ppSurf))
{
pNode->Free();
RETAILMSG (1, (L"AllocSurface - Out of Memory 1\n"));
return E_OUTOFMEMORY;
}
return S_OK;
}
if (surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY)
{
#ifdef DD_ENABLE
*ppSurf = (DDGPESurf *)NULL;
#else // DD_ENABLE
*ppSurf = (GPESurf *)NULL;
#endif // DD_ENABLE
RETAILMSG (1, (L"AllocSurface - Out of Memory 2\n"));
return E_OUTOFMEMORY;
}
}
if (surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY)
{
#ifdef DD_ENABLE
*ppSurf = (DDGPESurf *)NULL;
#else // DD_ENABLE
*ppSurf = (GPESurf *)NULL;
#endif // DD_ENABLE
RETAILMSG (1, (L"AllocSurface - Out of Memory 3\n"));
return E_OUTOFMEMORY;
}
// Allocate from system memory
RETAILMSG(0, (TEXT("Creating a GPESurf in system memory. EGPEFormat = %d\r\n"), (int) format));
#ifdef DD_ENABLE
{
/* //@@##$$ Old emulator allocating
DWORD bpp = EGPEFormatToBpp[format];
LONG align = 8; // quadword aligned
DWORD alignedWidth = ((width + align - 1) & (- align));
DWORD nSurfaceBytes = (bpp * (alignedWidth * height)) / 8;
DWORD stride = ((alignedWidth * bpp) / 8);
*ppSurf = new DDGPESurf(width, height, stride, format, pixelFormat);
*/
//@@##$$ Method used by VGAFlat & SA2Video
DWORD bpp = EGPEFormatToBpp[format];
DWORD stride = ((bpp * width + 31) >> 5) << 2;
DWORD nSurfaceBytes = stride * height;
*ppSurf = new DDGPESurf(width, height, stride, format, pixelFormat);
//----
}
#else // DD_ENABLE
*ppSurf = new GPESurf(width, height, format);
#endif // DD_ENABLE
if (*ppSurf != NULL)
{
// check we allocated bits succesfully
if (((*ppSurf)->Buffer()) == NULL)
{
delete *ppSurf;
}
else
{
return S_OK;
}
}
RETAILMSG (1, (L"AllocSurface - Out of Memory 4\n"));
return E_OUTOFMEMORY;
}
#ifdef DD_ENABLE
void
XSLGPE::SetVisibleSurface( GPESurf *pTempSurf, BOOL bWaitForVBlank)
{
XSLGPESurf *pSurf = (XSLGPESurf *) pTempSurf;
// if(bWaitForVBlank)
// {
// WAIT_FOR_VBLANK;
// }
// // set CRT memory offset without changing CRT pitch
// _memwD_reg(CRTC_OFF_PITCH, (_memrD_reg(CRTC_OFF_PITCH) & 0xffc00000) | ((pSurf->Stride() * pSurf->Top()) >> 3));
}
#endif // DD_ENABLE
XSLGPESurf::XSLGPESurf(int width, int height, ULONG offset, PVOID pBits, int stride, EGPEFormat format, Node2D *pNode)
#ifdef DD_ENABLE
: DDGPESurf (width, height, pBits, stride, format)
#else // DD_ENABLE
: GPESurf(width, height, pBits, stride, format)
#endif // DD_ENABLE
{
m_pNode2D = pNode;
m_fInVideoMemory = FALSE;
m_nOffsetInVideoMemory = offset;
}
#ifdef DD_ENABLE
XSLGPESurf::XSLGPESurf(int width, int height, ULONG offset, PVOID pBits, int stride, EGPEFormat format, EDDGPEPixelFormat pixelFormat, Node2D *pNode)
: DDGPESurf (width, height, pBits, stride, format, pixelFormat)
{
m_pNode2D = pNode;
m_fInVideoMemory = FALSE;
m_nOffsetInVideoMemory = offset;
}
#endif
XSLGPESurf::~XSLGPESurf(void)
{
m_pNode2D->Free();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -