FeVeR
asked on
read char from screen
how do i read a character from any given location on the screen
And don't forget:
my CPU is ______
Assuming DOS/Intel, video memory starts at either b800: or A000:, depending on video card and mode. Further assuming you're in text mode, characters are stored in two bytes - the first for the character, the second for its' display attribute (color, blink, etc).
If you're in graphics mode, all you can get is pixels - there are no characters per se stored.
If you're under Windows, same thing - it's all graphics data.
my CPU is ______
Assuming DOS/Intel, video memory starts at either b800: or A000:, depending on video card and mode. Further assuming you're in text mode, characters are stored in two bytes - the first for the character, the second for its' display attribute (color, blink, etc).
If you're in graphics mode, all you can get is pixels - there are no characters per se stored.
If you're under Windows, same thing - it's all graphics data.
BTW, you really ought to update your other two questions in this topic. They've been languishing for almost two weeks.
There are lots of people here who won't take the time to respond to folks they think have a spotty grading record.
There are lots of people here who won't take the time to respond to folks they think have a spotty grading record.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
kmullin - I see you're new here, so you probably aren't aware of the convention of posting only comments. Posting an answer locks the question, and many people don't even bother looking at locked questions, thereby denying the questioner the added audience.
But don't worry about it - lots of folks do it.
And welcome to EE...
FeVeR:
Here's some sample MSC 16-bit code:
unsigned char _far *Addr;
unsigned int Addr_Seg;
unsigned int Addr_Off;
unsigned char ScreenChar;
unsigned char AttrByte;
// Get top left hand screen character
_FP_SEG(Addr)=0xAF000;
_FP_OFF(Addr)=0;
ScreenChar=*Addr;
AttrByte=*(Addr+1);
Other compilers use different ways of specifying address segments and offsets. Your mileage may vary.
But don't worry about it - lots of folks do it.
And welcome to EE...
FeVeR:
Here's some sample MSC 16-bit code:
unsigned char _far *Addr;
unsigned int Addr_Seg;
unsigned int Addr_Off;
unsigned char ScreenChar;
unsigned char AttrByte;
// Get top left hand screen character
_FP_SEG(Addr)=0xAF000;
_FP_OFF(Addr)=0;
ScreenChar=*Addr;
AttrByte=*(Addr+1);
Other compilers use different ways of specifying address segments and offsets. Your mileage may vary.
This will work in text mode on standart PC:
#include <dos.h>
int get_char(int x,int y) {
return peekb(0xb800,y*80*2+x*2);
}
#include <dos.h>
int get_char(int x,int y) {
return peekb(0xb800,y*80*2+x*2);
}
ASKER
sorry,
no pc for a few weeks
ummm ok i didn't know that it was not possible. i thought C was pretty much capable of anything anyway, ill try out a few of these ideas and get back....
thanks all
no pc for a few weeks
ummm ok i didn't know that it was not possible. i thought C was pretty much capable of anything anyway, ill try out a few of these ideas and get back....
thanks all
I may be splitting hairs here, but C can do anything. Because of the way it deals with addresses and how it deals with bit manipulation, you can code it to do anything. BUT, C doesn't know HOW to do everything. You have to provide the HOW TO DO IT, and then you can code C to do it. For example, on your particular hardware, perhaps setting a certain video register bit to 1 will cause your display to clear itself on the next refresh cycle. So, you have to do the investigation to find out 1) what address is the video register stored in, 2) code a C program to access that address (via a pointer set to that address), then set that particular bit with the appropriate bit operations. Does the above mean that C can clear the screen? No, but you knew how to do it for your hardware, and using that knowledge, you coded a C routine to do it for you.
the compiler is _________