Solved

read char from screen

Posted on 2000-04-03
8
228 Views
Last Modified: 2010-04-02
how do i read a character from any given location on the screen
0
Comment
Question by:FeVeR
8 Comments
 
LVL 2

Expert Comment

by:yairy
ID: 2682204
My OS is _____

the compiler is _________

0
 
LVL 22

Expert Comment

by:cookre
ID: 2682334
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.
0
 
LVL 22

Expert Comment

by:cookre
ID: 2682348
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.
0
 

Accepted Solution

by:
kmullin earned 50 total points
ID: 2684857
The ANSI C standard answer is, you can't.  That screen is hardware, and as any C programmer knows, C doesn't know anything about the hardware.  It knows standard-in and standard-out.  But, in a sense, it doesn't know what those really are.  They are byte streams, as far as C is concerned.  Getting to a specific pont on the screen and interpreting what is there as a character (as opposed to some sort of graphic image) is hardware realated.  You can probably do it via some sort of API function that is provided to you by the hardware manufacturer.  But C doesn't know how.  C doesn't know anything about the hardware of your particular machine.  It has getchar and scanf (which uses getchar, by the way).  There are other derivations of these basics.  But they all simply get the next byte from the standard-in stream, which is NOT a terminal, but a byte stream.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 22

Expert Comment

by:cookre
ID: 2685001
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.
0
 
LVL 2

Expert Comment

by:kamarey
ID: 2693013
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);
}
0
 

Author Comment

by:FeVeR
ID: 2729114
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
0
 

Expert Comment

by:kmullin
ID: 2730931
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.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now