delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/10/06/22:42:44

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: A pointer to physical memory?
Date: Sun, 06 Oct 1996 21:34:36 -0700
Organization: Three pounds of chaos and a pinch of salt
Lines: 63
Message-ID: <3258885C.3092@cs.com>
References: <3251736e DOT 1891011 AT news DOT direct DOT ca>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp232.cs.com
Mime-Version: 1.0
To: Wesley Terpstra <paradox AT direct DOT ca>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Wesley Terpstra wrote:
> 
>         Hi.  I just recently switched to the DJGPP GNU C++ compiler,
> and have encountered two problems... 1) I need to get a pointer to the
> VGA memory.  I know that I can make an array in virtual memory, write
> screen output to that, and then use dosmemput to stick it onto the
> VGA, but that has overhead I would rather not have...  Is there any
> way to directly get a pointer to the VGA memory so that I don't have
> to deal with an inbetween buffer?  I could just go char far *vga =
> (char far *)0xA0000000L;  if it was TC++, but that doesn't work in
> DJGPP due to, (I assume) the memory paging or something to do with
> protected mode?

You have to use either the _farpeekX/_farpokeX paradigm or disable
memory protection to access the video memory directly.  Look in the
DJGPP FAQ (v2/faq201b.zip), section 10, for tips on graphics programming
and pointers to some tutorials on the subject.  Also examine the libc
docs for _farpoke/_farpeek and the function __djgpp_nearptr_enable().

> 2) I was also wondering if using
> __dpmi_lock_linear_region would work to hold a buffer in one region of
> physical memory so that I could get the DMA to read from it?  Will the
> __dpmi_lock_... work to hold it in one place - and if it does, how can
> I get the physical address it is stuck at?  If you know the answer to
> either of these questions, PLEASE send me e-mail! :)
> (paradox AT direct DOT ca)

That's not what the locking functions are used for.  They are primarily
useful for installing interrupt handlers and other routines that _must_
always stay in memory.

The formula for calculating the virtual address of any absolute address
is to add the value of the __djgpp_conventional_base variable to it. 
So, the address of the VGA memory is ( __djgpp_conventional_base +
0xA0000 ).  This only works with memory protection disabled, however.

> P.S.  In case it's not obvious from these questions I know VERY little
> about protected and 386 enhanced modes.  In fact, I don't even know
> which one DJGPP is using... :)  - Where could I get a good explanation
> of what protected mode / 386 enhanced mode does, and how to use it?

DJGPP v2 operates in DPMI (Dos Protected Mode Interface) which allows it
to use the full 32-bit capacity of the processor, as well as to operate
on all memory as if it were one large segment with a maximum limit of 4
GB.  There are many other aspects to DPMI, but those are the basics. 
386-enhanced mode is a term for the enhanced capabilities of MS Windows
3.* when run on a 386 or greater processor.

To understand the mechanisms behind DPMI, you can look in the libc docs
under the __dpmi_* and _go32_dpmi_* functions, and/or download a copy of
the DPMI 0.9 spec (pointers in the FAQ).  I'm not sure where to go for a
complete tutorial - somebody else will have to answer that.  :) 
However, the great secret to DPMI is that you should very seldom have to
worry about what it is actually doing!  Unless you deliberately decide
to use direct hardware access or write interrupt handlers, the DPMI
aspects of djgpp will be completely transparent.

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I  |        fighteer AT cs DOT com         |
| Plan:  To find ANYONE willing to |   http://www.cs.com/fighteer   |
| play Descent 2 on DWANGO!        | Tagline: <this space for rent> |
---------------------------------------------------------------------

- Raw text -


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