home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TMODEM.ZIP / BASIC.INC next >
Encoding:
Text File  |  1987-06-15  |  6.6 KB  |  268 lines

  1. (****************************************************************************)
  2. (*               BASIC Functions Programmed in Turbo PASCAL.                *)
  3. (****************************************************************************)
  4.  
  5.  
  6. (****************************************************************************)
  7. (*                              INKEY$                                      *)
  8. (****************************************************************************)
  9. type
  10.    kbdtype = string[2];
  11. function
  12.    inkey : kbdtype;
  13. var
  14.    a     : string[2];
  15.    ch    : char;
  16. begin
  17.    if keypressed then begin
  18.       read(kbd,ch);
  19.       a := ch;
  20.       if ch = #27 then begin
  21.          read(kbd,ch);
  22.          a := concat(a,ch);
  23.       end;
  24.    end
  25.    else
  26.       a := '';
  27.    inkey := a;
  28. end;
  29.  
  30. (****************************************************************************)
  31. (*                               STRING$                                    *)
  32. (****************************************************************************)
  33. function
  34.    bstring( n : integer; x : char ) : strtype;
  35. var
  36.    j    : integer;
  37.    y    : strtype;
  38. begin
  39.    y[0] := chr(n);
  40.    for j:=1 to n do y[j]:=x;
  41.    bstring := y;
  42. end;
  43.  
  44. (****************************************************************************)
  45. (*                                  VAL                                     *)
  46. (****************************************************************************)
  47. function
  48.    bval( x : strtype ) : integer;
  49. var
  50.    i,j,err,a : integer;
  51. begin
  52.    a := 0;
  53.    if length(x) > 0 then begin
  54.       i := 1;
  55.       while x[i] = ' ' do i := i+1;
  56.       j := length(x)-i+1;
  57.       val(copy(x,i,j),a,err);
  58.       if err > 1 then begin
  59.          j := err-1;
  60.          val(copy(x,i,j),a,err);
  61.       end;
  62.    end;
  63.    bval := a;
  64. end;
  65.  
  66. (****************************************************************************)
  67. (*                                   HEX$                                   *)
  68. (****************************************************************************)
  69. function
  70.    hex( n : integer ) : strtype;
  71. type
  72.    hexdigits  = 0..15;
  73.    hexarray   = array[hexdigits] of char;
  74. const
  75.    hextab : hexarray = ('0','1','2','3','4','5','6','7',
  76.                         '8','9','A','B','C','D','E','F');
  77. var
  78.    a      : string[4];
  79.    i,x    : integer;
  80. begin
  81.    x := n;
  82.    for i:=1 to 4 do begin
  83.       a := concat(hextab[x and $000F],a);
  84.       x := x shr 4;
  85.    end;
  86.    hex := a;
  87. end;
  88.  
  89. (****************************************************************************)
  90. (*                               INPUT                                      *)
  91. (****************************************************************************)
  92. procedure
  93.    input(var s : strtype);
  94. var
  95.    ix,iy,ip    : byte;
  96.    ins_mode    : boolean;
  97.    ich         : kbdtype;
  98.  
  99.    procedure
  100.       shape_cursor(st,en : integer);
  101.    type
  102.       registerpack = record
  103.                         AX,BX,CX,DX,BP,DI,SE,DS,ES,Flags : integer;
  104.                      end;
  105.    var
  106.       reg          : registerpack;
  107.       crtmode      : byte absolute $0040:$0049;
  108.    begin
  109.       if crtmode = 7 then begin
  110.          st := st + 5;
  111.          en := en + 5;
  112.       end;
  113.       reg.AX := $0100;
  114.       reg.CX := (st shl 8) + en;
  115.       intr($10,reg);
  116.    end;
  117.  
  118.    procedure
  119.       end_of_line(s : strtype);
  120.    begin
  121.       ix:=wherex+length(s)-ip+1;
  122.       ip:=length(s)+1;
  123.       gotoxy(ix,iy);
  124.    end;
  125.  
  126.    procedure
  127.       left_arrow;
  128.    begin
  129.       if ip>1 then begin
  130.          ip:=ip-1;
  131.          ix:=wherex-1;
  132.          gotoxy(ix,iy);
  133.       end;
  134.    end;
  135.  
  136.    procedure
  137.       right_arrow(s : strtype);
  138.    begin
  139.       if ip<=length(s) then begin
  140.          ip:=ip+1;
  141.          ix:=wherex+1;
  142.          gotoxy(ix,iy);
  143.       end;
  144.    end;
  145.  
  146.    procedure
  147.       del_char(var s : strtype);
  148.    var
  149.       i      : byte;
  150.    begin
  151.       if length(s)>0 then begin
  152.          if ip<=length(s) then begin
  153.             delete(s,ip,1);
  154.             ix:=wherex;
  155.             for i:=ip to length(s) do write(s[i]);
  156.             write(' ');
  157.             gotoxy(ix,iy);
  158.          end
  159.          else begin
  160.             ix:=wherex-1;
  161.             ip:=ip-1;
  162.             gotoxy(ix,iy);
  163.          end;
  164.       end;
  165.    end;
  166.  
  167.    procedure
  168.       del_pre_char(var s : strtype);
  169.    begin
  170.       if ip>1 then begin
  171.          ip:=ip-1;
  172.          ix:=wherex-1;
  173.          gotoxy(ix,iy);
  174.          del_char(s);
  175.       end;
  176.    end;
  177.  
  178.    procedure
  179.       process_change(var s : strtype);
  180.    var
  181.       i     : byte;
  182.    begin
  183.       case ich[1] of
  184.          #210 : begin
  185.                    ins_mode := true;
  186.                    shape_cursor(1,7);
  187.                 end;
  188.          ^M   : ;
  189.          #207 : end_of_line(s);
  190.          #211 : del_char(s);
  191.          ^H   : del_pre_char(s);
  192.          #205 : right_arrow(s);
  193.          #203 : left_arrow;
  194.       else
  195.          if ip<=length(s) then
  196.             s[ip] := ich
  197.          else
  198.             s := s+ich;
  199.          ip:=ip+1;
  200.          write(ich);
  201.       end;
  202.    end;
  203.  
  204.    procedure
  205.       process_insert(var s : strtype);
  206.    var
  207.       i            : byte;
  208.    begin
  209.       case ich[1] of
  210.          #210 : begin
  211.                    ins_mode := false;
  212.                    shape_cursor(6,7);
  213.                 end;
  214.          ^M   : ;
  215.          #207 : end_of_line(s);
  216.          #211 : del_char(s);
  217.          ^H   : del_pre_char(s);
  218.          #205 : right_arrow(s);
  219.          #203 : left_arrow;
  220.       else
  221.          if ip>length(s) then begin
  222.             ip:=ip+1;
  223.             s:=s+ich;
  224.             write(ich);
  225.          end
  226.          else begin
  227.             insert(ich,s,ip);
  228.             ix:=wherex+1;
  229.             for i:=ip to length(s) do write(s[i]);
  230.             ip:=ip+1;
  231.             gotoxy(ix,iy);
  232.          end;
  233.       end;
  234.    end;
  235.  
  236. begin
  237.    ip:=1;
  238.    iy:=wherey;
  239.    ins_mode:=false;
  240.    repeat
  241.       ich:=inkey;
  242.    until ich <> '';
  243.    repeat
  244.       if length(ich)=2 then ich:=chr(ord(ich[2])+128);
  245.       if ins_mode then
  246.          process_insert(s)
  247.       else
  248.          process_change(s);
  249.       if ich <> ^M then begin
  250.          repeat
  251.             ich:=inkey;
  252.          until ich <> '';
  253.       end;
  254.    until ich = ^M;
  255.    shape_cursor(6,7);
  256. end;
  257.  
  258. (****************************************************************************)
  259. (*                               UP CASE STRING                             *)
  260. (****************************************************************************)
  261.    procedure
  262.       upstring( var s : strtype );
  263.    var
  264.       i   : integer;
  265.    begin
  266.       for i:=1 to length( s ) do
  267.          s[i] := upcase( s[i] );
  268.    end;