delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/16/15:17:31

From: tlenat AT flashnet DOT it (Tiziano)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Accessing video memory directly.
Date: Mon, 16 Mar 1998 20:04:46 GMT
Organization: Customer of Flashnet S.p.A. - http://www.flashnet.it
Lines: 53
Message-ID: <350cf33a.5464648@news.flashnet.it>
References: <350a4783 DOT 8500878 AT news DOT manawatu DOT gen DOT nz>
NNTP-Posting-Host: ip014.pool-17.flashnet.it
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


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