home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / pascal / pasdox / char.txt < prev    next >
Text File  |  1985-11-18  |  9KB  |  240 lines

  1. { -----------------------------------------------------------------------------
  2.  
  3.                                  NOTICE:
  4.  
  5.       THESE MATERIALS are UNSUPPORTED by OSS!  If you do not understand how to
  6.       use them do not contact OSS for help!  We will not teach you how to 
  7.       program in Pascal.  If you find an error in these materials, feel free
  8.       to SEND US A LETTER explaining the error, and how to fix it.
  9.  
  10.       THE BOTTOM LINE:
  11.  
  12.          Use it, enjoy it, but you are on your own when using these materials!
  13.  
  14.  
  15.                                DISCLAIMER:
  16.  
  17.       OSS makes no representations or warranties with respect to the contents
  18.       hereof and specifically disclaim all warranties of merchantability or
  19.       fitness for any particular purpose.   This document is subject to change
  20.       without notice.
  21.       
  22.       OSS provides these materials for use with Personal Pascal.  Use them in
  23.       any way you wish.
  24.  
  25.    -------------------------------------------------------------------------- }
  26.  
  27.  
  28.  
  29.  
  30.  
  31. Character I/O                                                           Page 1
  32.  
  33.                           Character Input and Output
  34.  
  35. The  ST  supports  five  character  oriented devices.  Of these five, you will
  36. probably only use four, the printer port, the RS232 port, the MIDI  port,  and
  37. the  keyboard/console.   The  other  device  is  the internal data path to the
  38. intelligent keyboard unit (which handles the mouse and joysticks, as  well  as
  39. the keyboard); you will seldom, if ever, need to access that device directly!
  40.  
  41. One  of  the most common operations on character oriented devices is reading a
  42. single character.  The following few routines perform that function:
  43.  
  44. Read character from standard input.
  45.  
  46. FUNCTION conin : Long_Integer ;
  47.   GEMDOS( 1 ) ;
  48.  
  49. This call waits for a character to be typed from  the  standard  input  device
  50. (normally  the  keyboard),  echoes  it  to  the  standard output (normally the
  51. screen), and returns the character thus read in the same manner as the  bconin
  52. BIOS  call.   This  call  should only be used from a TOS application.  You can
  53. also get a character from the standard input by Reading  characters  from  the
  54. standard  file  Input,  which  is  equivalent to using this routine.  In fact,
  55. unless you have a real need to use the routines described here, it is  usually
  56. better to use built-in Pascal methods.
  57.  
  58. Get a character from the auxilliary (RS232) device.
  59.  
  60. FUNCTION auxin : Integer ;
  61.   GEMDOS( 3 ) ;
  62.  
  63. If  you  want  characters  from the RS232 device, use this routine.  Since the
  64. characters returned by this call are only 8 bits, the return value is only  an
  65. Integer.
  66.  
  67. Get character from character-oriented device.
  68.  
  69. This  next  routine  is  the underlying BIOS call which can be used to perform
  70. input from any of the five devices.  You should normally use one of the  above
  71. GEMDOS  calls  whenever  possible,  but if you need to get input from the MIDI
  72. port, for example, you will need this routine:
  73.  
  74. FUNCTION bconin( device : Integer ) : Long_Integer ;
  75.   BIOS( 2 ) ;
  76.  
  77. This function  returns  a  character  from  the  specified  character-oriented
  78. device.  The valid values for the device parameter are as follows:
  79.  
  80. 0  printer port (not used for input)
  81. 1  RS232 port
  82. 2  keyboard
  83. 3  MIDI port
  84. 4  intelligent keyboard (don't use!)
  85.  
  86. If no character was waiting when bconin was called, it waits until a character
  87. is  available.   If  you  don't  want  to wait for characters, you should call
  88. bconstat  first,  to  determine  that   a   character   is   available.    The
  89. bconin  function  returns  the character value in the low byte of the returned
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. Character I/O                                                           Page 2
  98.  
  99. Long_Integer.  If the specified device is the console (device 2), however, the
  100. return value is more complex.  In that case, the keyboard scancode is returned
  101. in the upper word, and the ASCII equivalent (if any) is returned in the  lower
  102. word.
  103.  
  104. If  you  only  want  the Integer return value, and you want to assign it to an
  105. Integer variable, remember that you must use  the  built-in  function  Int  to
  106. convert from a Long_Integer to an Integer.
  107.  
  108.  
  109.  
  110. You  may  wish to find out whether a character is available before calling one
  111. of the character input routines.  Just as we  saw  above,  there  are  several
  112. calls designed to get that status:
  113.  
  114. Get status of standard input.  Don't use this one!!!
  115.  
  116. FUNCTION c_conis : boolean ;
  117.   GEMDOS( 11 ) ;
  118.  
  119. This routine is supposed to return True if at least one character is available
  120. on  the standard input device (normally the keyboard).  If the keyboard buffer
  121. ever gets  full,  however,  this  routine  ceases  to  work  properly,  always
  122. returning True.  For this reason, we recommend you use the bconstat BIOS call,
  123. instead.
  124.  
  125. Get status of auxilliary (RS232) port.
  126.  
  127. FUNCTION auxstat : Boolean ;
  128.   GEMDOS( 18 ) ;
  129.  
  130. This  call returns True, if at least one character is ready for input from the
  131. RS232 port, and False, otherwise.
  132.  
  133. If you need to get the input status of the MIDI port or the keyboard  (because
  134. of  the  bug  in  constat,  above), you will have to use the following routine
  135. which is the underlying BIOS call:
  136.  
  137. Character-oriented device input status
  138.  
  139. FUNCTION bconstat( device : Integer ) : Boolean ;
  140.   BIOS( 1 ) ;
  141.  
  142. This function expects the number of a character oriented device, as  described
  143. above (0-4).  It returns a True value if at least one character is waiting for
  144. input  and  False  otherwise.  If the device is the printer, however, there is
  145. one situation where the returned status will not be correct.  You  might  want
  146. to  define  your  own  special-purpose status routine as follows, so you don't
  147. have to insert the device except in one place:
  148.  
  149.   (* Return True, if there is a keyboard character waiting. *)
  150.   FUNCTION Char_Waiting : Boolean ;
  151.  
  152.     CONST
  153.       keyboard = 2 ;   (* Device number of the keyboard. *)
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163. Character I/O                                                           Page 3
  164.  
  165.     FUNCTION bconstat( device : Integer ) : Boolean ;
  166.       BIOS( 1 ) ;
  167.  
  168.     BEGIN
  169.       Char_Waiting := bconstat( keyboard ) ;
  170.     END ;
  171.  
  172.  
  173. Besides character input and input status, you also need  to  be  able  to  put
  174. characters to character devices.  The following routines allow those actions:
  175.  
  176. Write a character to the standard output.
  177.  
  178. PROCEDURE conout( c : Integer ) ;
  179.   GEMDOS( 2 ) ;
  180.  
  181. This  call  puts  a  character  to  the  standard  output device (normally the
  182. screen).  The effect is identical to Writeing characters to the standard  file
  183. Output.  You should only use this call from a TOS application.
  184.  
  185. Put character to character-oriented device.
  186.  
  187. PROCEDURE bconout( device, c : integer ) ;
  188.   BIOS( 3 ) ;
  189.  
  190. This  routine  writes  a  single  character  to  the specified device.  If the
  191. device's output buffer is full, the routine will wait until the  character  is
  192. actually  placed  in  the  buffer.   If you don't want to wait for output, you
  193. should call bcostat first, to determine that the device is  ready  to  receive
  194. the next character.
  195.  
  196. Character-oriented device output status.
  197.  
  198. FUNCTION bcostat( device : Integer ) : Boolean ;
  199.   BIOS( 8 ) ;
  200.  
  201. This  routine  checks  to  see whether the specified device is ready to accept
  202. another character.  It returns True, if the device is ready  to  receive,  and
  203. False  otherwise.   If the ST is powered up while the printer is off-line, the
  204. hardware does not detect the off-line condition.  The bcostat call will return
  205. True, in this case, even though the printer is not ready to accept  data.   As
  206. soon as the printer is turned on-line again, the status is correct.
  207.  
  208. Get status of standard print device.
  209.  
  210. FUNCTION c_prnos : Boolean ;
  211.   GEMDOS( 17 ) ;
  212.  
  213. This  call  returns  True  if  the  printer is available to accept characters,
  214. False otherwise.  However, as mentioned in the section about the bcostat  BIOS
  215. call, the ST hardware cannot detect an off-line condition if the ST is powered
  216. up  while  the  printer  is off-line.  In this situation, the c_prnos function
  217. will erroneously return True.
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229. Character I/O                                                           Page 4
  230.  
  231. Check output status of auxilliary device (RS232).
  232.  
  233. FUNCTION c_auxos : Boolean ;
  234.   GEMDOS( 19 ) ;
  235.  
  236. This routine returns True, if the standard  auxilliary  device  (normally  the
  237. RS232  port) is ready to accept data, and False, otherwise.  If the auxilliary
  238. device is the RS232 port, this call will only return False if the RTS/CTS flow
  239. control method is used, and CTS goes to a false condition.
  240.