Mail Archives: djgpp/1998/01/18/20:01:36
Jeff W./DMT wrote:
>
> 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;
> }
IMHO, you are better of using a coordinate system with (0,0) as the
top-left corner of the screen. In any case, I think
unsigned char get_char(unsigned x, unsigned y)
{ /* assumes (0,0) is the top-left corner of the screen */
return _farpeekb(_dos_ds, 0xb8000+160*y+2*x);
}
is clearer, and more portable, and with any optimization, fast enough.
of course, if you want to write routine to copy a block of the screen,
you would be better of writing it in terms of movedata rather than
individual get_char()s in a loop.
> 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??
of course, you could use the available conio functions such as
ScreenGetChar, ScreenRetrieve etc. type info libc func conio to get the
info.
--
----------------------------------------------------------------------
A. Sinan Unur
Department of Policy Analysis and Management, College of Human Ecology,
Cornell University, Ithaca, NY 14853, USA
mailto:sinan DOT unur AT cornell DOT edu
http://www.people.cornell.edu/pages/asu1/
- Raw text -