Mail Archives: djgpp/1997/01/26/12:52:46
jonklipp AT freenet DOT edmonton DOT ab DOT ca wrote:
>
> : How would I create an array for video memory in djgpp?
> : Currently I have:
>
> : char far *video_buffer = (char far)0xA0000000L;
>
> char *video_buffer = (char *)0xA0000; // 0xA0000, because it uses 32-bit
> protected mode addresses (or something, I'm not quite sure :))
Close. This must read something like the following:
if ( __djgpp_nearptr_enable() )
{
char *video_buffer = (char *)(__djgpp_conventional_base + 0xA0000);
video_buffer[y*320+x] = color;
__djgpp_nearptr_disable();
}
You must always add __djgpp_conventional_base to the absolute memory
address, because all addresses are computed relative to your program's
address space!
Note also that there are some library functions that can change the
program's base address. For maximum safety, you should recalculate
__djgpp_conventional_base + 0xA0000 every time you call a given
function.
Also, the nearptr_enable and nearptr_disable functions are relatively
heavy cycle-eaters. If you are _certain_ that your program doesn't have
any rogue pointers that might damage sensitive areas of memory, you can
try disabling them at the beginning of your program and enabling them at
the end. Otherwise, it's probably best to leave near pointers off until
you enter those portions of your program that need them.
The FAQ discusses this subject quite extensively in chapters 10, 17, and
18, and also points you to several very handy references on the net.
For a way to do this sort of thing without needing to worry about all
the memory protection hacks, check out the allegro graphics library.
It's a fantastic library that runs nearly as fast as the best optimized
code, and it handles all the memory issues for you! The latest version
is available from
<ftp://x2ftp.oulu.fi/pub/msdos/programming/djgpp2/alleg211.zip> and
several other locations.
l8r
--
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I | fighteer AT cs DOT com |
| Call me for your free AOL disk! | http://www.cs.com/fighteer |
| Chain letters, work-at-home schemes, free long distance, etc., |
| are ILLEGAL! Keep the Internet litter-free... don't SPAM. |
---------------------------------------------------------------------
- Raw text -