⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vesa.cpp

📁 在DOS利用Watcom c++的保护模式4G内存
💻 CPP
📖 第 1 页 / 共 2 页
字号:
* Function:     VBE_detect
* Parameters:   vgaInfo - Place to store the VGA information block
* Returns:      VBE version number, or 0 if not detected.
* Description:  Detects if a VESA VBE is out there and functioning
*               correctly. If we detect a VBE interface we return the
*               VGAInfoBlock returned by the VBE and the VBE version number.
****************************************************************************/
{
    RMREGS      regs;
    short       *p1,*p2;
    VBE_vgaInfo vgaInfo;
    /* Put 'VBE2' into the signature area so that the VBE 2.0 BIOS knows
     * that we have passed a 512 byte extended block to it, and wish
     * the extended information to be filled in.
     */
    strncpy(vgaInfo.VESASignature,"VBE2",4);
    /* Get the SuperVGA Information block */
    regs.x.ax = 0x4F00;
    VBE_callESDI(&regs, &vgaInfo, sizeof(VBE_vgaInfo));
    if (regs.x.ax != 0x004F)
        return 0;
    if (strncmp(vgaInfo.VESASignature,"VESA",4) != 0)
        return 0;
    /* Now that we have detected a VBE interface, copy the list of available
     * video modes into our local buffer. We *must* copy this mode list, since
     * the VBE will build the mode list in the VBE_vgaInfo buffer that we have
     * passed, so the next call to the VBE will trash the list of modes. */
    p1 = (short *)LfbMapRealPointer(vgaInfo.VideoModePtr);
    p2 = VESA_modeList;
    while (*p1 != -1)
        *p2++ = *p1++;
    *p2 = -1;
    return vgaInfo.VESAVersion;
}

int VBE_getModeInfo(int mode,VBE_modeInfo *modeInfo)
/****************************************************************************
* Function:     VBE_getModeInfo
* Parameters:   mode        - VBE mode to get information for
*               modeInfo    - Place to store VBE mode information
* Returns:      1 on success, 0 if function failed.
* Description:  Obtains information about a specific video mode from the
*               VBE. You should use this function to find the video mode
*               you wish to set, as the new VBE 2.0 mode numbers may be
*               completely arbitrary.
****************************************************************************/
{
    RMREGS  regs;

    regs.x.ax = 0x4F01;             /* Get mode information         */
    regs.x.cx = mode;
    VBE_callESDI(&regs, modeInfo, sizeof(VBE_modeInfo));
    if (regs.x.ax != 0x004F)
        return 0;
    if ((modeInfo->ModeAttributes & vbeMdAvailable) == 0)
        return 0;
    return 1;
}

void VBE_setVideoMode(int mode)
/****************************************************************************
* Function:     VBE_setVideoMode
* Parameters:   mode    - VBE mode number to initialise
****************************************************************************/
{
    RMREGS  regs;
    regs.x.ax = 0x4F02;
    regs.x.bx = mode;
    DPMI_int86(0x10,&regs,&regs);
}

/*-------------------- Application specific routines ----------------------*/
void far *GetPtrToLFB(long physAddr)
/****************************************************************************
* Function:     GetPtrToLFB
* Parameters:   physAddr    - Physical memory address of linear framebuffer
* Returns:      Far pointer to the linear framebuffer memory
****************************************************************************/
{
    int     sel;
    long    linAddr,limit = (4096 * 1024) - 1;

    sel = DPMI_allocSelector();
    linAddr = DPMI_mapPhysicalToLinear(physAddr,limit);
    DPMI_setSelectorBase(sel,linAddr);
    DPMI_setSelectorLimit(sel,limit);
    return MK_FP(sel,0);
}

void AvailableModes(void)
/****************************************************************************
* Function:     AvailableModes
* Description:  Display a list of available LFB mode resolutions.
****************************************************************************/
{
	short           *p;
	VBE_modeInfo    modeInfo;

	printf("Usage: LFBPROF <xres> <yres>\n\n");
	printf("Available 256 color video modes:\n");
	for (p = VESA_modeList; *p != -1; p++)
	 {
		if (VBE_getModeInfo(*p, &modeInfo)) {
			/* Filter out only 8 bit linear framebuffer modes */
//			if ((modeInfo.ModeAttributes & vbeMdLinear) == 0)
//				continue;
//			if (modeInfo.MemoryModel != vbeMemPK
//				|| modeInfo.BitsPerPixel != 32
//				|| modeInfo.NumberOfPlanes != 1)
//				continue;
			printf("   mode=%04x %4d x %4d %d bits per pixel\n",
				*p,
				modeInfo.XResolution, modeInfo.YResolution,
				modeInfo.BitsPerPixel);
			}
		}
	getch();
	exit(1);
}

short VESA_InitGraphics(int x,int y)
/****************************************************************************
* Function:     InitGraphics
* Parameters:   x,y - Requested video mode resolution
* Description:  Initialise the specified video mode. We search through
*               the list of available video modes for one that matches
*               the resolution and color depth are are looking for.
****************************************************************************/
{
//*
	short           *p;
    VBE_modeInfo    modeInfo;

	for (p = VESA_modeList; *p != -1; p++)
	{
		if (VBE_getModeInfo(*p, &modeInfo)) {
			// Filter out only 8 bit linear framebuffer modes
//			printf("Cur Mode X Res: %d Y Res: %d  bit=%d\n", modeInfo.XResolution, modeInfo.YResolution, modeInfo.BitsPerPixel);
//			if ((modeInfo.ModeAttributes & vbeMdLinear) == 0)
//				continue;
//			if (modeInfo.MemoryModel != vbeMemPK
//								|| modeInfo.BitsPerPixel != 32
//				|| modeInfo.NumberOfPlanes != 1)
//				continue;
			if (modeInfo.XResolution == x && modeInfo.YResolution == y && modeInfo.BitsPerPixel == 32 )
			{
				VESA_xres = x;
				VESA_yres = y;
				VESA_bytesperline = modeInfo.BytesPerScanLine;
				VESA_imageSize = VESA_bytesperline * VESA_yres;
				VBE_setVideoMode(*p | vbeUseLFB);
				VESA_LFBPtr = (char __far *)GetPtrToLFB(modeInfo.PhysBasePtr);
				return 0;
			}
//			else
//				getch();
		}
	}
	printf("Valid video mode not found\n");
	return 1;
//*/
}

void VESA_EndGraphics(void)
/****************************************************************************
* Function:     EndGraphics
* Description:  Restores text mode.
****************************************************************************/
{
    RMREGS  regs;
    regs.x.ax = 0x3;
    DPMI_int86(0x10, &regs, &regs);
}

void VESA_ScreenCopy(long offset, void * src, long ncopy)
/****************************************************************************
* Function:     VESA_ScreenCopy
* Description:  Copies a block of memory to a location on the screen
****************************************************************************/
{
   LfbMemcpy(FP_SEG(VESA_LFBPtr), offset, src, ncopy);
}
//#endif



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -