home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / draco / draco-1.ark / CRT.REF < prev    next >
Encoding:
Text File  |  1986-11-13  |  15.8 KB  |  363 lines

  1.                The Draco CRT Library
  2.  
  3.             Copyright 1983 by Chris Gray
  4.  
  5.  
  6. The Routines Provided in CRT.LIB
  7.  
  8.     The routines in CRT.LIB are declared in a Draco include file, CRT.G,
  9. which should be included via '\crt.g' at the beginning of each file of your
  10. program. If you use any of the CRT routines, you must include CRT.LIB, the
  11. library which actually contains the routines, as one of the parameters to the
  12. link-editor when you link-edit your program. Additional include file FORM.G
  13. is needed only if you use the form routines in the CRT library. Any program
  14. which correctly uses the CRT routines can (and must) be configured using the
  15. CONFIG.COM program before it can be used. This configuration inserts into
  16. the linked .COM program (renamed as .SET) the control sequences needed for
  17. the terminal the program is to run on. This is inconvenient for the
  18. programmer, but allows the program to be configurable without any additional
  19. effort.
  20.  
  21.     Note that this version of the CRT library only supports systems in which
  22. all actions are done by sending special control sequences out through CP/M's
  23. normal console driver (the DirectConsoleIO system call is used). An earlier
  24. attempt was made to provide a different version which supports memory-
  25. mapped character displays. This version was abandoned due to difficulties
  26. with generalizing things like cursor handling.
  27.  
  28.     The CRT routines require initialization before they will operate
  29. correctly. This is done by one of the magic '_initialize' routines which
  30. will be loaded and called before your 'main' routine is called. Thus, when
  31. using the CRT routines, no special actions need be taken by the programmer,
  32. except that using 'exit' may leave the terminal in a funny state if the
  33. terminal has a termination sequence (which will not be output).
  34.  
  35.     The routines provided in CRT.LIB are:
  36.  
  37.     CRT_NLines()ushort
  38.  
  39.     This call returns the number of lines on the screen of the terminal.
  40.     If your program is to be completely general, it should use the size
  41.     of the terminal to determine the format of the screen.
  42.  
  43.     CRT_NCols()ushort
  44.  
  45.     This call returns the number of columns in each line of the
  46.     terminal's screen. Note that you should avoid putting a character 
  47.     in the last column of the last line on the screen, since this can
  48.     cause some terminals to scroll the screen.
  49.  
  50.     CRT_Line()ushort
  51.  
  52.     Returns the line the cursor is currently on.
  53.  
  54.     CRT_Column()ushort
  55.  
  56.     Returns the column the cursor is currently on.
  57.  
  58.     CRT_AbortEnable()void
  59.     CRT_AbortDisable()void
  60.  
  61.     These routines control how the various CRT input routines react when
  62.     a CONTROL-C is typed. The default case is to send the termination
  63.     sequence and return to the operating system. This can be disabled
  64.     by calling 'CRT_AbortDisable', in which case CONTROL-C will be
  65.     either ignored or returned to the caller, depending on which of the
  66.     input routines is in effect. 'CRT_AbortEnable' will re-enable the
  67.     normal abort procedure. It is suggested that aborting not be
  68.     disabled on a program that is under development, since it is often
  69.     handy to be able to abort such programs.
  70.  
  71.     CRT_GetChar()char
  72.  
  73.     This call returns a character typed by the user. The character will
  74.     not appear on the screen, and no processing whatsoever will have
  75.     been done on the character.
  76.  
  77.     CRT_PutChar(char ch)void
  78.  
  79.     The passed character is displayed on the screen at the current
  80.     position. If you have not selected a position yet, then the character
  81.     will appear to the right of the previous character on the screen.
  82.     If the terminal cannot display lower case letters, they will be
  83.     translated into upper case.
  84.  
  85.     CRT_PutChars(*char charsPtr)void
  86.  
  87.     The passed 'chars' value is displayed on the screen.
  88.  
  89.     CRT_ClearScreen()void
  90.  
  91.     The entire screen will be cleared and the cursor will be left in the
  92.     top left-hand corner of the screen.
  93.  
  94.     CRT_ClearLine(ushort line)void
  95.  
  96.     The selected line will be cleared and the cursor will be left at the
  97.     beginning of that line. Note that both lines and columns are numbered
  98.     starting with 0. Thus, the last line on a terminal with 24 lines is
  99.     line number 23.
  100.  
  101.     CRT_ClearTail()void
  102.  
  103.     The current line, from the cursor column to the end of the line, will
  104.     be cleared to spaces. The position of the cursor will be unchanged.
  105.  
  106.     CRT_ClearToEnd(ushort line)void
  107.  
  108.     All lines on the screen from the selected line onward will be
  109.     cleared. The cursor will be left at the beginning of the selected
  110.     line.
  111.  
  112.     CRT_Move(ushort line, col)void
  113.  
  114.     The cursor will be moved to the selected line and column (both are
  115.     0 - origin). Any character output to the screen will appear at that
  116.     position.
  117.  
  118.     CRT_EnterHighLight()void
  119.  
  120.     If the terminal has a reverse video or other accentuation mode, then
  121.     that mode is entered, in that all characters output subsequently
  122.     will appear in that mode.
  123.  
  124.     CRT_ExitHighLight()void
  125.  
  126.     The accentuation of characters (if any) is stopped. All characters
  127.     output subsequently will appear in the normal style.
  128.  
  129.     CRT_Chars(*char charsPtr)void
  130.  
  131.     This routine provides a primitive text-formatting capability within
  132.     the screen of the terminal. The chars value passed can contain
  133.     carriage returns and linefeeds to direct the formatting. The lines
  134.     of text passed will be split up on the spaces between words so that
  135.     each line fits on a screen line. The text will not be right
  136.     justified, however. A sequence of more than one blank will be
  137.     preserved in the output (this is used for paragraph indentation,
  138.     etc.) When all but two lines of the screen have been filled, the
  139.     message 'Press SPACE to continue' will be centered in the bottom
  140.     line, and the routine will wait for the user to enter a space. This
  141.     routine is designed to ease the presentation of on-screen help
  142.     information and user instructions.
  143.  
  144.     CRT_Continue()void
  145.  
  146.     The last line on the screen is cleared, and the message 'Press
  147.     SPACE to continue' will be centered in it. CRT_Continue will not
  148.     return until the user enters a space. This routine can be used to
  149.     give the user time to read or examine some information, before going
  150.     on to another screen of data. The last line is cleared after the
  151.     user enters a space.
  152.  
  153.     CRT_Ask(*chars question)bool
  154.  
  155.     The last line on the screen is cleared, and the passed chars value
  156.     is displayed on that line. The user must then enter a 'y', 'Y', 'n',
  157.     or 'N'. The result from CRT_Ask is 'true' if the user entered a 'y'
  158.     or 'Y', and 'false' if the user entered a 'n' or 'N'. The last line
  159.     is cleared following the user's reply. 
  160.  
  161.     CRT_Scroll()void
  162.  
  163.     The screen is scrolled up one line, i.e. the top line is lost, all
  164.     others are moved up one line, and the last is left empty. The cursor
  165.     is left at the beginning of the new empty line.
  166.  
  167.     CRT_Center(ushort line; *char message)void
  168.  
  169.     The given message is displayed centered on the given line.
  170.  
  171.     CRT_Abort()void
  172.  
  173.     The termination sequence is sent to the terminal, and the program is
  174.     terminated.
  175.  
  176.     CRT_Reset()void
  177.  
  178.     The initialization sequence (if any) is sent to the terminal. This,
  179.     in conjunction with a full redraw of the screen, can be done to
  180.     recover from terminal failures, transmission errors, etc.
  181.  
  182.     CRT_Reply1(*char buffer; ushort length; *char prompt)void
  183.  
  184.     The screen is cleared, the prompt is displayed on line 6, and a
  185.     reply from the user (up to the given maximum length) is read into
  186.     the buffer. When entering the reply, the normal editing characters
  187.     (backspace to delete characters, CONTROL-X to delete the entire
  188.     line) are available. The input is terminated with a carriage return.
  189.     The data in the input buffer will always be terminated with a '\e'.
  190.  
  191.     CRT_Reply2(*char buffer; ushort length; *char prompt)void
  192.  
  193.     This is the same as CRT_Reply1, except that the screen is not cleared
  194.     and the question is asked on the last line of the screen.
  195.  
  196.     CRT_GetLine(*char buffer; ushort length)void
  197.  
  198.     An input reply is read, without any additional output being done.
  199.  
  200.     CRT_Read(*char buffer; ushort length; bool skipNext, skipPrev;
  201.          *char terminators, terminator)bool
  202.  
  203.     This is the bottom level input routine used by the above and also
  204.     by the form routines. 'skipNext' enables the termination of input
  205.     when the buffer is full. 'skipPrev' enables a return with an empty
  206.     buffer if the user backspaces past the beginning of the input.
  207.     'terminators' is a string containing the characters other than
  208.     carriage return and linefeed which are allowed to terminate the
  209.     input. 'terminator' returns the termination character that the user
  210.     used. 'true' is returned if the user typed any characters other than
  211.     a terminator. Note that while allowing user input, CONTROL-C aborts
  212.     are only active when the cursor is in the first column of the input.
  213.     This minimizes accidental aborts, but still allows the most common
  214.     use of them.
  215.  
  216.     CRT_Random(word randomRange)word
  217.  
  218.     The CRT routines maintain an internal random number seed, based on
  219.     a counter which spins while waiting for the user to type keys. This
  220.     routine uses that counter as a seed and returns a pseudo-random
  221.     number between 0 and the passed range.
  222.  
  223.     CRT_NonRandom(word seed)void
  224.  
  225.     This routine disables the above-mentioned counter and sets the seed
  226.     to the specified value.
  227.  
  228.     CRT_Error(*char message)void
  229.  
  230.     The given message is displayed on the last line of the screen, and
  231.     an internal flag is set, indicating the presence of an error message.
  232.  
  233.     CRT_ClearError()void
  234.  
  235.     If an error message is present, this routine clears it. A typical
  236.     sequence is to call 'CRT_Error' when something goes wrong, and just
  237.     continue with other processing. Eventually, an input routine will be
  238.     called to get input (often CRT_GetChar in cases where this is most
  239.     useful). After that routine returns with some input, CRT_ClearError
  240.     is called to clear any error. This ensures that the user has had a
  241.     chance to see the error message.
  242.  
  243.     CRT_Menu(*char menu)ushort
  244.  
  245.     This routine displays a menu on the screen, lets the user select an
  246.     entry from it, and returns the 1-origin index of the selected entry.
  247.     User errors are handled using CRT_Error and CRT_ClearError. The
  248.     screen will NOT be cleared on exit, thus giving the user something
  249.     to look at while the computer is off doing whatever it is doing.
  250.     The menu structure passed consists of: zero or more lines of header
  251.     information, separated by carriage returns and/or linefeeds, a '\e',
  252.     one or more menu entries, each terminated by '\e', and a final '\e'.
  253.     CRT_Menu will insert one or two digit indices in front of the menu
  254.     entries, so they should not be given explicitly. An example call:
  255.  
  256.         which := CRT_Menu(
  257.         "This is the first header line\n"
  258.         "\n"
  259.         "This is a second (spaced down) header line\e"
  260.         "menu item number 1\e"
  261.         "menu item number 2\e"
  262.         "menu item number 3\e"
  263.         );
  264.  
  265.     The final '\e' need not be given explicitly, since the compiler 
  266.     puts one at the end of all string constants. If the user makes no 
  267.     selection, i.e. just hits return, then 0 is returned, else the 
  268.     index of the selected entry is returned. The header lines are 
  269.     automatically centered within their lines, and the spacing of the
  270.     menu items is governed by their number and the screen size.
  271.  
  272.     The following routines are part of a simple but effective forms entry
  273. system. Using them and the above CRT_Menu routine, fairly fancy "user-
  274. friendly" applications can be written without a lot of the grunge work that
  275. is normally needed. The form routines are included in the CRT library, but
  276. additional include file 'FORM.G' should be included to get declarations of
  277. them and of values they use.
  278.  
  279.     CRT_FormStart()
  280.  
  281.     This routine is called to start the definition of a form. Any 
  282.     existing form is thrown away.
  283.  
  284.     CRT_FormInt(ushort line, column, length; *char heading;
  285.         *bool pChanged; *int resultPointer;
  286.         proc (int n)bool checker)void
  287.  
  288.     This adds an integer field to the current input form. The line and 
  289.     column are of the header message that will appear to the left of 
  290.     the actual input area. 'length' is the number of spaces to be 
  291.     allowed for input of the number. The bool pointed to by 'pChanged' 
  292.     will be set if the user changes this field. 'resultPointer' points 
  293.     at the variable containing both the initial value to be displayed
  294.     in the field, and the final value as modified by the user. The 
  295.     'checker' routine is called when the user terminates input for 
  296.     this field. It is passed the current value of the input integer. If 
  297.     it returns 'true', that value is accepted, else it should have 
  298.     displayed a message using 'CRT_Error', and the user will have to 
  299.     change the value. This routine had better work right, or the user 
  300.     might not have any way to enter a value which IS accepted. 
  301.  
  302.     CRT_FormIntOK(int n)bool
  303.  
  304.     This is a dummy int checker routine that just returns 'true'.
  305.  
  306.     CRT_FormChars(ushort line, column, length; *char heading;
  307.           *bool pChanged; *char buffer;
  308.           proc (*char value)bool checker)void
  309.  
  310.     This adds a string field to the current input form in a way totally
  311.     analagous to 'CRT_FormInt'. 'buffer' points at a buffer which
  312.     contains the initial value, and into which the final value is placed.
  313.  
  314.     CRT_FormRead(*char header; byte flags; *char terminators)char
  315.  
  316.     This routine presents and handles the input form specified by calls
  317.     to the previous routines. 'header' is a (possibly multiline) header
  318.     that is to be displayed at the top of the screen. As with CRT_Menu,
  319.     the header lines will be centered on the screen. 'flags' consists of
  320.     any combination of the following (defined in FORM.G):
  321.  
  322.         FORMHEADERS = 0x01 - specifies that the form and field headers
  323.         are to be displayed on this call. If the same form is used
  324.         several times in succession, much annoying screen I/O is
  325.         avoided if only the first use has FORMHEADERS set.
  326.         FORMSKIP = 0x02 - enables automatic skipping from one field to
  327.         the next at the end of a field and skipping from one field
  328.         to the previous when a backspace is typed at the beginning
  329.         of a field.
  330.         FORMINPUT = 0x04 - enables the input of data to the fields.
  331.         A call without this flag is useful for nicely displaying
  332.         the information.
  333.         FORMOUTPUT = 0x08 - enables all displaying associated with the
  334.         input form. Output is not needed if the program knows that
  335.         the current screen contents is correct. This could be from,
  336.         say, the user asking to edit the current record during a
  337.         browse of a set of records. (The browse would use CRT_GetChar
  338.         to input the browsing commands, one of which would request
  339.         the edit.)
  340.  
  341.     Parameter 'terminators' is a string containg the characters that
  342.     are to be recognized as field terminators. CRT_FormRead recognizes
  343.     the following as special:
  344.  
  345.         CONTROL-R - undo changes to the current field
  346.         CONTROL-Q - quick exit with fields as they appear
  347.         CONTROL-Z - cancel all changes and redraw the fields
  348.         ESCAPE - cancel all changes, redraw the fields, and exit
  349.  
  350.     These special functions are enabled by including the corresponding
  351.     characters in the 'terminators' string. 'FORM.G' declares a string
  352.     constant, 'TERMINATORS', containing just these terminators.
  353.     CRT_FormRead returns the terminator character which the user typed
  354.     to terminate form input. Note that CRT_FormRead uses CRT_ClearError
  355.     and the storage allocator (for structures and backup buffers).
  356.  
  357.     The screen is NOT cleared either before or after the the form is
  358.     displayed and read. The programmer is responsible for this. This is
  359.     done so that a form can appear in a small section of the screen. For
  360.     example, the screen might be divided into two parts, each of which
  361.     is used as an input form for different, but related data. Careful
  362.     use of the flags can result in a very clean use of screen updates.
  363.