delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1996/07/11/10:06:09

From: k3040e4 AT c210 DOT edvz DOT uni-linz DOT ac DOT at (Oberhumer Markus)
Message-Id: <199607111354.PAA21145@c210.edvz.uni-linz.ac.at>
Subject: Re: limited nearptr ?
To: djgpp-workers AT delorie DOT com (djgpp-workers)
Date: Thu, 11 Jul 1996 15:54:57 -0200 (MET DST)
Return-Read-To: markus DOT oberhumer AT jk DOT uni-linz DOT ac DOT at

===============================================================================
Markus F.X.J. Oberhumer <markus DOT oberhumer AT jk DOT uni-linz DOT ac DOT at>

Subject: Re: limited nearptr ?
To: djgpp-workers AT delorie DOT com
===============================================================================

> You have 3 options for using an external video buffer with DJGPP:
> 
> 1) Use farptr.h.  You said you didn't want to do this due to code changes.
> 2) Use nearptr.h.  You said you didn't want to do this, but this is what
>    you will probably end up doing.
> 3) Limit yourself to running on hosts with DPMI 1.0 functionality that
>    support function 0x508, and map the video memory into a block you
>    malloc()ed.
>    
> The solutions you suggested (including the RSX one) essentially all boil
> down to #2 above - which is sys/nearptr.h.

Seems like I've been looking for option #3. In the meantime I've
also discovered the helper function __djgpp_map_physical_memory
and the test program below works fine with CWSDPMI (it does *not*
work with PMODE/DJ or Win 3.1).


I still have some more questions for use in reliable code
using VESA 2.0 linear framebuffer:

- is there a speed difference to nearptrs ?

- can I somehow avoid wasting memory (think of a card with 4 MB VRAM) ?

- do I have to unmap or is this done automatically ?

- do I have to lock the memory - and unlock it ?

- what happens if video memory is alread mapped with
  __dpmi_physical_address_mapping ?

- are there some other pitfalls (sbrk, etc.) or is this pretty safe ?


bye,
Markus



/***********************************************************************
// Markus F.X.J. Oberhumer <markus DOT oberhumer AT jk DOT uni-linz DOT ac DOT at>
//
// simple VGA demo program of __djgpp_map_physical_memory 
//
// !! needs CWSDPMI !!
************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <conio.h>
#include <go32.h>
#include <dpmi.h>

int main()
{
    unsigned char *mem, *vidmem;
    unsigned vidsize = 0x10000;         /* 64 kB VGA memory */
    unsigned i, j;
    __dpmi_regs r;
    static int dummy;

    /* allocate a page aligned buffer for video memory */
    mem = malloc(vidsize + 0xfff);
    if (mem == 0)
        return 1;
    vidmem = (unsigned char *) (((unsigned long)mem + 0xfff) & ~0xfff);

    /* map VGA video memory into our address space */
    if (__djgpp_map_physical_memory (vidmem, vidsize, 0xa0000) != 0)
    {
        if (errno == EACCES)
            printf("mapping rejected !\n");
        else
            printf("mapping failed !\n");
        return 1;
    }

    /* set mode 0x13 */
    r.x.ax = 0x13;
    __dpmi_int(0x10,&r);

    /* now draw onto the screen using a simple pointer */
    for (j = 1; j < 5; j++)
    {
        for (i = 0; i < vidsize; i++)
            vidmem[i] = j;
        getch();
    }

    /* return to text mode */
    r.x.ax = 0x03;
    __dpmi_int(0x10,&r);

    /* inspect pointers */
    printf("Everything ok: dummy=0x%p vidmem=0x%p\n", &dummy, vidmem);
    free(mem);
    return 0;
}

- Raw text -


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