Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TSR, Reading Ascii Chars from Screen, Keyboard Buffers

Status
Not open for further replies.

TheElusiveYak

Programmer
Feb 8, 2004
19
0
0
US
I am trying to write a Rog-O-Matic type program. What it basically does is run in the background and reads charecters from the screen and outputs information into the keyboard buffer that will move the charecter in the game. Unfortunatly I know almost nothing about A) Writing Terminat Stay Resident Programs B) Reading ASCII chars from the screen in text mode C) Writing to the keyboard buffer indirectly.
P.S. I assume this requires a bit of Assembler, which I know very little about incorperating with Pascal (i.e. reading/writing to variables usable in pascal code). Again, thank you for your invaluable advice and patience.
 
And this is talking DOS programming now:

A) Writing Terminat Stay Resident Programs

This basically involves installing some kind of ISR hook and then staying in memory. If I recall, "keep" is what you want, though you will want to research. Generally, though, most of these are done with assembler.

B) Reading ASCII chars from the screen in text mode.

Define a pointer pointing to your text screen at $B800. Each character takes two bytes, the byte itself, and a character attribute. I don't have a sample handy, but I can get you one if need be, since I've done this one.

C) Writing to the keyboard buffer indirectly.

Some function of the keyboard interrupt no doubt. Again a research project.

If no one has any more direct things to post when I am able to dig up that sample, I can try to look up a few things.
 
For Item B, here's the promised sample. Noting that people get paranoid about this stuff, I should reiterate that NO THIS IS NOT A VIRUS.

Add a delay after the dropchar() proc if you want to see the effect of each character dropping.

Code:
program cascade; uses crt;
 { simulates the action of the old "cascade virus" as a demonstration of
   manipulating text mode memory.  Takes each and every character on 
   and drops it until it either hits the bottom of the screen or another
   character }
   
  const
    segB800 = $B800;
  type
    chtype = record
      value: char;
      attribute: byte;
    end;
    scrtype = array[1..25, 1..80] of chtype;
    scrptr = ^scrtype;
  var
    screen: scrptr;
    y, x: byte;
    i: longint;

  procedure dropchar(var screen:scrptr; x, y: byte);
    var
      ycnt: byte;
    begin
      ycnt := y;
      while (ycnt < 25) do
        begin
          if screen^[ycnt+1, x]. value in [#00, ' '] then
            begin
              screen^[ycnt+1, x].value := screen^[ycnt, x].value;
              screen^[ycnt+1, x].attribute := screen^[ycnt, x].attribute;
              screen^[ycnt, x].value := ' ';
              screen^[ycnt, x].attribute := 7;
            end
          else
            begin
              ycnt := 25;
            end;
          inc(ycnt);
        end;
    end;

  begin
    screen := Ptr(SegB800,0);
    for i := 1 to 20 do
      for y := 1 to 25 do
        for x := 1 to 80 do
          dropchar(screen, x, y);
  end.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top