delorie.com is funded by banner ads.
  www.delorie.com/djgpp/v2faq/faq082.html   search  

| Previous | Next | Up | Top |

10.2 Accessing the video memory

Q: I try to access the video memory at 0xa0000, but my program crashes with SIGSEGV...

Q: How can I access the text-mode video memory of my VGA?


A: Absolute addresses of memory-mapped devices are mapped differently under DJGPP than what you might be used to under other DOS development environments. That's because DJGPP is a protected-mode environment, in which you can't just poke any address: that's what protected mode is all about! To access such absolute addresses, use the so-called "farptr" functions like _farpeekb and _farpokew; they are described in the C Library reference. See more details on using "farptr" functions to access absolute addresses in low memory, below.

For text-mode screen updates, you can use the ScreenUpdate and ScreenUpdateLine library functions to quickly update the screen from a text buffer.

Using the _farpeekX/_farpokeX paradigm to access memory isn't much slower than direct access (they compile into 2 machine instructions when optimizations are enabled). But if you need even faster access (and don't want to write it in assembly), see using the "nearptr" access facilities, as described below.

If your video card supports the VBE 2.0 standard, you can access the linear frame buffer as a normal array in memory. For an example of such a technique, see the VBE example code by Charles Sandmann. You can also reach this file via the Web. Some examples of how to access video memory from DJGPP programs are available from Brennan Underwood's Web page.


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright ⌐ 1998   by Eli Zaretskii     Updated Sep 1998  

Powered by Apache!

You can help support this site by visiting the advertisers that sponsor it! (only once each, though)