home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / pdp11 / k11mco.mac < prev    next >
Text File  |  2020-01-01  |  43KB  |  1,417 lines

  1.     .TITLE    K11MCO - Robin's Connect Code
  2.     .IDENT    /1.1/
  3.     .ENABL    LC
  4.  
  5. ; Note:
  6. ;
  7. ; This  code  is  (currently,  13-Feb-86 13:24:03) selected with the SET
  8. ; RSX CON ALT command. At some near point in the future it  will  likely
  9. ; be  default for M+. The older K11CON.MAC will always be used for P/OS.
  10. ;
  11. ; As of 28-Feb-86  09:14:26, it is the default for RSX11M/M+ (not P/OS).
  12. ; As of 05-Mar-86  12:30:29, K11CON is historical, K11PCO is for P/OS.
  13. ;
  14. ;                            Brian Nelson
  15. ;                            13-Feb-86  13:26
  16. ; 12-Sep-86  13:48:12 BDN Changes for I/D space
  17. ; 07-Feb-89  00:00:00 Jerry Hudgins
  18. ;            Added buffering to local terminal handling to
  19. ;            prevent high-speed local input from overwriting
  20. ;            outgoing modem QIO buffer.
  21.  
  22.  
  23.  
  24.     .if ndf, K11INC
  25.     .ift
  26.     .include    /IN:K11MAC.MAC/
  27.     .endc
  28.  
  29.  
  30. ;+
  31. ;
  32. ;              Free software BY
  33. ;               Northern Telecom, Inc.
  34. ;
  35. ; This  software  is  furnished  for  free and may be used and copied as
  36. ; desired.  This software or any other copies thereof may be provided or
  37. ; otherwise  made  available  to  any  other  person.  No  title  to and
  38. ; ownership of the software is hereby transferred or allowed. 
  39. ;
  40. ; The  information  in this software is subject to change without notice
  41. ; and should not be construed as a commitment by NORTHERN TELECOM, INC.
  42. ;
  43. ; NORTHERN TELECOM assumes no responsibility for the use or  reliability  
  44. ; of this software on any equipment whatsoever.
  45. ;
  46. ;    Northern Telecom, Inc.
  47. ;    Network Support Systems Division
  48. ;    54 Regional Drive
  49. ;    Concord, New Hampshire 03301
  50. ;    (603) 224-6511 Ext. 2529
  51. ;
  52. ;
  53. ; Title:    K11RTM
  54. ; Author:    Robin Miller
  55. ; Date:        January 29, 1986
  56. ;
  57. ; Description:
  58. ;
  59. ;    This module contains the connect code which is used in virtual
  60. ; terminal mode when talking to a remote system.
  61. ;
  62. ;-
  63.  
  64.     .enabl    lsb
  65.  
  66.  
  67. doconn::
  68. xdorsx::tstb    ttname            ; insure that a device name is set
  69.     bne    1$            ; ok
  70.     message    <You must first define an output port:>,cr    ;jfp 840607
  71.     message    <Use the SET LINE command for this.>,cr
  72.     return
  73.  
  74.     
  75. 1$:    message    <Connecting to line >    ; Print the line and speed out
  76.     print    #ttname            ; the link name
  77.     calls    ttspee    ,<#ttname>    ; get the speed now
  78.     tst    r0            ; not if we can't get it
  79.     ble    5$            ; yes, do not print 0 or -1 baud
  80.     message    < at >            ; and the speed
  81.     sub    #10    ,sp        ; try to format the response a little
  82.     mov    sp    ,r1        ; allocate a buffer and point to it
  83.     deccvt    r0,r1,#4        ; convert to decimal, 4 wide
  84.     print    r1    ,#4        ; print it
  85.     add    #10    ,sp        ; pop the buffer
  86.     message    < baud>,cr        ; and finish off the message
  87. 5$:    message    < Type CTRL >
  88.     clr    -(sp)            ; allocate a text buffer
  89.     bisb    conesc    ,(sp)        ; get it
  90.     add    #100    ,(sp)        ; convert it back to printable
  91.     mov    sp    ,r0        ; point to it now
  92.     print    r0    ,#1        ; at last
  93.     tst    (sp)+            ; pop the buffer
  94.     message    < and then C to return to command level>,cr
  95.     call    altrsx            ; /44/
  96.  
  97.  
  98. 100$:    return
  99.  
  100.     .dsabl    lsb
  101.  
  102.     global    <conesc    ,getsys    ,ttcons    ,ttname    ,lun.co    ,lun.ti>
  103.  
  104.  
  105.     .enabl    gbl
  106.     .NLIST    BEX
  107.  
  108.     .MCALL    ALUN$S, ASTX$S, CLEF$S, CMKT$S, DIR$, DSAR$S, DSCP$S
  109.     .MCALL    ENAR$S, ENCP$S, EXIT$S, MRKT$S, QIOW$, QIOW$S, QIO$
  110.     .MCALL    QIO$S, SETF$S, SREX$S, TTSYM$, WTSE$S
  111.  
  112.  
  113.     TTSYM$                ; Define terminal symbols.
  114.  
  115.     global    <conesc, getsys, ttcons, ttname, lun.co, lun.ti>
  116.  
  117.     .SBTTL    Definitions
  118.  
  119. ;    Event flags:
  120.  
  121.     ef.rem    = 14.            ; Remote event flag.
  122.     ef.loc    = 15.            ; Local event flag.
  123.     ef.kill    = 16.            ; Kill I/O event flag.
  124.     ef.time    = 17.            ; Mark time event flag.
  125.     ef.wait    = 18.            ; Main wait event flag.
  126.     ef.sync    = 19.            ; Synchronize event flag.
  127.  
  128. ;    Marktime equates:
  129.  
  130.     TICKS    =    1        ; Ticks.
  131.     SECNDS    =    2        ; Seconds.
  132.     MINUTE    =    3        ; Minutes.
  133.     HOURS    =    4        ; Hours.
  134.  
  135. ;    ASCII Equates.
  136.  
  137.     XON    =    17.        ; Transmission on (CTRL/Q).
  138.     XOFF    =    19.        ; Transmission off (CTRL/S).
  139.  
  140. ;    Remote terminal equates.
  141.  
  142.     BUFSIZ    =    512.        ; Size of transmission buffers.
  143.     COMCHR  =     32.        ; Size of each remote buffer.
  144.     COMTIM  =     6.        ; Max time for buffer fill (ticks).
  145.     COMNBF  =    <BUFSIZ/COMCHR>    ; Number of remote buffers.
  146.     COMQNM    =    4        ; Number of reads to queue.
  147.     COMCTS  =     <COMCHR*3>    ; Number of bytes before XOFF.
  148.     COMSIZ    =   <COMNBF*COMCHR>    ; Size of main remote buffer.
  149.  
  150. ;     Local terminal equates.
  151.  
  152.     TTYCHR  =     64.        ; Maximum local bytes to write.
  153.     LOCSIZ    =:    64.        ; /60/ size of circular local input
  154. ;                    ; /60/ buffer, bytes
  155.  
  156.     .SBTTL    FILTBL - Terminal Fill Table.
  157. ;
  158. ;    This table defines the amount of time to wait for a remote
  159. ;    buffer to fill.  Since this time is speed dependent, the speed
  160. ;    selected is used to index this table and set the fill time.
  161. ;
  162. ;    Note:    The time here will actually be multiplied by the
  163. ;        number of active remote reads which speed dependant.
  164. ;
  165.  
  166.     .psect    $PDATA    ,D
  167.  
  168. FILTBL:    .BYTE    12.        ; S.0
  169.     .BYTE    12.        ; S.50
  170.     .BYTE    12.        ; S.75
  171.     .BYTE    12.        ; S.100
  172.     .BYTE    12.        ; S.110
  173.     .BYTE    10.        ; S.134
  174.     .BYTE    10.        ; S.150
  175.     .BYTE    10.        ; S.200
  176.     .BYTE    10.        ; S.300
  177.     .BYTE    8.        ; S.600
  178.     .BYTE    8.        ; S.1200
  179.     .BYTE    8.        ; S.1800
  180.     .BYTE    6.        ; S.2000
  181.     .BYTE    6.        ; S.2400
  182.     .BYTE    6.        ; S.3600
  183.     .BYTE    6.        ; S.4800
  184.     .BYTE    6.        ; S.7200
  185.     .BYTE    6.        ; S.9600
  186.     .BYTE    6.        ; S.EXTA
  187.     .BYTE    6.        ; S.EXTB
  188.     .BYTE    4.        ; S.19.2
  189.     .BYTE    4.        ; S.38.4
  190.     .EVEN
  191.  
  192.     .SBTTL    CHRTBL - Character Read Table.
  193. ;
  194. ;    This table is used to set the maximum number of characters
  195. ;    per remote read QIO.  At slower speeds, the size is reduced
  196. ;    since it takes too much time to fill each read buffer.  The
  197. ;    affect of this is smoother output to the local terminal since
  198. ;    input and output are taking place at the same time.
  199. ;
  200. CHRTBL:    .WORD    COMCHR/8.    ; S.0
  201.     .WORD    COMCHR/8.    ; S.50
  202.     .WORD    COMCHR/8.    ; S.75
  203.     .WORD    COMCHR/6    ; S.100
  204.     .WORD    COMCHR/6    ; S.110
  205.     .WORD    COMCHR/4    ; S.134
  206.     .WORD    COMCHR/4    ; S.150
  207.     .WORD    COMCHR/3    ; S.200
  208.     .WORD    COMCHR/3    ; S.300
  209.     .WORD    COMCHR/2    ; S.600
  210.     .WORD    COMCHR/2    ; S.1200
  211.     .WORD    COMCHR/2    ; S.1800
  212.     .WORD    COMCHR        ; S.2000
  213.     .WORD    COMCHR        ; S.2400
  214.     .WORD    COMCHR        ; S.3600
  215.     .WORD    COMCHR        ; S.4800
  216.     .WORD    COMCHR        ; S.7200
  217.     .WORD    COMCHR        ; S.9600
  218.     .WORD    COMCHR        ; S.EXTA
  219.     .WORD    COMCHR        ; S.EXTB
  220.     .WORD    COMCHR        ; S.19.2
  221.     .WORD    COMCHR        ; S.38.4
  222.  
  223.     .SBTTL    QUETBL - Queue Reads Table.
  224. ;
  225. ;    This table is used to set the number of reads to queue to the
  226. ;    remote whenever input arrives.  At high speeds, a large number
  227. ;    of reads must be queued or else input is lost.  At slow speeds
  228. ;    this number can be less so we reduce the number of reads queued
  229. ;    to minimumize overhead.
  230. ;
  231. QUETBL:    .BYTE    COMQNM-2.    ; S.0
  232.     .BYTE    COMQNM-2.    ; S.50
  233.     .BYTE    COMQNM-2.    ; S.75
  234.     .BYTE    COMQNM-2    ; S.100
  235.     .BYTE    COMQNM-2    ; S.110
  236.     .BYTE    COMQNM-2    ; S.134
  237.     .BYTE    COMQNM-2    ; S.150
  238.     .BYTE    COMQNM-2    ; S.200
  239.     .BYTE    COMQNM-2    ; S.300
  240.     .BYTE    COMQNM-2    ; S.600
  241.     .BYTE    COMQNM-2    ; S.1200
  242.     .BYTE    COMQNM-1    ; S.1800
  243.     .BYTE    COMQNM-1    ; S.2000
  244.     .BYTE    COMQNM-1    ; S.2400
  245.     .BYTE    COMQNM-1    ; S.3600
  246.     .BYTE    COMQNM        ; S.4800
  247.     .BYTE    COMQNM        ; S.7200
  248.     .BYTE    COMQNM        ; S.9600
  249.     .BYTE    COMQNM        ; S.EXTA
  250.     .BYTE    COMQNM        ; S.EXTB
  251.     .BYTE    COMQNM        ; S.19.2
  252.     .BYTE    COMQNM        ; S.38.4
  253.     .EVEN
  254.  
  255.     .SBTTL    Local Terminal Characteristics.
  256.  
  257.     .psect    RWDATA    ,D,RW,LCL,REL,CON
  258.  
  259. ;    Local terminal characteristics to save.
  260.  
  261. TTYSV:    .BYTE    TC.ACR,0        ; {No} Wrap-around.
  262.     .BYTE    TC.BIN,0        ; {No} Read-passall.
  263.     .BYTE    TC.FDX,0        ; {No} Full-duplex.
  264.     .BYTE    TC.HLD,0        ; {No} Hold screen.
  265.     .BYTE    TC.NEC,0        ; {No} Echo.
  266.     .BYTE    TC.RAT,0        ; {No} Typeahead.
  267.     .BYTE    TC.SCP,0        ; {No} Scope.
  268.     .BYTE    TC.SMR,0        ; {No} Lowercase.
  269.     .BYTE    TC.SLV,0        ; {No} Slave.
  270.     .BYTE    TC.TTP            ; Terminal type.
  271. TTYPE:    .BYTE    T.V100            ; Default terminal type.
  272.     TTYSVL = .-TTYSV
  273.  
  274. ;    Local characteristics to fix at startup time.
  275.  
  276. FIXCH:    .BYTE    TC.BIN,0        ; No Read-passall.
  277.     .BYTE    TC.NEC,0        ; Echo.
  278.     FIXCHL=.-FIXCH
  279.  
  280. ;    Local characteristics to change.
  281.  
  282. TTYCH:    .BYTE    TC.ACR,0        ; No Wrap-around.
  283.     .BYTE    TC.BIN,1        ; Read-passall.
  284.     .BYTE    TC.FDX,1        ; Full-duplex.
  285.     .BYTE    TC.HLD,0        ; No Hold screen.
  286.     .BYTE    TC.NEC,1        ; No Echo.
  287.     .BYTE    TC.RAT,1        ; Typeahead.
  288.     .BYTE    TC.SCP,1        ; Scope.
  289.     .BYTE    TC.SMR,1        ; Lowercase.
  290.     TTYCHL = .-TTYCH
  291.  
  292.     .SBTTL    Remote Terminal Characteristics.
  293.  
  294. ;    Remote terminal characteristics to save.
  295.  
  296. COMSV:    .BYTE    TC.ACR,0        ; {No} Wrap-around.
  297.     .BYTE    TC.BIN,0        ; {No} Read-passall.
  298.     .BYTE    TC.FDX,0        ; {No} Full-duplex.
  299.     .BYTE    TC.HLD,0        ; {No} Hold screen.
  300.     .BYTE    TC.NEC,0        ; {No} Echo.
  301.     .BYTE    TC.NBR,0        ; {No} Broadcast.
  302.     .BYTE    TC.RAT,0        ; {No} Typeahead.
  303.     .BYTE    TC.SCP,0        ; {No} Scope.
  304.     .BYTE    TC.SMR,0        ; {No} Lowercase.
  305.     .BYTE    TC.SLV,0        ; {No} Slave.
  306.     .byte    TC.PTH,0        ; /60/ {no} pasthru
  307.     .byte    TC.8BC,0        ; /60/ {no} EBC
  308.     .byte    TC.HHT,0        ; /60/ {no} hardware tab
  309.     .byte    TC.HFF,0        ; /60/ {no} hardware FF
  310.     .byte    TC.HFL,0        ; /60/ {no} horizontal fill
  311.     .byte    TC.VFL,0        ; /60/ {no} vertical fill
  312.     .byte    TC.ESQ,0        ; /60/ {no} ESC sequence recognition
  313.     .BYTE    TC.TBS,0        ; Typeahead buffer size.
  314.     COMSVL = .-COMSV
  315.  
  316. ;    Remote characteristics to save for modems.
  317.  
  318. COMDSV:    .BYTE    TC.ABD,0        ; {No} Autobaud.
  319.     .BYTE    TC.WID,0        ; Terminal width.
  320.     .BYTE    TC.DLU,0        ; {No} Remote.
  321.     RMODEM == .-1            ; The remote modem flag <> 0 = True.
  322.     COMDSL = .-COMDSV
  323.  
  324. ;    Remote terminal characteristics to change.
  325.  
  326. COMCH:    .BYTE    TC.ACR,0        ; No Wrap-around.
  327.     .BYTE    TC.BIN,1        ; Read-Passall.
  328.     .BYTE    TC.FDX,1        ; Full-duplex.
  329.     .BYTE    TC.HLD,0        ; No Hold-screen.
  330.     .BYTE    TC.NEC,1        ; No Echo.
  331.     .BYTE    TC.NBR,1        ; No Broadcast.
  332.     .BYTE    TC.RAT,1        ; Typeahead.
  333.     .BYTE    TC.SCP,1        ; Scope.
  334.     .BYTE    TC.SMR,1        ; Lowercase.
  335.     .BYTE    TC.SLV,1        ; Slave.
  336.     .byte    TC.PTH,1        ; /60/ pasthru
  337.     .byte    TC.8BC,1        ; /60/ EBC
  338.     .byte    TC.HHT,1        ; /60/ hardware tab
  339.     .byte    TC.HFF,1        ; /60/ hardware FF
  340.     .byte    TC.HFL,0        ; /60/ no horizontal fill
  341.     .byte    TC.VFL,0        ; /60/ no vertical fill
  342.     .byte    TC.ESQ,0        ; /60/ no escape sequence recognition
  343.     .BYTE    TC.TBS,255.        ; Typeahead buffer size.
  344.     COMCHL = .-COMCH
  345.  
  346. ;    Remote characteristics to change for modems.
  347.  
  348. COMDCH:    .BYTE    TC.ABD,0        ; No Autobaud.
  349.     .BYTE    TC.WID,255.        ; Terminal width.
  350.     .BYTE    TC.DLU,0        ; {No} Remote.
  351.     SMODEM == .-1            ; The remote modem location to change.
  352.     COMDCL = .-COMDCH
  353.  
  354. ;    Ensure we are saving all changed remote characteristics.
  355.  
  356.     .IF NE <COMSVL-COMCHL>
  357.     .ERROR    ; Remote save and change characteristics length different.
  358.     .ENDC
  359.  
  360.  
  361. ;    Clear the remote typeahead buffer.
  362.  
  363. COMCLR:    .BYTE    TC.TBF,0        ; Clear the typeahead buffer.
  364.     COMCLN = .-COMCLR
  365.  
  366. ;    Save the remote terminal speed (if possible).
  367.  
  368. COMSPD:    .BYTE    TC.RSP,0        ; The receive speed.
  369.     .BYTE    TC.XSP,0        ; The transmit speed.
  370.     COMSPL = .-COMSPD        ; Length of speed params.
  371.  
  372.     .SBTTL    Data/Buffer Area.
  373.  
  374. BUFADR:    .WORD    0        ; ENDING BUFFER ADDRESS
  375. BUFLEN:    .WORD    0        ; # OF BYTES TO WRITE
  376. BUFSRT:    .WORD    0        ; START OF BUFFER
  377. BUFLUN:    .WORD    0        ; LUN TO WRITE TO
  378. BUFEND:    .WORD    0        ; END OF BUFFER AREA
  379.  
  380. ESEEN:    .WORD    0        ; Interrupt character seen.
  381. TTYBUF:    .WORD    0        ; Local input buffer.
  382. locbuf:    .blkw    <LOCSIZ+1>/2    ; /60/ circular local input write buffer
  383. locptr:    .blkw    1        ; /60/ local input write buffer pointer
  384.  
  385. COMBUF:    .BLKB    COMSIZ        ; The main remote input buffer.
  386. COMEND:                ; Ending address of main buffer.
  387.  
  388. SRTCOM:    .REPT    COMNBF        ; Generate remote QIO buffers.
  389.     .BLKW    2        ; The I/O status block.
  390.     .BLKB    COMCHR        ; The remote buffer area.
  391.     .ENDR
  392. ENDCOM:                ; End of remote QIO buffer area.
  393. LSTCOM:    .WORD    SRTCOM        ; Pointer to first/next buffer.
  394.  
  395. ; -=user did CTRL/S, +=buffer ovrflw caused CTRL/S, 0=no CTRL/S
  396.  
  397. COMCTL:    .WORD    0        ; The XON/XOFF control flag.
  398.  
  399. ;    Debug storage area:
  400.  
  401. MAXBC:    .WORD    0        ; Maximum size of read completed.
  402. MAXCOM:    .WORD    0        ; Maximum count of remote buffer.
  403. COMABO:    .WORD    0        ; Reads completed via abort code.
  404. COMKIL:    .WORD    0        ; Marktime I/O kill operations.
  405. COMFUL:    .WORD    0        ; Number of full read completed.
  406. COMNOT:    .WORD    0        ; Remote AST notification count.
  407. RCHIN:    .BLKW    2        ; The remote characters in.
  408. QIOCNT:    .WORD    0        ; Number of remote reads issued.
  409. MINFRE:    .WORD    COMNBF        ; Minimum number of free buffers.
  410. PGMXOF:    .WORD    0        ; XOFF's sent by the program.
  411. USRXOF:    .WORD    0        ; XOFF's sent by the user.
  412. PGMXON:    .WORD    0        ; XON's sent by the program.
  413. USRXON:    .WORD    0        ; XON's sent by the user.
  414.  
  415. ;    End of debug storage area.
  416.  
  417. COMFRE:    .WORD    COMNBF        ; Number of free remote buffers.
  418. COMPTR:    .WORD    COMBUF        ; Pointer to remote input buffer.
  419. COMCNT:    .WORD    0        ; Character count in remote buffer.
  420. COMMKT:    .WORD    0        ; # of MRKT$'s outstanding for remote.
  421. COMNUM:    .WORD    COMQNM        ; Current number of reads to queue.
  422. COMQIO:    .WORD    COMCHR        ; Number of characters for remote QIO.
  423. COMQUE:    .WORD    COMQNM        ; Number of remote reads to queue.
  424. TTYCNT:    .WORD    TTYCHR        ; Number of characters for local QIO.
  425. FILTIM:    .WORD    COMTIM        ; Time to wait for buffer to fill.
  426.  
  427. RIOSB:    .BLKW    2        ; The remote I/O status block.
  428. LIOSB:    .BLKW    2        ; The local I/O status block.
  429. XIOSB:    .BLKW    2        ; The transfer I/O status block.
  430. ERRFLG:    .WORD    0        ; Error on remote read QIO$.    <> 0 = TRUE
  431. EXFLG:    .WORD    0        ; EXIT TO SYSTEM FLAG        <> 0 = TRUE
  432. INTFLG:    .WORD    0        ; INTERRUPT CHARACTER TYPED    <> 0 = TRUE
  433.  
  434.  
  435. ;    Directive Parameter Blocks (DPB's).
  436.  
  437. ASTLOC:    QIOW$    IO.ATA,lun.co,ef.loc,,LIOSB,,<TTYAST> ; Local UNSOL/AST attach.
  438.  
  439. ASTREM:    QIOW$    IO.ATA!TF.NOT,lun.ti,ef.rem,,RIOSB,,<COMAST> ; Remote UNSOL/AST.
  440.  
  441. ATTREM:    QIOW$    IO.ATT,lun.ti,ef.rem,,RIOSB ; Attach the remote terminal.
  442.  
  443. CLRCOM:    QIOW$    SF.SMC,lun.ti,ef.rem,,RIOSB,,<COMCLR,COMCLN> ; Clear typeahead.
  444.  
  445. DETLOC:    QIOW$    IO.DET,lun.co,ef.loc    ; Detach the local terminal.
  446.  
  447. DETREM:    QIOW$    IO.DET,lun.ti,ef.rem    ; Detach the remote terminal.
  448.  
  449. GETLOC:    QIOW$    SF.GMC,lun.co,ef.loc,,LIOSB,,<TTYSV,TTYSVL> ; Get local.
  450.  
  451. GETREM:    QIOW$    SF.GMC,lun.ti,ef.rem,,RIOSB,,<COMSV,COMSVL> ; Get remote.
  452.  
  453. GETDLU:    QIOW$    SF.GMC,lun.ti,ef.rem,,RIOSB,,<COMDSV,COMDSL> ; Get modem.
  454.  
  455. GETSPD:    QIOW$    SF.GMC,lun.ti,ef.rem,,RIOSB,,<COMSPD,COMSPL> ; Get speed.
  456.  
  457. HANGUP:    QIOW$    IO.HNG,lun.ti,ef.rem,,RIOSB    ; Hangup remote modem.
  458.  
  459. KILLOC:    QIO$    IO.KIL,lun.co,ef.kill    ; Kill local terminal I/O.
  460.  
  461. KILREM:    QIO$    IO.KIL,lun.ti,ef.kill    ; Kill remote terminal I/O.
  462.  
  463. RESLOC:    QIOW$    SF.SMC,lun.co,ef.loc,,LIOSB,,<TTYSV,TTYSVL> ; Local restore.
  464.  
  465. RESREM:    QIOW$    SF.SMC,lun.ti,ef.rem,,RIOSB,,<COMSV,COMSVL> ; Remote restore.
  466.  
  467. RESDLU:    QIOW$    SF.SMC,lun.ti,ef.rem,,RIOSB,,<COMDSV,COMDSL> ; Modem restore.
  468.  
  469. SETLOC:    QIOW$    SF.SMC,lun.co,ef.loc,,LIOSB,,<TTYCH,TTYCHL> ; Local changes.
  470.  
  471. SETREM:    QIOW$    SF.SMC,lun.ti,ef.rem,,RIOSB,,<COMCH,COMCHL> ; Remote changes.
  472.  
  473. SETDLU:    QIOW$    SF.SMC,lun.ti,ef.rem,,RIOSB,,<COMDCH,COMDCL> ; Modem changes.
  474.  
  475. SETSPD:    QIOW$    SF.SMC,lun.ti,ef.rem,,RIOSB,,<COMSPD,COMSPL> ; Set speed.
  476.  
  477. XOFREM:    QIO$    IO.WAL!TF.WBT,lun.ti,,,,,<CTRLS,1,0> ; Send XOFF to remote.
  478.  
  479. XONREM:    QIO$    IO.WAL!TF.WBT,lun.ti,,,,,<CTRLQ,1,0> ; Send XON to remote.
  480.  
  481. rmtout:    Qio$    IO.WAL!TF.WBT,lun.ti,,,,,<0,1,0> ; /60/ write to remote port
  482. ;
  483. ; ASCII messages.
  484. ;
  485.     .NLIST    BEX
  486.  
  487. CTRLQ:    .ASCII    <XON>        ; Transmission ON character.
  488. CTRLS:    .ASCII    <XOFF>        ; Transmission OFF character.
  489.  
  490.     .EVEN
  491.  
  492.     .psect    $CODE    ,I
  493.  
  494.  
  495.     .SBTTL    XDORSX  - Mainline Code.
  496. ;+
  497. ;
  498. ; XDORSX - Mainline code.
  499. ;
  500. ;-
  501.  
  502.     .psect    $CODE    ,I
  503.  
  504. ALTRSX:    call    getprv            ; Enable task privilege.
  505.     clr    eseen            ; Show escape not yet seen.
  506.     mov    #locbuf,locptr        ; /60/ init local write buffer ptr
  507.     calls    ttpars    ,<#ttname>    ; Get the remote unit number.
  508.     alun$s    #lun.ti,r1,r0        ; Assign LUN to the remote.
  509.     alun$s    #lun.co,#"TI,#0        ; Assign our local terminal
  510. ;
  511. ;    Setup the buffer pointers and associated variables:
  512. ;
  513.     MOV    #COMNBF,COMFRE        ; Set all remote buffers free.
  514.     MOV    #COMNBF,MINFRE        ; Set minimum buffers free.
  515.     MOV    #SRTCOM,LSTCOM        ; Set pointer to 1st buffer.
  516.     CLR    COMCNT            ; Clear the buffer count.
  517.     CLR    COMCTL            ; CLear the XOFF/XON flag.
  518.     MOV    #COMBUF,COMPTR        ; Reset the buffer pointer.
  519.     CLR    EXFLG            ; Initialize the exit flag.
  520.     CLR    INTFLG            ; Reset the interrupt flag.
  521.  
  522. ;    Get the current local terminal characteristics.
  523.  
  524.     DIR$    #GETLOC            ; Get local characteristics.
  525.  
  526. ; Detach the local terminal and re-attach with unsolicited AST input.
  527.  
  528.     DSAR$S                ; Disable AST'S for a while.
  529.     DIR$    #DETLOC            ; Detach the local terminal.
  530.  
  531. ;    Set up the new local terminal characteristics.
  532.  
  533.     DIR$    #SETLOC            ; Setup local characteristics.
  534.     CALL    CHKLIO            ; Check/report any errors.
  535.     DIR$    #ASTLOC            ; Attach local with unsol/AST.
  536.     CALL    CHKLIO            ; Check/report any errors.
  537.  
  538. ;    Now get the remote characteristics and setup new ones.
  539.  
  540.     DIR$    #GETREM            ; Get remote characteristics.
  541.     DIR$    #GETDLU            ; Get modem characteristics.
  542.     DIR$    #GETSPD            ; Get the remote port speed.
  543.     CLRB    SMODEM            ; Presume it's not a modem.
  544.     TSTB    RMODEM            ; Is terminal set for modem ?
  545.     BEQ    50$            ; If EQ, no.
  546.     MOVB    #2,SMODEM        ; Yes, change value of TC.DLU.
  547. 50$:    DIR$    #SETREM            ; Setup remote characteristics.
  548.     DIR$    #SETDLU            ; Setup modem characteristics.
  549.     DIR$    #SETSPD            ; Set the remote port speed.
  550.     BCS    60$            ; If CS, presume not variable.
  551.  
  552. ;    Set up various parameters based on the remote speed.
  553.  
  554.     MOVB    COMSPD+1,R2        ; Copy the remote port speed.
  555.     MOVB    FILTBL(R2),FILTIM    ; Set time for remote buffer fill.
  556.     MOVB    QUETBL(R2),COMQUE    ; Set number of reads to queue.
  557.     ASL    R2            ; Convert into a word index.
  558.     MOV    CHRTBL(R2),COMQIO    ; Set maximum remote read count.
  559.  
  560. 60$:    DIR$    #DETREM            ; Detach the remote terminal.
  561.     DIR$    #ASTREM            ; Reattach with UNSOL/AST'S.
  562.     CALL    CHKRIO            ; Check/report any errors.
  563.     DIR$    #CLRCOM            ; Clear the typeahead buffer.
  564.  
  565.     ENAR$S                ; Re-enable AST'S.
  566.     dscp$s                ; *** DISABLE CHECKPOINTING ***
  567.     SREX$S    #RSXABO            ; Setup the abort AST routine.
  568.  
  569.     .SBTTL    LOOP - Loop Reading From Terminals.
  570. ;+
  571. ;
  572. ; LOOP - Loop reading from local and remote terminals.
  573. ;
  574. ; This is the mainline routine which simply waits for input from the
  575. ; remote and then controls output to the local terminal.  Since all
  576. ; local and remote input is either done or activated via AST's, we
  577. ; don't have to post any reads in this routine.
  578. ;
  579. ;-
  580. LOOP:    TST    COMCTL            ; Did the user type XOFF ?
  581.     BMI    50$            ; If MI, yes (wait awhile).
  582.     TST    COMCNT            ; Anything in main buffer ?
  583.     BEQ    40$            ; If EQ, no.
  584.     DSAR$S                ; Yes, disable AST'S.
  585.     CMP    COMCNT,MAXCOM        ; Need to update max count ?
  586.     BLOS    5$            ; If LOS, no.
  587.     MOV    COMCNT,MAXCOM        ; Yes, so set new maximum.
  588. 5$:    MOV    COMPTR,BUFADR        ; Save the buffer pointer.
  589.     MOV    TTYCNT,BUFLEN        ; Set the local output size.
  590.     MOV    COMCNT,R3        ; Copy the main buffer count.
  591.     SUB    TTYCNT,R3        ; Adjust the buffer count.
  592.     BHIS    10$            ; If HIS, not too much.
  593.     ADD    R3,BUFLEN        ; TTYCNT was too many.
  594.     CLR    R3            ; Initialize the buffer count.
  595.  
  596. 10$:    MOV    R3,COMCNT        ; Save new main buffer count.
  597.     SUB    R3,BUFADR        ; Point to end of this group.
  598.     BCS    20$            ; If CS, rewrap.
  599.     CMP    BUFADR,#COMBUF        ; Pointed before beginning ?
  600.     BHIS    30$            ; If HIS, no.
  601. 20$:    ADD    #COMSIZ,BUFADR        ; Point to that much before end.
  602. 30$:    ENAR$S                ; Enable AST'S.
  603.     MOV    #COMBUF,BUFSRT        ; Set the starting address.
  604.     MOV    #COMEND,BUFEND        ; Set the ending address.
  605.     MOV    #lun.co,BUFLUN        ; Set the LUN to write to.
  606.     CALL    BUFOUT            ; Write buffer to device.
  607.  
  608. 40$:    TST    COMCTL            ; Did the progam send XOFF ?
  609.     BLE    45$            ; If LE, no (user did).
  610.     CMP    COMCNT,#COMCTS        ; Still near buffer overflow ?
  611.     BHIS    45$            ; If HIS, yes.
  612.     BIC    #77777,COMCTL        ; Clear the XOFF flag
  613.     DIR$    #XONREM            ; Send an XON to the remote.
  614.     INC    PGMXON            ; Adjust program XON count.
  615.  
  616. 45$:    TST    INTFLG            ; Was interrupt key typed ?
  617.     BNE    100$            ; If NE, yes.
  618.     TST    COMCNT            ; Anything else to output ?
  619.     BNE    LOOP            ; If NE, yes (write more).
  620.  
  621. ;    We simply wait here for something to do.
  622.  
  623. 50$:    WTSE$S    #ef.wait        ; Wait for something to do.
  624.     CLEF$S    #ef.wait        ; Clear our wait event flag.
  625.  
  626. ;    If the exit flag is set, go exit the program.
  627.  
  628.     TST    EXFLG            ; Was exit set via abort AST ?
  629.     BEQ    60$            ; If EQ, no.
  630.     JMP    EXISYS            ; Yes, so exit to the system.
  631.  
  632. ;    If the interrupt key was typed, request a command.
  633.  
  634. 60$:    TST    INTFLG            ; Was interrupt key typed ?
  635.     BNE    100$            ; If NE, yes.
  636. ;
  637. ;    If the remote error was "Device Not Ready" (IE.DNR) then reset
  638. ;    the remote terminal characteristics and speed since the terminal
  639. ;    driver changes certain characteristics when a modem is hungup.
  640. ;
  641.     TST    ERRFLG            ; Was there a remote error ?
  642.     BEQ    70$            ; If EQ, no.
  643.     CMPB    #IE.DNR,RIOSB        ; Was error "Device Not Ready" ?
  644.     BNE    65$            ; If NE, no.
  645.     calls    suspend    ,<#2,#0>    ; Wait for device to be ready.
  646.     DIR$    #SETREM            ; Setup remote characteristics.
  647.     DIR$    #SETSPD            ; Set the remote port speed.
  648. 65$:    CLR    ERRFLG            ; Reset the remote error flag.
  649.  
  650. 70$:    JMP    LOOP            ; Go check for local output.
  651.  
  652. ;    Exit virtual terminal mode.
  653.  
  654. 100$:    CALL    CANCEL            ; Cancel all outstanding I/O.
  655.     DIR$    #RESLOC            ; Reset local characteristics.
  656.     DIR$    #DETLOC            ; Detach the local terminal.
  657.     CALL    REMRES            ; Restore/detach remote port.
  658.     encp$s                ; *** ENABLE CHECKPOINTING ***
  659.     call    setcc            ; Set CTRL/C handler ???
  660.     call    drpprv            ; Drop task privilege.
  661.     return                ; Return from connect mode.
  662.  
  663.     .SBTTL    TTYAST - Local Character AST Routine.
  664. ;+
  665. ;
  666. ; TTYAST - Local terminal character AST routine.
  667. ;
  668. ; This routine is entered when the user types a character at the local
  669. ; terminal.  If we're in command mode, we check for CTRL/C to set the
  670. ; abort flag for file transfer commands.  Otherwise, we process special
  671. ; characters such as XON and XOFF, then write the character to the remote.
  672. ;
  673. ; Inputs:
  674. ;    (SP) = The local input character.
  675. ;
  676. ;-
  677. TTYAST:
  678.     mov    (SP)+,ttybuf        ; /60/ fetch the local character
  679.     Save    <R0,R1>            ; save some registers.
  680.     movb    ttybuf,R1        ; /60/ copy byte to R1
  681.     bicb    #200,R1            ; /60/ clear possible parity bit.
  682.     movb    R1,@locptr        ; /60/ save it in the write buffer
  683.  
  684. ;    Check for the local escape character.
  685.  
  686.     cmpb    r1,conesc        ; /60/ Console escape ?
  687.     bne    10$            ; If NE, no.
  688.     tst    eseen            ; Already seen one escape ?
  689.     bne    20$            ; If NE, yes (send this one).
  690.     inc    eseen            ; No, show escape was seen.
  691.     br    90$            ; And exit the routine ...
  692.  
  693. ;    If escape has been seen, process the following character.
  694.  
  695. 10$:    tst    eseen            ; Character following escape ?
  696.     beq    20$            ; If NE, no (send it).
  697.     call    concmd            ; Yes, so go process it.
  698.     clr    eseen            ; Clear the escape seen flag.
  699.     tst    r0            ; Should we exit CONNECT mode ?
  700.     beq    20$            ; If EQ, not a valid command.
  701.     blt    90$            ; If LT, it's a valid command.
  702.     MOV    #-1,INTFLG        ; Else, show interrupt typed.
  703.     DIR$    #KILLOC            ; Kill I/O on the local port.
  704.     DIR$    #KILREM            ; Kill I/O on the remote port.
  705.     SETF$S    #ef.wait        ; Wakeup the mainline.
  706.     BR    90$            ; And use common exit.
  707.  
  708. 20$:    clr    eseen            ; Clear the escape seen flag.
  709.  
  710. ;    Check for special control characters.
  711.  
  712. 30$:    CMPB    #XOFF,R1        ; /60/ Was CTRL/S typed ?
  713.     BNE    40$            ; If NE, no.
  714.     BIS    #100000,COMCTL        ; Yes, show XOFF typed.
  715.     INC    USRXOF            ; Adjust user XOFF count.
  716.     BR    70$            ; Send it to the remote.
  717.  
  718. 40$:    CMPB    #XON,R1            ; /60/ Was CTRL/Q typed ?
  719.     BNE    70$            ; If NE, no.
  720.     BIC    #100000,COMCTL        ; Yes, clear XOFF flag.
  721.     INC    USRXON            ; Adjust user XON count.
  722.     SETF$S    #ef.wait        ; Wakeup mainline to output.
  723.     TST    COMCTL            ; Did we send an XOFF ?
  724.     BNE    90$            ; If NE, yes (no XON yet).
  725. ;
  726. ;    If local echo, append this character to the remote buffer
  727. ;    for output via the mainline.  The character will also get
  728. ;    written to the logfile using this mechanism.
  729. ;
  730. 70$:    TSTB    duplex            ; Need to do a local echo ?
  731.     BEQ    80$            ; If EQ, no.
  732.     SETF$S    #ef.wait        ; Wakeup mainline to output.
  733.     MOVB    R1,@COMPTR        ; /60/ Copy character main buffer.
  734.     INC    COMPTR            ; Adjust the buffer pointer.
  735.     INC    COMCNT            ; Adjust the buffer count.
  736.     CMP    COMPTR,#COMEND        ; Are we at end of buffer ?
  737.     BNE    80$            ; If NE, no.
  738.     MOV    #COMBUF,COMPTR        ; Yes, wrap to beginning.
  739.  
  740. ;    Write the local character to the remote port.
  741.  
  742. 80$:    setpar    @locptr,@locptr        ; /60/ set correct outgoing parity.
  743.     mov    locptr,rmtout+Q.IOPL    ; /60/ address of byte in DPB
  744.     Dir$    #rmtout            ; /60/ write character to remote port
  745.     BCC    85$            ; /60/ If CC, success.
  746.     CALL    CHKDIR            ; Else, report the error.
  747. 85$:
  748.     inc    locptr            ; /60/ point at next buffer position
  749.     cmp    #locbuf+LOCSIZ,locptr    ; /60/ time to wrap buffer pointer?
  750.     bne    90$            ; /60/ nope, no yet
  751.     mov    #locbuf,locptr        ; /60/ yes, point at beginning
  752. 90$:
  753.     Unsave    <R1,R0>            ; restore saved registers.
  754.     ASTX$S                ; Exit from the AST.
  755.  
  756.     .SBTTL    COMAST - Remote Character AST Routine.
  757. ;+
  758. ;
  759. ; COMAST - Remote character AST routine.
  760. ;
  761. ; This routine is entered to notify us that characters have arrived
  762. ; on the remote port.  Since this is notification only, characters
  763. ; arriving are stored in the typeahead buffer until we issue a read.
  764. ;
  765. ; Inputs:
  766. ;    (SP) = The AST parameter in our attach QIO.
  767. ;
  768. ; Outputs:
  769. ;    All registers are preserved.
  770. ;
  771. ;-
  772. COMAST:    TST    (SP)+            ; Discard stack parameter.
  773.     TST    EXFLG            ; Does user want to exit ?
  774.     BNE    100$            ; If NE, yes (discard).
  775.     TST    INTFLG            ; Exiting the connect code ?
  776.     BNE    100$            ; If NE, yes (discard).
  777.     INC    COMNOT            ; Count AST notifications.
  778.     MOV    R4,-(SP)        ; Save R4
  779.     MOV    R5,-(SP)        ;     and R5.
  780.     MOV    COMQUE,COMNUM        ; Set number of reads to queue.
  781. ;
  782. ;    If we're queuing up another set of reads, that means characters
  783. ;    are arriving faster than our current reads can complete.  When
  784. ;    this happens, we'll send an XOFF to stop the remote output.
  785. ;
  786.     MOV    #COMNBF,R4        ; Set number of free buffers.
  787.     SUB    COMQUE,R4        ; Calculate number now free.
  788.     CMP    COMFRE,R4        ; Queing another set of reads ?
  789.     BHIS    10$            ; If HIS, no.
  790.     TST    COMCTL            ; Did we already send XOFF ?
  791.     BNE    10$            ; If NE, yes.
  792.     DIR$    #XOFREM            ; Send an XOFF to the remote.
  793.     INC    COMCTL            ; Show we sent the XOFF.
  794.     INC    PGMXOF            ; Adjust program XOFF count.
  795.  
  796. 10$:    BR    COMARM            ; Queue up the remote reads.
  797. ;
  798. ;    If in command mode, clear the remote typeahead buffer or else
  799. ;    additional notifiation AST's won't be delevered when we return
  800. ;    to the virtual terminal mode.
  801. ;
  802. 100$:    DIR$    #CLRCOM            ; Clear the typeahead buffer.
  803.     ASTX$S                ; Exit the AST.
  804.  
  805.     .SBTTL    COMARM - Arm The Remote Reads.
  806. ;+
  807. ;
  808. ; COMARM - Arm the remote reads.
  809. ;
  810. ; This routine is used to queue the read requests to the remote terminal.
  811. ; For each read, a marktime is also scheduled.  When all marktimes have
  812. ; expired, this means that little or no data has arrived on the remote
  813. ; port and all queued reads get killed.  The read AST routine will then
  814. ; copy any characters which have arrived to the main buffer where they
  815. ; will be output to the local terminal by the mainline routine.
  816. ;
  817. ;    Note:  This routine is called at AST level.
  818. ;
  819. ; Inputs:
  820. ;    2(SP) = The saved R5.
  821. ;    4(SP) = The saved R4.
  822. ;
  823. ; Outputs:
  824. ;    All registers are preserved.
  825. ;
  826. ;-
  827.     .ENABL    LSB
  828.  
  829. COMARM:    TST    ERRFLG            ; Was there a remote error ?
  830.     BNE    100$            ; If NE, yes (no QIO's).
  831.     TST    COMFRE            ; Are all the buffers in use ?
  832.     BLE    100$            ; If LE, yes.
  833.     TST    COMNUM            ; Already queued enough reads ?
  834.     BLE    100$            ; If LE, yes.
  835.  
  836. QIOCOM:    MOV    LSTCOM,R4        ; Set address of next buffer.
  837.     MOV    R4,R5            ; Copy starting buffer address.
  838.     ADD    #4,R5            ; Point past I/O status block.
  839.     QIO$S    #IO.RAL,#lun.ti,,,R4,#REMAST,<R5,COMQIO>
  840.     BCS    90$            ; If CS, the directive failed.
  841.     INC    QIOCNT            ; Count number of remote QIO's.
  842.     DEC    COMFRE            ; Adjust the free buffer count.
  843.     CMP    COMFRE,MINFRE        ; Low water free buffer mark ?
  844.     BHIS    10$            ; If HIS, no.
  845.     MOV    COMFRE,MINFRE        ; Set new low water buffer mark.
  846. 10$:    DEC    COMNUM            ; Adjust the reads queued count.
  847.     MRKT$S    ,FILTIM,#TICKS,#TIMCOM     ; Set the timer for buffer fill.
  848.     BCS    90$            ; If CS, the directive failed.
  849.     INC    COMMKT            ; Count number of timers queued.
  850.     MOV    R4,LSTCOM        ; Copy the current buffer address.
  851.     ADD    #COMCHR+4,LSTCOM    ; Point to the next free buffer.
  852.     CMP    LSTCOM,#ENDCOM        ; Are we at end of buffer area ?
  853.     BNE    20$            ; If NE, no.
  854.     MOV    #SRTCOM,LSTCOM        ; Yes, point to starting area.
  855. 20$:    BR    COMARM            ; Try to arm another read.
  856.  
  857. 90$:    CALL    CHKDIR            ; Report the directive error.
  858.  
  859. 100$:    MOV    (SP)+,R5        ; Restore R4
  860.     MOV    (SP)+,R4        ;       and R5.
  861.     SETF$S    #ef.wait        ; Wakeup mainline for output.
  862.     ASTX$S                ; And exit the AST.
  863.  
  864.     .DSABL    LSB
  865.  
  866.     .SBTTL    TIMCOM - Remote Marktime AST Routine.
  867. ;+
  868. ;
  869. ; TIMCOM - Remote Marktime AST routine.
  870. ;
  871. ; This routine is entered when the marktime issued after a read to the
  872. ; remote expires.  After all marktimes have expired, the remote I/O is
  873. ; killed and REMAST is entered with the bytes received from the remote.
  874. ;
  875. ;-
  876. TIMCOM:    TST    EXFLG            ; EXIT FLAG SET ?
  877.     BNE    10$            ; IF NE, YES (KILL I/O)
  878.     TST    INTFLG            ; Exiting the connect code ?
  879.     BEQ    20$            ; IF EQ, NO (CONTINUE)
  880. ;
  881. ; If exiting the connect code or exiting the program, cancel marktimes,
  882. ; and kill remote I/O so KERMIT commands will not get screwed.
  883. ;
  884. 10$:    CMKT$S    ,#TIMCOM        ; Cancel any remote marktimes.
  885.     CLR    COMMKT            ; Initialize the marktime count.
  886.     BR    30$            ; And kill the remote I/O.
  887. 20$:    DEC    COMMKT            ; Adjust the marktime count.
  888.     BNE    40$            ; If NE, more timers queued.
  889. 30$:    DIR$    #KILREM            ; Else, kill the remote I/O.
  890.     INC    COMKIL            ; Adjust kill operation count.
  891. 40$:    TST    (SP)+            ; Remove event flag number.
  892.     ASTX$S                ; And exit the AST.
  893.  
  894.     .SBTTL    REMAST - Remote Read AST Routine.
  895. ;+
  896. ;
  897. ; REMAST - Remote read AST completion routine.
  898. ;
  899. ; This routine is entered when a remote read completes.  Its function
  900. ; is to copy any characters received to the main buffer, wakeup the
  901. ; mainline to start output to the local terminal, and to re-issue the
  902. ; read if there have been no errors and something was read.
  903. ;
  904. ; Inputs:
  905. ;    (SP) = The I/O status block address.
  906. ;
  907. ; Outputs:
  908. ;    All registers are preserved.
  909. ;
  910. ;-
  911. REMAST:    INC    COMFRE            ; Adjust free buffer count.
  912.     TST    EXFLG            ; Are we exiting the program ?
  913.     BNE    10$            ; If NE, yes.
  914.     TST    INTFLG            ; Exiting the connect code ?
  915.     BEQ    20$            ; If EQ, no (continue ...)
  916. 10$:    TST    (SP)+            ; Remove status block address.
  917.     ASTX$S                ; And exit the AST.
  918.  
  919. 20$:    MOV    R4,-(SP)        ; Save
  920.     MOV    R5,-(SP)        ;    some
  921.     MOV    R1,-(SP)        ;     registers
  922.     MOV    R3,-(SP)        ;      on the stack.
  923.     MOV    COMPTR,R1        ; Copy the buffer pointer.
  924.     MOV    COMCNT,R3        ; And the buffer byte count.
  925.     MOV    10(SP),R4        ; Copy status block address.
  926.     MOV    R4,R5            ; Copy this address,
  927.     ADD    #4,R5            ; and point to the data area.
  928.     TSTB    (R4)            ; Was there any errors ?
  929.     BPL    50$            ; If PL, no.
  930.     CMPB    #IE.ABO,(R4)        ; Was the read killed ?
  931.     BNE    40$            ; If NE, no.
  932.     INC    COMABO            ; Adjust aborted reads count.
  933. ;
  934. ;    When the reads get killed, only the current outstanding read
  935. ;    has an AST delivered.  All other reads which are queued, get
  936. ;    killed, but the specified AST is not delevered.  Therefore,
  937. ;    we must set all buffers as free when abort is detected.
  938. ;
  939.     MOV    #COMNBF,COMFRE        ; Yes, set all buffers free.
  940. ;
  941. ;    Sometimes when our read is killed, there is a very large byte
  942. ;    count in the I/O status block.  Just another RSX-11M mystery.
  943. ;
  944.     CMP    #COMCHR,2(R4)        ; Is byte count too large ?
  945.     BLO    80$            ; If LO, yes (don't use).
  946.     BR    50$            ; Don't report this error.
  947.  
  948. 40$:    MOV    (R4),RIOSB        ; Copy the I/O error code.
  949.     CALL    CRIOSB            ; Write the error message.
  950.     MOV    #-1,ERRFLG        ; Show there was an error.
  951.  
  952. 50$:    MOV    2(R4),R4        ; Copy the byte count.
  953.     BEQ    85$            ; If EQ, nothing was read.
  954.     CMP    R4,MAXBC        ; Is this the MAX so far ?
  955.     BLO    55$            ; If LO, no.
  956.     MOV    R4,MAXBC        ; Yes, save for status.
  957.  
  958. 55$:    ADD    R4,RCHIN+2        ; Count the characters read.
  959.     ADC    RCHIN            ; Add in the carry (if any).
  960.     CMP    R4,COMQIO        ; Is this a full buffer ?
  961.     BNE    60$            ; If NE, no.
  962.     INC    COMFUL            ; Adjust full buffer count.
  963.  
  964. 60$:    tst    con8bit            ; Should we pass eight bits ?
  965.     bne    65$            ; If NE, yes.
  966.     bicb    #200,(r5)        ; No, so clear the high bit.
  967.  
  968. 65$:    MOVB    (R5)+,(R1)+        ; Copy bytes to main buffer.
  969.     INC    R3            ; Adjust the byte count.
  970.     CMP    R1,#COMEND        ; At end of main buffer ?
  971.     BNE    70$            ; If NE, no.
  972.     MOV    #COMBUF,R1        ; Yes, reset to beginning.
  973.  
  974. 70$:    SOB    R4,60$            ; Loop until we're done.
  975.     CMP    R3,#COMCTS        ; Getting near buffer overflow ?
  976.     BLO    80$            ; If LO, no.
  977.     TST    COMCTL            ; Did we already send XOFF ?
  978.     BNE    80$            ; If NE, yes.
  979.     DIR$    #XOFREM            ; Send as XOFF to the remote.
  980.     INC    COMCTL            ; Show we sent the XOFF.
  981.     INC    PGMXOF            ; Adjust program XOFF count.
  982.  
  983. 80$:    MOV    10(SP),R4        ; Copy the status block address.
  984.     MOV    R1,COMPTR        ; Save the new buffer pointer
  985.     MOV    R3,COMCNT        ;   and the main buffer count.
  986.     TST    ERRFLG            ; Was there a remote error ?
  987.     BEQ    90$            ; If EQ, no (continue ...)
  988.     CMPB    #IE.DNR,(R4)        ; Was error "Device Not Ready" ?
  989.     BNE    90$            ; If NE, no (queue next read).
  990.  
  991. 85$:    MOV    (SP)+,R3        ; Restore
  992.     MOV    (SP)+,R1        ;    all
  993.     MOV    (SP)+,R5        ;     saved
  994.     MOV    (SP)+,R4        ;      registers.
  995.     TST    (SP)+            ; Remove status block address.
  996.     SETF$S    #ef.wait        ; Wakeup mainline for output.
  997.     ASTX$S                ; And exit the AST.
  998.  
  999. 90$:    MOV    (SP)+,R3        ; Restore R3
  1000.     MOV    (SP)+,R1        ;        and R1.
  1001.     MOV    R4,R5            ; Copy the status block address.
  1002.     ADD    #4,R5            ; Point to the data buffer.
  1003.     MOV    2(SP),4(SP)        ; Move R4 down on the stack.
  1004.     MOV    (SP)+,(SP)        ; Move R5 down and clean stack.
  1005.     JMP    QIOCOM            ; Now go queue another read.
  1006.  
  1007.     .SBTTL    BUFOUT - Write Buffer to Device.
  1008. ;+
  1009. ;
  1010. ; BUFOUT - Write a buffer to a device.
  1011. ;
  1012. ; Inputs:
  1013. ;    BUFADR = The ending address to write.
  1014. ;    BUFSRT = The starting buffer address.
  1015. ;    BUFEND = The ending buffer address.
  1016. ;    BUFLUN = The device LUN to write to.
  1017. ;    BUFLEN = The number of bytes to write.
  1018. ;
  1019. ; Outputs:
  1020. ;    All registers are preserved.
  1021. ;
  1022. ;-
  1023. BUFOUT:    CALL    $SAVAL            ; Save all registers.
  1024.     TST    EXFLG            ; Is the exit flag set ?
  1025.     BNE    20$            ; If NE, yes.
  1026.     TST    INTFLG            ; Exiting the connect code ?
  1027.     BNE    20$            ; If NE, yes.
  1028.     MOV    BUFLUN,R0        ; Copy the LUN to write to.
  1029.     MOV    BUFADR,R2        ; Copy the ending address.
  1030.     SUB    BUFLEN,R2        ; Calculate starting address.
  1031.     CMP    R2,BUFSRT        ; Does buffer wrap around ?
  1032.     BLT    10$            ; If LT, yes.
  1033.  
  1034. ;    Write the buffer to the log file and the terminal.
  1035.  
  1036.     MOV    BUFLEN,R3        ; Copy the byte count.
  1037.     CALL    WRTLOG            ; Write it to the logfile,
  1038.     QIOW$S    #IO.WAL,R0,#ef.sync,,#XIOSB,,<R2,R3,#0> ; & terminal.
  1039.     CALL    CHKXIO            ; Check/report any errors.
  1040.     BR    20$            ; Use common return.
  1041.  
  1042. ;    The buffer wraps around, use two QIO's to write buffer.
  1043.  
  1044. 10$:    MOV    BUFADR,R3        ; Copy the ending address.
  1045.     SUB    BUFSRT,R3        ; Calculate bytes from start.
  1046.     MOV    R3,-(SP)        ; Save beginning byte count.
  1047.     MOV    BUFLEN,R3        ; Copy # of bytes to write.
  1048.     SUB    (SP),R3            ; Minus chars at beginning.
  1049.     MOV    BUFEND,R2        ; Copy the ending address.
  1050.     SUB    R3,R2            ; Calculate starting address.
  1051.  
  1052. ;    Write the buffer to the log file and the terminal.
  1053.  
  1054.     CALL    WRTLOG            ; Write it to the logfile,
  1055.     QIOW$S    #IO.WAL,R0,#ef.sync,,#XIOSB,,<R2,R3,#0> ; & terminal.
  1056.     CALL    CHKXIO            ; Check/report any errors.
  1057.     MOV    (SP)+,R3        ; Restore beginning byte count.
  1058.     BEQ    20$            ; If EQ, nothing to write.
  1059.     CMPB    XIOSB,#IE.ABO        ; Was the first QIO aborted ?
  1060.     BEQ    20$            ; If EQ, yes (no 2nd QIO).
  1061.     TST    EXFLG            ; Is the exit flag set ?
  1062.     BNE    20$            ; If NE, yes.
  1063.     TST    INTFLG            ; Exiting the connect code ?
  1064.     BNE    20$            ; If NE, yes.
  1065.  
  1066. ;    Write the buffer to the log file and the terminal.
  1067.  
  1068.     MOV    BUFSRT,R2        ; Copy the starting address.
  1069.     CALL    WRTLOG            ; Write it to the logfile,
  1070.     QIOW$S    #IO.WAL,R0,#ef.sync,,#XIOSB,,<R2,R3,#0> ; & terminal.
  1071.     CALL    CHKXIO            ; Check/report any errors.
  1072.  
  1073. 20$:    RETURN
  1074.  
  1075.     .SBTTL    CANCEL - Cancel Local and Remote I/O.
  1076. ;+
  1077. ;
  1078. ; CANCEL - Cancel the local and remote I/O.
  1079. ;
  1080. ; Be careful if calling this routine from AST level since outstanding
  1081. ; I/O will cause us to hang since other I/O can't complete.
  1082. ;
  1083. ;-
  1084. CANCEL:    DIR$    #KILLOC            ; Kill I/O on local port.
  1085.     BCS    10$            ; If CS, don't wait.
  1086.     WTSE$S    #ef.kill        ; Wait for the kill I/O.
  1087.  
  1088. 10$:    DIR$    #KILREM            ; Kill I/O on remote port.
  1089.     BCS    20$            ; If CS, don't wait.
  1090.     WTSE$S    #ef.kill        ; Wait for the kill I/O.
  1091.  
  1092. 20$:    RETURN
  1093.  
  1094.     .SBTTL    CHKDIR - CHECK FOR DIRECTIVE ERROR
  1095.     .SBTTL    CHKLIO - CHECK FOR LOCAL I/O ERROR
  1096.     .SBTTL    CHKRIO - CHECK FOR REMOTE I/O ERROR
  1097. ;+
  1098. ;
  1099. ; CHKDIR - Check for a directive error.
  1100. ; CHKLIO - Check for local I/O error code.
  1101. ; CHKRIO - Check for remote I/O error code.
  1102. ;
  1103. ; These routines are called to check for QIO errors for both
  1104. ; the local terminal and the remote terminal port.
  1105. ;
  1106. ; Inputs:
  1107. ;    $DSW, LIOSB, RIOSB, or XIOSB status blocks.
  1108. ;
  1109. ; Outputs:
  1110. ;    C bit clear/set = success/failure.
  1111. ;
  1112. ;    All registers are preserved.
  1113. ;
  1114. ;-
  1115.     .ENABL    LSB
  1116.  
  1117. CHKDIR:    JSR    R2,$SAVVR        ; Save R0 - R2.
  1118.     BCC    100$            ; If CC, then success.
  1119.     MOV    $DSW,R0            ; Else, copy the error code.
  1120.     BR    20$            ; And use common code.
  1121.  
  1122. CHKXIO:    BCS    CHKDIR            ; If CS, directive error.
  1123.     JSR    R2,$SAVVR        ; Save R0 - R2.
  1124.     MOVB    XIOSB,R0        ; Copy the I/O code.
  1125.     BPL    100$            ; If PL, then success.
  1126.     BR    10$            ; Else, use common code.
  1127.  
  1128. CHKLIO:    BCS    CHKDIR            ; If CS, directive error.
  1129.     JSR    R2,$SAVVR        ; Save R0 - R2.
  1130.     MOVB    LIOSB,R0        ; Copy the I/O code.
  1131.     BPL    100$            ; If PL, then success.
  1132.     BR    10$            ; Continue ...
  1133.  
  1134. CHKRIO:    BCS    CHKDIR            ; If CS, directive error.
  1135. CRIOSB:    JSR    R2,$SAVVR        ; Save R0 - R2.
  1136.     MOVB    RIOSB,R0        ; Copy the I/O code.
  1137.     BPL    100$            ; If PL, then success.
  1138.  
  1139. 10$:    CMPB    #IE.ABO,R0        ; Was the I/O killed ?
  1140.     BEQ    100$            ; If EQ, yes (expected).
  1141.  
  1142. 20$:    CALL    CHKERR            ; Check/write error message.
  1143. ;    SEC                ; Show we've had an error.
  1144.     RETURN                ; Return status from CHKERR.
  1145.  
  1146. 100$:    CLC                ; Success or non-fatal error.
  1147.     RETURN
  1148.  
  1149.     .DSABL    LSB    
  1150.  
  1151.     .SBTTL    CHKERR - Check/Write An Error Message.
  1152. ;+
  1153. ;
  1154. ; CHKERR - Check and write an error message.
  1155. ;
  1156. ; Thie routine checks a table for allowable errors and if the error
  1157. ; code isn't found in the table, the error is reported.
  1158. ;
  1159. ; Inputs:
  1160. ;    R0 = The error code.
  1161. ;
  1162. ; Outputs:
  1163. ;    C bit clear/set = Allowable/Unacceptable Error.
  1164. ;
  1165. ;    All registers are preserved.
  1166. ;
  1167. ;-
  1168. CHKERR:    mov    r5    ,-(sp)        ; insure this is saved
  1169.     movb    r0,r5            ; Copy the error code.
  1170.     scan    r5    ,#$errlst    ; allowable error code ?
  1171.     tst    r0            ; well
  1172.     bne    180$            ; yes, let it through
  1173.     neg    r5            ; make > 0 for direrr macro
  1174.     direrr    r5            ; simple
  1175.     sec                ; failure, exit to command level
  1176.     br    190$            ; bye
  1177. 180$:    clc                ; success, stay in connect code
  1178. 190$:    mov    (sp)+    ,r5        ; restore old r0 please
  1179.     return
  1180.  
  1181.     .save
  1182.     .psect    $PDATA    ,D
  1183. $errlst:.byte    IE.BCC    ,IE.DAO    ,IE.IES    ,IE.NOD    ,IE.PES    ,IE.VER    ,IE.ABO ,0
  1184.     .even
  1185.     .restore
  1186.  
  1187.     global    <conesc, ttcons, ttname, lun.co, lun.ti>
  1188.  
  1189.     .SBTTL    WRTLOG - Write I/O to a log file.
  1190. ;+
  1191. ;
  1192. ; WRTLOG - Write I/O to a log file.
  1193. ;
  1194. ; This routine is used to write output from the remote system to
  1195. ; a log file (if enabled).
  1196. ;
  1197. ; Inputs:
  1198. ;    R2 = The buffer address.
  1199. ;    R3 = The buffer byte count.
  1200. ;
  1201. ; Outputs:
  1202. ;    All registers are preserved.
  1203. ;
  1204. ;-
  1205. WRTLOG:    call    $saval            ; Save all registers.
  1206.     bit    #log$co    ,trace        ; is this enabled ?
  1207.     beq    100$            ; no
  1208.     bit    #log$op    ,trace        ; is it open
  1209.     beq    100$            ; no
  1210.  
  1211. 10$:    movb    (r2)+,r0        ; Copy the next character.
  1212.     mov    #lun.lo    ,r1        ; Set the unit number.
  1213.     call    putcr0            ; Write it to the log file.
  1214.     sob    r3,10$            ; Write the next character.
  1215.  
  1216. 100$:    return
  1217.  
  1218.  
  1219.     global    <lun.lo, putcr0, trace, conflow>
  1220.  
  1221.     .SBTTL    REMRES - Restore Remote Characteristics.
  1222. ;+
  1223. ;
  1224. ; REMRES - Restore the remote characteristics.
  1225. ;
  1226. ; Restore the remote characteristics and detach the terminal.
  1227. ;
  1228. ;-
  1229. REMRES:    DIR$    #KILREM            ; Kill any I/O on remote LUN.
  1230.     WTSE$S    #ef.kill        ; Wait for the kill to complete.
  1231.     DIR$    #RESREM            ; Yes, reset the characteristics.
  1232.     DIR$    #RESDLU            ; Reset the modem characteristics.
  1233.     DIR$    #DETREM            ; Detach the remote terminal.
  1234. 100$:    RETURN
  1235.  
  1236.     .SBTTL    RSXABO - Process an ABORT AST.
  1237. ;+
  1238. ;
  1239. ; RSXABO - Process an ABORT AST.
  1240. ;
  1241. ; This routine is called as the result of KERMIT being ABOrted.  The
  1242. ; first time we are entered we simply kill all I/O and try to wakeup
  1243. ; the mainline to actually exit the program.  We also start a timer
  1244. ; which if it expires, will simply exit the program so we don't hang.
  1245. ; We don't do too much work here because if we stay at AST level, we
  1246. ; prevent other AST's from completing which may hang the program.
  1247. ;
  1248. ;
  1249. ; Inputs:
  1250. ;    (SP)  = Number of bytes to remove from the stack.
  1251. ;    2(SP) = The reason for being aborted.
  1252. ;
  1253. ;-
  1254. RSXABO:    ADD    (SP),SP            ; Remove abort information.
  1255.     SREX$S                ; Remove abort AST routine.
  1256.     CMKT$S                ; Cancel outstanding timers.
  1257.     SETF$S    #ef.time        ; Set the delay event flag.
  1258.     DIR$    #KILLOC            ; Kill I/O on local port.
  1259.     DIR$    #KILREM            ; Kill I/O on remote port.
  1260.     SETF$S    #ef.wait        ; Wakeup the mainline.
  1261.     MOV    #-1,EXFLG        ; Tell the mainline to exit.
  1262.     MRKT$S    ,#5,#SECNDS,#ABOTMO    ; Initiate an abort timer.
  1263.     ASTX$S                ; Exit the AST.
  1264. ;+
  1265. ;
  1266. ; This routine is entered when the marktime issued in the abort AST
  1267. ; routine expires.  If this timer expires, this means the mainline
  1268. ; hasn't detected our exit request so we cancel all I/O, reset the
  1269. ; terminal characteristics, and then exit the program.
  1270. ;
  1271. ;-
  1272. ABOTMO:    TST    (SP)+            ; Remove marktime parameter.
  1273. EXISYS:    CALL    CANCEL            ; Cancel all outstanding I/O.
  1274.     DIR$    #RESLOC            ; Reset local characteristics.
  1275.     CALL    REMRES            ; Restore/detach remote port.
  1276.     DIR$    #HANGUP            ; Ensure the modem is hungup.
  1277.     EXIT$S                ; And exit to the system ...
  1278.  
  1279.  
  1280.     .sbttl    concmd    terminal emulation escape commands
  1281.     .enabl    lsb
  1282.  
  1283. concmd::save    <r1>
  1284.     bicb    #^C177    ,r1
  1285.     scan    r1,#200$        ; look for a match here
  1286.     tst    r0            ; if no match, return 0
  1287.     beq    100$            ; ok
  1288.     asl    r0            ; word offsets
  1289.     jsr    pc    ,@210$(r0)    ; dispatch to the correct routine
  1290.     tst    r0            ; if not set then set to -1
  1291.     bne    100$            ; already set
  1292.     dec    r0            ; set to -1
  1293. 100$:    unsave    <r1>            ; pop r1 and exit
  1294.     return
  1295.  
  1296.  
  1297.     .save
  1298.     .psect    $PDATA    ,D
  1299.  
  1300. 200$:    .byte    'C&137    ,'c!40        ; drop connection ctrl \ C
  1301.     .byte    'I&137    ,'i!40        ; init the line
  1302.     .byte    'Q&137    ,'q!40        ; quit logging but leave file open
  1303.     .byte    'R&137    ,'r!40        ; resume logging if file is open
  1304.     .byte    'X&137    ,'X!40        ; control Q and then thats all
  1305.     .byte    'B&137    ,'b!40
  1306.     .byte    '?    ,177        ; help, rub for send break
  1307.     .byte    'H&137    ,'h!40
  1308.     .byte    0
  1309.     .even
  1310.  
  1311. 210$:    .word    con.$            ; unknown escape command
  1312.     .word    con.c    ,con.c        ; drop connection
  1313.     .word    con.i    ,con.i        ; get modems attention
  1314.     .word    con.q    ,con.q        ; turn console logging off
  1315.     .word    con.r    ,con.r        ; turn it back on please
  1316.     .word    con.x    ,con.x        ; send XON
  1317.     .word    con.br    ,con.br        ; break
  1318.     .word    con.hl    ,con.br        ; print out commands
  1319.     .word    con.hl    ,con.hl        ; help
  1320.  
  1321. $bell:    .byte    'G&37
  1322. $xon:    .byte    'Q&37
  1323. $null2:    .byte    0,0
  1324.     .even
  1325.     .restore
  1326.     .dsabl    lsb
  1327.  
  1328.  
  1329. con.$:    calls    binwri    ,<#$bell,#1,#lun.co>    ; beep at user
  1330.     clr    r0
  1331.     return
  1332.  
  1333.  
  1334.  
  1335. con.c:    mov    #1    ,r0        ; set flag to exit connect code
  1336.     return                ; simple
  1337.  
  1338.  
  1339. con.i:    calls    ttydtr    ,<#ttname>    ; try to force DTR up on the line
  1340.     clr    r0
  1341.     return
  1342.  
  1343.  
  1344. con.q:    bic    #log$co    ,trace        ; turn off console logging
  1345.     clr    r0
  1346.     return
  1347.  
  1348.  
  1349. con.r:    bit    #log$op    ,trace        ; if the file is open do it
  1350.     beq    100$            ; no
  1351.     bis    #log$co    ,trace        ; yes, enable this
  1352. 100$:    clr    r0
  1353.     return
  1354.  
  1355.  
  1356. con.x:    calls    binwri    ,<#$xon,#1,#lun.ti>; insure a control Q goes down
  1357.     calls    ttxon    ,<#ttname>
  1358.     Call    getprv            ; /60/ restore privs dropped by TTXON
  1359.     clr    r0
  1360.     return
  1361.  
  1362.  
  1363. con.br:    save    <r1,r2>            ; save scratch registers please
  1364.     clr    -(sp)            ; clear a sf.gmc buffer out
  1365.     clr    -(sp)            ; ditto
  1366. 10$:    mov    sp    ,r2        ; and a pointer to it please
  1367.     movb    #tc.xsp    ,@r2        ; we want the current speed settings
  1368.     movb    #tc.rsp    ,2(r2)        ; ditto
  1369.     QIOW$S    #SF.GMC,#LUN.TI,,,,,<r2,#4>
  1370.     movb    1(r2)    ,r1        ; save the old speed setting please
  1371.     mov    sp    ,r2        ; reset the buffer address please
  1372.     movb    #tc.xsp    ,(r2)+        ; stuff xmitter change code in
  1373.     movb    #s.300    ,(r2)+        ; and the desired speed now
  1374.     movb    #tc.rsp    ,(r2)+        ; stuff receiver change code in
  1375.     movb    #s.300    ,(r2)+        ; and the desired speed now
  1376.     mov    sp    ,r2        ; point back to the buffer now
  1377.     QIOW$S    #SF.SMC,#LUN.TI,,,,,<r2,#4>
  1378.     QIOW$S    #IO.WAL,#LUN.TI,,,,,<#$null2,#2>
  1379.     mov    sp    ,r2        ; reset the buffer address please
  1380.     movb    #tc.xsp    ,(r2)+        ; stuff xmitter change code in
  1381.     movb    r1    ,(r2)+        ; and the old speed now
  1382.     movb    #tc.rsp    ,(r2)+        ; stuff receiver change code in
  1383.     movb    r1    ,(r2)+        ; and the old speed now
  1384.     mov    sp    ,r2        ; point back to the buffer now
  1385.     QIOW$S    #SF.SMC,#LUN.TI,,,,,<r2,#4>
  1386. 100$:    cmp    (sp)+    ,(sp)+        ; pop local buffer and exit
  1387.     clr    r0            ; no errors are ever returned
  1388.     unsave    <r2,r1>            ; pop local registers and exit
  1389.     return                ; bye
  1390.  
  1391.  
  1392.  
  1393.  
  1394.  
  1395.  
  1396. con.hl::strlen    #htxt
  1397.     calls    binwri    ,<#htxt,r0,#lun.co>
  1398.     clr    r0
  1399.     return
  1400.  
  1401.     .save
  1402.     .psect    $PDATA    ,D
  1403.  
  1404. htxt:    .ascii    /B    Try to send a  break to the  remote/<cr><lf>
  1405.     .ascii    /C    Connect back to the local Kermit-11/<cr><lf>
  1406.     .ascii    /I    Drop  and raise DTR (for RSTS only)/<cr><lf>
  1407.     .ascii    /Q    Quit console logging.   See SET LOG/<cr><lf>
  1408.     .ascii    /R    Resume console logging. See SET LOG/<cr><lf>
  1409.     .ascii    /X    Send XON and cancel any active XONs/<cr><lf>
  1410.     .asciz    /RUBOUT    Try to fake a break to the remote/<cr><lf>
  1411.     .ascii    /?    Print this message/<cr><lf>
  1412.     .byte    0
  1413.     .even
  1414.     .restore
  1415.  
  1416.     .END
  1417.