home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / decpro300 / procon.mac < prev    next >
Text File  |  2020-01-01  |  39KB  |  1,468 lines

  1.     .TITLE    KERCON - KERMIT connect module
  2.     .SBTTL    S Hecht/D Stevens/R McQueen
  3.  
  4. ;++
  5. ; This module contains the terminal emulation code for Pro/Kermit.
  6. ;--
  7.  
  8. ; Version number
  9.  
  10.     .IDENT    /1.0.05/
  11.  
  12. ; Directives
  13.  
  14.     .ENABLE    LC            ; Enable lower case in ASCIx
  15.     .NLIST    BEX
  16.     .LIBRARY /KERMLB/        ; Kermit macro library file
  17.  
  18.     .SBTTL    Revision History
  19.  
  20. ;++
  21. ; Version 1.0.00
  22. ;
  23. ; 1.0.00    By: Authors        On: Many days
  24. ;        Create this module
  25. ;
  26. ; 1.0.01    By: Robert C McQueen        On: 28-Feb-1984
  27. ;        Rewrite lost of the console terminal processing so that
  28. ;        Ctl-O, Ctl-C, etc get to the -10 a lot faster.
  29. ;
  30. ; 1.0.02    By: Robert C. McQueen        On: 27-March-1984
  31. ;        Try once again to fix the ^C problem.
  32. ;
  33. ; 1.0.03    By: Robert C. McQueen        On: 6-April-1984
  34. ;        Send RIS character sequence to the terminal after we exit
  35. ;        the connect processing.
  36. ;
  37. ; 1.0.04    By: Robert C. McQueen        On: 16-April-1984
  38. ;        Make this a seperate task.  Solves some of the problem
  39. ;        of needing a DTE equiv for Tool kit and also get lots of
  40. ;        address space for logging.
  41. ;
  42. ; 1.0.05    By: Robert C. McQueen        On: 11-May-1984
  43. ;        Fix local echo for the F11 to F13 keys (ESC, BS, LF).
  44. ;--
  45.  
  46.     .SBTTL    External symbols
  47.  
  48. ; Get the KERMLB definitions
  49.  
  50.     .MCALL    KERDEF
  51.     KERDEF                ; Get the general symbol definitions
  52.  
  53.     .MCALL    CHRDEF            ; Get the character definition macro
  54.     CHRDEF                ; Define the special characters
  55.  
  56.     .MCALL    IOSBDF            ; IOSB definitions
  57.     IOSBDF                ; Define the offsets
  58.  
  59.     .MCALL    BLSRTN            ; Allow use of BLISS macros from
  60.     .MCALL    BLSCAL            ;   library
  61.     .MCALL    TABLE            ; Macro to generate tables 
  62.     .MCALL    MSG            ; Macro to define text literals.
  63.     .MCALL    PJMP            ; Jump and return from routine
  64.     .MCALL    ND            ; If not defined, define symbol macro
  65. ;
  66. ; System routines used in Kercon
  67. ;
  68.  
  69.     .MCALL    QIO$S            ; QIO on the stack
  70.     .MCALL    QIOW$S            ; QIOW using the stack
  71.     .MCALL    QIOW$C            ; QIOW
  72.     .MCALL    ASTX$S            ; Exit from an AST routine
  73.     .MCALL    CLEF$S            ; Clear event flag
  74.     .MCALL    MRKT$S            ; Mark time
  75.     .MCALL    SETF$S            ; Set event flag
  76.     .MCALL    WTSE$S            ; Wait for single EFN using stack
  77.     .MCALL    ALUN$C            ; Assign a LUN
  78.     .MCALL    EXIT$S            ; Exit from the routines
  79.  
  80.     .SBTTL    Macro definitions -- Escape commands
  81.  
  82. ;++
  83. ; This macro contains the valid commands that can follow an escape character
  84. ;--
  85.  
  86. .MACRO    ESCCMD
  87.  $TABA    'C,C$EXIT        ;; Close communications port
  88.  $TABA    'B,C$BREAK        ;; Send a break
  89.  $TABA    'S,C$STAT        ;; Issue the status
  90.  $TABA    '?,C$HELP        ;; Issue the help text
  91. .ENDM
  92.  
  93. ;
  94. ; Now expand the table.
  95. ;
  96. TABLE    ESC,ESCCMD
  97.  
  98.     .SBTTL    Macro definitions -- Function keys allowed
  99.  
  100. ;++
  101. ; The following macro will generate the possible function keys that we
  102. ; can handle.
  103. ;--
  104.  
  105.  
  106. .MACRO    FNCKEY
  107.  KY    '13~',C$BREAK,            ; F3  - Break key
  108.  KY    '20~',C$EXIT,            ; F9  - Main Screen
  109.  KY    '21~',C$EXIT,            ; F10 - Exit key
  110.  KY    '23~',C$CHAR,.CHESC        ; F11 - Generate an escape character
  111.  KY    '24~',C$CHAR,.CHCNH        ; F12 - Generate a backspace character
  112.  KY    '25~',C$CHAR,.CHLFD        ; F13 - Generate a line feed character
  113.  KY    '28~',C$HELP,            ; F15 - Call help routine
  114. .ENDM
  115. ;
  116. ; Now generate the tables
  117. ;
  118. .MACRO    KY    TEXT,ROUTIN,ADDTNL,?TXTADR
  119.     ;;
  120.     ;; Save the current state of the psects
  121.     ;;
  122.     .SAVE                ;; Save the current PSECT
  123.     .ENABL LSB                ;; Start local symbol block
  124.     ;;
  125.     ;; First generate the text
  126.     ;;
  127.     .PSECT    $TEXT$, RO, D        ;; $TEXT$ psect
  128.     ;;
  129. TXTADR:    .ASCIZ    TEXT
  130.     .EVEN
  131.     ;;
  132.     ;; Now store the address in the table
  133.     ;;
  134.     .RESTORE                ;; Restore the PSECT
  135.     ;;
  136.     ;; Generate the address of the item
  137.     ;;
  138.     .WORD TXTADR
  139.     .DSABL LSB                ;; End of local symbol block
  140.     ;;
  141. .ENDM
  142.  
  143. ;
  144. ; Now generate the table of text
  145. ;
  146.     .PSECT    $TABL$, RO, D
  147. T$KEY:    FNCKEY                ; Generate the function keys
  148. KEY$L=.-T$KEY                ; Length of the table
  149. ;
  150. ; Now generate the routines that get called.
  151. ;
  152. .MACRO    KY    TEXT,ROUTINE,ADDTNL,?TXTADR
  153.     .WORD    ROUTINE
  154. .ENDM
  155.  
  156.     FNCKEY                ; Generate the routine addresses
  157. ;
  158. ; Now generate the addition information
  159. ;
  160. .MACRO    KY    TEXT,ROUTINE,ADDTNL,?TXTADR
  161.     .IF NB <ADDTNL>
  162.     .WORD    ADDTNL
  163.     .IFF
  164.     .WORD    0
  165.     .ENDC
  166. .ENDM
  167.  
  168.     FNCKEY
  169.  
  170.     .SBTTL    Symbol definitions
  171.  
  172. ;++
  173. ; The following are local symbol definitiosn for the KERCON module.
  174. ;--
  175.  
  176.                     ; \/ \/ MUST BE A POWER OF 2.
  177. ND    NM.TIC,    64.            ; Allow 64 characters input buffer
  178. ND    NM.QIO, 4.            ; Up to four output QIO's pending at once
  179.                     ; /\ /\ MUST BE A POWER OF 2.
  180.  
  181.     .SBTTL    State definitions for Console Terminal Input
  182.  
  183. ;++
  184. ; The following define the various states of the Console Terminal Input
  185. ; routines.  These input routines are all at AST level and the states
  186. ; describe what happens there.
  187. ;--
  188.  
  189.     $CSINI=    0        ; Initial state
  190.     $CSESC=    1*2        ; Saw an <Escape>
  191.     $CSCSI=    2*2        ; Saw a CSI
  192.     $CSSQB=    3*2        ; Saw a [
  193.     $CSDG1=    4*2        ; Saw first digit
  194.     $CSDG2=    5*2        ; Saw second digit
  195.     $CSCEC=    6*2        ; Saw connect escape character (ESCCHR)
  196.  
  197.     .SBTTL    General storage locations
  198.  
  199.     .PSECT    $OWN$, RW, D
  200.  
  201. INPCHR:    .BLKW    1            ; Place to read characters into
  202. CONXIT:    .BLKW    1            ; Exit connect processing
  203. FNCPTR:    .BLKW    1            ; Pointer into FNCTXT
  204. FNCTXT:    .BLKW    3            ; Function key text
  205. NOBIT8:    .BLKW    1            ; No bit 8
  206. ;
  207. ; Terminal input data
  208. ;
  209. TILOCK:    .BLKW    1            ; Interlock for the terminal data base
  210. TTIBUF:    .BLKB    NM.TIC            ; Number of terminal characters allowed
  211. TTINCH:    .BLKW    1            ; Number of characters in TRMBUF
  212. TTIIDX:    .BLKW    1            ; Index into TTIBUF
  213. TTISTO:    .BLKW    1            ; Index to store characters into TTIBUF
  214. TIIOSB:    .BLKB    IB.MSZ            ; IOSB for QIO
  215. TIQIO:    .BLKW    1            ; QIO pending for the console input
  216. STATE:    .BLKW    1            ; State of the AST routine
  217. TBC:    .BLKB    2            ; Type ahead buffer count
  218. QIOIDX:    .BLKB    1            ; Current output QIO number
  219.     .EVEN
  220. ;
  221. ; Terminal output data
  222. ;
  223. TOIOSB:    .BLKB    IB.MSZ            ; IOSB for non-AST level outputs
  224. TOIOS0:    .BLKB    <IB.SIZ*NM.QIO>        ; IOSB's for QIO
  225. TOLOCK:    .BLKW    1            ; Interlock for console type out
  226. OUTCHR:    .BLKW    1            ; Character to be output
  227.  
  228.     .SBTTL    CONNECT processing
  229.  
  230. ;++
  231. ; The following is the main processing for the terminal emulation.
  232. ;--
  233.  
  234.     .PSECT    $CODE$, RO, I
  235.  
  236. MAIN:    ALUN$C    XKLUN,XK,0,$CODE$    ; Assign XK LUN
  237.     ALUN$C    TERLUN,TI,0,$CODE$    ; Assign the terminal LUN
  238.     JSR    PC,INILIB        ; Initialize the library routines
  239.     JSR    PC,CRECON        ; Make the connect character ascii
  240.     BLSCAL    TT.INIT            ; Initialize terminal processing
  241.  
  242.     JSR    PC,CONECT        ; Do the connect processing
  243.     JSR    PC,S$CLEAR        ; Clear the screen
  244.     EXIT$S                ; Exit the task
  245.  
  246.     .SBTTL    Main connect routine (entry point)
  247.  
  248. ;++
  249. ; This routine will handle the processing of the CONNECT command.  It is
  250. ; called directly from the command dispatch processing.
  251. ;
  252. ; Usage:
  253. ;    JSR    PC,CONNECT
  254. ;    (Return)
  255. ;
  256. ;--
  257.  
  258.     .PSECT    $CODE$, RO, I
  259.  
  260. CONECT::
  261. ;
  262. ; First initialize some local parameters, so we don't have to do this
  263. ; every time
  264. ;
  265.     MOV    #FALSE,NOBIT8        ; Assume we are not removing bit 8
  266.     CMP    #PR.MARK,PARITY        ; Using mark parity?
  267.     BEQ    5$            ; Yes, must remove the bit
  268.     BIT    #TRUE,TRM7BT        ; Only passing 7 bit codes?
  269.     BNE    10$            ; Don't have to remove the bit
  270. 5$:    MOV    #TRUE,NOBIT8        ; Flag we must remove bit 8
  271.  
  272. ;
  273. ; Initialize the two different ports
  274. ;
  275. 10$:    CLR    CONXIT            ; Clear the exit flag
  276.  
  277.     JSR    PC,CT.INI        ; Initialize the CT port
  278.     BCS    90$            ; Failed, print an error message
  279.  
  280.     CLR    R0            ; Use the default
  281. 13$:    MOV    #DUMPXK,R1        ; Routine to do direct XK dumps
  282.     JSR    PC,XK.INI        ; Open the XK port
  283.     BCS    100$            ; Could not get XK
  284. ;
  285. ; At this point we have the two ports attached, so we just clear the
  286. ; screen and output the banner for terminal emulation.
  287. ;
  288.     JSR    PC,S$CLEAR        ; Clear screen
  289.     JSR    PC,C$BANR        ; Output the connect banner
  290. ;
  291. ; The following is commented out since most systems will screw up when getting
  292. ; the leading CSI's from the function keys.  Everything at this point
  293. ; expects <ESC>[ rather than <CSI>.
  294. ;
  295. ; Set up terminal subsystem so that we get correct type of codes from
  296. ; the keys.
  297. ;
  298.     MOV    #RTN7BT,R0        ; Assume we want 7 bit codes
  299. ;    CMP    #PR.NONE,PARITY.TYPE    ; No parity?
  300. ;    BNE    15$            ; If not, we can't pass 8 bit codes anyway
  301. ;    BIT    #TRUE,TRM7BT        ; 7-bit desired?
  302. ;    BNE    15$            ; Yes, do that
  303. ;    MOV    #RTN8BT,R0        ; No, use 8-bit data
  304. 15$:    BLSCAL    TT.TEXT,R0        ; Send the string
  305.     BLSCAL    TT.OUTPUT        ; And force it out
  306.  
  307.     JSR    PC,CT.QIO        ; Post the initial QIO for the terminal
  308. ;    CMP    DUPLEX,#DP.HAL        ; Check for half duplex
  309. ;    BNE    20$            ; If not skip
  310. ;
  311. ;    MOV    IBM.CHAR,R0        ; If half then send turn around char.
  312. ;    JSR    PC,CT.PAR        ; Generate the parity
  313. ;    JSR    PC,XK.OUT        ; Write the character with parity
  314. ;
  315. ;
  316. ; Here to start the terminal emulation
  317. ;
  318.  
  319. 20$:    JSR    PC,DUMPXK        ; Dump XK input to console screen
  320.     JSR    PC,DUMPCT        ; Dump the console input to the XK
  321.     JSR    PC,XK.QIO        ; Make sure a QIO is posted for the XK
  322.     JSR    PC,CT.QIO        ; Make sure there is a QIO posted
  323.     TST    CONXIT            ; Must we exit?
  324.     BNE    40$            ; Yes, just exit
  325. ;
  326. ; Here to wait for the EFNs to be set by somebody
  327. ;
  328.     WTSE$S    #CONEFN            ; Wait until we have input
  329.     CLEF$S    #CONEFN            ; Clear so we know when none.
  330.     MRKT$S    #CONEFN,#1.,#2.        ; Make sure we run at least once a second
  331.     BR    20$            ; Loop for more input
  332. ;
  333. ; Here to exit from the connect processing
  334. ;
  335. 40$:    JSR    PC,XK.SHT        ; Shut down the XK
  336.     JSR    PC,CT.SHT        ; Shut this down too
  337.     BLSCAL    TT.TEXT,#M$RIS        ; Send the reset string
  338.     BLSCAL    TT.OUTPUT        ; Force it out
  339.     RTS    PC            ; Return to the caller
  340. ;
  341. ; Here if we can not get the console terminal
  342. ;
  343. 90$:    BLSCAL    BL$MOV,<#CTBS$L,#M$CTBS,#MSG1> ; Console is busy
  344.     JSR    PC,S$CLEAR        ; Clear the screen
  345.     BLSCAL    TT.TEXT,#M$CTBS,+    ; Port is busy
  346.     BLSCAL    TT.TEXT,#RESTXT,+    ; Say he should type resume
  347.     BLSCAL    TT.OUTPUT,,-        ; Force the output
  348.     CALL    WTRES            ; Wait for resume key
  349.     RTS    PC            ; And return
  350.  
  351. ;
  352. ; Here if we can not get the XK port
  353. ;
  354. 100$:    JSR    PC,CT.SHT        ; Release the console terminal
  355.     BLSCAL    BL$MOV,<#XKBS$L,#M$XKBS,#MSG1> ; XK is busy
  356.     JSR    PC,S$CLEAR        ; Clear the screen
  357.     BLSCAL    TT.TEXT,#M$XKBS,+    ; Port is busy
  358.     BLSCAL    TT.TEXT,#RESTXT,+    ; Say he should type resume
  359.     BLSCAL    TT.OUTPUT,,-        ; Force the output
  360.     CALL    WTRES            ; Wait for resume key
  361.     RTS    PC            ; And return
  362.  
  363. ; Text for various items above
  364.  
  365.     .PSECT    $PLIT$, RO, D        ; This is data
  366.  
  367. M$RIS:    .ASCIZ    <.CHESC>/c/        ; Reset to initial state
  368.  
  369. MSG    XKBS,<Communications port in use by another task - try again when free>
  370. MSG    CTBS,<Console terminal in use by another task>
  371. RESTXT:    .ASCIZ    <.CHCRT><.CHLFD>/Press RESUME to continue/<.CHCRT><.CHLFD>
  372.  
  373. ;RTN8BT:    .ASCIZ    <.CHESC>/ G/        ; Want 8-bit codes from function keys
  374. RTN7BT:    .ASCIZ    <.CHESC>/ F/        ; Want 7-bit codes from function keys
  375.     .EVEN                ; Make sure we are on a word boundary
  376.  
  377.     .SBTTL    C$BANR - Connect banner type out
  378.  
  379. ;++
  380. ; This routine will type the banner for the connect.  This is displayed when
  381. ; terminal emulation is entered.
  382. ;--
  383.  
  384.     .PSECT    $PLIT$, RO, D
  385.  
  386. CONMG1:    .ASCII    <.CHCR><.CHLF><.CHLF>\PRO/Kermit - \
  387.     .ASCII    \Terminal Emulation version 1.0\
  388.     .ASCII    <.CHCR><.CHLF><.CHLF><.CHLF>
  389.     .ASCII    \Now entering Terminal Emulation mode\<.CHCR><.CHLF><.CHLF>
  390.     .ASCIZ    \Type \
  391. CONMG2:    .ASCIZ    \C \
  392. CONMG3:    .ASCIZ    \or press MAIN SCREEN or EXIT \
  393. CONMG4:    .ASCII    \to return to PRO/Kermit, \
  394.     .ASCIZ    <.CHCR><.CHLF>/Type /
  395. CONMG5:    .ASCIZ    \? \
  396. CONMG6:    .ASCIZ    \or press HELP \
  397. CONMG7:    .ASCIZ    \for help.\<.CHCR><.CHLF>
  398.     .EVEN
  399.  
  400.     .PSECT    $CODE$, RO, I
  401.  
  402. C$BANR:    BLSCAL    TT.TEXT,#CONMG1,+    ; Output the first part
  403.     BLSCAL    TT.TEXT,#CONCHR,+    ; And the connect character
  404.     BLSCAL    TT.TEXT,#CONMG2,+    ; Second part
  405.     BIT    #TRUE,TRMTRN        ; Terminal in transparent mode?
  406.     BNE    10$            ; Yes, don't output the following
  407.  
  408.     BLSCAL    TT.TEXT,#CONMG3,+    ; Output some more
  409. 10$:    BLSCAL    TT.TEXT,#CONMG4,+    ; Output the rest of the line
  410.     BLSCAL    TT.TEXT,#CONCHR,+    ; And the connect character
  411.     BLSCAL    TT.TEXT,#CONMG5,+    ; And the last part
  412.     BIT    #TRUE,TRMTRN        ; Transparent mode?
  413.     BNE    20$            ; Yes, skip this about HELP key
  414.     BLSCAL    TT.TEXT,#CONMG6,+    ; Output about HELP
  415. 20$:    BLSCAL    TT.TEXT,#CONMG7,+    ; Finish message off
  416.  
  417.     BLSCAL    TT.OUTPUT,,-        ; Output the rest of the characters
  418.     RTS    PC            ; Return to the caller
  419.  
  420.     .SBTTL    C$CHAR - Send a special character to the remote
  421.  
  422. ;++
  423. ; This routine will send a special character to the remote.
  424. ;
  425. ; Usage:
  426. ;    R1/ Information from table
  427. ;    JSR    PC,C$CHAR
  428. ;    (Return)
  429. ;--
  430.  
  431.     .PSECT    $CODE$, RO, I
  432.  
  433. C$CHAR:    PJMP    XKOUT            ; Send it
  434.  
  435.     .SBTTL    C$EXIT - Exit from terminal emulation
  436.  
  437. ;++
  438. ; This routine will be called to exit from the terminal emulation.  It
  439. ; will cause the flag to be set so that the loop level notices that we
  440. ; have to exit.
  441. ;
  442. ; Usage:
  443. ;    JSR    PC,C$EXIT
  444. ;    (Return)
  445. ;
  446. ;--
  447.  
  448.     .PSECT    $CODE$, RO, I
  449.  
  450. C$EXIT:    MOV    #1,CONXIT        ; Set the flag
  451.     RTS    PC            ; Return to the caller
  452.  
  453.     .SBTTL    C$BREAK - Send a break to the remote
  454.  
  455. ;++
  456. ; This routine will send a break character to the remote connection.
  457. ;
  458. ; Usage:
  459. ;    JSR    PC,C$BREAK
  460. ;    (Return)
  461. ;
  462. ;--
  463.  
  464.     .PSECT    $CODE$, RO, I
  465.  
  466. C$BREAK:
  467.     JSR    PC,XK.BRK        ; Send the break
  468.     RTS    PC            ; Return to the caller
  469.  
  470.     .SBTTL    C$STAT - Output the connection status
  471.  
  472. ;++
  473. ; This routine will output the connection status.  This routine is called
  474. ; after the escape character has been typed followed by an 'S'.
  475. ;--
  476.  
  477.     .PSECT    $PLIT$, RO, D
  478.  
  479. STAMG1:    .ASCIZ    <.CHCRT><.CHLFD><.CHLFD>/[The baud rate is /
  480. STAMG2:    .ASCIZ    \ (T)/\
  481. STAMG3:    .ASCIZ    / (R) bits per second.]/<.CHCRT><.CHLFD>/[Local echo /
  482. STAMG4:    .ASCIZ    /]/<.CHCRT><.CHLFD><.CHLFD>
  483.  
  484. MSG    ON,<on>
  485. MSG    OFF,<off>
  486.  
  487. .MACRO    SPD
  488.  $TAB    S.50,<50>
  489.  $TAB    S.75,<75>
  490.  $TAB    S.100,<100>
  491.  $TAB    S.110,<110>
  492.  $TAB    S.134,<134>
  493.  $TAB    S.150,<150>
  494.  $TAB    S.200,<200>
  495.  $TAB    S.300,<300>
  496.  $TAB    S.600,<600>
  497.  $TAB    S.1200,<1200>
  498.  $TAB    S.1800,<1800>
  499.  $TAB    S.2000,<2000>
  500.  $TAB    S.2400,<2400>
  501.  $TAB    S.3600,<3600>
  502.  $TAB    S.4800,<4800>
  503.  $TAB    S.7200,<7200>
  504.  $TAB    S.9600,<9600>
  505.  $TAB    S.19.2,<19200>
  506. ; $TAB    S.38.4,<38400>
  507. .ENDM
  508.  
  509. ; Now define the item in the table
  510.  
  511.     TABLE    SPD,SPD            ; Define the speed table
  512.  
  513.     .PSECT    $CODE$, RO, I
  514.  
  515. C$STAT:    BLSCAL    TT.TEXT,#STAMG1,+    ; Output the message.
  516.     MOV    #TC.XSP,R0        ; Get the transmit speed parameter
  517.     MOV    #CURXKP,R1        ; Use the current parameters
  518.     JSR    PC,FNDXKP        ; Find the parameter in the block
  519.     JSR    PC,C$SBAU        ; Output the baud rate
  520.     BLSCAL    TT.TEXT,#STAMG2,+    ; Output the message.
  521.     MOV    #TC.RSP,R0        ; Get the receive speed parameter
  522.     MOV    #CURXKP,R1        ; Use the current parameters
  523.     JSR    PC,FNDXKP        ; Find the parameter in the block
  524.     JSR    PC,C$SBAU        ; Output the baud rate
  525.     BLSCAL    TT.TEXT,#STAMG3,+    ; Output the message.
  526.     MOV    #M$ON,R2        ; Assume local echo
  527.     BIT    #TRUE,LCLECH        ; Local echo?
  528.     BNE    10$            ; If non-zero we are using local echo
  529.     MOV    #M$OFF,R2        ; If zero, we aren't
  530. 10$:    BLSCAL    TT.TEXT,R2,+        ; Output the message.
  531.     BLSCAL    TT.TEXT,#STAMG4,+    ; Output the message.
  532.  
  533.     BLSCAL    TT.OUTPUT,,-        ; Output the rest of the mess
  534.     RTS    PC            ; Return to the caller
  535. ;
  536. ; Subroutine to output the baud rate given the index.
  537. ;
  538. C$SBAU:    MOVB    (R0),R2            ; Get the index
  539.     MOV    #T$SPD,R0        ; Get the table
  540.     MOV    #SPD$L/2,R1        ; Get the length
  541.     JSR    PC,FNDOFS        ; Find the offset
  542.     TST    R0            ; Is this zero?
  543.     BEQ    99$            ; Yes, just return
  544.     ADD    #SPD$L,R0        ; Point to the entry
  545.     MOV    (R0),R2            ; Get the item
  546.     MOVB    (R2)+,R3        ; Get the length
  547.     TST    -(SP)            ; Allocate one word
  548. 10$:    MOVB    (R2)+,(SP)        ; Get the character
  549.     JSR    PC,TT.CHAR        ; Output the character
  550.     SOB    R3,10$            ; Loop for all character
  551.     TST    (SP)+            ; Clear up the stack
  552. 99$:    RTS    PC            ; Return to the caller
  553.  
  554.     .SBTTL    C$HELP - Help command for the connect processing
  555.  
  556. ;++
  557. ; This routine will issue the help message to the user's terminal.  It will
  558. ; then return to the calling routine.
  559. ;
  560. ; Usage:
  561. ;    JSR    PC,C$HELP
  562. ;    (Return)
  563. ;
  564. ;--
  565.  
  566.     .PSECT    $PLIT$, RO, D
  567.  
  568. CNHLP1:    .ASCII    <.CHCRT><.CHLFD>/CONNECT escape commands:/<.CHCRT><.CHLFD>
  569.     .ASCII    <.CHLFD>
  570.     .ASCII    /    B    Send a break/<.CHCRT><.CHLFD>
  571.     .ASCII    \    C    Close connect and return to PRO/Kermit\<.CHCRT><.CHLFD>
  572.     .ASCII    /    S    Type Status/<.CHCRT><.CHLFD>
  573.     .ASCII    /    ?    Help (this message)/<.CHCRT><.CHLFD>
  574.     .ASCIZ    /    /
  575.  
  576. CNHLP2:    .ASCIZ    /    Send the escape character/<.CHCRT><.CHLFD>
  577. CNHLP3:    .ASCII    \Press MAIN SCREEN or EXIT to return to PRO/Kermit\<.CHCRT><.CHLFD>
  578.     .ASCIZ    \Press HELP for this message\<.CHCRT><.CHLFD>
  579.     .EVEN
  580.  
  581.     .PSECT    $CODE$, RO, I
  582.  
  583. C$HELP:    BLSCAL    TT.TEXT,#CNHLP1,+    ; Output the first part of the help message
  584.     BLSCAL    TT.TEXT,#CONCHR,+    ; Output the escape character
  585.     BLSCAL    TT.TEXT,#CNHLP2,+    ; Last part of the text
  586.     BIT    #TRUE,TRMTRN        ; Transparent mode?
  587.     BNE    10$            ; Yes, don't say anything about function keys
  588.     BLSCAL    TT.TEXT,#CNHLP3,+    ; No, tell him about other keys
  589.  
  590. 10$:    BLSCAL    TT.OUTPUT,,-        ; Output the rest of the mess
  591.     RTS    PC            ; Return to the caller
  592.  
  593.     .SBTTL    CT.INI - Initialize the terminal processing
  594.  
  595. ;++
  596. ; This routine will initialize the terminal connect processing.
  597. ;
  598. ; Usage:
  599. ;    JSR    PC,CT.INI
  600. ;    (Return - Status in R0)
  601. ;
  602. ;--
  603.  
  604.     .PSECT    $CODE$, RO, I
  605.  
  606. CT.INI:    CLR    TTIIDX            ; Clear the pointers
  607.     CLR    TTISTO            ; . . .
  608.     CLR    TTINCH            ; . . .
  609.     CLR    STATE            ; Clear the character processing state
  610.     MOV    #1,TILOCK        ; Clear the interlock
  611.     MOV    #1,TOLOCK        ; Clear the interlock
  612.     MOV    #-1,TIQIO        ; And the QIO pending flag
  613.     QIOW$C    IO.ATT,TERLUN,TTAEFN, , , , ,$CODE$ ; Grab the device
  614. ;
  615. ; Now get the directive status and determine if we really did it correctly
  616. ;
  617.     MOV    $DSW,R0            ; Get the status
  618.     BGE    10$            ; Branch if no error
  619.     SEC                ; Mark the failure
  620.     RTS    PC            ; Return to the caller
  621.  
  622. ;
  623. ; Set the terminal for binary input.  This keeps control-C's from
  624. ;killing us.
  625. ;
  626.  
  627. 10$:    QIOW$C    SF.SMC,TERLUN,TTAEFN, , , ,<SMCBIN,SMCBNL>,$CODE$
  628.  
  629. ;
  630. ; Clear out the flag bytes in the output IOSB's so that they can be used.
  631. ;
  632.     MOV    #NM.QIO,R0        ; Get the count
  633.     MOV    #TOIOS0-IB.SIZ,R1    ; Point before first block
  634. 20$:    ADD    #IB.SIZ,R1        ; Point to next IOSB
  635.     CLRB    IB.FLG(R1)        ; Clear the flag
  636.     SOB    R0,20$            ; And loop for all IOSB's
  637. ;
  638. ; Give a good return
  639. ;
  640.     CLC                ; Clear the carry for the caller
  641.     RTS    PC            ; Return to the caller
  642.  
  643. ; Parameter list for SF.SMC function.  Sets the terminal for binary
  644. ;I/O.
  645.  
  646.     .PSECT    $TEXT$, RO, D
  647.  
  648. SMCBIN:    .BYTE    TC.BIN,1        ; Turn binary on
  649. SMCBNL=.-SMCBIN                ; Length of block
  650.  
  651.     .SBTTL    CT.SHT - Shut down the terminal processing
  652.  
  653. ;++
  654. ; This routine will shut down the connect terminal processing.
  655. ;
  656. ; Usage:
  657. ;    JSR    PC,CT.SHT
  658. ;    (Return - Status in R0)
  659. ;
  660. ;--
  661.  
  662.     .PSECT    $CODE$, RO, I
  663.  
  664. CT.SHT:    QIOW$C    IO.KIL,TERLUN,TTAEFN, , , , ,$CODE$    ; Kill QIO's
  665.     QIOW$C    SF.SMC,TERLUN,TTAEFN, , , ,<SMCCBN,SMCCBL>,$CODE$ ; Clear binary
  666.     QIOW$C    IO.DET,TERLUN,TTAEFN, , , , ,$CODE$    ; Detach the device
  667.     MOV    #-1,TIQIO        ; No QIO pending any more
  668.     RTS    PC            ; And return
  669.  
  670.     .PSECT    $TEXT$, RO, D
  671. SMCCBN:    .BYTE    TC.BIN, 0        ; Clear binary input
  672. SMCCBL=.-SMCCBN                ; Length of block
  673.  
  674.     .SBTTL    CT.INP - Read a character from the CT buffer
  675.  
  676. ;++
  677. ; This routine will read a character from the CT buffer.  It will then
  678. ; return the character to the calling routine
  679. ;
  680. ; Usage:
  681. ;    JSR    PC,CT.INP
  682. ;    (Return)
  683. ;
  684. ; On return:
  685. ;    Carry - Clear if no characters, set if there was one
  686. ;    R1/ Character if any there
  687. ;--
  688.  
  689.     .PSECT    $CODE$, RO, I
  690.  
  691. CT.INP:    DEC    TILOCK            ; Do I have the interlock?
  692.     BNE    90$            ; No, skip this
  693. ;
  694. ; Here with the interlock, see if there are characters to process
  695. ;
  696.     MOV    TTINCH,R0        ; Get the number of characters
  697.     BEQ    10$            ; Branch if none
  698. ;
  699. ; Here if we have characters that can be passed back to the caller
  700. ;
  701.     MOV    TTIIDX,R1        ; Get the index
  702.     MOVB    TTIBUF(R1),R1        ; Get the character
  703.     DEC    TTINCH            ; Decrement the number of characters
  704.     INC    TTIIDX            ; Increment
  705.     BIC    #^C<NM.TIC-1>,TTIIDX    ; Make sure we don't go over the end
  706.                     ;  of the buffer
  707.  
  708.     CLC                ; Clear the carry
  709.     MOV    #1,TILOCK        ; Clear the interlock
  710.     RTS    PC            ; Return to the caller
  711. ;
  712. ; Here if there were no characters, set the carry and return
  713. ;
  714. 10$:    SEC                ; Set the carry
  715.     MOV    #1,TILOCK        ; Clear the interlock
  716.     RTS    PC            ; Return to the caller
  717. ;
  718. ; Here if we could not get the interlock.  Just return as if there were no
  719. ; characters.
  720. ;
  721. 90$:    SEC                ; Set the carry
  722.     RTS    PC            ; Return to the caller
  723.  
  724.     .SBTTL    CT.QIO - Post initial QIO for console terminal
  725.  
  726. ;++
  727. ; This routine will post the initial QIO for the console terminal.
  728. ;
  729. ; Usage:
  730. ;    JSR    PC,CT.QIO
  731. ;    (Return)
  732. ;
  733. ;--
  734.  
  735.     .PSECT    $CODE$, RO, I
  736.  
  737. CT.QIO:    INC    TIQIO            ; Need a QIO?
  738.     BNE    99$            ; No, just return
  739.     CMP    TTINCH,#NM.TIC        ; Buffer full?
  740.     BEQ    10$            ; Branch if so
  741.     MOV    R1,-(SP)        ; Save R1
  742.     MOV    TTISTO,R1        ; Get the index
  743.     ADD    #TTIBUF,R1        ; Get the address to output
  744.     CLR    TIQIO            ; Flag QIO is posted
  745.     QIO$S    #IO.RAL!IO.RNE,#TERLUN,#TTREFN,,#TIIOSB,#CTIAST,<R1,#1>
  746.     MOV    (SP)+,R1        ; Restore R1
  747. 99$:    RTS    PC            ; Return to the caller
  748.  
  749. ; Here if there is no room to read into.  Remember we don't have a QIO
  750. ;outstanding.
  751.  
  752. 10$:    MOV    #-1,TIQIO        ; No QIO
  753.     RTS    PC            ; Return
  754.  
  755.     .SBTTL    CTIAST - Handle ASTs for incoming characters
  756.  
  757. ;++
  758. ; This routine will handle console terminal input ASTs.  This routine
  759. ; will normally be called because there was a single character QIO
  760. ; outstanding for the console terminal.
  761. ;
  762. ; Usage:
  763. ;    AST level call.
  764. ;
  765. ;--
  766.  
  767.     .PSECT    $CODE$, RO, I
  768.  
  769. CTIAST::MOV    R0,-(SP)        ; Save this register
  770.     MOV    2(SP),R0        ; Get the current IOSB
  771.     JSR    PC,1$            ; Call the processing routine
  772.     MOV    (SP)+,R0        ; Restore the register
  773.     TST    (SP)+            ; Remove the IOSB from the stack
  774.     ASTX$S                ; Exit from the AST level routine
  775. ;
  776. ; The following is the main routine for the AST level processing.
  777. ;
  778. 1$:    MOV    #-1,TIQIO        ; No QIO pending now
  779. ;
  780. ; Now determine if there is an error from the QIO.
  781. ;
  782.     TSTB    IB.STS(R0)        ; Was there any errors?
  783.     BGE    10$            ; Branch if there were no errors
  784.     RTS    PC            ; Just return if errors
  785. ;
  786. ; Here if we have input some characters, determine the number and update
  787. ; the counts
  788. ;
  789. 10$:    MOV    IB.CNT(R0),R0        ; Get the count of characters
  790.     BEQ    20$            ; No characters, just exit
  791. ;
  792. ; Here if we have read some characters from the console terminal
  793. ;
  794.     SETF$S    #CONEFN            ; Set the event flag
  795.  
  796.     ADD    R0,TTISTO        ; Point the index to the end
  797.     BIC    #^C<NM.TIC-1>,TTISTO    ; Make sure queue works correctly
  798.     ADD    R0,TTINCH        ; Count up number of characters available
  799. 20$:    JSR    PC,DUMPCT        ; Dump console to the XK
  800.  
  801.     PJMP    CT.QIO            ; Issue the QIO
  802.  
  803.     .SBTTL    CTDUMP - Dump the console input
  804.  
  805. ;++
  806. ; This routine will dump the console input to the communications line.  It
  807. ; will return when all of the characters have been processed.
  808. ;
  809. ; Usage:
  810. ;    JSR    PC,DUMPCT        ; Call the routine
  811. ;    (Return)
  812. ;
  813. ;--
  814.  
  815. DUMPCT:    JSR    R1,$SAVE4        ; Save some registers
  816.  
  817. 10$:    JSR    PC,CT.INP        ; Get a character
  818.     BCS    99$            ; Branch if no more characters
  819. ;
  820. ; Now branch to the correct state.
  821. ;
  822.     MOV    STATE,R0        ; Get the state
  823.     MOV    CTIDSP(R0),R0        ; Get the routine address
  824.     JSR    PC,@R0            ; Dispatch to the routine
  825.     BR    10$            ; Loop for the next character
  826.  
  827. ;
  828. ; Here to return to the caller
  829. ;
  830. 99$:    RTS    PC            ; Return
  831.  
  832. ;++
  833. ; The following is the dispatch table for the various routines.  These
  834. ; routines will process the character that we received from the console
  835. ; terminal.
  836. ;--
  837.  
  838.     .PSECT    $PLIT$, RO, D
  839.  
  840. CTIDSP:    .WORD    ASTINI            ; Initial state
  841.     .WORD    ASTESC            ; Saw an <Escape>
  842.     .WORD    ASTCSI            ; Saw a CSI
  843.     .WORD    ASTSQB            ; Saw a [
  844.     .WORD    ASTDG1            ; Saw first digit
  845.     .WORD    ASTDG2            ; Saw second digit
  846.     .WORD    ASTCEC            ; Saw connect escape character (ESCCHR)
  847.  
  848.     .SBTTL    CTDUMP - ASTINI - Initial state
  849.  
  850. ;++
  851. ; This routine will handle the initial state for the AST processing.
  852. ;
  853. ; Usage:
  854. ;    R1/ Character
  855. ;    JSR    PC,@R0
  856. ;    (Return)
  857. ;
  858. ;--
  859.  
  860.     .PSECT    $CODE$, RO, I
  861.     .ENABL    LSB            ; Start local symbol block
  862.                     ;  (QIOW$C causes problems)
  863.  
  864. ASTINI:    CMP    R1,ESCCHR        ; Is this the escape character?
  865.     BEQ    30$            ; Yes, handle differently
  866.  
  867.     CMP    R1,#.CHCSI        ; Is this a CSI?
  868.     BEQ    40$            ; Check if allowed
  869.  
  870.     CMP    R1,#.CHESC        ; Start of an escape sequence?
  871.     BEQ    40$            ; Yes, handle it differently
  872.  
  873. 10$:    JSR    PC,XKOUT        ; Output the character
  874.     RTS    PC            ; Return to the caller
  875. ;
  876. ; Here after we have gotten an escape character in the initial state
  877. ;
  878.  
  879. 30$:    MOV    #$CSCEC,STATE        ; Set the new state
  880.     RTS    PC            ; Return to the caller
  881.  
  882. ;
  883. ; Here after we have gotten an Escape (33 octal) or a CSI
  884. ;
  885.  
  886. 40$:    BIT    #TRUE,TRMTRN        ; Terminal transparent mode?
  887.     BNE    10$            ; Branch if so
  888. ;
  889. ; Now determine if we have enough character coming from the keyboard for this
  890. ; to possibly be a function key.
  891. ;
  892.     MOVB    #TC.TBF,TBC        ; Store the function
  893.     QIOW$C    SF.GMC,TERLUN,TTREFN,,TIIOSB,,<TBC,2>,$CODE$
  894.     CMPB    #4,TBC+1        ; Do we have enough characters?
  895. ;    BLE    50$            ; Skip if enough
  896. ;    JMP    10$            ; Else output the character
  897.     BGT    10$            ; No, output the escape/CSI
  898. ;
  899. ; Here if we may have the start of an escape sequence.
  900. ;
  901.  
  902. 50$:    CLR    FNCTXT            ; Clear this
  903.     CLR    FNCTXT+2        ;  block
  904.     CLR    FNCTXT+4        ;   of characters
  905.  
  906.     MOV    #FNCTXT,R2        ; Get a pointer to the block
  907.     MOVB    R1,(R2)+        ; Store the characters
  908.     MOV    R2,FNCPTR        ; Store the pointer
  909.     MOV    #$CSESC,STATE        ; Assume we got an escape
  910.     CMP    #.CHESC,R1        ; Correct?
  911.     BEQ    99$            ; Yes, just return
  912.     MOV    #$CSCSI,R1        ; No, return CSI state
  913. 99$:    RTS    PC            ; Return to the caller
  914.  
  915.     .DSABL    LSB            ; End of local symbol block
  916.  
  917.     .SBTTL    CTDUMP - ASTESC - Process after an <Esc>
  918.  
  919. ;++
  920. ; This routine will handle the processing after an .CHESC character
  921. ; has been input.  It will determine if the next character is a square
  922. ; bracket and change state to handle it if it is.
  923. ;
  924. ; Usage:
  925. ;    R1/ Character
  926. ;    JSR    PC,@R0
  927. ;    (Return)
  928. ;
  929. ;--
  930.  
  931.     .PSECT    $CODE$, RO, I
  932.  
  933. ASTESC:    MOVB    R1,@FNCPTR        ; Store the character
  934.     INC    FNCPTR            ; Point to the next position
  935.     CMPB    #'[,R1            ; Is this a square bracket?
  936.     BEQ    10$            ; Yes, process it
  937.     MOV    #$CSINI,STATE        ; Store the new state
  938.     PJMP    CT.DFK            ; Dump the function key
  939. ;
  940. ; Here to get the new state
  941. ;
  942. 10$:    MOV    #$CSSQB,STATE        ; Set the new state
  943.     RTS    PC            ; Return to the caller
  944.  
  945.     .SBTTL    CTDUMP - ASTCSI - Process after a CSI
  946.  
  947. ;++
  948. ; This routine will handle the processing after a CSI character has
  949. ; been input.  It will determine if the next character is a digit and
  950. ; change state, so that the ASTDG1 routine is called if it is.
  951. ;
  952. ; Usage:
  953. ;    R1/ Character
  954. ;    JSR    PC,@R0
  955. ;    (Return)
  956. ;
  957. ;--
  958.  
  959.     .PSECT    $CODE$, RO, I
  960.  
  961. ASTCSI:    MOVB    R1,@FNCPTR        ; Store the character
  962.     INC    FNCPTR            ; Point to the next position
  963.  
  964.     JSR    PC,CHKDIG        ; Is this character a digit?
  965.     BCS    10$            ; Branch if that was a digit
  966.     JSR    PC,CT.DFK        ; Dump the function key text
  967.     MOV    #$CSINI,STATE        ; Back to the initial state
  968.     RTS    PC            ; Return to the caller
  969. ;
  970. ; Here if the information was a digit, change to the next possible state
  971. ; ($CSDG1)
  972. ;
  973. 10$:    MOV    #$CSDG1,STATE        ; Set the state
  974.     RTS    PC            ; Return to the caller
  975.  
  976.     .SBTTL    CTDUMP - ASTSQB - Process after a square bracket.
  977.  
  978. ;++
  979. ; This routine will handle the processing after an escape [ has been seen.
  980. ; It will determine if the next character is a digit and then proceed to
  981. ; process them.
  982. ;
  983. ; Usage:
  984. ;    R1/ Character
  985. ;    JSR    PC,@R0
  986. ;    (Return)
  987. ;
  988. ;--
  989.  
  990.     .PSECT    $CODE$, RO, I
  991.  
  992. ASTSQB= ASTCSI
  993.  
  994.     .SBTTL    CTDUMP - ASTDG1 - Here after the first digit of a function key
  995.  
  996. ;++
  997. ; This routine will handle the processing after the first digit of a function
  998. ; key.  It is assumed that either another digit or a tilda will follow the
  999. ; function key that was input.  If the function key is followed by a tilda
  1000. ; then we will attempt to find the function key in the table.  If it is not
  1001. ; in the table then the information will be output to the user's terminal.
  1002. ;
  1003. ; Usage:
  1004. ;    R1/ Character
  1005. ;    JSR    PC,@R0
  1006. ;    (Return)
  1007. ;
  1008. ;--
  1009.  
  1010.     .PSECT    $CODE$, RO, I
  1011.  
  1012. ASTDG1:    MOVB    R1,@FNCPTR        ; Store the character
  1013.     INC    FNCPTR            ; Point to the next position
  1014.  
  1015.     CMPB    #'~,R1            ; Is this a tilda?
  1016.     BEQ    20$            ; Yes, process it
  1017.  
  1018.     JSR    PC,CHKDIG        ; Is this character a digit?
  1019.     BCS    10$            ; Branch if that was a digit
  1020.     JSR    PC,CT.DFK        ; Dump the function key text
  1021.     BR    30$            ; Output the function key
  1022. ;
  1023. ; Here if the information was a digit, change to the next possible state
  1024. ; ($CSDG1)
  1025. ;
  1026. 10$:    MOV    #$CSDG2,STATE        ; Set the state
  1027.     RTS    PC            ; Return to the caller
  1028. ;
  1029. ; Here if we have gotten the last character of the function key.  Attempt
  1030. ; to find it in the table.  If it is in the table then we will process
  1031. ; the function, else we will output the function key to the XK port
  1032. ;
  1033. 20$:    JSR    PC,CT.FFK        ; Find the function key
  1034.     BCC    30$            ; Branch if we did the function
  1035.     JSR    PC,CT.DFK        ; Didn't, so dump the function key
  1036. 30$:    MOV    #$CSINI,STATE        ; Set the new state
  1037.     RTS    PC            ; Return to the caller
  1038.  
  1039.     .SBTTL    CTDUMP - ASTDG2 - Here after the second digit of a function key
  1040.  
  1041. ;++
  1042. ; This routine will be called after the second digit of a function key.  It
  1043. ; wants a tilda to be the character that was input in this state.  If the
  1044. ; character is not a tilda, then the function key is output to the XK port.
  1045. ;
  1046. ; Usage:
  1047. ;    R1/ Character
  1048. ;    JSR    PC,@R0
  1049. ;    (Return)
  1050. ;
  1051. ;--
  1052.  
  1053.     .PSECT    $CODE$, RO, I
  1054.  
  1055. ASTDG2:    MOVB    R1,@FNCPTR        ; Store the character
  1056.     INC    FNCPTR            ; Point to the next position
  1057.  
  1058.     CMPB    #'~,R1            ; Is this a tilda?
  1059.     BEQ    20$            ; Yes, process it
  1060.  
  1061.     JSR    PC,CT.DFK        ; Dump the function key text
  1062.     BR    30$            ; Exit the routine
  1063. ;
  1064. ; Here if we have gotten the last character of the function key.  Attempt
  1065. ; to find it in the table.  If it is in the table then we will process
  1066. ; the function, else we will output the function key to the XK port
  1067. ;
  1068. 20$:    JSR    PC,CT.FFK        ; Find the function key
  1069.     BCC    30$            ; Branch if we did the function
  1070.     JSR    PC,CT.DFK        ; Didn't, so dump the function key
  1071. 30$:    MOV    #$CSINI,STATE        ; Set the new state
  1072.     RTS    PC            ; Return to the caller
  1073.  
  1074.     .SBTTL    CTDUMP - ASTCEC - Saw connect escape character
  1075.  
  1076. ;++
  1077. ; Here after we have seen a connect escape character.  This routine will
  1078. ; determine if the character following it is a valid command character.  If
  1079. ; it is then it will dispatch to the correct routine, else it will send a bell
  1080. ; to the console.
  1081. ;
  1082. ; Usage:
  1083. ;    R1/ Character
  1084. ;    JSR    PC,@R0
  1085. ;    (Return)
  1086. ;
  1087. ;--
  1088.  
  1089.     .PSECT    $CODE$, RO, I
  1090.  
  1091. ASTCEC:    MOV    R1,R2            ; Copy the character
  1092.     CMPB    #'a,R2            ; Is this a lower case character?
  1093.     BGT    10$            ; Branch if it is
  1094.     SUB    #'a-'A,R2        ; Convert to upper case
  1095. 10$:    CMPB    R2,ESCCHR        ; Is this the escape character?
  1096.     BNE    30$            ; No, go find it in the table
  1097.     JSR    PC,XKOUT        ; Output the character
  1098.     BR    99$            ; Finish up
  1099. ;
  1100. ; Here if we have to find the character in the table.
  1101. ;
  1102. 30$:    MOV    #T$ESC,R0        ; Get the escape character table
  1103.     MOV    #<ESC$L/2>,R1        ; And the length
  1104.     JSR    PC,FNDOFS        ; Find the item
  1105.     TST    R0            ; Find it?
  1106.     BNE    20$            ; Branch if we did
  1107.     JSR    PC,CT.BEL        ; Output a bell and then the characters
  1108.     BR    99$            ; Finish up
  1109. ;
  1110. ; Here if we have found the entry in the table
  1111. ;
  1112. 20$:    ADD    #ESC$L,R0        ; Point to the other entry
  1113.     MOV    (R0),R0            ; Get the address of the routine
  1114.     JSR    PC,@R0            ; Jump to the routine
  1115. ;
  1116. ; Here to reset the state
  1117. ;
  1118. 99$:    MOV    #$CSINI,STATE        ; Store the new state
  1119.     RTS    PC            ; Return to the caller
  1120.  
  1121.     .SBTTL    CT.FFK - Find a function key
  1122.  
  1123. ;++
  1124. ; This routine will find a function key.  It is assume that the function
  1125. ; key text has been accumulated in the FNCTXT locations.
  1126. ;
  1127. ; Usage:
  1128. ;    JSR    PC,CT.FFK
  1129. ;    (Return)
  1130. ;
  1131. ; On return:
  1132. ;    If carry set - Not found
  1133. ;    If carry clear - Found and processed.
  1134. ;--
  1135.  
  1136. CT.FFK:    MOV    #<KEY$L/2>,R0        ; Get the number of function keys
  1137.     MOV    #T$KEY,R1        ; Get the address of the table
  1138. ;
  1139. ; Now loop to find the function key
  1140. ;
  1141. 10$:    MOV    (R1)+,R2        ; Get the address of the text
  1142.     MOV    #4,R3            ; Number of characters to check
  1143.     MOV    #FNCTXT+2,R4        ; First character
  1144.     CMPB    FNCTXT,#.CHCSI        ; First character of string a CSI?
  1145.     BNE    20$            ; No, just enter loop
  1146.     DEC    R4            ; Yes, start one character earlier
  1147.  
  1148. 20$:    CMPB    (R4)+,(R2)+        ; Is this the same?
  1149.     BNE    30$            ; Jump if not
  1150.     SOB    R3,20$            ; Loop for all characters
  1151.     BR    40$            ; Found what we need, go handle it
  1152.  
  1153. 30$:    SOB    R0,10$            ; Loop for all function keys possible
  1154.     SEC                ; Set the carry
  1155.     RTS    PC            ; And return to the caller
  1156.  
  1157. 40$:    ADD    #KEY$L-2,R1        ; Point to the entry
  1158.     MOV    (R1),R0            ; Get the routine address
  1159.     ADD    #KEY$L,R1        ; Point to the addition information
  1160.     MOV    (R1),R1            ; Get it
  1161.     JSR    PC,(R0)            ; Call the routine and return
  1162.     CLC                ; Clear the carry
  1163.     RTS    PC            ; Return to the caller
  1164.  
  1165.     .SBTTL    CT.DFK - Dump a function key
  1166.  
  1167. ;++
  1168. ; This routine will unwind a function key we have be accumlating in the
  1169. ; FNCTXT locations.  The text will be output to the XK port and then
  1170. ; the routine will return.
  1171. ;
  1172. ; Usage:
  1173. ;    JSR    PC,CT.DFK
  1174. ;    (Return)
  1175. ;
  1176. ;--
  1177.  
  1178.     .PSECT    $CODE$, RO, I
  1179.  
  1180. CT.DFK:    MOV    #5,R3            ; Maximum number of characters
  1181.     MOV    #FNCTXT,R2        ; Address of the text
  1182. 10$:    MOVB    (R2)+,R1        ; Get a character
  1183.     BEQ    20$            ; Branch if finished
  1184.     JSR    PC,XKOUT        ; Output it
  1185.     SOB    R3,10$            ; Loop for all keys read
  1186. 20$:    RTS    PC            ; Return to the caller
  1187.  
  1188. ;
  1189. ; SUBROUTINE - CHKDIG - Check to see if R1 contains a digit
  1190. ;
  1191. CHKDIG:    CMPB    #'0,R1            ; Compare against zero
  1192.     BGT    10$            ; If less than zero not a digit
  1193.     CMPB    #'9,R1            ; Compare against nine
  1194.     BLT    10$            ; If greater than nine not a digit
  1195.     SEC                ; Set the carry bit
  1196.     RTS    PC            ; Return to the caller
  1197. ;
  1198. ; Here if not a digit, clear the carry
  1199. ;
  1200. 10$:    CLC                ; Clear the carry
  1201.     RTS    PC            ; Return to the caller
  1202.  
  1203.     .SBTTL    CT.BEL - Output a bell to the user
  1204.  
  1205. ;++
  1206. ; This routine will output a bell to the console terminal.  This is done
  1207. ; for the internal buffers being full, or the fact that the user has
  1208. ; given a bad escape command.
  1209. ;
  1210. ; Usage:
  1211. ;    JSR    PC,CT.BEL
  1212. ;    (Return)
  1213. ;
  1214. ;--
  1215.  
  1216.     .PSECT    $CODE$, RO, I
  1217.  
  1218. CT.BEL:    QIO$S    #IO.WVB,#TERLUN,#TTWEFN,,#TOIOSB,,<#M$BELL,#1>
  1219.     RTS    PC
  1220.  
  1221.     .PSECT    $PLIT$, RO, I
  1222.  
  1223. M$BELL:    .ASCIZ    <.CHCNG>
  1224.  
  1225.     .SBTTL    CT.PAR - Add parity to a character
  1226.  
  1227. ;++
  1228. ; This routine will append the parity bit to the character given it.
  1229. ;
  1230. ; Usage:
  1231. ;    R0/ Character
  1232. ;    JSR    PC,CT.PAR
  1233. ;    (Return - R0 with character + parity)
  1234. ;
  1235. ;--
  1236.  
  1237.     .PSECT    $CODE$, RO, I
  1238.  
  1239. CT.PAR:                    ; FROM BLISS-16 code of GEN.PARITY
  1240.     BIT    #TRUE,DEV.PARITY.FLAG    ; Have hardware doing the parity?
  1241.     BEQ    99$            ; Yes, just return
  1242.     JSR    R1,$SAVE2        ;
  1243.     BIT    #1,IBM.FLAG        ;
  1244.     BEQ    1$
  1245.     BR    9$
  1246. 1$:    MOV    R1,R2            ; CHARACTER,*
  1247.     MOV    PARITY.TYPE,R0        ;
  1248.     ASL    R0
  1249.     ADD    P.AAQ(R0),PC        ; Case dispatch
  1250. 3$:    MOV    R2,R1            ;
  1251.     RTS    PC
  1252. 4$:    MOV    R2,R1            ;
  1253.     BR    9$
  1254. 5$:    MOV    R2,R1            ; *,TEMP.CHAR
  1255.     BIC    #177600,R1        ; *,TEMP.CHAR
  1256.     BIS    #200,R1            ; *,TEMP.CHAR
  1257.     BR    7$            ;
  1258. 6$:    MOV    R2,R1            ; *,TEMP.CHAR
  1259.     BIC    #177600,R1        ; *,TEMP.CHAR
  1260. 7$:    MOV    R1,R0            ; TEMP.CHAR,*
  1261.     ASH    #-4,R0
  1262.     XOR    R0,R1            ; *,TEMP.CHAR
  1263.     MOV    R1,R0            ; TEMP.CHAR,*
  1264.     ASR    R0
  1265.     ASR    R0
  1266.     XOR    R0,R1            ; *,TEMP.CHAR
  1267.     MOV    R1,R0            ; TEMP.CHAR,*
  1268.     BIC    #177774,R0
  1269.     CMP    R0,#1
  1270.     BEQ    8$
  1271.     BIC    #177774,R1
  1272.     CMP    R1,#2
  1273.     BNE    10$
  1274. 8$:    MOV    R2,R1            ;
  1275.     BIC    #177600,R1
  1276. 9$:    BIS    #200,R1
  1277.     RTS    PC
  1278. 10$:    MOV    R2,R1
  1279.     BIC    #177600,R1
  1280. 99$:    RTS    PC            ;
  1281.  
  1282.     .PSECT    $PLIT$,  RO ,  D  
  1283.  
  1284. P.AAQ:                        ; CASE Table for GEN.PARITY
  1285. 2$:    .WORD    0                ; [3$]
  1286.     .WORD    4                ; [4$]
  1287.     .WORD    24                ; [6$]
  1288.     .WORD    10                ; [5$]
  1289.     .WORD    114                ; [10$]
  1290.  
  1291.     .SBTTL    Create escape character
  1292.  
  1293. ; Create the ascii for the escape character
  1294.  
  1295.     .PSECT    $CODE$,    RO, I
  1296.  
  1297. CRECONCHR::
  1298.     MOV    ESCCHR,R1        ; Get the escape character
  1299.     MOV    #CONCHR,R0        ; Point to the place to store info
  1300.     CMPB    R1,#40            ; Compare against 40
  1301.     BLT    10$            ; Branch if less than
  1302.     CMPB    R1,#177            ; Is this a delete?
  1303.     BEQ    30$            ; Jump if it is
  1304.     JMP    20$            ; Jump to the right routine.
  1305.  
  1306. ; Here if we have a control character
  1307.  
  1308. 10$:    MOVB    #'^,(R0)+        ; Store it
  1309.     ADD    #'A-1,R1        ; Make this a real character
  1310. 20$:    MOVB    R1,(R0)+        ; Store it
  1311.     CLRB    (R0)+            ; Clear the last character location
  1312.     RTS    PC            ; Return to sender
  1313.  
  1314. ; Here if we have a delete, store the <del>
  1315.  
  1316. 30$:    MOVB    #'<,(R0)+        ; Store the opening bracket
  1317.     MOVB    #'d,(R0)+        ; Store the d
  1318.     MOVB    #'e,(R0)+        ; Store the e
  1319.     MOVB    #'l,(R0)+        ; Store the l
  1320.     MOVB    #'>,(R0)+        ; Store the closing bracket
  1321.     CLRB    (R0)+            ; Clear the last byte
  1322.     RTS    PC            ; Return to sender
  1323.  
  1324.     .SBTTL    CT.OUT - Output a single character to the screen
  1325.  
  1326. ;++
  1327. ; This routine will output a single character to the screen.
  1328. ; It is used for the local echo processing.
  1329. ;
  1330. ; Usage:
  1331. ;
  1332. ;    R1/ Character
  1333. ;    JSR    PC,CT.OUT
  1334. ;     return here always
  1335. ;
  1336. ;--
  1337.  
  1338.     .PSECT    $CODE$, RO, I
  1339.  
  1340. CT.OUT:    MOV    R1,OUTCHR    ; Save the character
  1341.     QIOW$C    IO.WVB,TERLUN,TTWEFN,,TOIOSB,,<OUTCHR,1>, $CODE$
  1342.     RTS    PC        ; And return
  1343.  
  1344.     .SBTTL    DUMPXK - Dump directly from the XK buffer
  1345.  
  1346. ;++
  1347. ; This routine will be called directly from the XK ast input routine.  This
  1348. ; routine will do a QIO to directly output the characters so that there
  1349. ; can be no delay in processing the input from the XK.  The only way we will
  1350. ; delay is if there is input from the console terminal pending.
  1351. ;--
  1352.  
  1353. DUMPXK:    DEC    TOLOCK            ; Do I have the interlock?
  1354.     BNE    99$            ; No, just exit
  1355.  
  1356.     JSR    R1,$SAVE3        ; Save R1-3
  1357. ;
  1358. ; Here if we can queue the XK output directly to the user terminal.
  1359. ;
  1360.  
  1361. 10$:    CMP    XKNXTC,XKFREC        ; Is the buffer empty?
  1362.     BEQ    90$            ; Yes, just exit
  1363. ;
  1364. ; Here if we have something in the buffer
  1365. ;
  1366.     MOVB    QIOIDX,R2        ; And set up the pointer
  1367.     ASL    R2            ; Mul by two
  1368.     MOV    R2,R0            ; Get a copy
  1369.     ASL    R2            ; So we have address offset
  1370.     ADD    R0,R2            ; For correct IOSB
  1371.     ADD    #TOIOS0,R2        ; Point at correct IOSB
  1372.     TSTB    IB.FLG(R2)        ; Is this IOSB free?
  1373.     BNE    90$            ; No, we must wait
  1374.     INCB    IB.FLG(R2)        ; Flag this IOSB is in use
  1375.  
  1376.     INCB    QIOIDX            ; Count up to next IOSB
  1377.     BICB    #^C<NM.QIO-1>,QIOIDX    ; Make sure it stays in range
  1378.  
  1379. ;
  1380. ; Determine how big a QIO we can post to output the information to the
  1381. ; console
  1382. ;
  1383.     MOV    #XKBUFLEN,R0        ; Get the length of the buffer
  1384.     SUB    XKNXTC,R0        ; Compute the pointer to end of buffer
  1385.     CMP    XKNXTC,XKFREC        ; Determine if in the right order
  1386.     BGT    20$            ; If free is before next then just
  1387.                     ;  output to the end of the buffer
  1388.     MOV    XKFREC,R0        ; Get the address of the next free
  1389.     SUB    XKNXTC,R0        ; Subtract the next character pointer
  1390. ;
  1391. ; Here after we have determine the amount of characters to output to the
  1392. ; terminal
  1393. ;
  1394. 20$:    MOV    XKNXTC,R1        ; Get the pointer to the next character
  1395.     ADD    #XKBUFF,R1        ; Point to the buffer
  1396. ;
  1397. ; At this point we must determine if we must strip the 8th bit from the
  1398. ; characters that we just read or can leave them on.
  1399. ;
  1400.  
  1401.     BIT    #TRUE,NOBIT8        ; Must strip the 8th bit?
  1402.     BNE    40$            ; No, just do the QIO
  1403. ;
  1404. ; Here to loop removing the 8th bit from the input (bit number 7)
  1405. ;
  1406.     MOV    R0,-(SP)        ; Save the length
  1407.     MOV    R1,-(SP)        ; Save the address
  1408.  
  1409. 30$:    BICB    #200,(R1)+        ; Clear the bit
  1410.     SOB    R0,30$            ; Loop for all characters
  1411.  
  1412.     MOV    (SP)+,R1        ; Restore R1
  1413.     MOV    (SP)+,R0        ; And R0
  1414. ;
  1415. ; Now do the QIO to output the information to the user's screen
  1416. ;
  1417. 40$:    QIO$S    #IO.WVB,#TERLUN,#TTWEFN,,R2,#CTOAST,<R1,R0>
  1418.     ADD    R0,XKNXTC        ; Update the pointer to the next
  1419.     BIC    #^C<XKBUFLEN-1>,XKNXTC    ; Make sure we are a circular buffer
  1420.     BR    10$            ; Loop and see if anything more
  1421. ;
  1422. ; Now clear the interlock, restore R1 and return
  1423. ;
  1424. 90$:    MOV    #1,TOLOCK        ; Release the interlock
  1425. 99$:    RTS    PC            ; Return to the caller
  1426.  
  1427.     .SBTTL    CTOAST - AST routine XK to CT dump routine
  1428.  
  1429. ;++
  1430. ; This routine will handle the ASTs that are generated by the dumping of
  1431. ; data directly from the XK (Comm port) to the CT (Console Terminal)
  1432. ; It will update the counters that the XK port uses to store information
  1433. ; into its buffer.  It will also light the CONEFN so that if we are
  1434. ; waiting we will start up again.
  1435. ;--
  1436.  
  1437. CTOAST:    SETF$S    #CONEFN            ; Light the event flag
  1438.     ADD    #IB.CNT,(SP)        ; Point to count word in IOSB
  1439.     ADD    @(SP),XKFREE        ; Update the number of free characters
  1440.     SUB    @(SP),XKUSED        ; Decrease the amount used
  1441.     ADD    #IB.FLG-IB.CNT,(SP)    ; Point to flag byte
  1442.     CLRB    @(SP)            ; Clear the flag - IOSB is free
  1443.     TST    (SP)+            ; Remove the IOSB from the stack
  1444.     ASTX$S                ; Return from the AST routine
  1445.  
  1446.     .SBTTL    XKOUT - Support local echo
  1447.  
  1448. ;++
  1449. ; This routine will support the local echo processing and add any parity
  1450. ; character before sending the character to the XK port.
  1451. ;
  1452. ; Usage:
  1453. ;    R0/ Character
  1454. ;    JSR    PC,XKOUT
  1455. ;    (Return via XK.OUT)
  1456. ;
  1457. ;--
  1458.  
  1459. XKOUT:    BIT    #TRUE,LCLECH        ; Local echo?
  1460.     BEQ    10$            ; No, just send it to XK
  1461.     JSR    PC,CT.OUT        ; Yes, write on screen also
  1462. 10$:    JSR    PC,CT.PAR        ; Generate the parity
  1463.     PJMP    XK.OUT            ; Write the character
  1464.  
  1465.     .SBTTL    End of KERCON
  1466.  
  1467.     .END    MAIN
  1468.