home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / pdp11 / k11rco.mac < prev    next >
Text File  |  2020-01-01  |  25KB  |  907 lines

  1.     .sbttl    K11RCO    New RT11 connect code
  2.     .psect
  3.     .ident    /3.51.4/
  4.  
  5.  
  6.  
  7.     .if ndf, K11INC
  8.     .ift
  9.     .include    /IN:K11MAC.MAC/
  10.     .endc
  11.  
  12.     .enabl    gbl
  13.     
  14. ;    Copyright (C) 1986 Change Software, Inc
  15. ;
  16. ;    07-MAY-1986 10:55  Brian Nelson
  17. ;
  18. ;    Edits:
  19. ;
  20. ;    16-May-86  11:12:55
  21. ;
  22. ;3.51.2    Add tasks to watch for carrier transitions and hung XOFF'ed
  23. ;    status (XC/XL/CL only).
  24. ;3.51.3 Check for tt output ring buffer overflow.
  25. ;3.51.4 Kludge to correct for bug in RT11 5.1 XL handler
  26. ;3.56.5 Allow XL a little time to finish 09-Dec-86  10:52:04
  27. ;3.56.6 Fix LF processing. Not strictly needed because the XL driver
  28. ;    under 5.2 and later filters LF's that follow CR's. We will do
  29. ;    it here anyway though for non-DEC drivers (like CL and KL).
  30. ;
  31. ;
  32. ;
  33. ;     Complete rewrite of RT11 connect code.  For XC/XL/CL, we use
  34. ;    a multitasking  approach and drive it via interupts (actually
  35. ;    timer and read completions). For MultiTerminal data, see code
  36. ;    at DOMT:.  Maybe the MT code will run on SJ now, the XL/CL/XC
  37. ;    code will NOT.
  38.  
  39.  
  40.     .psect    concod    ,ro,i,lcl,rel,con
  41.     .psect    condat    ,rw,d,lcl,rel,con
  42.  
  43.  
  44.     JSW    =    44
  45.     ERRBYTE    =    52
  46.     $XLV51    =    16.        ; XL/XC for RT11 v5.1
  47.     $XLV52    =    17.        ; XL/XC for RT11 v5.2
  48.  
  49.     .mcall    .WRITC    ,.SPFUN    ,.TTINR    ,.TTYIN    ,.TTYOU    ,.TTOUTR
  50.     .mcall    .MRKT    ,.CMKT    ,.TWAIT    ,.SCCA    ,.QSET    ,.PRINT
  51.     .mcall    .RSUM    ,.SPND    ,.RCTRLO,.GVAL    ,.SERR    ,.HERR
  52.  
  53.     .iif ndf, SJ$TEST    ,SJ$TEST = 0
  54.  
  55.     GLOBAL    <SJ$TEST>
  56.  
  57.     .if ne    ,SJ$TEST
  58.     .ift
  59.  
  60.     .macro    .RSUM
  61.     .endm    .RSUM
  62.  
  63.     .macro    .SPND
  64.     .endm    .SPND
  65.  
  66.     .macro    .MRKT    a,b,c,d,e,f
  67.     .endm    .MRKT
  68.  
  69.     .macro    .TWAIT    a,b,c,d,e,f
  70.     .endm    .TWAIT
  71.  
  72.     .macro    .CMKT    a,b,c
  73.     .endm    .CMKT
  74.  
  75.     .endc                ; IF ne, SJ$TEST
  76.  
  77.  
  78.  
  79.  
  80.     .psect    condat
  81.  
  82.     .even
  83.  
  84.     .macro    BEEP
  85.     mov    #7    ,r0
  86.     .TTOUTR
  87.     .endm    BEEP
  88.  
  89.     .macro    SCHEDULE    taskheader
  90.     mov    r0    ,-(sp)
  91.     mov    taskheader,r0
  92.     mov    #runable,STATE(r0)
  93.     mov    (sp)+    ,r0
  94.     .endm    SCHEDULE
  95.  
  96.     RUNABLE    =    1
  97.     STATE    =    0
  98.     TASKADDR=    2
  99.     IODONE    =    4
  100.     IOPEND    =    6
  101.     IOBUFF    =    10
  102.     IOSTALL    =    12
  103.  
  104. ;    This is the schedulers 'JOB' table.
  105.  
  106.  
  107. tlist:
  108.  
  109. ;          STATE    DISPATCH IODONE IOPEND  IOBUFF  IOSTALL
  110.  
  111. xkhead:    .word    0    ,XKPROC    ,0    ,0    ,0    ,0
  112. tthead:    .word    0    ,TTPROC    ,0    ,0    ,0    ,0
  113. rmhead:    .word    0    ,RMPROC    ,0    ,0    ,TTBUFF    ,0
  114. sthead:    .word    0    ,STPROC    ,0    ,0    ,0    ,0
  115. wthead:    .word    0    ,WTPROC    ,0    ,0    ,0    ,0
  116.     .word    -1    ,-1    ,-1    ,-1    ,0    ,0
  117.  
  118. sjlist:    .word    STSDONE    ,WTDONE    ,TTDONE    ,0
  119.  
  120. hdsize    =    tthead - xkhead
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.     .if NE    ,SJ$TEST
  128.     .ift
  129. sj.dec:    .word    1            ; Testing under XM
  130.     .iff
  131. sj.dec:    .word    0            ; SJ and no .MRKT if NE
  132.     .endc
  133.  
  134. crflag:    .blkw    1            ; CR seen flag
  135. xk:    .blkw    1            ; Save flag
  136. rt.v51:    .blkw    1            ; Need to know Xl handler version
  137. xksdon:    .blkw    1            ; Remote terminal set done
  138. ttsdon:    .blkw    1            ; Local terminal set done
  139. ioseen:    .blkw    1            ; Some input was seen somewhere
  140. ttio:    .blkw    1            ; Console read worked
  141. xkio:    .blkw    1            ; Remote read worked
  142. eseen:    .blkw    1            ; Control \ happened at console
  143. ttunit:    .blkw    1            ; Our console terminal unit
  144. xkunit:    .blkw    1            ; Connected line's unit number
  145. scca:    .word    0,0,0            ; For getting control C's
  146. mark:    .blkw    4            ; For MARKTIME
  147. short:    .word    0,1            ;
  148. mtime:    .word    0,0            ; Timeout value
  149. twait:    .word    0,0,0,0            ; 'AREA' for TWAITS
  150. cancel:    .word    0,0,0,0            ; 'AREA' for CANCEL mark time
  151. rmwork:    .word    0,0,0,0
  152. rmtime:    .word    0,3*60.
  153. ttmark:    .word    0,0,0,0
  154. ttwait:    .word    0,3
  155. suspend:.word    0
  156. xkrd1:    .word    0,0,0,0,0,0
  157. xkrd2:    .word    0,0,0,0,0,0
  158. xkr1do:    .word    0
  159. xkr2do:    .word    0
  160. xkwork:    .word    0,0,0,0,0,0
  161. done:    .word    0
  162. xkmark:    .word    0,0,0,0
  163. xktime:    .word    0,10.
  164. idle:    .word    0
  165. idmark:    .word    0,0,0,0
  166. idtime:    .word    0,62.            ; Check for idle state
  167.  
  168. stswork:.word    0,0,0,0,0,0        ; For status watcher task's .SPFUN
  169. stsmark:.word    0,0,0,0            ; For .MRKT to schedule status watcher
  170. ststime:.word    0,20.            ; Schedule status watcher 20 ticks
  171. wtmark:    .word    0,0,0,0            ; For XOFF watcher
  172. wttime:    .word    0,20.            ; Do it every 20 ticks
  173. xksts:    .word    0,0            ; Save status
  174. wtsts:    .word    0,0            ; Save status again
  175. wtcount:.word    0            ; Save low 16 bits of char count
  176. charcou:.word    0,0            ; Total chars sent by HOST
  177.  
  178. tsxbrk:    .byte    0,133            ; TSX+ SET break address
  179.     .word    0            ; No 'break' char
  180.     .word    brkast            ; Where to jump to
  181. tsxnbrk:.byte    0,133            ; TSX+, turn break AST's off
  182.     .word    0,0            ; Disable
  183.  
  184. XKSIZE    =    200            ; Large buffers for remote reads
  185. xkbuff:    .blkb    XKSIZE+2        ; Buffer for connected line
  186. xkpoint:.word    xkbuff
  187. ttbuff:    .blkb    80.            ; Buffer for console terminal
  188. rmbuff:    .blkb    2
  189. msg:    .blkb    110
  190. co:    .asciz    /Connecting to /
  191. spd:    .asciz    /  Speed: /<200>
  192.     .even
  193.  
  194.  
  195.     .psect    concod
  196.     .enabl    lsb
  197.  
  198. doconn::call    check            ; SJ checks
  199.     .iif NE, SJ$TEST, clr clkflg    ; For testing
  200.     clr    xk            ; Clear device type
  201.     tstb    ttname            ; Anything there ?
  202.     bne    1$            ; Yes
  203.     message    <Please use the SET LINE command>,cr
  204.     return                ; Exit
  205. 1$:    strcpy    #msg    ,#co        ; Build a header up.
  206.     strcat    #msg    ,#ttname    ; ...
  207.     strcat    #msg    ,#spd        ; ......
  208.     cmpb    ttname    ,#'0        ; Is this using XC/XL/CLn?
  209.     blo    5$            ; No
  210.     cmpb    ttname    ,#'9        ; Well?
  211.     bhi    5$            ; No
  212.     call    domt            ; Switch modes then.
  213.     return                ; Exit
  214. 5$:    inc    xk            ; Flag device class
  215.     call    init            ; Startup
  216.     bcs    100$            ; Oops
  217.     call    ttinit            ; Save terminal characteristics
  218.     bcs    90$            ; Die
  219.                     ;
  220.  
  221. 10$:    tst    done            ; Time to go now ?
  222.     bne    90$            ; Yes, exit
  223.     mov    #ttbuff    ,r4        ; Pointer to local term buffer
  224.     inc    suspend            ; Count the number of suspends
  225.     .SPND                ; Suspend ourself
  226.     clr    idle            ; No longer idle
  227.     tst    sj.dec            ; Minimal SJ system?
  228.     beq    25$            ; No
  229.     mov    #sjlist    ,r5        ; Yes, No mark time so we will
  230. 20$:    tst    @r5            ; have to call all of the watchers
  231.     beq    25$            ; If zero, all done
  232.     jsr    pc    ,@(r5)+        ; Do it for Sj krud
  233.     br    20$            ; Check for more calls needed for SJ
  234. 25$:    mov    #tlist    ,r5        ; Find out who woke up
  235. 30$:    cmp    taskaddr(r5),#-1    ; End of the table now?
  236.     beq    50$            ; Yes, suspend again
  237.     tst    state(r5)        ; Runnable task ?
  238.     beq    40$            ; No
  239.     jsr    pc    ,@taskaddr(r5)    ; Yes, run the sucker.
  240. 40$:    add    #HDSIZE    ,r5        ; Next task control block please
  241.     br    30$            ; ...
  242. 50$:    br    10$            ; Go away until something happens
  243.  
  244. 90$:    .CMKT    #cancel,#0        ; Kill all marktime requests
  245.     call    ttrst            ; Restore terminal chars
  246.  
  247. 100$:    bic    #40000+10000+100,@#JSW    ; Clear special modes
  248.     .SCCA    #scca,#0        ; Enable control C stuff again
  249.     .CMKT    #cancel,#0        ; Kill all marktime requests
  250.     return
  251.  
  252.     .dsabl    lsb
  253.  
  254.     .sbttl    misc support routines
  255.     .enabl    lsb
  256.     .mcall    .scca
  257.  
  258.  
  259.     $TCFIG    =    424
  260.  
  261. ttinit:    clc                ; Basically a NO-OP
  262.     return                ; Exit
  263.  
  264. init:    tst    tsxsave            ; True TSX+ today?
  265.     beq    5$            ; No
  266.     .SERR                ; To be safe
  267.     mov    #tsxbrk    ,r0        ; Set break AST
  268.     EMT    375            ; Do it.
  269.     .HERR                ; Normal now
  270. 5$:    mov    #tlist    ,r0        ; Clear out task list
  271. 10$:    cmp    TASKAD(r0),#-1        ; All done with list
  272.     beq    20$            ; Yes
  273.     clr    STATE(r0)        ; No
  274.     clr    IODONE(r0)        ; ...
  275.     clr    IOPEND(r0)        ; ...
  276.     clr    IOSTALL(r0)        ; Stalled flag.
  277.     add    #HDSIZE    ,r0        ; Next please
  278.     br    10$            ; ...
  279. 20$:    clr    eseen            ; No escape seen
  280.     clr    crflag            ; No carriage returns yet
  281.     clr    idle            ;
  282.     clr    done            ; ...
  283.     clr    xkr1done        ; Clear out
  284.     clr    xkr2done        ; Ditto
  285.     clr    xkio            ; No remote I/O seen
  286.     clr    ttio            ; No local I/O seen
  287.     clr    ioseen            ; No I/O at all happened
  288.     clr    ttsdon            ; No terminal settings done yet
  289.     clr    xksdon            ; No terminal settings done yet
  290.     clr    charcount        ; Clear out data count
  291.     clr    charcount+2        ; All 32 bits of it please.
  292.     mov    #1    ,suspend    ; Suspension count
  293.     mov    #xkbuff    ,xkpoint    ; Current pointer into buffer.
  294.     .SCCA    #scca    ,#scca+4    ; Trap all control c's
  295.     calls    ttyset    ,<#ttname,#LUN.XK>
  296.     calls    ttyini    ,<#ttname,#LUN.XK,#0>
  297.     tst    r0            ; Successfull setup of port?
  298.     beq    25$            ; Yes, continue
  299.     jmp    90$            ; No, exit
  300.                     ;
  301. 25$:    .print    #msg            ; A header
  302.     message    <Unknown>,cr        ; ...
  303.     message    <Type your local escape sequence to return to RT11>,cr
  304.                     ;
  305.                     ; All done, prime the system.
  306.     .MRKT    #idmark,#idtime,#iddone,#11
  307.     .MRKT    #stsmark,#ststime,#stsdone,#7
  308.     .MRKT    #wtmark,#wttime,#wtdone,#10
  309.     .SPFUN    #stswork,#XC.CONTROL,#STSDRV,#xksts,#0,#1    
  310.     clr    rt.v51            ; Flag if 5.1 or 5.2 please
  311.     cmpb    xksts+1    ,#$XLV51    ; Is this a 5.1 system?
  312.     bne    30$            ; No, must be 5.2 or later.
  313.     inc    rt.v51            ; Yes, a serious bug in XL/XC
  314. 30$:                    ;
  315.     .SPFUN    #xkrd1,#LUN.XK,#203,#xkbuff,#xksize,#1,#xkdone
  316.     .MRKT    #ttmark,#ttwait,#ttdone,#3
  317.     clc                ; Successfull exit
  318.     br    100$            ; Exit
  319.                     ;
  320. 90$:    mov    r0    ,r1        ; Save error code
  321.     message    <Error from line initialization - >
  322.     direrr    r1
  323.     sec                ; Failure to initialize things
  324. 100$:    return                ; Exit INIT code
  325.  
  326.     .dsabl    lsb
  327.  
  328.  
  329.     .sbttl    Restore line settings, check options for SJ exec
  330.  
  331. ttrst:    .TWAIT    #twait,#short        ; Eat up extra .RSUM's ?
  332.     .TWAIT    #twait,#short        ; ...Ditto (one Tick)
  333.     .TWAIT    #twait,#short        ;    ...Ditto
  334.     .TWAIT    #twait,#short        ;       ...Ditto
  335.     calls    ttyfin    ,<#ttname,#LUN.XK>; Drop things and exit
  336.     calls    ttyrst    ,<#ttname,#LUN.XK>;
  337.     .SERR                ; To be safe
  338.     tst    tsxsave            ; TSX+
  339.     beq    100$            ; No
  340.     mov    #tsxnbrk,r0        ; Yes, turn break AST's off
  341.     EMT    375            ; Do it
  342. 100$:    .HERR                ; Restore
  343.     return                ; Bye
  344.  
  345.  
  346.     .enabl    lsb
  347.  
  348.     $CONFIG    =    300
  349.     $SYSGEN    =    372
  350.  
  351.     SJMON    =    1        ; RMON offset 300 (Config)
  352.     CLOCK    =    100000        ; RMON offset 300 (Config)
  353.     MRKTIM    =    2000        ; RMON offset 372 (Sysgen)
  354.  
  355.     .mcall    .GVAL
  356.  
  357.  
  358. check:    .GVAL    #xkwork,#$CONFIG    ; Get the configuration word
  359.     bit    #SJMON    ,r0        ; Is this a SJ monitor ?
  360.     bne    100$            ; No, just exit
  361.     bit    #CLOCK    ,r0        ; SJ, is there a clock present
  362.     bne    10$            ; Yes
  363.     message    <%Kermit-W  Kermit needs a line or programable CLOCK>,CR
  364. 10$:    .GVAL    #xkwork    ,#$SYSGEN    ; Check for MARK TIME support
  365.     bit    #MRKTIM    ,r0        ; Well?
  366.     bne    100$            ; Yes, support is present
  367.     message    <%Kermit-W  The SJ executive should have timer support>,CR
  368.     message    <sysgen'ed for the optimal operation of Kermit.>,CR
  369.     inc    sj.dec            ; Save the result
  370.     sec                ; Flag
  371.     return                ; Exit
  372. 100$:    clc                ; Success
  373.     return                ; Exit
  374.  
  375.  
  376.  
  377.  
  378.     .sbttl    reading from XK (XC/XL/CL) and TT:
  379.     .enabl    lsb
  380.  
  381. ttdone:    mov    r0    ,-(sp)        ; Save this
  382.     clr    tthead+state        ; Assume no data present
  383.     bis    #40000+10000+100+20,@#JSW; Enable special modes
  384.     .TTINR                ; Check for input waiting for term
  385.     bcs    90$            ; Nothing to do
  386.     bicb    #^C177    ,r0        ; Strip any parity bits please
  387.     tst    rt.v51            ; Is this RT11 5.1 and OLD XL/XC
  388.     bne    10$            ; Yes, kludge a bug in the handler
  389.     asr    crflag            ; See if a carriage return preceeds
  390.     bcc    5$            ; a line feed. Was last one a CR?
  391.     cmpb    r0    ,#12        ; Ignore LINE feeds Please
  392.     beq    90$            ; Exit on <LF>
  393. 5$:    cmpb    r0    ,#15        ; Is this one a carriage return?
  394.     bne    10$            ; No
  395.     inc    crflag            ; Yes, save for next time.
  396. 10$:    movb    r0    ,ttbuff        ; Insure we save this
  397.     SCHEDULE #TTHEAD        ; Get a process going to use data
  398.     tst    suspend            ; Fix up the .SPND count
  399.     beq    20$            ; ...
  400.     dec    suspend            ; ...
  401.     .RSUM                ; Get scheduler going
  402. 20$:    br    100$            ; Exit
  403.                     ;
  404. 90$:    .MRKT    #ttmark,#ttwait,#ttdone,#3
  405.                     ;
  406. 100$:    mov    (sp)+    ,r0        ; Restore this
  407.     return                ; Exit
  408.  
  409.  
  410.     .dsabl    lsb
  411.  
  412. ttproc:    clr    STATE(r5)        ; Don't come back right away
  413.     save    <r0,r1,r4>        ; Save registers we use
  414.     mov    #ttbuff    ,r4        ; Point to terminal buffer
  415.     movb    @r4    ,r0        ; Get the data please
  416.     cmpb    r0    ,conesc        ; Escape sequence today?
  417.     bne    50$            ; No, must dump character as is
  418.     mov    #10*60.    ,r1        ; Loop a while looking for data
  419. 10$:    bis    #40000+10000+100+20,@#JSW ; Enable special modes
  420.     .TTINR                ; Was the escape characters, trynext
  421.     bcc    30$            ; Got something valid
  422.     .TWAIT    #twait,#short        ; Nothing, wait a little bit
  423.     tst    sj.dec            ; Did we have timer support?
  424.     beq    20$            ; Yes
  425.     CPUWAIT    #1            ; No (really should boot FB up)
  426. 20$:    sob    r1    ,10$        ; Next please
  427.     br    100$            ; Exit as we did not get any data
  428. 30$:    bicb    #^C177    ,r0        ; Strip junk from the character
  429.     movb    r0    ,@r4        ; Insure we save this
  430.     cmpb    r0    ,conesc        ; Double escape sequence read?
  431.     beq    50$            ; Yes, dump that character as is
  432.     call    concmd            ; No, check for emulator command
  433.     br    100$            ;
  434. 50$:    tst    duplex            ; Need local echoing today?
  435.     beq    60$            ; No
  436.     .TTOUTR                ; Yes, echo the data please
  437. 60$:    setpar    (r4)    ,(r4)        ; Set parity up if needed
  438.     SCHEDULE #RMHEAD        ; Dump the data down the line
  439. 100$:    .MRKT    #ttmark,#ttwait,#ttdone,#3
  440.     unsave    <r4,r1,r0>        ; Pop and exit
  441.     return                ; Exit
  442.  
  443.  
  444.  
  445.  
  446. xkdone:    SCHEDULE #XKHEAD        ; Get things going when we exit
  447.     clr    xkhead+iopend        ; I/O is complete
  448.     mov    sp    ,xkhead+iodone    ; Say so.
  449.     mov    #xkbuff    ,xkpoint    ; Reset buffer pointer now.
  450.     tst    suspend            ; Fix up suspention count
  451.     beq    100$            ; No
  452.     dec    suspend            ; Yes, suspend--
  453.     .RSUM                ; Resume mainline
  454. 100$:    return                ; Thus XKPROC will get called
  455.  
  456.  
  457. xkredo:    SCHEDULE #XKHEAD        ; If we need to retry terminal output
  458.     tst    suspend            ; Fix up suspention count
  459.     beq    100$            ; No
  460.     dec    suspend            ; Yes, suspend--
  461.     .RSUM                ; Resume mainline
  462. 100$:    return                ; Thus XKPROC will get called
  463.  
  464.  
  465. xkproc:    mov    r0    ,-(sp)        ; Save please
  466.     mov    r1    ,-(sp)        ; Ditto
  467.     mov    r3    ,-(sp)        ; ....
  468.     mov    xkpoint    ,r1        ; Dump the buffer now
  469.     mov    sp    ,ioseen        ; Say we got some data
  470. 210$:    tstb    (r1)            ; All done yet?
  471.     beq    240$            ; Yes
  472.     movb    (r1)+    ,r0        ;
  473.     cmpb    parity    ,#PAR$NO    ; No parity?
  474.     bne    215$            ; No, clear high bit
  475.     tst    con8bit            ; SET CON 7/8 ?
  476.     bne    215$            ; No
  477.     bicb    #200    ,r0        ; Strip high bit now
  478. 215$:    .TTOUTR                ; No, dump the data
  479.     bcs    220$            ; If we fail, come back later
  480.     add    #1    ,charcount    ; Bump up the character count
  481.     adc    charcount+2        ; The high part also.
  482.     inc    xkpoint            ; Remember where we were at now.
  483.     br    210$            ; Next please
  484.                     ;
  485. 220$:    .MRKT    #xkmark,#xktime,#xkredo,#13 ; Output ring buffer is FULL.
  486.     inc    IOSTALL(r5)        ; Flag we are stalled.
  487.     clr    STATE(r5)        ; No longer runable please
  488.     br    250$            ; Exit
  489.                     ;
  490. 240$:    mov    #xkbuff    ,xkpoint    ; Reset the pointer now.
  491.     mov    #xkbuff    ,r3        ; Disk logging next
  492.     call    dumplog            ;
  493.     clr    STATE(r5)        ;
  494.     clr    IODONE(r5)        ; 
  495.     clr    IOSTALL(r5)        ;
  496.     mov    sp    ,IOPEND(r5)    ; ...
  497.     .TWAIT    #twait    ,#short        ; /56/
  498.     .SPFUN    #xkrd1,#LUN.XK,#203,#xkbuff,#xksize,#1,#xkdone
  499. 250$:    mov    (sp)+    ,r3        ; Pop r3
  500.     mov    (sp)+    ,r1        ; Pop r1
  501.     mov    (sp)+    ,r0        ; And R0 please
  502.     return                ; Exit
  503.  
  504.  
  505. rmproc:    mov    r0    ,-(sp)        ; Save
  506.     mov    r1    ,-(sp)        ; ...
  507.     tst    IOPENDING(r5)        ; Are we still waiting for XC/XL?
  508.     beq    30$            ; /56/ No
  509.     .CMKT    #cancel    ,#3        ; /56/ Disable terminal input checking
  510.     mov    #10.    ,r1        ; /56/ Wait a total of 10 ticks
  511. 10$:    tst    IOPENDING(r5)        ; /56/ Done YET?
  512.     beq    20$            ; /56/ Yes, at last
  513.     .TWAIT    #twait    ,#short        ; /56/ Wait a tick
  514.     sob    r1    ,10$        ; /56/ And go back and take a peek
  515. 20$:    .MRKT    #ttmark,#ttwait,#ttdone,#3 ; /56/ Reenable terminal checking
  516. 30$:    mov    IOBUFF(r5),r1        ; /56/ Pointer to I/O buffer
  517.     movb    @r1    ,rmbuff        ; Copy the data
  518.     clrb    rmbuff+1        ; Tack a NULL on the end.
  519.     mov    sp    ,IOPENDING(r5)    ; Flag that we are waiting here.
  520.     .MRKT    #rmwork,#rmtime,#300$,#5; Start timer to clear driver.
  521.     .WRITC    #xkwork,#LUN.XK,#rmbuff,#1,#200$,#1
  522. 100$:    mov    (sp)+    ,r1        ; Pop
  523.     mov    (sp)+    ,r0        ; ...
  524.     clr    STATE(r5)        ; Don't reschedule please.
  525.     return                ; Simple
  526.                     ;
  527.                     ; XC/XL WRITE completion.
  528. 200$:    clr    RMHEAD+IOPENDING    ; I/O no longer pending
  529.     .CMKT    #rmwork,#5        ; Stop the marktime for XOFFED
  530.     return                ; Ast completion is a NO-OP
  531.                     ;
  532.                     ; MARKTIME completion.
  533. 300$:    call    x.ttxon            ; Force a driver reset.
  534.     clr    RMHEAD+IOPENDING    ; Say we are ready for MORE data
  535.     return                ; Done.
  536.  
  537.  
  538.     .sbttl    Status watchers
  539.  
  540. stsdone:mov    r0    ,-(sp)        ; Save this (?)
  541.     SCHEDULE #STHEAD        ; Schedule the status checker
  542.     br    wtexit            ; Exit now
  543.  
  544. wtdone:    mov    r0    ,-(sp)        ; Save this (?)
  545.     SCHEDULE #WTHEAD        ; Schedule the xon/xoff checker
  546. wtexit:    tst    suspend            ; Fix the suspended count
  547.     beq    100$            ; No
  548.     dec    suspend            ; Yes, suspend--
  549.     .RSUM                ; Start scheduler now
  550. 100$:    mov    (sp)+    ,r0        ; Pop R0 and exit
  551.     return                ; Exit the ast now
  552.  
  553.  
  554.     .enabl    lsb
  555.  
  556. stproc:    save    <r0,r1,r2>        ; Save registers we may need
  557.     clr    STATE(r5)        ; No longer runnable
  558.     mov    xksts    ,r2        ; Save old status word
  559.     .SPFUN    #stswork,#XC.CONTROL,#STSDRV,#xksts,#0,#1
  560.     bcs    100$            ; Failed??
  561.     mov    xksts    ,r1        ; Get the current status
  562.     bic    #^C4    ,r2        ; Leave only the carrier detect
  563.     bic    #^C4    ,r1        ; bits on for the status
  564.     cmp    r1    ,r2        ; Are they the same?
  565.     beq    100$            ; Yes, then ignore
  566.     BEEP                ; Make a small noise
  567.     tst    r1            ; Not the same, did we loose it?
  568.     bne    10$            ; No, we must have just gotten it
  569.     message    <%Kermit-11 Carrier lost>,cr
  570.     br    100$            ; Exit
  571. 10$:    message    <%Kermit-11 Carrier detected>,cr
  572. 100$:    .MRKT    #stsmark,#ststime,#stsdone,#7 ; Reschedule us
  573.     unsave    <r2,r1,r0>        ; Pop registers and exit
  574.     return                ; Exit
  575.  
  576.     .dsabl    lsb
  577.  
  578.     .sbttl    Check for hung driver
  579.  
  580.     .enabl    lsb
  581.  
  582. wtproc:    save    <r0,r1,r2>        ; Save registers please
  583.     clr    STATE(r5)        ; No longer runnable
  584.     mov    wtsts    ,r2        ; Save old Status flags
  585.     .SPFUN    #stswork,#XC.CONTROL,#STSDRV,#wtsts,#0,#1
  586.     bcs    100$            ; It should ALWAYS work.
  587.     mov    wtsts    ,r1        ; Get new status
  588.     bic    #^C3    ,r2        ; Leave only XOFF'ed status
  589.     bic    #^C3    ,r1        ; Same for the current status word
  590.     tst    r1            ; See if XOFF'ed at either end
  591.     beq    100$            ; No, so just reschedule ourself
  592.     cmp    r2    ,r1        ; Same status as last time here?
  593.     bne    100$            ; No, just exit normally then.
  594.     mov    #tlist    ,r0        ; Ok, check for any i/o stalled.
  595. 10$:    cmp    TASKAD(r0),#-1        ; End of list so far ?
  596.     beq    20$            ; Yes, fix the line up
  597.     tst    IOSTALL(r0)        ; No, anybody stalled intentionally?
  598.     bne    100$            ; Yes, just reschedule ourself
  599.     add    #HDSIZE    ,r0        ; No, check next task out
  600.     br    10$            ; Next please
  601. 20$:                    ;
  602.     .SPFUN    #stswork,#XC.CONTROL,#CLRDRV,#0,#0,#1
  603. 100$:    .MRKT    #wtmark,#wttime,#wtdone,#10
  604.     mov    charcount,wtcount    ; Copy low 16 bits of char count.
  605.     unsave    <r2,r1,r0>        ; Pop registers 
  606.     return                ; Exit
  607.  
  608.     .dsabl    lsb
  609.  
  610.  
  611. iddone:    inc    idle            ; Has anything happended in a while?
  612.     cmp    idle    ,#3        ; Well?
  613.     ble    100$            ; No
  614.     clr    idle            ; Yes, force a .RSUM
  615.     clr    suspend            ; Clear suspended flag
  616.     .RSUM                ; Force mainline to run
  617. 100$:    .MRKT    #idmark,#idtime,#iddone,#11 ; Reshedule
  618.     return                ; And exit
  619.  
  620.  
  621.  
  622.  
  623.     .sbttl    Connect for RT11 Multiple terminal service ONLY
  624.  
  625. ;    Rewitten: 08-May-86  14:49:40  Brian Nelson
  626.  
  627.  
  628.     .save
  629.     .psect    mtdata    ,rw,d,lcl,rel,con
  630. chcount:.word    0
  631. needxon:.word    0
  632. mtbuff:    .word    0
  633. mttime:    .word    0,0
  634. mtwait:    .word    0,1
  635.     .restore
  636.     .enabl    lsb
  637.  
  638. domt:    clr    done            ; Not done yet, please.
  639.     mov    #10    ,chcount    ; Count down for rt11 to do an XOFF
  640.     .SCCA    #scca,#scca+4        ; No control C's please
  641.     clr    needxon            ; Don't need to send xon yet
  642.     calls    noecho    ,<#ttname>    ; Don't want echoing please
  643.     calls    ttyini    ,<#ttname,#LUN.XK,#0>
  644.     tst    r0            ; Did the initialization work ?
  645.     beq    1$            ; Yes
  646.     jmp    90$            ; No, exit
  647. 1$:    calls    ttyset    ,<#ttname>    ; Ok, set some useful things up
  648.     mov    #mtbuff    ,r3        ; A tiny one character buffer.
  649.     .print    #msg            ;
  650.     calls    ttspeed    ,<#ttname>    ; ......
  651.     tst    r0            ; This is getting tedious
  652.     bgt    5$            ; ...
  653.     message    <Unknown>,cr        ; 
  654.     br    6$            ; And so on
  655. 5$:    decout    r0            ; A REAL speed that RT11 knows about
  656.     message                ; CR/LF
  657. 6$:    message    <Type your local escape sequence to return to RT11>,cr
  658.     mov    r3    ,r4        ; Compatibility with XM code
  659.  
  660.  
  661.     .sbttl    Main loop for MT reading
  662.  
  663.  
  664.  
  665. 10$:    tst    done
  666.     bne    100$            ; Exit
  667.     calls    xbinrea    ,<#LUN.XK,#-1>    ; Try to get a charater from remote
  668.     tst    r0            ; Did the read succeed?
  669.     bne    20$            ; No, try console terminal then
  670.     clrpar    r1            ; Yes, drop any aprity bits please
  671.     clr    @r3            ; Insure .asciz string here.
  672.     bisb    r1    ,@r3        ; Yes, get the character and print
  673.     cmpb    r1    ,#'S&37        ; Xoff?
  674.     beq    15$            ; Yes, ignore
  675.     movb    r1    ,r0        ; Copy the data now.
  676.     .TTOUTR                ; Dump the character
  677. 15$:    call    dumplo            ; Dump to a log file perhaps
  678.     dec    chcount            ; Is it time to do a RT11 XOFF ?
  679.     bne    25$            ; No, wait a while then
  680.     mov    #2    ,needxon    ; Will need to send xon later
  681.     call    sxoff            ; Yes, send an xoff please
  682.     mov    #10    ,chcount    ; And reset the character counter
  683.     br    25$            ; And look for local terminal input
  684. 20$:    tst    needxon            ; Really send an xon today?
  685.     beq    25$            ; No
  686.     dec    needxon            ; Don't overdo sending xon's please
  687.     call    sxon            ; No data, send an xon please
  688.                     ;
  689. 25$:    bis    #40000+10000+100+20,@#JSW ; Insure special modes
  690.     .TTINR                ; Try to read something now
  691.     bcs    70$            ; No data, exit
  692.     movb    r0    ,@r3        ; yes, get it and send it to the
  693.     bic    #^C177    ,r0        ; insure no high bits are set.
  694.     cmpb    r0    ,#12        ; Ditch LINE FEEDS Please.
  695.     beq    25$            ; A Line Feed, next please?
  696.     cmpb    r0    ,conesc        ; other system unless it's the escape
  697.     bne    50$            ;
  698.     mov    #20*60    ,r1        ; Loop a bit for a read
  699. 30$:    bis    #40000+10000+100,@#JSW    ; Insure special modes
  700.     .TTINR                ; Try to read something now.
  701.     bcc    40$            ; Successfull read, exit
  702.     .TWAIT    #twait,#short        ; Wait a moment now.
  703.     sob    r1    ,30$        ; Try again
  704.     br    70$            ; Nothing, ignore please
  705. 40$:    bic    #^C177    ,r0        ; Insure no high bits are set.
  706.     cmpb    r0    ,#12        ; Ditch LINE FEEDS Please.
  707.     beq    30$            ; A Line Feed, next please?
  708.     movb    r0    ,@r3        ; Must save it here!
  709.     cmpb    r0    ,conesc        ; Really send the escape ?
  710.     beq    50$            ; Yes
  711.     call    concmd            ; Yes, do the command
  712.     br    70$            ; No, next please
  713.                     ;
  714. 50$:    setpar    @r3    ,@r3        ; Insure correct outgoing parity now
  715.     calls    binwri    ,<r3,#1,#LUN.XK>; The data is for the remote system
  716.     tst    duplex            ; Full or half duplex connection?
  717.     beq    70$            ; Full
  718.     movb    @r3    ,r0        ; Half duplex, echo the data now.
  719.     .TTOUTR                ; Simple to do.
  720. 70$:                    ;
  721. 80$:    br    10$            ; and back for more
  722.  
  723.         
  724. 90$:    direrr    r0            ; problems in getting the connection
  725.  
  726. 100$:    calls    ttyfin    ,<#ttname,#LUN.XK>
  727.     bic    #40000+10000+100,@#JSW    ; Get rid of special modes
  728.     .SCCA    #scca,#0        ; Get rid of control C trapping
  729.     return                ; And exit now.
  730.  
  731.     .dsabl    lsb
  732.  
  733.  
  734. sxon:    tst    conflow
  735.     beq    100$
  736.     calls    binwri    ,<#$xon,#1,#LUN.XK>
  737. 100$:    return
  738.  
  739. sxoff:    tst    conflow
  740.     beq    100$
  741.     calls    binwri    ,<#$xoff,#1,#LUN.XK>
  742. 100$:    return
  743.  
  744.  
  745.  
  746.  
  747.     .sbttl    concmd    terminal emulation escape commands
  748.     .enabl    lsb
  749.  
  750. concmd::mov    r1    ,-(sp)        ; Save it
  751.     movb    @r4    ,r1        ; Get the character to check
  752.     bicb    #^C177    ,r1        ; Must drop parity 
  753.     scan    r1    ,#200$        ; look for a match here
  754.     asl    r0            ; word offsets
  755.     jsr    pc    ,@210$(r0)    ; dispatch to the correct routine
  756. 100$:    mov    (sp)+    ,r1        ; Pop R1 and exit
  757.     return
  758.  
  759.  
  760.     .save
  761.     .psect    rwdata    ,rw,d,lcl,rel,con
  762.  
  763. 200$:    .byte    'C&137    ,'c!40        ; drop connection ctrl \ C
  764.     .byte    'I&137    ,'i!40        ; init the line
  765.     .byte    'Q&137    ,'q!40        ; quit logging but leave file open
  766.     .byte    'R&137    ,'r!40        ; resume logging if file is open
  767.     .byte    'X&137    ,'X!40        ; control Q and then thats all
  768.     .byte    'B&137    ,'b!40
  769.     .byte    '?    ,177        ; help, rub for send break
  770.     .byte    'H&137    ,'h!40
  771.     .byte    0
  772.     .even
  773.  
  774. 210$:    .word    con.$            ; unknown escape command
  775.     .word    con.c    ,con.c        ; drop connection
  776.     .word    con.i    ,con.i        ; get modems attention
  777.     .word    con.q    ,con.q        ; turn console logging off
  778.     .word    con.r    ,con.r        ; turn it back on please
  779.     .word    con.x    ,con.x        ; send XON
  780.     .word    con.br    ,con.br        ; break
  781.     .word    con.hl    ,con.br        ; print out commands
  782.     .word    con.hl    ,con.hl        ; help
  783.  
  784.     .restore            ; Pop code psect context
  785.     .dsabl    lsb            ; Turn off current symbol block
  786.  
  787.  
  788. con.$:    movb    $bel    ,r0
  789.     .TTOUTR                ; Beep a little
  790.     clc                ; commands. Say it is not fatal.
  791.     return                ; Bye
  792.  
  793.  
  794. con.c:    mov    sp    ,done        ; Exit connection
  795.     return                ; And return
  796.  
  797.  
  798. con.i:    calls    ttydtr    ,<#ttname>    ; try to force DTR up on the line
  799.     clc                ; And say it's NOT fatal
  800.     return                ; Exit
  801.  
  802.  
  803. con.q:    bic    #log$co    ,trace        ; turn off console logging
  804.     clc                ; Successfull
  805.     return                ; Exit
  806.  
  807.  
  808. con.r:    bit    #log$op    ,trace        ; if the file is open do it
  809.     beq    100$            ; no
  810.     bis    #log$co    ,trace        ; yes, enable this
  811. 100$:    clc                ; Success
  812.     return                ; Exit
  813.  
  814.  
  815.     .enabl    lsb
  816.  
  817. con.x:    tst    xk            ; MT or XC/XL/CL today?
  818.     beq    30$            ; MT service
  819.     .SPFUN    #200$,#XC.CONTROL,#CLRDRV,#0,#0,#1
  820.     mov    #tlist    ,r0        ; Ok, check for any i/o stalled.
  821. 10$:    cmp    TASKAD(r0),#-1        ; End of list so far ?
  822.     beq    20$            ; Yes, fix the line up
  823.     clr    IOSTALL(r0)        ; Clear task stalled flags
  824.     add    #HDSIZE    ,r0        ; No, check next task out
  825.     br    10$            ; Next please
  826. 20$:    .WRITC    #200$,#LUN.XK,#$xon,#1,#190$,#1
  827.     br    100$            ; Exit
  828. 30$:    calls    ttxon    ,<#ttname>    ; and try to clear our xoffed state
  829. 100$:    clc                ; Success
  830.     return                ; Exit
  831.  
  832. 190$:    return                ; AST write completion
  833.  
  834.     .save
  835.     .psect    rwdata    ,d,lcl
  836. 200$:    .word    0,0,0,0,0,0,0
  837.     .restore
  838.     .dsabl    lsb
  839.  
  840. brkast:    call    con.br
  841.     mov    #tsxbrk    ,r0
  842.     EMT    375
  843.     return
  844.  
  845. con.br:    calls    senbrk    ,<#ttname,#lun.ti>
  846.     clc
  847.     return
  848.  
  849.  
  850.  
  851. con.hl::.print    #hlptxt
  852.     clc
  853.     return
  854.  
  855.     .save
  856.     .psect    rwdata    ,rw,d,lcl,rel,con
  857. hlptxt:    .ascii    /B    Try to send a  break to the  remote/<cr><lf>
  858.     .ascii    /C    Connect back to the local Kermit-11/<cr><lf>
  859.     .ascii    /I    Drop  and raise DTR (for RSTS only)/<cr><lf>
  860.     .ascii    /Q    Quit console logging.   See SET LOG/<cr><lf>
  861.     .ascii    /R    Resume console logging. See SET LOG/<cr><lf>
  862.     .ascii    /X    Send XON and cancel any active XONs/<cr><lf>
  863.     .asciz    /RUBOUT    Try to fake a break to the remote/<cr><lf>
  864.     .ascii    /?    Print this message/<cr><lf>
  865.     .byte    0
  866.     .even
  867.     .restore
  868.  
  869.  
  870.  
  871.  
  872.     .sbttl    dump i/o to a log file ?
  873.  
  874.  
  875. ;    Passed:    r3    buffer address
  876.  
  877.  
  878. dumplo:    bit    #LOG$CO    ,trace        ; Is this enabled ?
  879.     beq    100$            ; No
  880.     bit    #LOG$OP    ,trace        ; Is it open
  881.     beq    100$            ; No
  882.     save    <r0,r1,r2,r3>        ; Save work registers
  883.     strlen    r3            ; Get size
  884.     mov    r0    ,r2        ; Copy size
  885.     beq    90$            ; Nothing to do ?
  886. 10$:    clrb    r0            ; Avoid sign extension
  887.     bisb    (r3)+    ,r0        ; Get the next character
  888.     mov    #LUN.LO    ,r1        ; Unit number
  889.     call    putcr0            ; Thats it folks
  890.     sob    r2    ,10$        ; Next please
  891. 90$:    unsave    <r3,r2,r1,r0>        ; Pop registers and exit
  892. 100$:    clc                ; May as well say it worked
  893.     return                ; Bye
  894.  
  895.  
  896.  
  897.     .save
  898.     .psect    rwdata
  899. $xon:    .byte    'Q&37,0
  900. $xoff:    .byte    'S&37,0
  901. $bel:    .byte    'G&37,0
  902.     .even
  903.     .restore
  904.  
  905.  
  906.     .end
  907.