vesavbe.c

来自「适合KS8695X」· C语言 代码 · 共 1,215 行 · 第 1/3 页

C
1,215
字号
	    }
	}
    else size = (size + 0xFFFFL) & 0xFFFF0000L;
    return size;
}

ibool VBEAPI VBE_setVideoModeExt(int mode,VBE_CRTCInfo *crtc)
/****************************************************************************
*
* Function:     VBE_setVideoModeExt
* Parameters:   mode    - SuperVGA video mode to set.
* Returns:      True if the mode was set, false if not.
*
* Description:  Attempts to set the specified video mode. This version
*               includes support for the VBE/Core 3.0 refresh rate control
*               mechanism.
*
****************************************************************************/
{
    RMREGS  regs;

    if (state->VBEVersion < 0x200 && mode < 0x100) {
	/* Some VBE implementations barf terribly if you try to set non-VBE
	 * video modes with the VBE set mode call. VBE 2.0 implementations
	 * must be able to handle this.
	 */
	regs.h.al = (ushort)mode;
	regs.h.ah = 0;
	PM_int86(0x10,&regs,&regs);
	}
    else {
	if (state->VBEVersion < 0x300 && (mode & vbeRefreshCtrl))
	    return false;
	regs.x.ax = 0x4F02;
	regs.x.bx = (ushort)mode;
	if ((mode & vbeRefreshCtrl) && crtc)
	    VBE_callESDI(&regs, crtc, sizeof(*crtc));
	else
	    PM_int86(0x10,&regs,&regs);
	if (regs.x.ax != VBE_SUCCESS)
	    return false;
	}
    return true;
}

ibool VBEAPI VBE_setVideoMode(int mode)
/****************************************************************************
*
* Function:     VBE_setVideoMode
* Parameters:   mode    - SuperVGA video mode to set.
* Returns:      True if the mode was set, false if not.
*
* Description:  Attempts to set the specified video mode.
*
****************************************************************************/
{
    return VBE_setVideoModeExt(mode,NULL);
}

int VBEAPI VBE_getVideoMode(void)
/****************************************************************************
*
* Function:     VBE_getVideoMode
* Returns:      Current video mode
*
****************************************************************************/
{
    RMREGS  regs;

    regs.x.ax = 0x4F03;
    PM_int86(0x10,&regs,&regs);
    if (regs.x.ax != VBE_SUCCESS)
	return -1;
    return regs.x.bx;
}

ibool VBEAPI VBE_setBank(int window,int bank)
/****************************************************************************
*
* Function:     VBE_setBank
* Parameters:   window  - Window to set
*               bank    - Bank number to set window to
* Returns:      True on success, false on failure.
*
****************************************************************************/
{
    RMREGS  regs;

    regs.x.ax = 0x4F05;
    regs.h.bh = 0;
    regs.h.bl = window;
    regs.x.dx = bank;
    PM_int86(0x10,&regs,&regs);
    return regs.x.ax == VBE_SUCCESS;
}

int VBEAPI VBE_getBank(int window)
/****************************************************************************
*
* Function:     VBE_setBank
* Parameters:   window  - Window to read
* Returns:      Bank number for the window (-1 on failure)
*
****************************************************************************/
{
    RMREGS  regs;

    regs.x.ax = 0x4F05;
    regs.h.bh = 1;
    regs.h.bl = window;
    PM_int86(0x10,&regs,&regs);
    if (regs.x.ax != VBE_SUCCESS)
	return -1;
    return regs.x.dx;
}

ibool VBEAPI VBE_setPixelsPerLine(int pixelsPerLine,int *newBytes,
    int *newPixels,int *maxScanlines)
/****************************************************************************
*
* Function:     VBE_setPixelsPerLine
* Parameters:   pixelsPerLine   - Pixels per scanline
*               newBytes        - Storage for bytes per line value set
*               newPixels       - Storage for pixels per line value set
*               maxScanLines    - Storage for maximum number of scanlines
* Returns:      True on success, false on failure
*
* Description:  Sets the scanline length for the video mode to the specified
*               number of pixels per scanline. If you need more granularity
*               in TrueColor modes, use the VBE_setBytesPerLine routine
*               (only valid for VBE 2.0).
*
****************************************************************************/
{
    RMREGS  regs;

    regs.x.ax = 0x4F06;
    regs.h.bl = 0;
    regs.x.cx = pixelsPerLine;
    PM_int86(0x10,&regs,&regs);
    *newBytes = regs.x.bx;
    *newPixels = regs.x.cx;
    *maxScanlines = regs.x.dx;
    return regs.x.ax == VBE_SUCCESS;
}

ibool VBEAPI VBE_setBytesPerLine(int bytesPerLine,int *newBytes,
    int *newPixels,int *maxScanlines)
/****************************************************************************
*
* Function:     VBE_setBytesPerLine
* Parameters:   pixelsPerLine   - Pixels per scanline
*               newBytes        - Storage for bytes per line value set
*               newPixels       - Storage for pixels per line value set
*               maxScanLines    - Storage for maximum number of scanlines
* Returns:      True on success, false on failure
*
* Description:  Sets the scanline length for the video mode to the specified
*               number of bytes per scanline (valid for VBE 2.0 only).
*
****************************************************************************/
{
    RMREGS  regs;

    regs.x.ax = 0x4F06;
    regs.h.bl = 2;
    regs.x.cx = bytesPerLine;
    PM_int86(0x10,&regs,&regs);
    *newBytes = regs.x.bx;
    *newPixels = regs.x.cx;
    *maxScanlines = regs.x.dx;
    return regs.x.ax == VBE_SUCCESS;
}

ibool VBEAPI VBE_getScanlineLength(int *bytesPerLine,int *pixelsPerLine,
    int *maxScanlines)
/****************************************************************************
*
* Function:     VBE_getScanlineLength
* Parameters:   bytesPerLine    - Storage for bytes per scanline
*               pixelsPerLine   - Storage for pixels per scanline
*               maxScanLines    - Storage for maximum number of scanlines
* Returns:      True on success, false on failure
*
****************************************************************************/
{
    RMREGS  regs;

    regs.x.ax = 0x4F06;
    regs.h.bl = 1;
    PM_int86(0x10,&regs,&regs);
    *bytesPerLine = regs.x.bx;
    *pixelsPerLine = regs.x.cx;
    *maxScanlines = regs.x.dx;
    return regs.x.ax == VBE_SUCCESS;
}

ibool VBEAPI VBE_getMaxScanlineLength(int *maxBytes,int *maxPixels)
/****************************************************************************
*
* Function:     VBE_getMaxScanlineLength
* Parameters:   maxBytes    - Maximum scanline width in bytes
*               maxPixels   - Maximum scanline width in pixels
* Returns:      True if successful, false if function failed
*
****************************************************************************/
{
    RMREGS  regs;

    regs.x.ax = 0x4F06;
    regs.h.bl = 3;
    PM_int86(0x10,&regs,&regs);
    *maxBytes = regs.x.bx;
    *maxPixels = regs.x.cx;
    return regs.x.ax == VBE_SUCCESS;
}

ibool VBEAPI VBE_setDisplayStart(int x,int y,ibool waitVRT)
/****************************************************************************
*
* Function:     VBE_setDisplayStart
* Parameters:   x,y     - Position of the first pixel to display
*               waitVRT - True to wait for retrace, false if not
* Returns:      True if function was successful.
*
* Description:  Sets the new starting display position to implement
*               hardware scrolling.
*
****************************************************************************/
{
    RMREGS  regs;

    regs.x.ax = 0x4F07;
    if (waitVRT)
	regs.x.bx = 0x80;
    else regs.x.bx = 0x00;
    regs.x.cx = x;
    regs.x.dx = y;
    PM_int86(0x10,&regs,&regs);
    return regs.x.ax == VBE_SUCCESS;
}

ibool VBEAPI VBE_getDisplayStart(int *x,int *y)
/****************************************************************************
*
* Function:     VBE_getDisplayStart
* Parameters:   x,y - Place to store starting address value
* Returns:      True if function was successful.
*
****************************************************************************/
{
    RMREGS  regs;

    regs.x.ax = 0x4F07;
    regs.x.bx = 0x01;
    PM_int86(0x10,&regs,&regs);
    *x = regs.x.cx;
    *y = regs.x.dx;
    return regs.x.ax == VBE_SUCCESS;
}

ibool VBEAPI VBE_setDisplayStartAlt(ulong startAddr,ibool waitVRT)
/****************************************************************************
*
* Function:     VBE_setDisplayStartAlt
* Parameters:   startAddr   - 32-bit starting address in display memory
*               waitVRT     - True to wait for vertical retrace, false if not
* Returns:      True if function was successful, false if not supported.
*
* Description:  Sets the new starting display position to the specified
*               32-bit display start address. Note that this function is
*               different the the version above, since it takes a 32-bit
*               byte offset in video memory as the starting address which
*               gives the programmer maximum control over the stat address.
*
*               NOTE: Requires VBE/Core 3.0
*
****************************************************************************/
{
    RMREGS  regs;

    if (state->VBEVersion >= 0x300) {
	regs.x.ax = 0x4F07;
	regs.x.bx = waitVRT ? 0x82 : 0x02;
	regs.e.ecx = startAddr;
	PM_int86(0x10,&regs,&regs);
	return regs.x.ax == VBE_SUCCESS;
	}
    return false;
}

int VBEAPI VBE_getDisplayStartStatus(void)
/****************************************************************************
*
* Function:     VBE_getDisplayStartStatus
* Returns:      0 if last flip not occurred, 1 if already flipped
*               -1 if not supported
*
* Description:  Returns the status of the previous display start request.
*               If this function is supported the programmer can implement
*               hardware triple buffering using this function.
*
*               NOTE: Requires VBE/Core 3.0
*
****************************************************************************/
{
    RMREGS  regs;

    if (state->VBEVersion >= 0x300) {
	regs.x.ax = 0x4F07;
	regs.x.bx = 0x0004;
	PM_int86(0x10,&regs,&regs);
	if (regs.x.ax == VBE_SUCCESS)
	    return (regs.x.cx != 0);
	}
    return -1;
}

ibool VBEAPI VBE_enableStereoMode(void)
/****************************************************************************
*
* Function:     VBE_enableStereoMode
* Returns:      True if stereo mode enabled, false if not supported.
*
* Description:  Puts the system into hardware stereo mode for LC shutter
*               glasses, where the display swaps between two display start
*               addresses every vertical retrace.
*
*               NOTE: Requires VBE/Core 3.0
*
****************************************************************************/
{
    RMREGS  regs;

    if (state->VBEVersion >= 0x300) {
	regs.x.ax = 0x4F07;
	regs.x.bx = 0x0005;
	PM_int86(0x10,&regs,&regs);
	return regs.x.ax == VBE_SUCCESS;
	}
    return false;
}

ibool VBEAPI VBE_disableStereoMode(void)
/****************************************************************************
*
* Function:     VBE_disableStereoMode
* Returns:      True if stereo mode disabled, false if not supported.
*
* Description:  Puts the system back into normal, non-stereo display mode
*               after having stereo mode enabled.
*
*               NOTE: Requires VBE/Core 3.0
*
****************************************************************************/
{
    RMREGS  regs;

    if (state->VBEVersion >= 0x300) {
	regs.x.ax = 0x4F07;
	regs.x.bx = 0x0006;
	PM_int86(0x10,&regs,&regs);
	return regs.x.ax == VBE_SUCCESS;
	}
    return false;
}

ibool VBEAPI VBE_setStereoDisplayStart(ulong leftAddr,ulong rightAddr,
    ibool waitVRT)
/****************************************************************************
*
* Function:     VBE_setStereoDisplayStart
* Parameters:   leftAddr    - 32-bit start address for left image
*               rightAddr   - 32-bit start address for right image
*               waitVRT     - True to wait for vertical retrace, false if not
* Returns:      True if function was successful, false if not supported.
*
* Description:  Sets the new starting display position to the specified
*               32-bit display start address. Note that this function is
*               different the the version above, since it takes a 32-bit
*               byte offset in video memory as the starting address which
*               gives the programmer maximum control over the stat address.
*
*               NOTE: Requires VBE/Core 3.0
*
****************************************************************************/
{
    RMREGS  regs;

    if (state->VBEVersion >= 0x300) {
	regs.x.ax = 0x4F07;
	regs.x.bx = waitVRT ? 0x83 : 0x03;
	regs.e.ecx = leftAddr;
	regs.e.edx = rightAddr;
	PM_int86(0x10,&regs,&regs);
	return regs.x.ax == VBE_SUCCESS;
	}
    return false;
}

ulong VBEAPI VBE_getClosestClock(ushort mode,ulong pixelClock)
/****************************************************************************
*
* Function:     VBE_getClosestClock
* Parameters:   mode        - VBE mode to be used (include vbeLinearBuffer)

⌨️ 快捷键说明

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