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

  1. *.............................................................................
  2. *   Program Name: FOXCOM11         Copyright: Magna Carta Software, Inc.
  3. *   Date Created: 10-03-91         Language:  FoxPro 2.x
  4. *.............................................................................
  5. * Description: Sample Terminal Program. Based on FOXCOM10.PRG plus...
  6. * Terminal Emulation.
  7. *.............................................................................
  8. CLEAR ALL
  9. SET TALK OFF
  10. SET ESCAPE OFF
  11.  
  12. * Load the right library
  13. foxid = VERS()
  14. IF "2.0" $ foxid
  15.     SET LIBR TO ctf                 && Identified FoxPro 2.0
  16. ELSE
  17.     IF "2.5" $ VERS()
  18.         IF "Windows" $ foxid        && Identified FoxPro 2.5 for Windows
  19.             SET LIBR TO ctfw
  20.         ELSE
  21.             SET LIBR TO ctf25       && Identified FoxPro 2.5 for DOS
  22.         ENDIF
  23.     ENDIF
  24. ENDIF
  25.  
  26. SET COLOR OF SCHEME 17 TO SCHEME 1  && save default color scheme
  27. SET COLOR OF SCHEME 18 TO SCHEME 2
  28.  
  29. DO ctfhdr
  30. DO ctfutil
  31. SET PROCEDURE TO CTFUTIL
  32. version = 11
  33. portid  = 0
  34.  
  35. ACTIVATE WINDOW w_status
  36. ACTIVATE WINDOW w_term
  37.  
  38. ret = u8250_init(portid, COM1, 2400, 8, PARITY_NONE, 1)
  39. IF ret < 0
  40.     ? ret
  41.     =INKEY(0)
  42.     CANCEL
  43. ENDIF
  44. =CT_SET_WIN(portid)
  45.  
  46. ret =install_ipr(portid, RECEIVE, NULL, 1024)
  47. IF ret < 0
  48.     ? ret-1
  49.     =INKEY(0)
  50.     CANCEL
  51. ENDIF
  52. ret =install_ipr(portid, TRANSMIT, NULL, 4096)
  53. IF ret < 0
  54.     ? ret-1
  55.     =INKEY(0)
  56.     CANCEL
  57. ENDIF
  58. ret =install_isr(portid, 4, NULL)               && IRQ4 (use 3 for COM2)
  59. IF ret < 0
  60.     ? ret-2
  61.     =INKEY(0)
  62.     CANCEL
  63. ENDIF
  64.  
  65.  
  66. PUBLIC fh                                       && declare our file handle
  67.  
  68. IF ret == 0
  69.     =set_rx_xlat(portid, LOCAL_ECHO, TRUE)      && turn on RX echo
  70.     fh = FCREATE("mylog.log", 0)                && create log file
  71. ENDIF
  72.  
  73. DEFINE PAD p_ct_emul OF main_menu PROMPT "\<Emulation" AT 00, 37
  74.     ON SELECTION PAD p_ct_emul OF main_menu =do_term_emul(portid, 37)
  75.  
  76. ACTIVATE MENU main_menu
  77.  
  78. FUNCTION do_echo
  79.     PARAMETERS ch
  80.     =FWRITE(fh, ch)
  81. RETURN (NIL)
  82.  
  83.  
  84.  
  85. *
  86. * DO_TERM_EMUL(expN portid)
  87. * Show a menu that allows the user to select a terminal to emulate.
  88. * Called from mainmenu()
  89. *
  90. FUNCTION do_term_emul
  91.     PARAMETERS portid, col
  92.     PRIVATE nChoice, termtype
  93.  
  94.     termtype = get_terminal(col)
  95.     IF termtype != CT_EOF
  96.         * USE XONXOFF FLOW CONTROL (THIS LETS US BUFFER RECEIVED DATA) *
  97.         =set_tx_xlat(portid, FLOWCTL, XONXOFF)  && better accept flow control if > 2400 bps
  98.         =set_rx_xlat(portid, LOCAL_ECHO, TRUE)  && echo RX data to screen
  99.         =set_tx_xlat(portid, LOCAL_ECHO, FALSE) && (optionally) don't echo TX data
  100.         ret = term_init(portid, termtype)
  101.         =term_set(portid, TERM_ROWS, WROWS("w_term")+1) && Must be interior height of window+1
  102. *       =term_set(portid, TERM_ROWS, 25)        && Won't work. Must be interior height of window+1
  103.         =term_set(portid, TERM_COLS, 78)
  104.         =term_set(portid, TERM_KEYCLICK, 0)     && Drives you mad!
  105.         IF ret < 0
  106.             =status_msg(0, "Insufficient memory for terminal emulation")
  107.         ENDIF
  108.     ENDIF
  109. RETURN (ret)
  110.  
  111.  
  112.  
  113. *
  114. * GET_TERMINAL(expN tr, expN lc)
  115. * Show a menu that allows the user to select a terminal to emulate.
  116. * Called from do_terminal_menu()
  117. *
  118. FUNCTION get_terminal
  119.     PARAMETER col
  120.     PRIVATE termtype
  121.  
  122.     termtype = 0
  123.     DEFINE POPUP pop_terminal FROM 01, col;
  124.         IN SCREEN;
  125.         SHADOW
  126.         DEFINE BAR 1  OF pop_terminal PROMPT " \<TTY        "
  127.         DEFINE BAR 2  OF pop_terminal PROMPT " \<ANSI.SYS   "
  128.         DEFINE BAR 3  OF pop_terminal PROMPT " ANSI \<X3.64 "
  129.         DEFINE BAR 4  OF pop_terminal PROMPT " VT\<52       "
  130.         DEFINE BAR 5  OF pop_terminal PROMPT " VT\<100      "
  131.         DEFINE BAR 6  OF pop_terminal PROMPT " VT\<220      "
  132.  
  133.     ON SELECTION POPUP pop_terminal termtype=_terminal_menu(BAR())
  134.     ACTIVATE POPUP pop_terminal
  135.     DEACTIVATE POPUP pop_terminal
  136.     RELEASE POPUPS pop_terminal
  137. RETURN (termtype)
  138.  
  139.  
  140. FUNCTION _terminal_menu
  141.     PARAMETERS nChoice
  142.     PRIVATE termtype
  143.  
  144.     DO CASE
  145.         CASE nChoice = 1
  146.             termtype = TTY
  147.         CASE nChoice = 2
  148.             termtype = ANSI_SYS
  149.         CASE nChoice = 3
  150.             termtype = ANSI_X364
  151.         CASE nChoice = 4
  152.             termtype = DEC_VT52
  153.         CASE nChoice = 5
  154.             termtype = DEC_VT100
  155.         CASE nChoice = 6
  156.             termtype = DEC_VT220
  157.         OTHERWISE
  158.             termtype = CT_EOF
  159.     ENDCASE
  160.     =status_msg(0, "Terminal: " + ALLTRIM(PROMPT()))
  161. RETURN (termtype)
  162.  
  163.  
  164.  
  165. FUNCTION ct_online
  166.     PARAMETERS portid
  167.  
  168.     ACTIVATE WINDOW w_term
  169.     @ 00,00 SAY "CommTools Terminal Version " +;
  170.         ALLTRIM(STR(version)) + ": Press CTRL-HOME to return to menu"
  171.  
  172. *   =CT_SET_WIN(portid)
  173.     =set_rx_xlat(portid, FILE_ECHO, "DO_ECHO")  && turn on file echo
  174.     =c_term(portid)                             && switch to dumb terminal mode
  175. RETURN (0)
  176.  
  177.  
  178.  
  179. *
  180. * C_TERM -- This is a dumb terminal loop in FoxPro.
  181. * Alternately poll the serial input buffer and the keyboard for data.
  182. *
  183. FUNCTION c_term
  184.     PARAMETERS portid
  185.     PRIVATE c
  186.  
  187.     ?
  188.     DO WHILE .T.
  189.         * CHECK SERIAL PORT FOR BYTE *
  190.         c = c_getc(portid)                      && check the serial port for a byte
  191.         * CHECK KEYBOARD FOR A KEY PRESS *
  192.         * THE GRAND COMPROMISE...
  193.         * INKEY() IS SLOW, SO AVOID IT
  194.         * CHRSAW() DOES NOT DISPLAY THE CURSOR, SO CALL INKEY() PERIODICALLY
  195.         IF c == CT_EOF .OR. CHRSAW() == .T.
  196.             c = INKEY()                             && check keyboard for a key
  197.             DO CASE                                 && evaluate the received key
  198.                 CASE c == 29                        && CTRL-HOME was pressed
  199.                     RETURN (0)
  200.                 CASE c == DEL
  201.                     =c_putc(portid, BS)             && Fox Does not handle back space nicely
  202.                 CASE c <> 0
  203.                     =c_putc(portid, c)
  204.             ENDCASE
  205.         ENDIF
  206.     ENDDO                                       && do while .t.
  207. RETURN (0)
  208.