home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 16 / CD_ASCQ_16_0994.iso / news / 4608 / en160 / encomref.hlp < prev    next >
Text File  |  1993-01-31  |  50KB  |  1,251 lines

  1. `co(4,7);────────────────────────────── EnCom Functions ───────────────────────────────`co();
  2.  
  3.   `co(12,?);Core Functions          Extended Functions       Message Functions`co();
  4.   `keyword(A) com_config,/// com_config);           `keyword(M) com_getc_qty,/// com_getc_qty);          `keyword(Z) encrypt_msg,/// encrypt_msg);
  5.   `keyword(B) com_port_create,/// com_port_create);      `keyword(N) com_ungetc,/// com_ungetc);            `keyword(A) calc_crc,/// calc_crc);
  6.   `keyword(C) com_port_init,/// com_port_init);        `keyword(O) com_stuffc,/// com_stuffc);            `keyword(B) fmt_msg,/// fmt_msg);
  7.   `keyword(D) com_port_destroy,/// com_port_destroy);     `keyword(P) com_gets,/// com_gets);              `keyword(C) defmt_msg,/// defmt_msg);
  8.   `keyword(E) com_clear_que,/// com_clear_que);        `keyword(Q) com_putc_qty,/// com_putc_qty);          `keyword(D) get_msg,/// get_msg);
  9.   `keyword(F) com_getc,/// com_getc);             `keyword(R) send_break,/// send_break);            `keyword(E) mk_crc_tbl,/// mk_crc_tbl);
  10.   `keyword(G) com_putc,/// com_putc);             `keyword(S) set_xon_flow,/// set_xon_flow);          
  11.   `keyword(H) com_puts,/// com_puts);             `keyword(T) set_dcd_flow,/// set_dcd_flow);          `co(12,?);Keyboard/Timer/16550`co(); 
  12.   `keyword(I) prime_tx,/// prime_tx);             `keyword(U) set_dsr_flow,/// set_dsr_flow);          `keyword(F) init_ctrlc_hdlr,/// init_ctrlc_hdlr);
  13.   `keyword(J) force_tx,/// force_tx);             `keyword(V) suspend,/// suspend);               `keyword(G) end_ctrlc_hdlr,/// end_ctrlc_hdlr);
  14.   `keyword(K) com_irq_ctrl,/// com_irq_ctrl);         `keyword(W) wait_for_rx,/// wait_for_rx);           `keyword(H) init_clock,/// init_clock);
  15.   `keyword(L) com_232_ctrl,/// com_232_ctrl);         `keyword(X) wait_for_no_rx,/// wait_for_no_rx);        `keyword(I) end_clock,/// end_clock);
  16.                           `keyword(Y) modem_cmd,/// modem_cmd);             `keyword(J) tone,/// tone);
  17.                                                    `keyword(K) sound_off,/// sound_off);
  18.                                                    `keyword(L) set_idle_func,/// set_idle_func);
  19.                                                    `keyword(M) com_fifo_trigger,/// com_fifo_trigger);
  20.                                                    `keyword(N) com_fifo_ctrl,/// com_fifo_ctrl);
  21.  
  22. `co(10,1);/// com_config`co();      `keyword(source,[EN_MAIN.C]~com_config);
  23.     allows the user to "customize" the comm port configuration such as base
  24.     address and interrupt vector.  It is called before `keyword(com_port_create,/// com_port_create); to
  25.     specify an alternative base address or IRQ for the port.  Use -1 to
  26.     specify the default value for either the base address or IRQ.  This allows
  27.     great flexibility in port configuration.
  28.  
  29. Prototype:
  30.   int com_config( int chan, int base_addr, int irq );
  31.  
  32. Parameters:
  33. `co(11,1);  int chan`co();
  34.     The comm port channel COM1-COM4.
  35. `co(11,1);  int base_addr`co();
  36.     The I/O base address for this UART (-1 for default).
  37. `co(11,1);  int irq`co();
  38.     The hardware interrupt for this UART (-1 for default).
  39.  
  40. Usage:
  41.   PORT *cp = calloc(1, sizeof(PORT));
  42.   ...
  43.     com_config(COM3, 0x6f8, 5);
  44.   com_port_create(COM3, 2400L, 'N', 8, 1, 2048, 2048, cp);        
  45.  
  46. `co(10,1);/// com_port_create`co();      `keyword(source,[EN_MAIN.C]~com_port_create);
  47.     creates the port, initializing it to the values passed as parameters.
  48.   If the function returns a 0, then the port was created, UART initialized,
  49.   and transmit and receive queues allocated.  A negative number is returned
  50.   on error.
  51.  
  52.   Error Code    Meaning
  53.   -1            Cannot access device.
  54.   -2            Could not allocate receive queue.
  55.   -3            Could not allocate transmit queue.
  56.   -4            Invalid format parameters (baud, parity, data or stop bits).
  57.   -5            Invalid channel (COM1-4).
  58.  
  59.   See also `keyword(com_port_destroy,/// com_port_destroy);
  60.  
  61. Prototype:
  62.   int com_port_create( int chan, long baud, int parity, int data_bits,
  63.                        int stop_bits, int rx_size, int tx_size, PORT *cp );
  64.  
  65. Parameters:
  66. `co(11,1);  int chan`co();
  67.     The channel number #define.  The valid channel defines are COM1, COM2,
  68.     COM3, and COM4.
  69. `co(11,1);  long baud`co();
  70.     The initial baud rate.  A baud rate of 19.2K would be 19200L.
  71. `co(11,1);  int parity`co();
  72.     The initial parity.  Use the character 'N' for none, 'E' for even, 'O'
  73.     for odd, 'M' for mark, and 'S' for space.
  74. `co(11,1);  int data_bits`co();
  75.     The number of data bits per character, and can be from 5 to 8.
  76. `co(11,1);  int stop_bits`co();
  77.     The number of stop bits per character, either 1 or 2.
  78. `co(11,1);  int rx_size`co();
  79.     The size of the receive queue, up to 64K.
  80. `co(11,1);  int tx_size`co();
  81.     The size of the transmit queue, up to 64K.
  82. `co(11,1);  PORT *cp`co();
  83.     A pointer to a PORT structure.  The PORT structure must be either a
  84.     global variable, or a previously allocated structure.  Do NOT pass
  85.     an uninitialized pointer to the function as this routine clears
  86.     the structure!
  87.  
  88. Usage:
  89.   PORT *cp = calloc(1, sizeof(PORT));
  90.   ...
  91.   if( comm_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  92.   {
  93.     ...
  94.   }
  95.  
  96. `co(10,1);/// com_port_init`co();      `keyword(source,[EN_MAIN.C]~com_port_init);
  97.     initializes the port structure and UART, but does not allocate the
  98.   receive or transmit queues.  This function is called internally by
  99.   `keyword(com_port_create,/// com_port_create); to do the actual initialization.  You may call this
  100.   function any time after com_port_create to change the port parameters
  101.   without affecting the queues and is easier than the alternative of having
  102.   to call com_port_destroy followed by com_port_create.  Like com_port_create
  103.   a 0 is returned on success and a negative number on failure.
  104.  
  105.   Error Code    Meaning
  106.   -1            Invalid parity (N, O, E, M, or S).
  107.   -2            Invalid number of data bits (5, 6, 7, or 8).
  108.   -3            Invalid number of stop bits (1, or 2).
  109.  
  110.     You can use this function to change the data format within your program
  111.     at any time with no ill effect.
  112.  
  113. Prototype:
  114.   int com_port_init( long baud, int parity, int data_bits, int stop_bits,
  115.                      PORT *cp );
  116. Parameters:
  117. `co(11,1);  long baud`co();
  118.     The new baud rate.
  119. `co(11,1);  int parity`co();
  120.     The new parity.  Use the character 'N' for none, 'E' for even, 'O'
  121.     for odd, 'M' for mark, and 'S' for space.
  122. `co(11,1);  int data_bits`co();
  123.     The new number of data bits per char (5 to 8).
  124. `co(11,1);  int stop_bits`co();
  125.     The new number of stop bits per char (1 or 2).
  126. `co(11,1);  PORT *cp`co();
  127.     A pointer to a PORT structure.  The PORT structure must be either a
  128.     global variable, or a previously allocated structure.  Do NOT pass
  129.     an uninitialized pointer to the function.
  130.  
  131. Usage:
  132.   PORT *cp = calloc(1, sizeof(PORT));
  133.   ...
  134.   if( comm_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  135.   {
  136.     ...
  137.     com_port_init(2400L, 'E', 7, 1, cp);
  138.   }
  139.  
  140. `co(10,1);/// com_port_destroy`co();      `keyword(source,[EN_MAIN.C]~com_port_destroy);
  141.     destroys the port created with `keyword(com_port_create,/// com_port_create);.  The transmit and
  142.   receive queues are freed, and the port structure set to inactive.  Be
  143.   sure to use this function to destroy any ports you create.
  144.  
  145. Prototype:
  146.   void com_port_destroy( PORT *cp );
  147.  
  148. Parameters:
  149. `co(11,1);  PORT *cp`co();
  150.     A pointer to the PORT structure used in com_port_create.
  151.  
  152. Usage:
  153.   PORT *cp = calloc(1, sizeof(PORT));
  154.   ...
  155.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  156.   {
  157.     ...
  158.     com_port_destroy(cp);
  159.   }
  160.  
  161. `co(10,1);/// com_clear_que`co();      `keyword(source,[EN_MAIN.C]~com_clear_que);
  162.     can be use to clear either the port receive queue, the port transmit
  163.   queue, or both.
  164.  
  165. Prototype:
  166.   void com_clear_que( int mode, PORT *cp );
  167.  
  168. Parameters:
  169. `co(11,1);  int mode`co();
  170.     The queue or queues to clear.  Use the defines RX and TX to indicate
  171.   the queue.  To specify both queues, use RX | TX.
  172. `co(11,1);  PORT *cp`co();
  173.     A pointer to the PORT structure used in com_port_create.
  174.  
  175. Usage:
  176.   PORT *cp = calloc(1, sizeof(PORT));
  177.   ...
  178.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  179.   {
  180.     ...
  181.     com_clear_que( RX | TX, cp);
  182.   }
  183.  
  184. `co(10,1);/// com_getc`co();      `keyword(source,[EN_MAIN.C]~com_getc);
  185.     is used to get a character from the port receive queue.  If there is
  186.   no data in the receive queue, that is the rx_cnt member of the port
  187.   structure is 0, then -1 is returned.  If there is data in the receive
  188.   queue, then the next byte is returned. Please note that you can
  189.   check for a queue empty condition, by directly accessing the rx_cnt
  190.   variable of the port structure or using the com_rx_cnt macro.  If 
  191.   "queue status" mode is enabled, com_getc will return an integer, the
  192.   low byte is the character and the high byte is the status. Note that
  193.   it is possible for com_getc to return a -1 as a valid char/status
  194.   combination in this mode.  To prevent this, simply be sure to check
  195.   for data (using com_rx_cnt) before calling com_getc.
  196.  
  197. Prototype:
  198.   int com_getc( PORT *cp );
  199.  
  200. Parameters:
  201. `co(11,1);  PORT *cp`co();
  202.     The PORT pointer from which to receive.
  203.  
  204. Usage:
  205.   PORT *cp = calloc(1, sizeof(PORT));
  206.   int  next_byte;
  207.   ...
  208.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  209.   {
  210.     ...
  211.     if (com_rx_cnt(cp) > 0)
  212.       next_byte = com_getc(cp);
  213.   }
  214.  
  215. `co(10,1);/// com_putc`co();      `keyword(source,[EN_MAIN.C]~com_putc);
  216.     is used to put a character into the port transmit queue.  If there is
  217.   no room left in the queue, then the port member overflow is incremented
  218.   and a -1 is returned.  If the byte is queued, then 0 is returned.
  219.   Since EnCom is both receive and transmit interrupt driven, no other
  220.   function is necessary for the byte to be transmitted!
  221.  
  222. Prototype:
  223.   int com_putc( int c, PORT *cp );
  224.  
  225. Parameters:
  226. `co(11,1);  int c`co();
  227.     The byte to put into the transmit queue.
  228. `co(11,1);  PORT *cp`co();
  229.     The PORT pointer for transmission.
  230.  
  231. Usage:
  232.   PORT *cp = calloc(1, sizeof(PORT));
  233.   ...
  234.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  235.   {
  236.     ...
  237.     com_putc('A', cp);
  238.   }
  239.  
  240. `co(10,1);/// com_puts`co();      `keyword(source,[EN_MAIN.C]~com_puts);
  241.     is used to put a string into the port transmit queue.
  242.  
  243. Prototype:
  244.   int com_puts( uchar *s, PORT *cp );
  245.  
  246. Parameters:
  247. `co(11,1);  uchar *s`co();
  248.     The string to transmit.
  249. `co(11,1);  PORT *cp`co();
  250.     The PORT pointer for transmission.
  251.  
  252. Usage:
  253.   PORT *cp = calloc(1, sizeof(PORT));
  254.   ...
  255.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  256.   {
  257.     ...
  258.     com_puts("ATDT1-816-353-0991\r", cp);
  259.   }
  260.  
  261. `co(10,1);/// prime_tx`co();      `keyword(source,[EN_MAIN.C]~prime_tx);
  262.     "kick starts" the transmit interrupt by disabling then re-enabling the
  263.   THRE (transmit holding register empty) IRQ bit.  This causes the UART to
  264.   generate a THRE interrupt, and start transmission of the bytes that are in
  265.   the queue.  This function is used internally by the library (in `keyword(com_putc,/// com_putc);),
  266.   and is documented for those of you who wish to understand the internal
  267.   workings of the library.
  268.  
  269. Prototype:
  270.   void prime_tx( PORT *cp );
  271.  
  272. Parameters:
  273. `co(11,1);  PORT *cp`co();
  274.     The PORT pointer to "kick start".
  275.  
  276. Usage:
  277.   PORT *cp = calloc(1, sizeof(PORT));
  278.   ...
  279.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  280.   {
  281.     ...
  282.     if( !cp->tx_on )
  283.       cp->tx_on = ON, prime_tx(cp);
  284.   }
  285.  
  286. `co(10,1);/// force_tx`co();      `keyword(source,[EN_MAIN.C]~force_tx);
  287.     forces the character passed to be transmitted without going through
  288.   the usual queueing and interrupt-driven transmission.  It does check
  289.   to see if the UART is ready for the character.  If the character is
  290.   transmitted, a 1 is returned.  If the UART is not ready, the function
  291.   tries for 1 second, and returns 0 if the byte could not be sent.
  292.   This routine will only work if `keyword(init_clock,/// init_clock); has been called.
  293.  
  294. Prototype:
  295.   force_tx( int c, PORT *cp );
  296.  
  297. Parameters:
  298. `co(11,1);  int c`co();
  299.     The byte to transmit.
  300. `co(11,1);  PORT *cp`co();
  301.     The PORT pointer for transmission.
  302.  
  303. Usage:
  304.   PORT *cp = calloc(1, sizeof(PORT));
  305.   init_clock(0x3333);
  306.   ...
  307.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  308.   {
  309.     ...
  310.     force_tx( 'A', cp);
  311.   }
  312.  
  313. `co(10,1);/// com_irq_ctrl`co();      `keyword(source,[EN_MAIN.C]~com_irq_ctrl);
  314.     enables or disables the comm interrupts.  This function is used in
  315.   the library internally by `keyword(com_vect_init,/// com_vect_init);, and will not be called by the
  316.   programmer under most circumstances. The current state of the Interrupt
  317.   Enable register is returned.  You can "or" several value together to
  318.   enable/disable several interrupts at once;  the other bits will not be 
  319.   affected.
  320.  
  321. Prototype:
  322.   int com_irq_ctrl( int state, int mask, PORT *cp );
  323.  
  324. Parameters:
  325. `co(11,1);  int state`co();
  326.     The state to use, 0 for off and 1 for on.  You may use the defines ON
  327.     and OFF.
  328. `co(11,1);  int mask`co();
  329.     The IRQ bits to set.  The bits are defined as DR_IRQ, THRE_IRQ,
  330.     RLS_IRQ and MS_IRQ.
  331. `co(11,1);  PORT *cp`co();
  332.     The PORT pointer for IRQ control.
  333.  
  334. Usage:
  335.   PORT *cp = calloc(1, sizeof(PORT));
  336.   ...
  337.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  338.     com_irq_ctrl(ON, DR_IRQ | THRE_IRQ, cp);
  339.  
  340. `co(10,1);/// com_232_ctrl`co();      `keyword(source,[EN_MAIN.C]~com_232_ctrl);
  341.     turns on or off the control lines DTR, RTS, OUT1, OUT2 and LOOP.  The
  342.   combined state is returned.  To set several at once, simply "or" the
  343.   defines together.  This function is called internally by the library in
  344.   `keyword(com_port_init,/// com_port_init); to set DTR , RTS, & OUT2 on by default.
  345.     NOTE: OUT2 is used to mask interrupts from the serial board on many PC's.
  346.     If this is not set, or is cleared, interrupts generated by the UART will
  347.     not "get through" to the PC.  This is something to watch for when doing
  348.     a LOOP diagnostic check.  Since the UART "disconnects" all of these lines
  349.     from the outside world, the PC will stop getting interrupts, even though
  350.     the UART is trying to generate them.  Therefore, the loopback mode may not
  351.     work on some PC's, at least as far as interrupts go.
  352.  
  353. Prototype:
  354.   void com_232_ctrl( int state, int mask, PORT *cp );
  355.  
  356. Parameters:
  357. `co(11,1);  int state`co();
  358.     The state to set, 0 for off and 1 for on.  You may use the defines ON
  359.     and OFF.
  360. `co(11,1);  int mask`co();
  361.     The RS232 control bits to set.  The bits are defined as DTR, RTS,
  362.     OUT1, OUT2, and LOOP.
  363. `co(11,1);  PORT *cp`co();
  364.     The PORT pointer for RS232 control.
  365.  
  366. Usage:
  367.   PORT *cp = calloc(1, sizeof(PORT));
  368.   ...
  369.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  370.     com_232_ctrl(DTR | RTS, ON, cp);
  371.  
  372. `co(10,1);/// com_getc_qty`co();      `keyword(source,[EN_SUPP.C]~com_getc_qty);
  373.     is used to get one or more bytes from the port receive queue.  If there
  374.   is less than the requested number of bytes in the receive queue, then
  375.   a -1 is returned, otherwise a 1 is returned.  If "queue status" mode is
  376.   enabled, com_getc_qty will put char/status pairs into "data".  Note that
  377.   in this mode, "qty" will refer to char/status pairs, not bytes in the
  378.   queue, and the size of "data" must be large enough to hold both.
  379.  
  380. Prototype:
  381.   int com_getc_qty( uchar *data, uint qty, PORT *cp );
  382.  
  383. Parameters:
  384. `co(11,1);  uchar *data`co();
  385.     A pointer for storage of "qty" bytes/pairs of data from the receive
  386.     queue.
  387. `co(11,1);  uint qty`co();
  388.     The number of bytes/pairs to get from the queue.
  389. `co(11,1);  PORT *cp`co();
  390.     The PORT pointer to use.
  391.  
  392. Usage:
  393.   PORT *cp = calloc(1, sizeof(PORT));
  394.   uchar buffer[80];
  395.   ...
  396.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  397.   {
  398.     ...
  399.     com_getc_qty(buffer, 80, cp);
  400.   }
  401.  
  402. `co(10,1);/// com_ungetc`co();      `keyword(source,[EN_SUPP.C]~com_ungetc);
  403.     puts a character back into the receive queue.  If "queue status" mode is
  404.     in effect, the high 8 bits (the status) is also put back into the queue.
  405.     If no room for the character exists, -1 is returned, else, 0 is returned.
  406.     If you wish to put a character at the end of the receive queue (as opposed
  407.     to the beginning), use `keyword(com_stuffc,/// com_stuffc);.
  408.  
  409.   NOTE: This routine DOES NOT re-increment cp->msg_cnt.  Since it is the
  410.     responsibility of the caller to decrement this value, it is assumed that
  411.     if the character is being put back into the queue, the value was not
  412.     decremented.  It really doesn't matter who does it, but this gives the
  413.     most control to the caller.
  414.  
  415. Prototype:
  416.   int com_ungetc( int c, PORT *cp );
  417.  
  418. Parameters:
  419. `co(11,1);  int c`co();
  420.     The character to place back into the queue.
  421. `co(11,1);  PORT *cp`co();
  422.     The PORT pointer for the receive queue.
  423.  
  424. Usage:
  425.   PORT *cp = calloc(1, sizeof(PORT));
  426.   int  next_byte;
  427.   ...
  428.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  429.   {
  430.     ...
  431.     if (com_rx_cnt(cp) > 0)
  432.         {
  433.       next_byte = com_getc(cp);
  434.           if( next_byte == 'X' )
  435.               com_ungetc(next_byte, cp);
  436.       }
  437.   }
  438.  
  439. `co(10,1);/// com_stuffc`co();      `keyword(source,[EN_SUPP.C]~com_stuffc);
  440.     puts a character at the end of the receive queue.  If "queue status"
  441.     mode is in effect, the high 8 bits (the status) is also put into the
  442.     queue.  If no room for the character exists, -1 is returned, else, 0 is
  443.     returned.  This performs a similar function as `keyword(com_ungetc,/// com_ungetc);, except the
  444.     character is placed at the end of the queue, as opposed to the beginning.
  445.  
  446.   NOTE: This routine DOES NOT re-increment cp->msg_cnt.  Since it is the
  447.     responsibility of the caller to decrement this value, it is assumed that
  448.     if the character is being put back into the queue, the value was not
  449.     decremented.  It really doesn't matter who does it, but this gives the
  450.     most control to the caller.
  451.  
  452. Prototype:
  453.   int com_stuffc( int c, PORT *cp );
  454.  
  455. Parameters:
  456. `co(11,1);  int c`co();
  457.     The character to put at the end of the queue.
  458. `co(11,1);  PORT *cp`co();
  459.     The PORT pointer for the receive queue.
  460.  
  461. Usage:
  462.   PORT *cp = calloc(1, sizeof(PORT));
  463.   ...
  464.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  465.   {
  466.     ...
  467.     comm_stuffc(End_flag, cp);
  468.   }
  469.  
  470. `co(10,1);/// com_gets`co();      `keyword(source,[EN_SUPP.C]~com_gets);
  471.     is used to get a string from the port receive queue, stopping on the
  472.   passed byte, or until the passed quantity of bytes has been retrieved,
  473.   or the queue is empty.  The number of bytes retrieved is returned.
  474.   If the stop byte passed to the function is not 0, then the data will
  475.   not be null-terminated. As with com_getc_qty, if "queue status" mode
  476.   is enabled, "qty" char/status pairs will be returned.
  477.  
  478. Prototype:
  479.   int com_gets( uchar *data, uchar c, uint qty, PORT *cp );
  480.  
  481. Parameters:
  482. `co(11,1);  uchar *data`co();
  483.     A pointer for storage of the bytes of data from the receive queue.
  484. `co(11,1);  uchar c`co();
  485.     The stop byte.  Normally this would be 0, but it can be any value.
  486. `co(11,1);  uint qty`co();
  487.     The maximum number of bytes to get from the queue.  If the stop byte
  488.     is matched or the queue drains completely then the returned number
  489.     of bytes will be less than this quantity.
  490. `co(11,1);  PORT *cp`co();
  491.     The PORT pointer to use.
  492.  
  493. Usage:
  494.   PORT  *cp = calloc(1, sizeof(PORT));
  495.   uchar buffer[80];
  496.   int   total_rx;
  497.   ...
  498.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  499.   {
  500.     ...
  501.     total_rx = com_gets(buffer, 0, 80, cp);
  502.   }
  503.  
  504. `co(10,1);/// com_putc_qty`co();      `keyword(source,[EN_SUPP.C]~com_putc_qty);
  505.     is used to queue up qty bytes in the ports transmit queue, for
  506.   subsequent transmission via the interrupt routine.  If there is not enough
  507.   room in the transmit queue, a -1 is returned.  If the data was queued
  508.   successfully, a 0 is returned.
  509.  
  510. Prototype:
  511.   int com_putc_qty( uchar *data, uint qty, PORT *cp );
  512.  
  513. Parameters:
  514. `co(11,1);  uchar *data`co();
  515.     A pointer to the data to queue.
  516. `co(11,1);  uint qty`co();
  517.     The number of bytes of data to queue.
  518. `co(11,1);  PORT *cp`co();
  519.     The PORT pointer to use.
  520.  
  521. Usage:
  522.   PORT  *cp = calloc(1, sizeof(PORT));
  523.   ...
  524.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  525.   {
  526.     ...
  527.     com_putc_qty("THIS IS A TEST", 14, cp);
  528.   }
  529.  
  530. `co(10,1);/// send_break`co();      `keyword(source,[EN_SUPP.C]~send_break);
  531.     is used to set a break condition in the UART for a specified amount
  532.   of time.
  533.   This routine will only work if `keyword(init_clock,/// init_clock); has been called.
  534.  
  535. Prototype:
  536.   void send_break( int t, PORT *cp );
  537.  
  538. Parameters:
  539. `co(11,1);  int t`co();
  540.     The number of timer ticks the condition is to be held.
  541. `co(11,1);  PORT *cp`co();
  542.     The PORT pointer for the break.
  543.  
  544. Usage:
  545.   PORT  *cp = calloc(1, sizeof(PORT));
  546.   ...
  547.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  548.   {
  549.     ...
  550.     send_break(Tics_per_sec * 2, cp);              /* break for 2 seconds */
  551.   }
  552.  
  553. `co(10,1);/// set_xon_flow`co();      `keyword(source,[EN_SUPP.C]~set_xon_flow);
  554.     sets or resets the XON/XOFF flow control.  The XON/XOFF chars can also
  555.   be set, along with queue high and low water marks.
  556.  
  557. Prototype:
  558.   int set_xon_flow( int state, int xon_char, int xoff_char,
  559.                         uint highwater, uint lowwater, PORT *cp );
  560.  
  561. Parameters:
  562. `co(11,1);  int state`co();
  563.     The XON/XOFF state, either 1 or 0.  You may use the ON an OFF defines
  564.     if desired.
  565. `co(11,1);  int xon_char`co();
  566.     The XON character to use.  The define for the most commonly used
  567.     xon character is XON_CHAR.  To specify XON on any character, use the
  568.     XON_ANY define.
  569. `co(11,1);  int xoff_char`co();
  570.     The XOFF character to use.  The define for the most commonly used
  571.     xoff character is XOFF_CHAR.
  572. `co(11,1);  uint highwater`co();
  573.     The number of bytes (less than the size of the queue) to set for XOFF
  574.     triggering.  When the queue fills to this number, an XOFF character
  575.     will automatically be sent.
  576. `co(11,1);  uint lowwater`co();
  577.     The number of bytes to set for XON triggering.  When the queue drains to
  578.     this number, an XON character will automatically be sent.
  579. `co(11,1);  PORT *cp`co();
  580.     The PORT pointer for XON/XOFF flow control.
  581.  
  582. Usage:
  583.   PORT  *cp = calloc(1, sizeof(PORT));
  584.   ...
  585.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  586.   {
  587.     ...
  588.     set_xon_flow(ON, XON_ANY, XOFF_CHAR, 1800, 200, cp);
  589.   }
  590.  
  591. `co(10,1);/// set_dcd_flow`co();      `keyword(source,[EN_SUPP.C]~set_dcd_flow);
  592.     sets or resets the DCD flow control.
  593.  
  594. Prototype:
  595.   int set_dcd_flow( int state, PORT *cp );
  596.  
  597. Parameters:
  598. `co(11,1);  int state`co();
  599.     The DCD flow control state, either 1 or 0.  You may use the ON an OFF
  600.     defines if desired.
  601. `co(11,1);  PORT *cp`co();
  602.     The PORT pointer for DCD flow control.
  603.  
  604. Usage:
  605.   PORT  *cp = calloc(1, sizeof(PORT));
  606.   ...
  607.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  608.   {
  609.     ...
  610.     set_dcd_flow(ON, cp);
  611.   }
  612.  
  613. `co(10,1);/// set_dsr_flow`co();      `keyword(source,[EN_SUPP.C]~set_dsr_flow);
  614.     sets or resets the DSR flow control.
  615.  
  616. Prototype:
  617.   int set_dsr_flow( int state, PORT *cp );
  618.  
  619. Parameters:
  620. `co(11,1);  int state`co();
  621.     The DSR flow control state, either 1 or 0.  You may use the ON an OFF
  622.     defines if desired.
  623. `co(11,1);  PORT *cp`co();
  624.     The PORT pointer for DSR flow control.
  625.  
  626. Usage:
  627.   PORT  *cp = calloc(1, sizeof(PORT));
  628.   ...
  629.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  630.   {
  631.     ...
  632.     set_dsr_flow(ON, cp);
  633.   }
  634.  
  635. `co(10,1);/// suspend`co();      `keyword(source,[EN_SUPP.C]~suspend);
  636.     is used to wait for a desired number of clock ticks.  If you have
  637.   used `keyword(set_idle_func,/// set_idle_func); to set a background processing function, it will be
  638.   called for you during the suspend time.
  639.   This routine will only work if `keyword(init_clock,/// init_clock); has been called.
  640.  
  641. Prototype:
  642.   void suspend( int t );
  643.  
  644. Parameters:
  645. `co(11,1);  int t`co();
  646.     The number of timer ticks to suspend.
  647.  
  648. Usage:
  649.   suspend(Tics_per_sec / 2);                      /* wait for 1/2 sec     */
  650.  
  651. `co(10,1);/// wait_for_rx`co();      `keyword(source,[EN_SUPP.C]~wait_for_rx);
  652.     is used to wait for a given amount of time, or until a specified number
  653.   of characters has been received, whichever comes first.  While waiting,
  654.   if you have set a background processing function with `keyword(set_idle_func,/// set_idle_func);, it
  655.   will be called for you.  This function is useful when it is needed to
  656.   wait for a response from the modem, another computer, etc.
  657.   This routine will only work if `keyword(init_clock,/// init_clock); has been called.
  658.  
  659. Prototype:
  660.   int wait_for_rx( int t, uint cnt, PORT *cp );
  661.  
  662. Parameters:
  663. `co(11,1);  int t`co();
  664.     The number of timer ticks to wait.
  665. `co(11,1);  uint cnt`co();
  666.     The number of bytes to wait.
  667. `co(11,1);  PORT *cp`co();
  668.     The PORT pointer to use.
  669.  
  670. Usage:
  671.   com_puts("ATZ\r", cp);                          /* reset the modem     */
  672.   wait_for_rx(Tics_per_sec * 2, 3, cp);            /* wait for the OK     */
  673.  
  674. `co(10,1);/// wait_for_no_rx`co();      `keyword(source,[EN_SUPP.C]~wait_for_rx);
  675.     is used to wait until no data has been received for a given amount of
  676.   time.  While waiting, if you have set a background processing function
  677.   with `keyword(set_idle_func,/// set_idle_func);, it will be called for you.
  678.   This routine will only work if `keyword(init_clock,/// init_clock); has been called.
  679.  
  680. Prototype:
  681.   int wait_for_no_rx( int t, PORT *cp );
  682.  
  683. Parameters:
  684. `co(11,1);  int t`co();
  685.     The number of timer ticks to wait after the last byte is received.
  686. `co(11,1);  PORT *cp`co();
  687.     The PORT pointer to use.
  688.  
  689. Usage:
  690.   com_puts("ATZ\r", cp);                          /* reset the modem     */
  691.   wait_for_no_rx(Tics_per_sec * 2, cp);            /* wait for the OK     */
  692.  
  693. `co(10,1);/// modem_cmd`co();      `keyword(source,[EN_SUPP.C]~modem_cmd);
  694.     is one of the more versatile functions in EnCom.  With this one function
  695.   you can execute any modem command you wish.  Indeed, all of the modem
  696.   macros defined in ENCOM.H simply call this function with the appropriate
  697.   Hayes command string and timeout.  This function uses `keyword(wait_for_rx,/// wait_for_rx);,
  698.   `keyword(wait_for_no_rx,/// wait_for_no_rx); and finally `keyword(com_getc_qty,/// com_getc_qty); to get the response.  A string
  699.   is returned that contains the response.
  700.  
  701.   `co(15,?);NOTE:  This function interprets the '~' character as a delay for 1/2 of a
  702.   second.  If you wish to change the pause character to something else,
  703.   simply set the global variable Pause_char.`co();
  704.  
  705.  CAVEAT: This routine waits until a modem reply starts and then waits     
  706.          until no more data has been received from the modem for 1 second.
  707.          This works for most commands; however, when dialing, if echo is  
  708.          enabled, the modem will echo the dial command and then take as   
  709.          much as 45 seconds or more to connect.  By this time, the routine
  710.          returns the echoed command.  There is no real solution to this   
  711.          unless you wait 45 seconds or more, therefore it is highly       
  712.          recommended that the modem be put into a NO ECHO mode using      
  713.          "modem_echo(OFF,&Port)".  This routine will not see the dial     
  714.          string and will therefore return the result as soon as the modem 
  715.          sends it.                                                        
  716.   
  717. Prototype:
  718.     char *modem_cmd( char *cmd_str, int p, int t, PORT *cp );
  719.  
  720. Parameters:
  721. `co(11,1);  char *cmd_str`co();
  722.     A string containing the modem command.  A \r is not needed, as the
  723.     function will send a return for you.
  724. `co(11,1);  int p`co();
  725.     An optional numeric parameter if needed.  Use -1 if not.
  726. `co(11,1);  int t`co();
  727.     The number of ticks to wait for a reply.  If there is no response from
  728.     the modem within this time, the string returned will be NULL;
  729. `co(11,1);  PORT *cp`co();
  730.     The PORT pointer for the modem command.
  731.  
  732. Usage:
  733.   modem_cmd("+++~~~ATH0", -1, Tics_per_sec * 5, cp);  /* hangup the phone */
  734.  
  735. `co(10,1);/// encrypt_msg`co();      `keyword(source,[EN_MSG.C]~encrypt);
  736.     is used internally by `keyword(fmt_msg,/// fmt_msg); to encrypt the message.  The technique
  737.   used is a simple "exclusive or" of the data with the global variable
  738.   Encrypt_char.  When `keyword(defmt_msg,/// defmt_msg); is called, the message is decrypted by
  739.   the same operation.  For no encryption, the encryption character is set
  740.   to 0.  To setup message encryption for your port, first call the macro
  741.   `keyword(set_encrypt,/// set_encrypt); to set the character, followed by the macro `keyword(init_msg,/// init_msg);.
  742.  
  743. Prototype:
  744.   void encrypt_msg( uchar *msg, uint len );
  745.  
  746. Parameters:
  747. `co(11,1);  uchar *msg`co();
  748.     A pointer to the data to encrypt.
  749. `co(11,1);  uint len`co();
  750.     The length of the data.
  751.  
  752. Usage:
  753.   PORT  *cp = calloc(1, sizeof(PORT));
  754.   uchar msg[] = "THIS IS A READABLE STRING";
  755.   ...
  756.   if( com_port_create(COM2, 2400L, 'N', 8, 1, 2048, 2048, cp) == 0 )
  757.   {
  758.     set_encrypt(0xAA, cp);
  759.     init_msg(cp);
  760.     encrypt_msg(msg, strlen(msg));
  761.     ...
  762.   }
  763.  
  764. `co(10,1);/// calc_crc`co();      `keyword(source,[EN_MSG.C]~calc_crc);
  765.     is used to calculate the CRC value for a length of bytes.  This
  766.   function is used internally by `keyword(fmt_msg,/// fmt_msg);, `keyword(defmt_msg,,/// defmt_msg,); and `keyword(get_msg,/// get_msg); to ensure
  767.   data integrity.  You may use this routine if you wish to find the CRC
  768.   value for a given number of bytes.  Please note that this routine uses
  769.   the global CRC table, and assumes that the table has been initialized
  770.   by calling `keyword(mk_crc_tbl,/// mk_crc_tbl);.
  771.  
  772. Prototype:
  773.   uint calc_crc( uchar *msg, uint len );
  774.  
  775. Parameters:
  776. `co(11,1);  uchar *msg`co();
  777.     A pointer to the data for CRC calculation.
  778. `co(11,1);  uint len`co();
  779.     The length of the data.
  780.  
  781. Usage:
  782.   uchar msg[] = "THIS IS A TEST";
  783.   uint  crc_val;
  784.   ...
  785.   mk_crc_tbl( 0xFFFF, CRCCITT_REV, gen_crc_rev );
  786.   crc_val = calc_crc(  msg, strlen(msg) );
  787.  
  788. `co(10,1);/// fmt_msg`co();      `keyword(source,[EN_MSG.C]~fmt_msg);
  789.     formats a message by "quoting" the data and appending a 16 bit CRC to
  790.   the end, followed by an `keyword(End_flag,[ENCOM.HLP]uchar End_flag);. This is useful for "packetizing"
  791.   data for transmission to a remote computer.  By using the messaging
  792.   routines, you can guarantee that the data will be received at the
  793.   remote computer on a message by message basis, with any errors in
  794.   transmission being automatically detected.
  795.   
  796.   When formatting a message, be sure the destination area is longer than the
  797.   source message as the quoting process can cause an expansion to occur.
  798.   Typically, a few percent is enough but to be perfectly safe, make it (2 *
  799.   source size) + 5.  The extra five bytes are for the CRC and End_flag.
  800.   This assumes that every byte has to be quoted except for the End_flag
  801.   which is stored "in the clear".  The function will return the number of
  802.   bytes that are stored in the destination area.
  803.  
  804. Prototype:
  805.   uint fmt_msg( uchar *s, uchar *d, uint len );
  806.  
  807. Parameters:
  808. `co(11,1);  uchar *s`co();
  809.     The source data pointer.
  810. `co(11,1);  uchar *d`co();
  811.     The destination data pointer.
  812. `co(11,1);  uint len`co();
  813.     The length of the source data.
  814.  
  815. Usage:
  816.   uchar src[] = "THIS IS A TEST";
  817.   uchar dest[80];
  818.   uint  dest_len;
  819.   ...
  820.   mk_crc_tbl( 0xFFFF, CRCCITT_REV, gen_crc_rev );
  821.   dest_len = fmt_msg( src, dest, strlen(src) );
  822.  
  823. `co(10,1);/// defmt_msg`co();      `keyword(source,[EN_MSG.C]~defmt_msg);
  824.     is the complement to `keyword(fmt_msg,/// fmt_msg);. This function takes the formatted
  825.   message and returns it back to its original state.  If there was an
  826.   error in transmission (the CRC does not match the calculated value),
  827.   then a 0 is returned, otherwise the length of the destination is returned.
  828.   defmt_msg is the equivalent to get_msg, except that it extracts data from
  829.   a memory buffer, not the receive queue.
  830.  
  831. Prototype:
  832.   uint defmt_msg( uchar *src, uchar *dest );
  833.  
  834. Parameters:
  835. `co(11,1);  uchar *src`co();
  836.     The source data pointer.
  837. `co(11,1);  uchar *dest`co();
  838.     The destination data pointer.
  839.  
  840. Usage:
  841.   uchar src[] = "THIS IS A TEST";
  842.   uchar fmt[80], final[80];
  843.   uint  dest_len, defmt_len;
  844.   ...
  845.   mk_crc_tbl( 0xFFFF, CRCCITT_REV, gen_crc_rev );
  846.   dest_len = fmt_msg( src, fmt, strlen(src) );
  847.   defmt_len = defmt_msg( fmt, final );
  848.   if ( defmt_len != strlen(src) )
  849.     printf("error!");
  850.  
  851. `co(10,1);/// get_msg`co();      `keyword(source,[EN_MSG.C]~get_msg);
  852.     gets one message from the receive queue of the port.  Use the `keyword(msg_cnt,#define msg_cnt);
  853.   macro to determine if there is a message currently in the port receive
  854.   queue. Like defmt_msg, the length of the message is returned if the CRC
  855.   matches, otherwise a 0 is returned, and the message should not be used
  856.   as it is corrupted.  get_msg is the equivalent to fmt_msg, except that it
  857.   extracts data from the receive queue, not a memory buffer.  (The interrupt
  858.   routine increments the port message counter when a message is received,
  859.   and get_msg decrements it.)
  860.  
  861. Prototype:
  862.   uint get_msg( uchar *dest, PORT *cp );
  863.  
  864. Parameters:
  865. `co(11,1);  uchar *dest`co();
  866.     The destination data pointer.
  867. `co(11,1);  PORT *cp`co();
  868.     The PORT pointer that has the message in its receive queue.
  869.  
  870. Usage:
  871.   uchar buffer[1024];
  872.   ...
  873.    if ( msg_cnt(cp) )
  874.      dest_len = get_msg(buffer, cp);
  875.  
  876. `co(10,1);/// mk_crc_tbl`co();      `keyword(source,[EN_MSG.C]~mk_crc_tbl);
  877.     creates the global Crc_tbl used in `keyword(calc_crc,/// calc_crc);, which is called by the
  878.   message formatting functions.  Any CRC preset (the most common are
  879.   preset all zeros or all ones), any polynomial, and both forward and
  880.   reverse directions can be specified.
  881.  
  882. Prototype:
  883.   void mk_crc_tbl( ushort init, ushort poly, 
  884.                                    ushort (*crcfn)(ushort, ushort, ushort) );
  885.  
  886. Parameters:
  887. `co(11,1);  ushort init`co();
  888.     The CRC preset value, typically 0x0000 or 0xFFFF.
  889. `co(11,1);  ushort poly`co();
  890.     The CRC polynomial value.  Both CRCCITT and CRC16 are supported.  You
  891.     may use one of the pre-defined values CRCCITT, CRCCITT_REV, CRC16, or
  892.     CRC16_REV for this parameter.
  893. `co(11,1);  ushort (*crcfn)(ushort, ushort, ushort)`co();
  894.     A pointer to the function that generates the table.  We supply two
  895.     functions you may call, namely gen_crc and gen_crc_rev.
  896.  
  897. Usage:
  898.   mk_crc_tbl( 0xFFFF, CRCCITT, gen_crc );
  899.  
  900. `co(10,1);/// init_ctrlc_hdlr`co();      `keyword(source,[EN_KBD.C]~init_ctrlc_hdlr);
  901.     sets up a keyboard interrupt handler that translates the keys Ctrl-C and
  902.     Ctrl-Break to the benign value 0x2E1E. This prevents the infamous "^C"
  903.     from being displayed on your screen.  Call this function at the beginning
  904.     of your program, and the corresponding `keyword(end_ctrlc_hdlr,/// end_ctrlc_hdlr); at the end of your
  905.     program.
  906.  
  907.   NOTE: When either of these keys are pressed, the bios will give you back
  908.                 the value 0x1E.  If you wish, you can translate this yourself back
  909.                 to 0x03 for transmission as Ctrl-C.  If you are using UltraWin, you
  910.                 do not need to call init_ctrlc_hdlr as it is called for you by
  911.                 init_video.  In addition, the UltraWin keyboard functions will
  912.                 automatically translate the 0x1E back to 0x03 for you. 
  913.  
  914. Prototype:
  915.   void init_ctrlc_hdlr(void);
  916.  
  917. Parameters:
  918.     None.
  919.  
  920. Usage:
  921.   main()
  922.   {
  923.       init_ctrlc_hdlr();
  924.       ...
  925.       end_ctrlc_hdlr();
  926.   }
  927.  
  928. `co(10,1);/// end_ctrlc_hdlr`co();      `keyword(source,[EN_KBD.C]~end_ctrlc_hdlr);
  929.     terminates the keyboard interrupt handler, and restores the old key
  930.     interrupt vector.  It is the complement to init_ctrlc_hdlr.  If you called
  931.     init_ctrlc_hdlr, you MUST call end_ctrlc_hdlr before you exit the program.
  932.  
  933. Prototype:
  934.   void end_ctrlc_hdlr(void);
  935.  
  936. Parameters:
  937.   None.
  938.  
  939. Usage:
  940.   main()
  941.   {
  942.       init_ctrlc_hdlr();
  943.       ...
  944.       end_ctrlc_hdlr();
  945.   }
  946.  
  947. `co(10,1);/// init_clock`co();      `keyword(source,[EN_KBD.C]~init_clock);
  948.       takes over the PC timer interrupt and sets the timer rate to the desired
  949.     value.  This function is necessary as several of the timing functions
  950.     in the library utilize timers incremented in our custom timer interrupt
  951.     function.  Be sure to call `keyword(end_clock,/// end_clock); before you exit your program.
  952.  
  953. Prototype:
  954.   void init_clock( uint speed );
  955.  
  956. Parameters:
  957. `co(11,1);    uint  speed`co();
  958.     The countdown value for the PC timer chip.  0xffff is the standard
  959.     18.2 times per second. 0x7fff would increase the rate by 2, 0x3333
  960.     gives exactly 91 ticks per second, and is recommended.
  961.  
  962. Usage:
  963.   main()
  964.   {
  965.     init_clock(0x3333);                                            /* speed up by factor of 5 */
  966.       ...
  967.     end_clock();
  968.   }
  969.  
  970. `co(10,1);/// end_clock`co();   `keyword(source,[EN_KBD.C]~end_clock);
  971.       restores the timer interrupt and rate.  If you used `keyword(init_clock,/// init_clock);, be
  972.   sure to call this function before exiting your program.
  973.  
  974. Prototype:
  975.     void end_clock(void);
  976.  
  977. Parameters:
  978.      None.
  979.  
  980. Usage:
  981.   main()
  982.   {
  983.     init_clock(0x3333);                                            /* speed up by factor of 5 */
  984.       ...
  985.     end_clock();
  986.   }
  987.   
  988. `co(10,1);/// tone`co();      `keyword(source,[EN_KBD.C]~tone);
  989.       Sounds the PC speaker at the desired frequency for the desired amount of
  990.     time measured in timer tics. (91/s).  There is no need to turn the sound
  991.     off, this is automatically handled by the timer interrupt.  It is
  992.     perfectly safe to call tone even if a tone is already in progress.  The
  993.     new frequency and time will override the current values.  If you need to
  994.     turn the speaker off before the time has expired call `keyword(sound_off,/// sound_off);.
  995.   This routine will only work if `keyword(init_clock,/// init_clock); has been called.
  996.  
  997. Prototype:
  998.     void tone( uint freq, int dur );
  999.  
  1000. Parameters:
  1001. `co(11,1);    uint  freq`co();
  1002.     The desired frequency in hertz or cycles-per-second.   
  1003. `co(11,1);    int    dur`co();
  1004.     The duration of the tone in clock tics (91 per second).
  1005.  
  1006. Usage:
  1007.   if( error )
  1008.       tone(1024, 91);                                              /* sound at 1k for 1 second */
  1009.  
  1010. `co(10,1);/// sound_off`co();      `keyword(source,[EN_KBD.C]~sound_off);
  1011.       turns off any speaker sound in progress.  It is not necessary to call
  1012.     this function unless you want to turn off a tone before its duration time
  1013.     has expired.
  1014.  
  1015. Prototype:
  1016.   void sound_off(void);
  1017.  
  1018. Parameters:
  1019.   None.
  1020.   
  1021. Usage:
  1022.   tone(1024, 91);
  1023.   sound_off();
  1024.  
  1025. `co(10,1);/// set_idle_func`co();      `keyword(source,[EN_KBD.C]~set_idle_func);
  1026.       sets a background processing function that the library will call
  1027.   whenever it is involved in time-critical functions like `keyword(wait_for_rx,/// wait_for_rx);,
  1028.   `keyword(wait_for_no_rx,/// wait_for_no_rx); and `keyword(suspend,/// suspend);.  A good candidate might be a function that
  1029.   prints in the background.
  1030.  
  1031. Prototype:
  1032.   void set_idle_func( int (*func_ptr)(void) )
  1033.  
  1034. Parameters:
  1035. `co(11,1);    int (*func_ptr)(void)`co();
  1036.         A pointer to the function you wish to install as the idle function.
  1037.   
  1038. Usage:
  1039.   int process_routine()
  1040.   { ... }
  1041.   
  1042.   main()
  1043.   {
  1044.       set_idle_func( process_routine );
  1045.       ...
  1046.   }
  1047.  
  1048. `co(10,1);/// com_fifo_trigger`co();      `keyword(source,[EN_MAIN.C]~com_fifo_trigger);
  1049.     is used to set the trigger level for the 16550 receive FIFO.  This can
  1050.   be set to 1, 4, 8, or 14 using the defines RX_TRIG_1, RX_TRIG_4, RX_TRIG_8,
  1051.   and RX_TRIG_14.
  1052.  
  1053. Prototype:
  1054. int com_fifo_trigger( int level, PORT *cp );
  1055.  
  1056. Parameters:
  1057. `co(11,1);  int level`co();
  1058.     The trigger level mask, i.e. RX_TRIG_8 (don't pass the decimal value 8).
  1059. `co(11,1);  PORT *cp`co();
  1060.     The PORT pointer to use.
  1061.  
  1062. Usage:
  1063.   com_fifo_trigger( RX_TRIG_4, cp);                        /* set trigger level   */
  1064.  
  1065. `co(10,1);/// com_fifo_ctrl`co();      `keyword(source,[EN_MAIN.C]~com_fifo_ctrl);
  1066.     is used to set the FIFO's on or off, clear the rx or tx FIFO's, etc.
  1067.   Macros are provided to do these functions.
  1068.  
  1069. Prototype:
  1070. int com_fifo_ctrl( int state, int mask, PORT *cp );
  1071.  
  1072. Parameters:
  1073. `co(11,1);  int state`co();
  1074.     The FIFO state, ON or OFF.
  1075. `co(11,1);  int mask`co();
  1076.     The #defined bit masks i.e. FIFO_ON or RX_FIFO_RESET.
  1077. `co(11,1);  PORT *cp`co();
  1078.     The PORT pointer to use.
  1079.  
  1080. Usage:
  1081.   com_fifo_ctrl(ON, RX_FIFO_RESET, cp);                /* clear rx fifo       */
  1082.  
  1083. `co(4,7);─────────────────────────── EnCom General Macros ─────────────────────────────`co();
  1084.  
  1085.   `co(12,?);General Macros`co();
  1086.     #define lower(x, y)               (((x) < (y)) ? (x) : (y))
  1087.     #define upper(x, y)               (((x) > (y)) ? (x) : (y))
  1088.     #define lobyte(c)                   (uchar) ((c) & 0x00ff)
  1089.     #define hibyte(c)                   (uchar) ((c) >> 8)
  1090.     #define range(l,b,h)         ((((b) >= (l)) && ((b) <= (h))) ? 1:0)
  1091.     #define swap( a,b,c)           ((c) = (a), (a) = (b), (b) = (c))
  1092.     #define min(x, y)                   (((x) < (y)) ? (x) : (y))
  1093.     #define max(x, y)                   (((x) > (y)) ? (x) : (y))
  1094.  
  1095. `co(4,7);───────────────────────────── EnCom Comm Macros ──────────────────────────────`co();
  1096.  
  1097.   `co(12,?);Comm Macros`co();
  1098.     These macros are used to access the queue counts and status.
  1099.  
  1100.     #define com_tx_cnt(cp)       ((cp)->tx_cnt)
  1101.     #define com_rx_cnt(cp)       ((cp)->rx_cnt)
  1102.     #define com_tx_free(cp)      ((cp)->tx_size - (cp)->tx_cnt)
  1103.     #define com_rx_free(cp)      ((cp)->rx_size - (cp)->rx_cnt)
  1104.     #define is_rx_empty(cp)      ((cp)->rx_cnt ? 1 : 0)
  1105.     #define is_rx_full(cp)       ((cp)->rx_size == (cp)->rx_cnt)
  1106.     #define is_tx_empty(cp)      ((cp)->tx_cnt ? 1 : 0)
  1107.     #define is_tx_full(cp)       ((cp)->tx_size == (cp)->tx_cnt)
  1108.  
  1109. `co(4,7);──────────────────────────── EnCom Message Macros ────────────────────────────`co();
  1110.  
  1111.   `co(12,?);Message Macros`co();
  1112.     These macros are used to setup the messaging facility.  Be sure to call
  1113.   init_msg after calling set_encrypt and set_match or the messaging
  1114.   routines will not operate as desired.
  1115.  
  1116.     #define set_encrypt(c, cp)     ((cp)->encrypt_char = c)
  1117.     #define set_match(c, cp)         ((cp)->match_char = c)
  1118.     #define init_msg(cp)         (End_flag = (cp)->match_char,
  1119.                                   Encrypt_char = (cp)->encrypt_char)
  1120.     #define msg_cnt(cp)                     ((cp)->msg_cnt)
  1121.     #define clear_msg_cnt(cp)    ((cp)->msg_cnt = 0)
  1122.  
  1123.     These macros are used to enable/disable, and check on the `keyword(queue status,[ENCOM.HLP]EnCom's "Queue Status");
  1124.   mode.
  1125.  
  1126.     #define is_queue_status(x,cp)  ((cp)->que_stat_flag)
  1127.     #define set_queue_status(x,cp) ((cp)->que_stat_flag = x)
  1128.  
  1129. `co(4,7);───────────────────────── EnCom Handshaking Macros ───────────────────────────`co();
  1130.  
  1131.   `co(12,?);Handshaking Macros`co();
  1132.     These macros/functions allow you to set RTS/CTS, DCD, or DSR flow
  1133.     control using the set_ macros.  You can determine if flow control is
  1134.     enabled by using the is_ macros, and you can look at the current state
  1135.     using the _state macros.
  1136.  
  1137.   XON/XOFF flow control is set by the function `keyword(set_xon_flow,/// set_xon_flow);.
  1138.   DCD flow flow control is set by the function `keyword(set_dcd_flow,/// set_dcd_flow);.
  1139.   DSR flow flow control is set by the function `keyword(set_dsr_flow,/// set_dsr_flow);.
  1140.  
  1141.   #define set_cts_flow(x,cp)   ((cp)->rts_cts_mode = x)
  1142.  
  1143.     #define is_cts_flow(cp)         ((cp)->rts_cts_mode)
  1144.     #define is_dcd_flow(cp)        ((cp)->dcd_mode)
  1145.     #define is_dsr_flow(cp)      ((cp)->dsr_mode)
  1146.     #define is_xon_flow(cp)           ((cp)->xon_xoff_mode)
  1147.  
  1148.     #define cts_flow_state(cp)     ((cp)->rts_cts_state)
  1149.     #define dcd_flow_state(cp)      ((cp)->dcd_state)
  1150.     #define dsr_flow_state(cp)   ((cp)->dsr_state)
  1151.     #define xon_flow_state(cp)     ((cp)->xon_xoff_state)
  1152.  
  1153.       The following macros set and get the low and high water marks for
  1154.     XON/XOFF and high speed RTS/CTS flow control.  These values are
  1155.     initialized to 10% and 90% of the receive queue size when the comm port
  1156.     is created.
  1157.  
  1158.     #define set_lowwater(l,cp)   ((cp)->lowwater = l)
  1159.     #define set_highwater(h,cp)  ((cp)->highwater = h)
  1160.     #define get_lowwater(cp)     ((cp)->lowwater)
  1161.     #define get_highwater(cp)    ((cp)->highwater)
  1162.  
  1163. `co(4,7);──────────────────────────── EnCom Modem Macros ──────────────────────────────`co();
  1164.  
  1165.   `co(12,?);Modem Command Macros`co();
  1166.       These macros provide an "easier to read" method of performing common
  1167.     modem commands.  Notice how they are all implemented with the powerful
  1168.     `keyword(modem_cmd,/// modem_cmd); function.
  1169.     
  1170.     #define modem_reset(cp)             modem_cmd("ATZ",-1,Tics_per_sec*2,(cp))
  1171.     #define modem_dial(s,cp)         modem_cmd(s,-1,Tics_per_sec*45,(cp))
  1172.     #define modem_answer(cp)         modem_cmd("ATA",-1,Tics_per_sec,(cp))
  1173.     #define modem_hangup(cp)         modem_cmd("+++~~~ATH0",
  1174.                                                -1,Tics_per_sec*5,(cp))
  1175.     #define modem_online(cp)                modem_cmd("ATO",-1,Tics_per_sec,(cp))
  1176.     #define modem_repeat(cp)           modem_cmd("A/",-1,Tics_per_sec,(cp))
  1177.     #define modem_speaker(x,cp)        modem_cmd("ATM",x,Tics_per_sec,(cp))
  1178.     #define modem_echo(x,cp)             modem_cmd("ATE",x,Tics_per_sec,(cp))
  1179.     #define modem_word_reply(x,cp)   modem_cmd("ATV",x,Tics_per_sec,(cp))
  1180.     #define modem_extend_reply(x,cp) modem_cmd("ATX",x,Tics_per_sec,(cp))
  1181.     #define modem_duplex(x,cp)           modem_cmd("ATF",x,Tics_per_sec,(cp))
  1182.     #define modem_quiet(x,cp)                modem_cmd("ATQ",x,Tics_per_sec,(cp))
  1183.  
  1184.   `co(12,?);Current Modem Control Macros`co();
  1185.     These macros allow you to check the current state of the modem control
  1186.   lines.
  1187.   
  1188.     #define is_dtr(cp)            ((inbyte((cp)->uart[MCR]) & DTR)  ? 1 : 0)
  1189.     #define is_rts(cp)            ((inbyte((cp)->uart[MCR]) & RTS)  ? 1 : 0)
  1190.     #define is_out1(cp)           ((inbyte((cp)->uart[MCR]) & OUT1) ? 1 : 0)
  1191.     #define is_out2(cp)           ((inbyte((cp)->uart[MCR]) & OUT2) ? 1 : 0)
  1192.     #define is_loop(cp)           ((inbyte((cp)->uart[MCR]) & LOOP) ? 1 : 0)
  1193.  
  1194.   `co(12,?);Current Modem Status Macros`co();
  1195.     These macros allow you to check the current state of the modem status
  1196.   lines.  Use the static status macros for "block checking", calling
  1197.   clear_mstatus for each block.
  1198.     
  1199.     #define is_dcd(cp)            ((inbyte((cp)->uart[MSR]) & DCD) ? 1 : 0)
  1200.     #define is_cts(cp)            ((inbyte((cp)->uart[MSR]) & CTS) ? 1 : 0)
  1201.     #define is_dsr(cp)            ((inbyte((cp)->uart[MSR]) & DSR) ? 1 : 0)
  1202.     #define is_ri(cp)                ((inbyte((cp)->uart[MSR]) & RI ) ? 1 : 0)
  1203.  
  1204.   `co(12,?);Static Modem Status Macros`co();
  1205.     #define clear_mstatus(cp)           ((cp)->modem_status = 0)
  1206.     #define is_sdcd(cp)           (((cp)->smodem_status & DCD)  ? 1 : 0)
  1207.     #define is_scts(cp)           (((cp)->smodem_status & CTS)  ? 1 : 0)
  1208.     #define is_sdsr(cp)           (((cp)->smodem_status & DSR)  ? 1 : 0)
  1209.     #define is_sri(cp)            (((cp)->smodem_status & RI )  ? 1 : 0)
  1210.  
  1211.     #define is_sddcd(cp)          (((cp)->smodem_status & DDCD) ? 1 : 0)
  1212.     #define is_sdcts(cp)          (((cp)->smodem_status & DCTS) ? 1 : 0)
  1213.     #define is_sddsr(cp)          (((cp)->smodem_status & DDSR) ? 1 : 0)
  1214.     #define is_sdri(cp)           (((cp)->smodem_status & DRI)  ? 1 : 0)
  1215.  
  1216. `co(4,7);───────────────────────── EnCom Line Status Macros ───────────────────────────`co();
  1217.  
  1218.     These macros allow you to check the current state of the line status.
  1219.   Use the static status macros for "block checking", calling clear_lstatus
  1220.   for each block.
  1221.  
  1222.   `co(12,?);Current Line Status Macros`co();
  1223.     #define is_overrun_err(cp)    ((inbyte((cp)->uart[LSR]) & OE)  ? 1 : 0)
  1224.     #define is_parity_err(cp)     ((inbyte((cp)->uart[LSR]) & PE)  ? 1 : 0)
  1225.     #define is_framing_err(cp)    ((inbyte((cp)->uart[LSR]) & FE)  ? 1 : 0)
  1226.     #define is_break(cp)                ((inbyte((cp)->uart[LSR]) & BI)  ? 1 : 0)
  1227.  
  1228.   `co(12,?);Static Line Status Macros`co();
  1229.     #define clear_lstatus(cp)           ((cp)->sline_status = 0)
  1230.     #define is_soverrun_err(cp)   (((cp)->sline_status & OE)  ? 1 : 0)
  1231.     #define is_sparity_err(cp)    (((cp)->sline_status & PE)  ? 1 : 0)
  1232.     #define is_sframing_err(cp)   (((cp)->sline_status & FE)  ? 1 : 0)
  1233.     #define is_sbreak(cp)                (((cp)->sline_status & BI)  ? 1 : 0)
  1234.  
  1235. `co(4,7);───────────────────────── EnCom 16550 Support Macros ─────────────────────────`co();
  1236.  
  1237.         These macros support the 16550AF and 16550AFN FIFO parts.  They allow
  1238.     you do enable/disable the FIFO's and set and get the receive FIFO trigger
  1239.     level.  The trigger level is set by the function `keyword(com_fifo_trigger,/// com_fifo_trigger);.
  1240.  
  1241.   `co(12,?);16550 FIFO and Trigger Macros`co();
  1242.     #define fifo_enable(cp)           (com_fifo_ctrl( ON,FIFO_ON,(cp)),
  1243.                                                                     (cp)->fifos_enabled =  ON)
  1244.     #define fifo_disable(cp)          (com_fifo_ctrl(OFF,FIFO_ON,(cp)),
  1245.                                                                     (cp)->fifos_enabled = OFF)
  1246.     #define fifo_rx_reset(cp)         (com_fifo_ctrl(ON,RX_FIFO_RESET,(cp)))
  1247.     #define fifo_tx_reset(cp)         (com_fifo_ctrl(ON,TX_FIFO_RESET,(cp)))
  1248.  
  1249.     #define is_fifo_enabled(cp)   ((cp)->fifos_enabled)
  1250.     #define get_trigger_level(cp) ((cp)->rx_trig_level)
  1251.