Mail Archives: djgpp/1998/03/16/15:17:31
Hi!
>Hello,
>Can somebody please tell me why this won't work, and/or a better
>method of accessing video memory directly with djgpp.
>(This program is intended to put a smiley character in the top left of
>the text mode screen)
>
>#include <conio.h>
>
>main() {
> char *p = (char) 0xb8000;
> p = 1;
> getch();
>}
You must use a near or a far pointer to change memory and with p = 1
you are not writing to display memory, you only modify p value. With
p[0] = 1 you put a char in the first element of the array you are
pointing with p (see near pointer implementation).
Maybe there are other ways to do this but anyway I hope this is clear.
Bye!
#include <sys/nearptr.h>
#include <conio.h>
// near pointer to text screen
char *charbuffer = (char*) 0xb8000;
main() {
// disable memory protection
__djgpp_nearptr_enable();
// add the base memory used by Djgpp to the near pointer to
// the text screen
charbuffer += __djgpp_conventional_base;
charbuffer[0] = 1;
getch();
// enable memory protection
__djgpp_nearptr_disable();
}
or you can use this one with far pointers (a bit slower):
#include <sys/farptr.h>
#include <go32.h> // dos selector
#include <conio.h>
main() {
char color = 0x04; char character = 1;
char x = 0; char y = 0;
_farpokew(_dos_ds, 0xb8000 + x*2+y*160, (color << 8) + character);
getch();
}
- Raw text -