delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/18/15:15:36

From: dmt AT bigfoot DOT com (Jeff W./DMT)
Newsgroups: comp.os.msdos.djgpp
Subject: *help reading char in text mode from (X,Y)
Date: Sun, 18 Jan 1998 19:24:44 GMT
Organization: ZipLink -- America's Hottest ISP
Lines: 33
Message-ID: <34c256ed.471444@news.ziplink.net>
NNTP-Posting-Host: chi-ip-1-136.ziplink.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I know how to do it in turbo pascal:


FUNCTION GetChar(X,Y:BYTE) : CHAR
CONST
	ColorSeg = $B800;

BEGIN
	GetChar := Chr(Mem[ColorSeg:160*(Y-1) + 2*(X-1)]);
END;

but I can't figure out how to do the equivalent in DJGPP.  Here's what
I tried, but to no avail:

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??

- Raw text -


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