Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How to Grab a Character From The Screen? Posted by speedscoot on 11 Nov 2001 at 11:36 AM
I've been working on this new unit for a while, it will make it much easier for someone to create a dos-program with application like interface.

The Windows, shadows, dialog boxes and everything!

Now i have one problem: You can put a Character somewhere on the screen using GotoXY and Write, but is there a way to Grab a Character from the screen.

For example i want to get the character at the point 40x17!

Please Help!<br>

Report
Easy! Posted by Jaywalk on 13 Nov 2001 at 3:25 AM
: I've been working on this new unit for a while, it will make it much easier for someone to create a dos-program with application like interface.
:
: The Windows, shadows, dialog boxes and everything!
:
: Now i have one problem: You can put a Character somewhere on the screen using GotoXY and Write, but is there a way to Grab a Character from the screen.
:
: For example i want to get the character at the point 40x17!
:
: Please Help!
:
Nothing like this is built into Pascal, but there are 2 basic ways of doing it. One way is to request the proper service from BIOS using assembly. Otherwise you could just take a peek at the memory.

The info on the screen is stored starting at memory address $B800:0. Each character on the screen from left to right, top to bottom - uses 2 bytes: 1 for the ASCII code and 1 for the attributes like colour and blinking. This basic formula reads a character at (x,y) from the screen into a variable MyVar.

MyVar := Mem[$B800:x*2 + y*160];

Report
Re: How to Grab a Character From The Screen? Posted by Jaywalk on 13 Nov 2001 at 3:37 AM
Here's a trick. You can map an array to thte screen.

Type
   TextScreenChar = record
       Character: char;
       Attributes: byte;
   end;

Var
   TextScreen: array[1..25,1..40] of TextChar absolute $B800:0;


You want to read 40x17? It will be in TextScreen[17,40].Character

This code here counts x and y from 1 to 80 and 1 to 25, just like GotoXY (i.e. the top-left pixel is 1x1). The method I gave in my last post counted from 0 to 79 and 0 to 24 (i.e. the top-left pixel is at 0x0), so if you take that route remember to deduct 1 from your x and y.

Report
Re: How to Grab a Character From The Screen? Posted by Flub on 19 Nov 2001 at 4:26 AM
: Here's a trick. You can map an array to thte screen.
:
:
: Type
:    TextScreenChar = record
:        Character: char;
:        Attributes: byte;
:    end;
: 
: Var
:    TextScreen: array[1..25,1..40] of TextChar absolute $B800:0;
: 

:
: You want to read 40x17? It will be in TextScreen[17,40].Character
:
: This code here counts x and y from 1 to 80 and 1 to 25, just like GotoXY (i.e. the top-left pixel is 1x1). The method I gave in my last post counted from 0 to 79 and 0 to 24 (i.e. the top-left pixel is at 0x0), so if you take that route remember to deduct 1 from your x and y.
:

wow, cool


Report
Re: How to Grab a Character From The Screen? Posted by netgert on 8 Dec 2001 at 1:05 AM
: Here's a trick. You can map an array to thte screen.
:
:
: Type
:    TextScreenChar = record
:        Character: char;
:        Attributes: byte;
:    end;
: 
: Var
:    TextScreen: array[1..25,1..40] of TextChar absolute $B800:0;
: 

:
: You want to read 40x17? It will be in TextScreen[17,40].Character
:
: This code here counts x and y from 1 to 80 and 1 to 25, just like GotoXY (i.e. the top-left pixel is 1x1). The method I gave in my last post counted from 0 to 79 and 0 to 24 (i.e. the top-left pixel is at 0x0), so if you take that route remember to deduct 1 from your x and y.
:
:
That's cool. But what about 50 lines EGA or less than 80*25 lines (CO40+Font8x8)? How to make it there?

NetGert
Thanx[/b] in advance





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.