Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to Grab a Character From The Screen?

speedscootspeedscoot Posts: 11Member
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!


Comments

  • JaywalkJaywalk Posts: 105Member
    : 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];

  • JaywalkJaywalk Posts: 105Member
    Here's a trick. You can map an array to thte screen.

    [code]
    Type
    TextScreenChar = record
    Character: char;
    Attributes: byte;
    end;

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

    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.

  • FlubFlub Posts: 8Member
    : Here's a trick. You can map an array to thte screen.
    :
    : [code]
    : Type
    : TextScreenChar = record
    : Character: char;
    : Attributes: byte;
    : end;
    :
    : Var
    : TextScreen: array[1..25,1..40] of TextChar absolute $B800:0;
    : [/code]
    :
    : 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


  • netgertnetgert Posts: 331Member
    : Here's a trick. You can map an array to thte screen.
    :
    : [code]
    : Type
    : TextScreenChar = record
    : Character: char;
    : Attributes: byte;
    : end;
    :
    : Var
    : TextScreen: array[1..25,1..40] of TextChar absolute $B800:0;
    : [/code]
    :
    : 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?

    [blue][b][italic]NetGert[/italic][/blue] :-)
    [red]Thanx[/b] in [b]advance[/b][/red]


Sign In or Register to comment.