From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: *help reading char in text mode from (X,Y) Date: Sun, 18 Jan 1998 15:39:42 -0500 Organization: Two pounds of chaos and a pinch of salt. Lines: 95 Message-ID: <34C2688E.513D@cs.com> References: <34c256ed DOT 471444 AT news DOT ziplink DOT net> NNTP-Posting-Host: ppp227.cs.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------9D710015069" To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk This is a multi-part message in MIME format. --------------9D710015069 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Jeff W./DMT wrote: > > char GetChar(char x, char y) > { > //returns the character at (x,y) > unsigned char *videoptr = (unsigned char *)0xB800; > > __djgpp_nearptr_enable(); > c = videoptr[160*(y-1) + 2*(x-1) + __djgpp_conventional_base]; > return c; > > } > > I tried testing it out by doing: > clrscr(); > printf("a"); > c = GetChar(0,0); > printf("%c",c); > > and also c = GetChar(1,1) just in case the coordinates started at 1,1 > and not 0,0. Can anyone help me out?? Well, calling your function with coordinates {0, 0} obviously won't work because it would then try to read {-1, -1}. Calling it with {1, 1} should work, except that because standard output in DJGPP is line-buffered, the 'a' doesn't get displayed until you print a newline, so there's nothing at coordinates {0, 0} for your function to read. You should never mix stdio and conio functions without understanding how they work together. See chapter 9.4 of the Frequently Asked Questions list (v2/faq210b.zip or online at http://www.delorie.com/djgpp/v2faq/) to learn more. In this case, simply substituting cprintf() for printf() would have worked. Except for this line: > unsigned char *videoptr = (unsigned char *)0xB800; Try reading from 0xb8000, not 0xb800. Another bug: you don't declare 'c' in GetChar(). The attached program works correctly. -- --------------------------------------------------------------------- | John M. Aldrich | "Autocracy is based on the assumption| | aka Fighteer I | that one man is wiser than a million | | mailto:fighteer AT cs DOT com | men. Let's play that over again, | | http://www.cs.com/fighteer | too. Who decides?" - Lazarus Long | --------------------------------------------------------------------- --------------9D710015069 Content-Type: text/plain; charset=us-ascii; name="sgetchar.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="sgetchar.c" #include #include #include #include char GetChar(char x, char y) { char c; //returns the character at (x,y) unsigned char *videoptr = (unsigned char *)0xB8000; __djgpp_nearptr_enable(); c = videoptr[ ( x + y * 80 ) * 2 + __djgpp_conventional_base]; return c; } int main( void ) { char c; clrscr(); cprintf("a"); c = GetChar(0,0); printf("%c",c); return 0; } --------------9D710015069--