Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Programming With VESA BIOS Extensions


August 1996/Programming With VESA BIOS Extensions/Listing 1

Listing 1: VBE wrapper functions


#include <string.h>
#include <dos.h>
#include "vbe.h"    /* exports and data types */

/*------------------ local data -------------------*/

static VbeInfo_t _VbeInfo;  
static ModeInfo_t _ModeInfo;

static int _Width;   /* scan line width in bytes */
static long _Window; /* memory window size in bytes */
static int _Segment; /* mem window segment */

/*--------------- exported functions ---------------*/

int VbeGetVbeInfo(VbeInfo_t far *p)

/* fetches the vbe info block; returns 0 if no vbe. */
{
    union REGS r={0x4f00,0,0,0,0,FP_OFF(p)};
    struct SREGS s={FP_SEG(p)};

    if(!p) return 0;
        
    _fmemset(p,0,sizeof(VbeInfo_t));
    _fmemcpy(p->VbeSignature,"VBE2",4);
    int86x(0x10,&r,&r,&s);

    if(_fmemcmp(p->VbeSignature,"VESA",4)) return 0;
    return r.x.ax==0x4f;
}
int VbeGetModeInfo(int mode,ModeInfo_t far *p)

/* fetches the mode info block for the specified mode 
   number; returns 0 if mode unsupported by vbe. */
{
    union REGS r={0x4f01,0,mode,0,0,FP_OFF(p)};
    struct SREGS s={FP_SEG(p)};

    if(!p) return 0;
    
    _fmemset(p,0,sizeof(ModeInfo_t));
    int86x(0x10,&r,&r,&s);

    return r.x.ax==0x4f;
}
int VbeSetMode(int mode)

/* initializes the requested video mode; returns 0 if 
   there's no vbe or the mode is unavailable. */
{
    union REGS r={0x4f02,mode};

    if(!VbeGetVbeInfo(&_VbeInfo)) return 0;
    
    if(mode>=0x100)    /* svga mode */
    {
        if(!VbeGetModeInfo(mode,&_ModeInfo) || 
            !(_ModeInfo.ModeAttributes&1)) return 0;
    
        _Width=_ModeInfo.BytesPerScanLine;
        _Window=1024L*_ModeInfo.WinSize;    /* convert to bytes */
        _Segment=_ModeInfo.WinASegment;        
    }
    int86(0x10,&r,&r);
    
    return r.x.ax==0x4f;
}
void VbeSetPalette(const char far *p,int start,int n)

/* loads the dac palette registers; uses bios on vbe
   versions before 2.0 */
{
    if(_VbeInfo.VbeVersion<0x200)    /* use bios */
    {
        union REGS r={0x1012,start,n,FP_OFF(p)};
        struct SREGS s={FP_SEG(p)};
        int86x(0x10,&r,&r,&s);
    }
    else    /* use vbe */
    {
        union REGS r={0x4f09,0,n,start,0,FP_OFF(p)};
        struct SREGS s={FP_SEG(p)};
        int86x(0x10,&r,&r,&s);
    }
}
void VbeSetWindow(int window,int position)

/* repositions the indicates memory window to the new
   position (in WinGranularity units). */
{
    union REGS r={0x4f05,window,0,position};
    int86(0x10,&r,&r);
}
void VbeWrite(int x,int y,int bytes,const char far *buffer)

    /* copies the contents of the buffer (<64k) to display, 
    starting at pixel (x,y). */

{
    long absolute=x+(long)y*_Width;      /* absolute offset */
    long position=absolute/_Window;      /* of window */
    long offset=absolute%_Window;        /* of window */
    char far *vram=MK_FP(_Segment,0);    /* to window */

    VbeSetWindow(0,(int)position);
    
    if(offset+bytes>_Window)    /* data overruns window */
    {
        int    n=(int)(_Window-offset);  /* bytes left */
        
        _fmemcpy(vram+offset,buffer,n);  /* display 1st part */
        VbeSetWindow(0,(int)++position); /* move window */
        _fmemcpy(vram,buffer+n,bytes-n); /* display rest */
    }    
    else _fmemcpy(vram+offset,buffer,bytes);/* no overrun */
}
/* End of File */

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.