[comp.lang.pascal] TSR Programming

burkett@csd4.csd.uwm.edu (Edward W Burkett) (01/02/90)

I am interested in learning how to write TSR programs and was wondering if
someone could give me some hints.

Since a picture (or in this case source code) is worth a thousand words, I was
wondering if someone could send me (or post) an example of any source code in
Pascal or Quick Basic that illustrates the technique.  I don't care what the
code does, something simple would be fine.

Thanks a million in advance,

Ed Burkett
Dept. of Biological Sciences
University of Wisconsin - Milwaukee

azarian@hpcc01.HP.COM (Randy Azarian) (01/04/90)

Following is a Turbo Pascal (4.0) TSR that will compile and execute.  The 
results of which are probably less than desirable.  It converts the 
blinking cursor on the PC to that of a static block (an inverse character 
attribute, to be exact).  Like I say, it compiles and executes, but when 
the screen scrolls you won't be happy (probably).  The only application 
that is moderately tolerable was Walker, Richer, & Quinn's Reflection 7+ 
terminal emulator.  It depends upon how badly you hate the blinking cursor.

This was something I started a while ago (at the request of my boss), and 
never had the time to complete.  Good luck.  And if anyone does finish it
or has a good idea, please send it my way.  

     azarian@hpcc01.hp.com  415 857-5637

BTW, although I can't say for sure, but I have a feeling the results would be
totally unsatisfactory on a VGA screen without modification to the
CURSOR procedure (or its calls).  I wrote it on a EGA screen with a 
12Mhz 80286 Vectra ES/12 PC.

Also, since I never did finish it.  It may have extraneous variable 
declarations that I used in experimentation.



{$M 16384,0,6000}

uses    dos, crt;
const   timer = $1C;
type    screenptr = ^screentype;
        screentype = array[1..25,1..80] of record
          ch : char;
          5t : byte;
        end;
var     vector : pointer;
        tempx, tempy, tempchar, i : integer;

procedure cursor(startline,endline:integer);
(* this procedure alters size of the cursor off/on *)
(* stype and ttype define scan lines of cursor *)
var  regs : registers;
begin
  fillchar(regs,sizeof(regs),0);
  regs.ah:=$01;
  regs.cl:=endline;
  regs.ch:=startline;

  intr($10, regs);
end;

function keyready : boolean;
var regs : registers;
begin
  fillchar(regs,sizeof(regs),0);
  regs.ah := $01;
  intr($16,regs);
  if (regs.flags and fzero) = fzero then keyready := true 
				    else keyready := false;
end; 


(***********)

procedure IntHandler(Flags,CS,IP,AX,BX,CX,DX,SI,DI,DS,ES,BP : word); interrupt;
var regs : registers;

procedure cli; inline($FA);

procedure sti; inline($FB);

begin
    cli; { disable interrupts }
    cursor(16,0); { turn cursor off, diff screens may require diff parms }
    if keyready then
    if (wherex <> tempx) or (wherey <> tempy) then
    begin
      mem[$B800:(80*(tempy-1)+tempx-1)*2+1] := tempchar;
      tempchar := mem[$B800:(80*(wherey-1)+wherex-1)*2+1];
      mem[$B800:(80*(wherey-1)+wherex-1)*2+1] := 
      not mem[$B800:(80*(wherey-1)+wherex-1)*2+1] - 128; { inverse attrib }
      tempx := wherex; tempy := wherey;
    end;
    sti; { enable interrupts }
  end;

(***********)

begin
  clrscr;
  cursor(16,0);
  getintvec(timer,vector);
  setintvec(timer,@inthandler);
  keep(exitcode);
end.