home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / tsr / tsrunit / tsr.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-09-14  |  11.2 KB  |  500 lines

  1.  UNIT tsr;
  2.  
  3. {$B-,F-,I+,R-,S+}
  4.  
  5. INTERFACE
  6.  
  7. USES DOS,CRT;
  8. CONST
  9.      altkey=8;ctrlkey=4;leftkey=2;rightkey=1;
  10.      TSRversion : word = $0203;
  11.  
  12. TYPE
  13.     string80 = string[80];
  14.     chrwords = record case integer of
  15.                       1: (w : word);
  16.                       2: (c : char; a : byte);
  17.                end;                            linewords = array[1..80] of chrwords;
  18.     wordfuncs = function : word;
  19.  
  20. VAR
  21.    tsrscrptr : pointer;
  22.    tsrchrptr : pointer;
  23.    tsrmode   : byte;
  24.    tsrwidth  : byte;
  25.    tsrpage   : byte;
  26.    tsrcolumn : byte;
  27.    tsrrow    : byte;
  28.  
  29. procedure tsrinstall( tsrname  : string;
  30.                       tsrfunc  : wordfuncs;
  31.                       shiftcomb: byte;
  32.                       Keychr   : char);
  33. function printerokay : boolean;
  34. function printerstatus: byte;
  35. function screenlinestr (row : byte): string80;
  36. procedure screenline(row : byte; var line :linewords;
  37.                                  var words:byte);
  38.  
  39. IMPLEMENTATION
  40.  
  41. VAR
  42.    buffsize, initcmode : word;
  43.    npxflag               : boolean;
  44.    buffer                : array[0..8191] of word;
  45.    npxstate              : array[0..93] of byte;
  46.    retrnval, initvideo   : byte;
  47.    theirfunc             : wordfuncs;
  48.  
  49. CONST
  50.      unsafe = 0;    flg   = 1;     key     = 2;     shft  = 3;
  51.      stkofs = 4;    stkss = 6;     dossp   = 8;     dosss = 10;
  52.      prev   = 12;   flg9  = 13;    insnumb = 14;
  53.      dos21  = $10;        dos25  = dos21+4;     dos26  = dos25+4;
  54.      bios9  = dos26+4;    bios16 = bios9+4;     dostab = bios16+4;
  55.      our21  = dostab+99;  our25  = our21+51;    our26  = our25+24;
  56.      our09  = our26+24;   our16  = our09+127+8; inschr = our16+180-8;
  57.      popup  = inschr+4;
  58.  
  59. procedure asm;
  60. interrupt;
  61. begin
  62. inline(
  63.        >0/>0/
  64.        >0/>0/
  65.        >0/>0/
  66.        >0/>0/
  67.        >0/>0/
  68.  
  69.        0/0/0/0/0/0/0/0/  0/0/0/0/0/1/1/1/  1/1/1/1/1/1/1/1/
  70.        1/1/1/1/1/1/1/1/  1/1/1/1/1/1/0/1/  1/1/1/1/1/1/1/0/
  71.        1/0/0/0/0/0/1/1/  1/1/1/1/1/1/1/1/  1/1/1/1/1/1/1/1/
  72.        0/0/0/0/0/0/1/1/  0/0/0/0/1/0/1/1/  0/1/1/1/1/0/0/0/  0/0/0/
  73.  
  74. {**** OurIntr21 ****}
  75.       $9c/
  76.       $fb/
  77.       $80/$fc/$63/
  78.       $73/<22-7/
  79.       $50/
  80.       $53/
  81.       $bb/>dostab/
  82.       $8a/$c4/
  83.       $2e/
  84.       $d7/
  85.       $3c/$00/
  86.       $5b/
  87.       $58/
  88.       $74/$17/
  89.       $2e/
  90.       $fe/$06/>unsafe/
  91.       $9d/
  92.       $9c/
  93.       $2e/
  94.       $ff/$1e/>dos21/
  95.       $fb/
  96.       $9c/
  97.       $2e/
  98.       $fe/$0e/>unsafe/
  99.       $9d/
  100.       $ca/$02/$00/
  101.       $9d/
  102.       $2e/
  103.       $ff/$2e/>dos21/
  104.  
  105. {**** OurIntr25 ****}
  106.  
  107.       $9c/
  108.       $2e/
  109.       $fe/$06/>unsafe/
  110.       $9d/
  111.       $9c/
  112.       $2e/
  113.       $ff/$1e/>dos25/
  114.       $83/$c4/$02/
  115.       $9c/
  116.       $2e/
  117.       $fe/$0e/>unsafe/
  118.       $9d/
  119.       $cb/
  120.  
  121. {**** OurIntr26 ****}
  122.  
  123.       $9c/
  124.       $2e/
  125.       $fe/$06/>unsafe/
  126.       $9d/
  127.       $9c/
  128.       $2e/
  129.       $ff/$1e/>dos26/
  130.       $83/$c4/$02/
  131.       $9c/
  132.       $2e/
  133.       $fe/$0e/>unsafe/
  134.       $9d/
  135.       $cb/
  136.  
  137. {**** OurIntr9 ****}
  138.  
  139.       $9c/
  140.       $fb/
  141.       $1e/
  142.       $0e/
  143.       $1f/
  144.       $50/
  145.       $31/$c0/
  146.       $e4/$60/
  147.       $3c/$e0/
  148.       $74/<75-14/
  149.       $3c/$f0/
  150.       $74/<75-18/
  151.       $80/$3e/>flg9/$00/
  152.       $75/<77-25/
  153.       $3a/$06/>key/
  154.       $75/<88-31/
  155.  
  156.       $50/
  157.       $06/
  158.       $b8/$40/$00/
  159.       $8e/$c0/
  160.       $26/
  161.       $a0/>$0017/
  162.       $07/
  163.       $24/$0f/
  164.       $3a/$06/>shft/
  165.       $58/
  166.       $75/<88-52/
  167.  
  168.       $3a/$06/>prev/
  169.       $74/<107-58/
  170.       $a2/>prev/
  171.       $f6/$06/>flg/3/
  172.       $75/<99-68/
  173.       $80/$0e/>flg/1/
  174.       $eb/<107-75/
  175.  
  176.       $b4/$01/
  177.       $88/$26/>flg9/
  178.       $c6/$06/>prev/$ff/
  179.       $eb/<99-88/
  180.  
  181.       $3c/$ff/
  182.       $74/<99-92/
  183.       $3c/$00/
  184.       $74/<99-96/
  185.       $a2/>prev/
  186.  
  187.       $58/
  188.       $1f/
  189.       $9d/
  190.       $2e/
  191.       $ff/$2e/>bios9/
  192.  
  193.       $e4/$61/
  194.       $8a/$e0/
  195.       $0c/$80/
  196.       $e6/$61/
  197.       $86/$e0/
  198.       $e6/$61/
  199.       $b0/$20/
  200.       $e6/$20/
  201.       $58/
  202.       $1f/
  203.       $9d/
  204.       $cf/
  205.  
  206. {**** OurIntr16 ****}
  207.  
  208.       $58/
  209.       $1f/
  210.       $9d/
  211.       $2e/
  212.       $ff/$2e/>bios16/
  213.  
  214.       $9c/
  215.       $fb/
  216.       $1e/
  217.       $50/
  218.       $0e/
  219.       $1f/
  220.       $f6/$c4/$ef/
  221.       $75/<48-19/
  222.  
  223.       $f6/$06/>flg/1/
  224.       $74/<29-26/
  225.       $e8/>122-29/
  226.       $f6/$06/>flg/16/
  227.       $75/<48-36/
  228.       $fe/$c4/
  229.       $9c/
  230.       $fa/
  231.       $ff/$1e/>bios16/
  232.       $58/
  233.       $50/
  234.       $74/<19-48/
  235.  
  236.       $f6/$06/>flg/17/
  237.       $74/<-55/
  238.       $f6/$06/>flg/$01/
  239.       $74/<65-62/
  240.       $e8/>122-65/
  241.       $f6/$06/>flg/$10/
  242.       $74/<-72/
  243.       $f6/$c4/$ee/
  244.       $75/<-77/
  245.  
  246.       $58/
  247.       $53/
  248.       $06/
  249.       $c4/$1e/>inschr/
  250.       $26/
  251.       $8a/$07/
  252.       $07/
  253.       $5b/
  254.       $f6/$c4/$01/
  255.       $b4/$00/
  256.       $75/<114-96/
  257.       $fe/$06/>inschr/
  258.       $ff/$0e/>insnumb/
  259.       $75/<111-106/
  260.       $80/$26/>flg/$ef/
  261.       $1f/
  262.       $9d/
  263.       $cf/
  264.  
  265.       $1f/
  266.       $9d/
  267.       $50/
  268.       $40/
  269.       $58/
  270.       $ca/>0002/
  271.  
  272.       $50/
  273.       $fa/
  274.       $f6/$06/>unsafe/$ff/
  275.       $75/<177-131/
  276.       $a0/>flg/
  277.       $24/$fe/
  278.       $0c/$02/
  279.       $a2/>flg/
  280.  
  281.       $a1/>stkofs/
  282.       $87/$c4/
  283.       $a3/>dossp/
  284.       $8c/$16/>dosss/
  285.       $8e/$16/>stkss/
  286.       $fb/
  287.       $9c/
  288.       $ff/$1e/>popup/
  289.  
  290.       $fa/
  291.       $8b/$26/>dossp/
  292.       $8e/$16/>dosss/
  293.       $80/$26/>flg/$fd/
  294.  
  295.       $fb/
  296.       $58/
  297.       $c3);
  298.  
  299. end;
  300.  
  301. procedure popupcode;
  302. INTERRUPT;
  303. CONST     BSeg = $0040;    VBiosOfs = $49;
  304. TYPE
  305.     VideoRecs = RECORD
  306.                       VideoMode                      : BYTE;
  307.                       NumbCol, ScreenSize, MemoryOfs : WORD;
  308.                       CursorArea      : ARRAY[0..7] OF WORD;
  309.                       CursorMode                     : WORD;
  310.                       CurrentPage                    : BYTE;
  311.                       VideoBoardAddr                 : WORD;
  312.                       Current, CurrentColor          : BYTE;
  313.                   END;
  314. VAR
  315.    Regs               : Registers;
  316.    VideoRec           : Videorecs;
  317.    KeyLock            : BYTE;
  318.    ScrnSeg, NumbChr   : WORD;
  319.  
  320. BEGIN
  321.      swapvectors;
  322.      move(ptr(bseg,vbiosofs)^,videorec,sizeof(videorec));
  323.      with videorec, regs do begin
  324.           if (videomode > 7) or (screensize > buffsize) then BEGIN
  325.           swapvectors;
  326.           exit;
  327.       END;
  328.       keylock:=mem[bseg:$0017];
  329.       if videomode = 7 then scrnseg:=$b000
  330.       else scrnseg:=$b800;
  331.       move(ptr(scrnseg, memoryofs)^,buffer, screensize);
  332.       AX:=initvideo;
  333.       if (videomode >=4) and (videomode<=6) then intr($10,regs);
  334.       AX:=$0500;
  335.       intr($10,regs);
  336.       CX:=initcmode;
  337.       AH:=1;
  338.       intr($10,regs);
  339.  
  340.       tsrmode    := videomode;
  341.       tsrwidth   := numbcol;
  342.       tsrpage    := currentpage;
  343.       tsrcolumn  := succ(lo(cursorarea[currentpage]));
  344.       tsrrow     := succ(hi(cursorarea[currentpage]));
  345.  
  346.       if npxflag then inline($98/$dd/$36/>npxstate);
  347.  
  348.       numbchr:=theirfunc;
  349.       memw[cseg:insnumb]:=numbchr;
  350.       if numbchr>0 then begin
  351.          meml[cseg:inschr]:=longint(tsrchrptr);
  352.          mem[cseg:flg]:=mem[cseg:flg] or $10
  353.      END;
  354.  
  355.          if npxflag then
  356.             inline($98/$dd/$36/>npxstate);
  357.  
  358.          mem[bseg:$17]:=(mem[bseg:$17] and $0f) or (keylock and $f0);
  359.  
  360.          If mem[bseg:vbiosofs]<>videomode then begin
  361.             AX:=videomode;
  362.             intr($10,regs);
  363.         end;
  364.         AH:=1;  CX:=cursormode;
  365.         intr($10,regs);
  366.         ah:=5;al:=currentpage;
  367.         intr($10,regs);
  368.         ah:=2;bh:=currentpage;
  369.         dx:=cursorarea[currentpage];
  370.         intr($10,regs);
  371.         move(buffer,ptr(scrnseg,memoryofs)^,screensize);
  372.  
  373.         swapvectors;
  374.     end;
  375. end;
  376.  
  377. function printerstatus:byte;
  378.  
  379. VAR regs : registers;
  380.  
  381. BEGIN
  382.      with regs do begin
  383.           ah:=2; dx:=0;
  384.           intr($17,regs);
  385.           printerstatus:=ah;
  386.       end;
  387. end;
  388.  
  389. function printerokay: boolean;
  390. var s: byte;
  391. begin
  392.      s:=printerstatus;
  393.      if ((s and $10) <> 0) and ((s and $29) = 0) then
  394.         printerokay := true
  395.      else printerokay := false;
  396. end;
  397.  
  398. procedure screenline(row:byte;var line:linewords;var words:byte);
  399.  
  400. begin
  401.      words:=40;
  402.      if tsrmode>1 then words:=words*2;
  403.      move(buffer[pred(row)*words],line,words*2);
  404. end;
  405.  
  406. function screenlinestr(row:byte):string80;
  407. var
  408.    words,i     : byte;
  409.    lineword    : linewords;
  410.    line        : string80;
  411. begin
  412.      screenline(row,lineword,words);
  413.      line:='';
  414.      for i:=1 to words do insert(lineword[i].c,line,i);
  415.      screenlinestr:=line;
  416. end;
  417.  
  418. procedure tsrinstall( tsrname:string; tsrfunc:wordfuncs;
  419.                       shiftcomb:byte; keychr:char);
  420.  
  421. const
  422.      scanchr = '+1234567890++++QWERTYUIOP++++ASDFGHJKL++++ZXCVBNM';
  423.      combchr = 'RLCA"';
  424. var
  425.    plistptr            : ^string;
  426.    i, j, k             : word;
  427.    regs                : registers;
  428.    comb,scancode       : byte;
  429. begin
  430.      if ofs(asm)<>0 then exit;
  431.      memw[cseg:stkss]    := sseg;
  432.      memw[cseg:stkofs]   := sptr+562;
  433.      meml[cseg:popup]    := longint(@popupcode);
  434.      theirfunc           := tsrfunc;
  435.      writeln('Installing Stay Resident Program: ',TSRname);
  436.  
  437.      getintvec($09,pointer(meml[cseg:bios9]));
  438.      getintvec($16,pointer(meml[cseg:bios16]));
  439.      getintvec($21,pointer(meml[cseg:dos21]));
  440.      getintvec($25,pointer(meml[cseg:dos25]));
  441.      getintvec($26,pointer(meml[cseg:dos26]));
  442.  
  443.      with regs do begin
  444.           intr($11,regs);
  445.           npxflag:=(al and 2) = 2;
  446.           ah:=15;
  447.           intr($10,regs);
  448.           initvideo:=al;
  449.           ah:=3;bh:=0;
  450.           intr($10,regs);
  451.           initcmode:=cx;
  452.     end;
  453.  
  454.     buffsize:=sizeof(buffer);
  455.     tsrscrptr:=@buffer;
  456.  
  457.     comb:=0;i:=1;
  458.     plistptr:=ptr(prefixseg,$80);
  459.     while i<length(plistptr^) do begin
  460.           if plistptr^[i] = '/' then begin
  461.              inc(i);
  462.              j:=pos(upcase(plistptr^[i]),combchr);
  463.              if (j>0) and (j<5) then comb:=comb or (1 shl pred(j))
  464.              else if j<>0 then begin
  465.                   inc(i);k:=succ(i);
  466.                   if i>length(plistptr^) then keychr:=#0
  467.                   else begin
  468.                   if ((k<=length(plistptr^)) and (plistptr^[k]='"'))
  469.                      or (plistptr^[i]<>'"') then keychr:=plistptr^[i]
  470.                   else keychr:=#0;
  471.               end;
  472.           end;
  473.       end;
  474.       inc(i);
  475.    end;
  476.    if comb=0 then comb:=shiftcomb;
  477.    if comb=0 then comb:=altkey;
  478.    scancode:=pos(upcase(keychr),scanchr);
  479.    if scancode<2 then begin
  480.       scancode:=2;keychr:='1';
  481.    end;
  482.    mem[cseg:shft]:=comb;
  483.    mem[cseg:key]:=scancode;
  484.    writeln('Memory used is approximately ',(($1000+seg(freeptr^)-prefixseg)/64.0):7:1,' K (K=1024).');
  485.    writeln('Activate program by pressing the following keys simultaneously:');
  486.           if (comb and 1)<>0 then write(' [Right Shift]');
  487.           if (comb and 2)<>0 then write(' [Left Shift]');
  488.           if (comb and 4)<>0 then write(' [Ctrl]');
  489.           if (comb and 8)<>0 then write(' [Alt]');
  490.           writeln(' and "', keychr, '".');
  491.    setintvec($21,ptr(cseg,our21));
  492.    setintvec($25,ptr(cseg,our25));
  493.    setintvec($26,ptr(cseg,our26));
  494.    setintvec($16,ptr(cseg,our16));
  495.    setintvec($09,ptr(cseg,our09));
  496.    swapvectors;
  497.    memw[cseg:unsafe]:=0;
  498.    keep(0);
  499. end;
  500. end.