home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / CRT.ZIP / CRT.PAS
Encoding:
Pascal/Delphi Source File  |  1985-12-28  |  8.1 KB  |  299 lines

  1. program CRT;
  2.   {CRT.PAS Turbo Pascal 3.0 CRT Characteristics Display Utility
  3.  
  4.         V01 L00  original CompuServe Borland SIG edition created on 85-05-22 by
  5.                  Dennis E. Hamilton for demonstrating the use of the extra
  6.                  CRT interfaces made available in T3CRT.PLB.
  7.  
  8.         Turbo Pascal support for CRT display devices allows programs to obtain
  9.         standard operations such as ClrScr, GotoXY, and LowVideo without having
  10.         to incorporate hardware-dependent information.  That is because the
  11.         same terminal configuration already installed into the production copy
  12.         of the compiler is automatically incorporated into compiled programs.
  13.  
  14.         The file T3CRT.PLB defines additional interfaces beside the standard
  15.         built-in ones.  These interfaces allow a compiled program to INSPECT
  16.         its terminal configuration and adjust its behavior accordingly.  This
  17.         lets generic programs be designed to accomodate the one weakness of the
  18.         basic Turbo Pascal scheme: Not all built-in operations are operational
  19.         for all terminal configurations.  By accessing the auxilliary T3CRT.PLB
  20.         information, a generic program can adapt itself to use of those display
  21.         features which are actually available.  In this way, full use of the
  22.         equipment is obtained without requiring custom installation.
  23.  
  24.         CRT.PAS simply provides a capability report about the terminal display
  25.         configuration that carried over from its compilation.  This is offered
  26.         as an example of T3CRT.PLB usage.  For more details, it is useful to
  27.         review the T3CRT.PLB file and the additional information supplied in
  28.         file T3CRT.HLP.  (Current versions of all of these files can be found
  29.         on the CompuServe CP-MIG and Borland International SIG databases.)    }
  30.  
  31.  
  32. {$I T3CRT.PLB } {Vintage #1.00 or later}
  33. {...
  34.                                     ... }
  35. type
  36.  
  37.    CrtCtlString = string[20]
  38.                   {Typical string for a Crt control sequence};
  39.  
  40. var
  41.  
  42.           clock: integer
  43.                  {clock rate specified for this system};
  44.  
  45. procedure
  46.  
  47.    CrtClr;
  48.  
  49.    var i: integer {counter};
  50.    begin {Procedure to clear the display the best way available, and then
  51.           position to the top line if it can be reached.}
  52.    if length(CrtClrStr) = 0
  53.    then begin
  54.         for i := 1 to CrtRows
  55.          do CrtLn;
  56.             {Scrolling the display full of blank lines}
  57.         if length(CrtGotoStr) > 0 then GotoXY(1,1);
  58.             {Homing if there is any way to do it}
  59.         end
  60.    else ClrScr;
  61.            {Using the direct approach when it is installed}
  62.    end {CrtClr};
  63.  
  64.  
  65. procedure
  66.  
  67.    space(n: integer);
  68.  
  69.    begin {skip n columns}
  70.    for n := n downto 1
  71.     do CrtOut(' ');
  72.    end;
  73.  
  74.  
  75. procedure
  76.  
  77.    NotImplemented;
  78.  
  79.    begin {Describe a non-implemented display function}
  80.    write('not implemented');
  81.       {Note assumption that OUTPUT is assigned to CrtOut's device}
  82.    end;
  83. {...
  84.                                     ... }
  85. procedure
  86.  
  87.    CharName(ch: integer {ord of a character});
  88.  
  89.    const {names of the ASCII control characters}
  90.  
  91.       cn1: string[34] = 'dnsseeeabbhlvfcssdddddnsecesefgrus';
  92.       cn2: string[34] = 'euottoncestftfroilccccaytamusssssp';
  93.       cn3: string[34] = 'llhxxtqkl        e1234knbn bc     ';
  94.  
  95.    begin {Describe a character code by its ASCII name/graphic}
  96.  
  97.    if ch = 127 then ch := -1
  98.       {folding DEL code to front with the other controls};
  99.  
  100.    if ch > 125
  101.    then begin LowVideo; write('#', ch); end
  102.            {handling tilde and 8-bit values by their decimal numeric codes}
  103.    else if ch > 32
  104.         then begin NormVideo; CrtOut(chr(ch)); end
  105.                 {directly showing the character for safe, plain ascii codes}
  106.         else begin
  107.              LowVideo;
  108.              ch := ch+2;
  109.              CrtOut(cn1[ch]);
  110.              CrtOut(cn2[ch]);
  111.              ch := ord(cn3[ch]);
  112.              if ch <> ord(' ') then CrtOut(chr(ch));
  113.              end;
  114.                 {giving the standard acronym for the character}
  115.    NormVideo;
  116.    end {CharName};
  117.  
  118.  
  119.  
  120. procedure
  121.  
  122.    SequenceName(st: CrtCtlString);
  123.  
  124.    var   i: integer {counter};
  125.  
  126.    begin {Presenting the CharNames for each in a control sequence}
  127.    for i := 1 to length(st)
  128.     do begin
  129.        if i>1 then CrtOut(' ');
  130.           {being careful to separate a CharName from its predecessor}
  131.        CharName(ord(st[i]));
  132.        end;
  133.    end {Sequence Name};
  134. {...
  135.                                     ... }
  136. procedure
  137.  
  138.    DelayAmount(d: integer);
  139.  
  140.    begin {describe unsigned millisecond delay amount}
  141.    write('     -- followed by ');
  142.    if d >= 0
  143.    then write(d)
  144.    else write(65536.0+d:0:0);
  145.    write('ms delay');
  146.    end;
  147.  
  148.  
  149. procedure
  150.  
  151.    DescribeSequence(st: CrtCtlString;
  152.                      d: integer);
  153.  
  154.    begin {Describe the specified string with its delay}
  155.    if length(st) = 0
  156.    then NotImplemented
  157.    else begin
  158.         SequenceName(st);
  159.         if d <> 0
  160.         then DelayAmount(d);
  161.         end;
  162.    end {DescribeSequence};
  163.  
  164.  
  165. procedure
  166.  
  167.    BailOut(n: integer;
  168.            p: integer);
  169.    begin {Error procedure for correct release of terminal on quit.}
  170.    CrtExit;
  171.    if n = 1 then halt;
  172.       {exit without error report if CTRL-C User-Break encountered}
  173.    end;
  174. {...
  175.                                     ... }
  176.  
  177. BEGIN
  178. CrtInit;
  179.    {Insuring that any initialization requirements are satisfied.}
  180. ErrorPtr := Addr(BailOut);
  181.    {Guaranteeing that cleanup is done even if the program terminates
  182.     because of a run-time or input-output error.}
  183.  
  184. CrtClr;
  185. writeln('CRT> #1.00 85-05-22 TURBO PASCAL CRT-CONFIGURATION PARAMETERS');
  186.    {Telling the folks who we are}
  187.  
  188. CrtLn;
  189.  
  190. {Identify the overall terminal configuration:}
  191.    begin
  192.    clock := CrtClockMHz mod 32;
  193.    if clock = 0 then clock := 32;
  194.    space(5);
  195.    LowVideo;  write(clock, 'MHz');
  196.    NormVideo; write(' Z80 COMPUTER WITH ');
  197.    LowVideo;  write(CrtRows, '-by-', CrtColumns);
  198.    NormVideo; write(' ');
  199.    LowVideo;  write(CrtType);
  200.    NormVideo; writeln(' DISPLAY');
  201.    end;
  202.  
  203. CrtLn;
  204.  
  205. {Show the initialization and termination sequences:}
  206.    begin
  207.    space(5);
  208.    write(' CrtInit: ');
  209.    DescribeSequence(CrtInitStr, CrtCtlDelay);
  210.    CrtLn;
  211.  
  212.    space(5);
  213.    write(' CrtExit: ');
  214.    DescribeSequence(CrtExitStr, CrtCtlDelay);
  215.    CrtLn;
  216.    end;
  217.  
  218. CrtLn;
  219. {...
  220.                                     ... }
  221.  
  222. {Show the home and GotoXY-sequence information:}
  223.    begin
  224.    space(5);
  225.    write(' CrtHome: ');
  226.    DescribeSequence(CrtHomeStr, CrtCtlDelay);
  227.    CrtLn;
  228.  
  229.    CrtLn;
  230.  
  231.    space(5);
  232.    write('  GotoXY: ');
  233.    if length(CrtGotoStr) = 0
  234.    then NotImplemented
  235.    else begin
  236.         SequenceName(CrtGotoStr);
  237.         DelayAmount(CrtGotoDelay);
  238.         Crtln;
  239.         space(15);
  240.         write('column number (X-1)+', CrtColAdjust,
  241.               ' goes to position ', CrtColPlace,
  242.               ' in ');
  243.         if CrtRadix = CrtDecimal
  244.         then writeln('decimal,')
  245.         else writeln('binary,');
  246.         space(15);
  247.         write('   row number (Y-1)+', CrtRowAdjust,
  248.               ' goes to position ', CrtRowPlace, '.');
  249.         end;
  250.    CrtLn;
  251.    end;
  252.  
  253. CrtLn;
  254.  
  255. {...
  256.                                     ... }
  257. {Describe the other editing operations also:}
  258.    begin
  259.    space(5); write('  ClrScr: ');
  260.    if length(CrtClrStr) = 0
  261.    then if length(CrtHomeStr) <> 0
  262.         then write('implemented in CrtHome sequence!?')
  263.         else NotImplemented
  264.    else begin
  265.         if length(CrtHomeStr) <> 0
  266.         then write('CrtHome plus ');
  267.         DescribeSequence(CrtClrStr, CrtClrDelay);
  268.         end;
  269.    CrtLn;
  270.    space(5); write('  ClrEol: ');
  271.    DescribeSequence(CrtEolStr, CrtCtlDelay);
  272.    CrtLn;
  273.    space(5); write(' DelLine: ');
  274.    DescribeSequence(CrtDelStr, CrtClrDelay);
  275.    CrtLn;
  276.    space(5); write(' InsLine: ');
  277.    DescribeSequence(CrtInsStr, CrtClrDelay);
  278.    CrtLn;
  279.    end;
  280.  
  281. CrtLn;
  282.  
  283. {Describe the mode strings:}
  284.    begin
  285.    write('    NormVideo: ');
  286.    DescribeSequence(CrtNormStr, CrtCtlDelay);
  287.    CrtLn;
  288.  
  289.    space(5); write('LowVideo: ');
  290.    DescribeSequence(CrtAltStr, CrtCtlDelay);
  291.    CrtLn;
  292.    end;
  293.  
  294. CrtLn;
  295. CrtExit;
  296.    {Releasing the terminal to its non-application configuration,
  297.     in case there is any difference.}
  298. END.
  299.