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

From: "Tony O'Bryan" <aho450s AT nic DOT smsu DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: *help reading char in text mode from (X,Y)
Date: Sun, 18 Jan 1998 14:31:19 -0600
Organization: Southwest Missouri State University
Lines: 77
Message-ID: <34C26697.5E3@nic.smsu.edu>
References: <34c256ed DOT 471444 AT news DOT ziplink DOT net>
Reply-To: aho450s AT nic DOT smsu DOT edu
NNTP-Posting-Host: clark.a28.smsu.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

This is a multi-part message in MIME format.

--------------45ABE89971
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Jeff W./DMT wrote:
> 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;
> 
> }

Since you left out all header files (nearptr.h especially), your results
would have been confusing anyway.  Since DJGPP is a 32-bit system, you
must use 32-bit addresses.  The 32-bit absolute address of the color
text screen is 0xb8000.  Here is an example based on the information
given in the DJGPP FAQ (which will answer a LOT of questions that
shouldn't be continually asked in the newsgroup):

-- 
Tony O'Bryan

http://www.geocities.com/SiliconValley/Park/7201

--------------45ABE89971
Content-Type: text/plain; charset=us-ascii; name="Test.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="Test.c"

#include <dpmi.h>
#include <sys/farptr.h>

/*
 * Uses DPMI services to setup a pointer to the color text screen.  This is
 * taken directly (really.  It was cut and paste) from the DJGPP FAQ section
 * 18.4.
 */
int TxtVRAMSetupSelector (void)
  {
  static char selectorData[8] = {0xff, 0xff, 0x00, 0x80,0x0b, 0xf3, 0x40, 0x00};
  int screenSelector = __dpmi_allocate_ldt_descriptors (1);

  if (__dpmi_set_descriptor (screenSelector, selectorData) < 0)
    abort ();
  return screenSelector;
  }

/*
 * Unneeded overhead, but it might be easier for you to follow.
 */
unsigned char GetChar(int ScreenSelector,int x,int y)
  {
  return _farpeekb(ScreenSelector,(y * 160) + (x * 2));
  }

/*
 * Tada!
 */
int main(void)
  {
  int Screen = TxtVRAMSetupSelector();
  int Byte = GetChar(Screen,0,0);

  return Byte;
  }


--------------45ABE89971--

- Raw text -


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