home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a081 / 2.ddi / CTFXX.EXE / CTFDPC00.PRG < prev    next >
Encoding:
Text File  |  1993-05-14  |  8.5 KB  |  236 lines

  1. *.............................................................................
  2. *   Program Name: CFDPC11.PRG       Copyright: Magna Carta Software, Inc. 1992.
  3. *   Date Created: 05-18-92          Language: FoxPro v2.0x
  4. *.............................................................................
  5. * Description: Example of DigiBoard PC/X (PC/4 or PC/8) usage with CommTools
  6. * Based on FOXCOM11.
  7. * Usage Notes:
  8. * 1) Install the DigiBoard PC/X in the PC. You may choose any desired I/O
  9. * address for the ports, and the "status register" supported by the DigiBoard.
  10. * You may also choose any IRQ line supported by the card.
  11. *
  12. * 2) If you plan to use only ONE port on the DigiBoard, you can use any of the
  13. * FOXCOMxx examples. You do not need the routines contained herein;
  14. *
  15. * 3) If you plan to use the DigiBoard in "polled mode" (i.e., you do not
  16. * intend to use interrupts) you can use any of the FOXCOMxx examples. For each
  17. * port that you intend to use, call u8250_init() with the correct I/O address
  18. * for the port that you wish to use on the board.
  19. *
  20. * 4) If the above cases do not apply, you plan to use the DigiBoard in
  21. * interrupt-driven mode, using more than one port. The following applies to
  22. * your situation.
  23. * a) Think of the DigiBoard PC/X as an array of 4 (PC/4) or 8 (PC/8) standard
  24. * 8250 ports. We call u8250_init() once for each port that we plan to use;
  25. * b) Install the IPRs that you wish to use on each port. For example, if you
  26. * are using 4 ports, and you wish to use receive interrupts on each, call
  27. * install_ipr() 4 times (once to each port);
  28. * c) Since we need to install a special ISR that supports the DigiBoard, do
  29. * NOT call install_isr(). Instead, call DIGIPC_INSTALL_ISR() as shown below.
  30. * We call this only once, since one ISR handles all of the ports on the board.
  31. * The prototype for DIGIPC_INSTALL_ISR() is:
  32. *
  33. *   DIGIPC_INSTALL_ISR(expN portid, expN irq, expN status_addr)
  34. *   Arguments:
  35. *       _parni(1)   -- CommTools port ID;
  36. *       _parni(2)   -- interrupt request line (IRQ) to use;
  37. *       _parni(3)   -- Address of DigiPC/X status port;
  38. *   Return value:
  39. *       0           -- Success;
  40. *       -2          -- No IPRs installed;
  41. *       PARMERROR   -- Incorrect number or type of parameters;
  42. *
  43. * Note: The parameter 'portid' may be any one of the port IDs used to
  44. * reference a port on the DigiBoard. For example, if you are using all 8 ports
  45. * of a PC/8, and assign CommTools port IDs 5-12 to the DigiBoard ports, you
  46. * could specify any number from 5 to 12 as the parameter 'portid' in
  47. * DIGIPC_INSTALL_ISR().
  48. *
  49. * From this point on in the program, all of the CommTools device-independent
  50. * calls that work with a standard serial port, work with the DigiBoard.
  51. *
  52. * Note: The UARTs on these boards are socketed and may be replaced with
  53. * NS16550A UARTs for better performance. See the CommTools "Communications
  54. * Reference" for a description of the NS16550, and the CommTools "Technical
  55. * Reference" under "set_16550_threshold()" for the method used to set the FIFO
  56. * buffers.
  57. *.............................................................................
  58.  
  59. CLEAR ALL
  60. SET TALK OFF
  61. SET ESCAPE OFF
  62.  
  63. * Load the right library
  64. foxid = VERS()
  65. IF "2.0" $ foxid
  66.     SET LIBR TO ctf                 && Identified FoxPro 2.0
  67. ELSE
  68.     IF "2.5" $ VERS()
  69.         IF "Windows" $ foxid        && Identified FoxPro 2.5 for Windows
  70.             CANCEL
  71.         ELSE
  72.             SET LIBR TO ctf25       && Identified FoxPro 2.5 for DOS
  73.         ENDIF
  74.     ENDIF
  75. ENDIF
  76.  
  77. SET COLOR OF SCHEME 17 TO SCHEME 1  && save default color scheme
  78. SET COLOR OF SCHEME 18 TO SCHEME 2
  79.  
  80. DO ctfhdr
  81. DO ctfutil
  82. SET PROCEDURE TO CTFUTIL
  83. version = 11
  84. portid  = 0
  85.  
  86. ACTIVATE WINDOW w_status
  87. ACTIVATE WINDOW w_term
  88.  
  89. activeport = 0                          && use port ID 0 for demo purposes
  90.  
  91.  
  92. * Initialize 4 ports on the PC/X. Assume the I/O addresses are set to 108h,
  93. * 110h, 120h, 130h. Note: This illustrates that the port I/O addresses
  94. * do not have to be evenly spaced on the PC/X.
  95. =u8250_init(0, x2d("108"), 19200, 8, PARITY_NONE, 1)
  96. =u8250_init(1, x2d("110"), 19200, 8, PARITY_NONE, 1)
  97. =u8250_init(2, x2d("120"), 19200, 8, PARITY_NONE, 1)
  98. =u8250_init(3, x2d("130"), 19200, 8, PARITY_NONE, 1)
  99.  
  100. * Now install a receive IPR on EACH of the ports initialized above.
  101. * Just for grins, we will make the interrupt buffer sizes different.
  102. =install_ipr(0, RECEIVE, NULL, 1024)   && initialize receive IPR
  103. =install_ipr(1, RECEIVE, NULL, 1536)   && initialize receive IPR
  104. =install_ipr(2, RECEIVE, NULL, 2048)   && initialize receive IPR
  105. =install_ipr(3, RECEIVE, NULL, 2560)   && initialize receive IPR
  106.  
  107. * Here's the only DigiBoard PC/X-specific call we use. Install the ISR
  108. * (we will assume we configured the board IRQ selection jumpers to IRQ 2).
  109. * We further assume that the status register is at 141h;
  110. =digipc_install_isr(0, 2, x2d("141"))
  111.  
  112. * From here on out it's business as usual. All we do is use "activeport" to
  113. * provide a dumb terminal.
  114.  
  115. @ 00,00 SAY "CommTools DigiBoard PC/X Terminal Version " +;
  116.     ALLTRIM(STR(version)) + ": Press CTRL-A to return to menu"
  117.  
  118. DEFINE PAD p_ct_emul OF main_menu PROMPT "\<Emulation" AT 00, 37
  119.     ON SELECTION PAD p_ct_emul OF main_menu =do_term_emul(portid, 37)
  120.  
  121. ACTIVATE MENU main_menu
  122.  
  123.  
  124.  
  125. *
  126. * DO_TERM_EMUL(expN portid)
  127. * Show a menu that allows the user to select a terminal to emulate.
  128. * Called from mainmenu()
  129. *
  130. FUNCTION do_term_emul
  131.     PARAMETERS portid, col
  132.     PRIVATE nChoice, termtype
  133.  
  134.     termtype = get_terminal(col)
  135.     IF termtype != CT_EOF
  136.         * USE XONXOFF FLOW CONTROL (THIS LETS US BUFFER RECEIVED DATA) *
  137.         =set_tx_xlat(portid, FLOWCTL, XONXOFF)   && better accept flow control if > 2400 bps
  138.         =set_rx_xlat(portid, LOCAL_ECHO, TRUE)   && echo RX data to screen
  139.         =set_tx_xlat(portid, LOCAL_ECHO, FALSE)  && (optionally) don't echo TX data
  140.         ret = term_init(portid, termtype)
  141.         =term_set(portid, TERM_ROWS, 45)
  142.         =term_set(portid, TERM_COLS, 78)
  143. *       =term_set(portid, TERM_KEYCLICK, 0)     && "Click, click..."
  144.         IF ret < 0
  145.             =status_msg(0, "Insufficient memory for terminal emulation")
  146.         ENDIF
  147.     ENDIF
  148. RETURN (ret)
  149.  
  150.  
  151.  
  152. *
  153. * GET_TERMINAL(expN tr, expN lc)
  154. * Show a menu that allows the user to select a terminal to emulate.
  155. * Called from do_terminal_menu()
  156. *
  157. FUNCTION get_terminal
  158.     PARAMETER col
  159.     PRIVATE termtype
  160.  
  161.     termtype = 0
  162.     DEFINE POPUP pop_terminal FROM 01, col;
  163.         IN SCREEN;
  164.         SHADOW
  165.         DEFINE BAR 1  OF pop_terminal PROMPT " \<TTY        "
  166.         DEFINE BAR 2  OF pop_terminal PROMPT " \<ANSI.SYS   "
  167.         DEFINE BAR 3  OF pop_terminal PROMPT " ANSI \<X3.64 "
  168.         DEFINE BAR 4  OF pop_terminal PROMPT " VT\<52       "
  169.         DEFINE BAR 5  OF pop_terminal PROMPT " VT\<100      "
  170.         DEFINE BAR 6  OF pop_terminal PROMPT " VT\<220      "
  171.  
  172.     ON SELECTION POPUP pop_terminal termtype=_terminal_menu(BAR())
  173.     ACTIVATE POPUP pop_terminal
  174.     DEACTIVATE POPUP pop_terminal
  175.     RELEASE POPUPS pop_terminal
  176. RETURN (termtype)
  177.  
  178.  
  179. FUNCTION _terminal_menu
  180.     PARAMETERS nChoice
  181.     PRIVATE termtype
  182.  
  183.     DO CASE
  184.         CASE nChoice = 1
  185.             termtype = TTY
  186.         CASE nChoice = 2
  187.             termtype = ANSI_SYS
  188.         CASE nChoice = 3
  189.             termtype = ANSI_X364
  190.         CASE nChoice = 4
  191.             termtype = DEC_VT52
  192.         CASE nChoice = 5
  193.             termtype = DEC_VT100
  194.         CASE nChoice = 6
  195.             termtype = DEC_VT220
  196.         OTHERWISE
  197.             termtype = CT_EOF
  198.     ENDCASE
  199.     =status_msg(0, "Terminal: " + ALLTRIM(PROMPT()))
  200. RETURN (termtype)
  201.  
  202.  
  203.  
  204. FUNCTION ct_online
  205.     PARAMETERS portid
  206.  
  207.     ACTIVATE WINDOW w_term
  208. *   =CT_SET_WIN(portid)
  209.     =c_term(portid)                 && switch to dumb terminal mode
  210. RETURN (0)
  211.  
  212.  
  213.  
  214. *
  215. * C_TERM -- This is a dumb terminal loop in FoxPro.
  216. * Alternately poll the serial input buffer and the keyboard for data.
  217. *
  218. FUNCTION c_term
  219.     PARAMETERS portid
  220.     PRIVATE c
  221.  
  222.     ?
  223.     DO WHILE .T.
  224.         * CHECK SERIAL PORT FOR BYTE *
  225.         c = c_getc(portid)                      && check the serial port for a byte
  226.         * CHECK KEYBOARD FOR A KEY PRESS *
  227.         c = INKEY()                             && check keyboard for a key
  228.         DO CASE                                 && evaluate the received key
  229.             CASE c == 1                         && CTRL-A was pressed
  230.                 RETURN (0)
  231.             CASE c <> 0
  232.                 =c_putc(portid, c)
  233.         ENDCASE
  234.     ENDDO                                       && do while .t.
  235. RETURN (0)
  236.