delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/29/15:06:51

Message-ID: <3842D52E.7BBA7F2E@interlog.com>
From: Alan Illeman <illeman AT interlog DOT com>
X-Mailer: Mozilla 4.04 [en] (Win95; U)
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: nearptr access to memory mapped devices
References: <81s582$bmt$1 AT nntp8 DOT atl DOT mindspring DOT net>
Lines: 76
Date: Mon, 29 Nov 1999 14:34:06 -0500
NNTP-Posting-Host: 154.11.82.190
X-Trace: cac1.rdr.news.psi.ca 943903627 154.11.82.190 (Mon, 29 Nov 1999 14:27:07 EST)
NNTP-Posting-Date: Mon, 29 Nov 1999 14:27:07 EST
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Marp wrote:
> 
> I have a question about accessing a memory mapped device using a near
> pointer. I was reading through the vbe 3.0 spec and it suggested the
> following to access the linear frame buffer:
[snip]

this works for me..

static int GetModeInfo(unsigned short mode)
{
    long modeptr;
    int i, error;
    __dpmi_meminfo mapping;

    if((error=GetVESAINFO()) != VESA_SUCCESS)
        return error;

    /* convert the mode list pointer from seg:offset to a linear address */
    modeptr = ((vesainfo.VideoModePtr & 0xFFFF0000) >> 12) + 
               (vesainfo.VideoModePtr & 0xFFFF);

    for(i=0; ;i++) {
        if(_farpeekw(_dos_ds, modeptr) == 0xFFFF)
            return VESA_MODE_ERROR;
        if(_farpeekw(_dos_ds, modeptr) == mode)
            break;
        modeptr += 2;  /* next WORD */
    }

    if((error=GetMODEINFO(mode)) != VESA_SUCCESS)
        return error;

    /* check for linear frame buffer capability */
    if(!(modeinfo.ModeAttributes & 0x0080))
 	return VESA_LINEAR_ERROR;
 
    /* create direct pointer to video memory */
    if (!__djgpp_nearptr_enable())
        return VESA_MAPPING_ERROR;

    /* map into linear memory */
    mapping.address = modeinfo.PhysBasePtr;
    mapping.size = vesainfo.TotalMemory << 16;
    if (__dpmi_physical_address_mapping(&mapping) != 0)
        return VESA_MAPPING_ERROR;

    video = (unsigned char *)(mapping.address + __djgpp_conventional_base);
    xres  = modeinfo.XResolution;
    yres  = modeinfo.YResolution;
    return VESA_SUCCESS;
}

int SetVesaMode(unsigned short mode)
{
    __dpmi_regs r;
    int error;

    if((error=GetModeInfo(mode)) != VESA_SUCCESS)
        return error;

    /* get current video mode */
    oldmode = _farpeekb(_dos_ds, 0x449);  /* byte at 40:49h */

    /* call the VESA function */
    r.x.ax = SET_VESA_MODE;
    r.x.bx = mode | SET_VESA_LINEAR;
    __dpmi_int(0x10, &r);

    if (r.d.eax == -1)
        return VESA_ERROR;

    return VESA_SUCCESS;
}

If you want the rest of it, say.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019