home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / b / krtxl.mac < prev    next >
Text File  |  2020-01-01  |  21KB  |  680 lines

  1.     .title    KRTXL    I/O for CL/KM/XC/XL handlers
  2.     .ident    "V03.63"
  3.  
  4. ; /63/    27-Sep-97  Billy Youdelman  V03.63
  5.  
  6. ; /62/    27-Jul-93  Billy Youdelman  V03.62
  7. ;
  8. ;    corrected suggested XL BUFSIZ to 256.
  9. ;    keep XL open even for XM, to accommodate RT-11 V5.6
  10. ;    add support for KM handler
  11. ;    add version testing to support RT-11 V4
  12. ;    add DCDTST for status during file transfers
  13. ;    skip .ABTIO for XC/XL under ALL RT-11 V5.6 monitors
  14. ;    to avoid hang/race/?
  15.  
  16. ; /BBS/     1-Dec-91  Billy Youdelman  V03.61
  17. ;
  18. ;    DTR drop sped up to a 0.5 second interval..
  19. ;    dumped waitti as multiple byte reads accomplish the same thing
  20. ;    CLHOSE defined for use in clearing CL handler, uses spfun 265
  21. ;    CLSTAT defined and inqdtr added, for CL lines only..
  22. ;    enhanced set$speed error handling
  23. ;    mapxl now allocates the handler under TSX
  24. ;    added inqcd
  25. ;
  26. ;    mapxl now uses .cstat to get physical name from logical name
  27. ;    one may ASS CL0 PHN then run Kermit and SET LINE PHN within it
  28. ;
  29. ;    dropped TSX hi-eff term mode when data are going thru a handler
  30. ;    allowing use of ^A and etc during transfers under TSX
  31. ;
  32. ;    allow LFOUT operation of CL handler.  under TSX return is made
  33. ;    an activation character, thus no LF is appended..
  34.  
  35. ;    13-Oct-84  11:02:39  Brian Nelson
  36. ;
  37. ;    6-May-85             Basically had to add in checks for XL and TSX
  38. ;                            and then roll in some of the code from k11tsx
  39. ;                            in order to properly use the CL lines under
  40. ;                            TSX.  (Ned W. Rhodes)
  41. ;    04-Nov-85  13:59:39  Mods suggested by Chuck Sadoian for TSX (BDN)
  42. ;    31-Dec-85  04:25:02  Added DTR control for RT-11 5.2 and XC/XL
  43. ;    02-Sep-86  09:31:48  Fix SET SPEED for TSX+, edit /54/
  44.  
  45. ;    Copyright 1984,1985 Change Software, Inc.
  46.  
  47.  
  48. ;                  NOTICE: !!!!!!
  49. ;
  50. ;   To operate properly at high speeds (2400 and up) and with Kermits
  51. ;   not supporting XOFF flow control the XL or XC device handler MUST
  52. ;   be modified to increase the internal buffer size and repress XOFF
  53. ;   transmission within a packet.  This is very easy to do.
  54. ;
  55. ;   First copy XM.MAC, XL.MAC, XM.ANS, SYSGEN.COM and for the PRO/300
  56. ;   XC.MAC from the RT-11 distribution to DK, ASSIGN DK SRC, and then
  57. ;   in the copy of the file XL.MAC change the line:
  58. ;
  59. ;    from:    BUFSIZ    = 64.
  60. ;    to:    BUFSIZ    = 256.
  61. ;
  62. ;   Then IND SYSGEN and tell it to use the saved answer file XM.ANS.
  63. ;   When SYSGEN exits, it  will  have created, among other things, a
  64. ;   file called XM.CND which is needed for the driver assembly.  For
  65. ;   the PRO/300 series substitute XC for XL in the following command
  66. ;   procedure to build the handler:
  67. ;
  68. ;    .COPY SY:XLX.SYS SY:XLX.OLD        ! save a copy
  69. ;    .REN/NOPRO SY:XLX.SYS SY:XLX.SYS    ! unprotect file
  70. ;    .UNLOAD XL                ! unload handler
  71. ;    .REMOVE XL                ! and remove it
  72. ;    .MACRO/OBJ:XLX (XM,XM.CND,XL)        ! assemble new
  73. ;    .LINK/EXE:SY:XLX.SYS XLX        ! RT V4, handler on SY
  74. ;    .LINK/NOBIT/EXE:SY:XLX.SYS XLX        ! if RT V5, do this
  75. ;    .INSTALL XL                ! install it and
  76. ;    .LOAD XL                ! load into memory
  77.  
  78.  
  79.     .include "IN:KRTMAC.MAC"
  80.     .iif ndf  KRTINC  .error    <; .include for IN:KRTMAC.MAC failed>
  81.  
  82.  
  83. ; /62/    .ABTIO bypassed for V4, also expanded to allow assembly under same
  84.  
  85.     .mcall    .CLOSE    ,.CSTAT    ,.GVAL    ,.LOOKUP,.MRKT
  86.     .mcall    .PURGE    ,.SPFUN    ,.TWAIT    ,.WRITC
  87.  
  88.  
  89.     .sbttl    Global and local data
  90.  
  91.     .psect    xcdata    ,rw,d,gbl,rel,con
  92. alloc:    .byte    0 ,156            ; /BBS/ allocate a device emt args
  93.     .word    dblk            ; /BBS/ device name goes here
  94. xcsts::    .word    0            ; /62/ saved from stsdrv
  95. xcwork:    .word    0 ,0 ,0 ,0 ,0 ,0    ; for async calls to the handler
  96. xcwrite:.word    0            ; if <> write is in progress
  97.  
  98.     .psect    xcrw    ,rw,d,lcl,rel,con
  99. getspd:    .word    0            ; /62/ buffer speed until confirmed ok
  100. rdmode:    .word    0            ; read mode "XON if no data" flag..
  101. setpri:    .byte    0 ,150            ; /BBS/ TSX set priority emt
  102.     .word    0            ; /BBS/ raise to this for CL handler
  103.  
  104.     .psect    $pdata
  105. third:    .word    0 ,20.            ; wait 1/3 second
  106. wait:    .word    0 ,1            ; wait one tick (1/60 second)
  107. r50tbl:    .asciz  " ABCDEFGHIJKLMNOPQRSTUVWXYZ   0123456789" ; /62/ device only
  108. xl.01:    .asciz    "%"<bell>"KRTXL-W-Carrier " ;^^a space'll never get this far..
  109. xl.02:    .asciz    "lost"
  110. xl.03:    .asciz    "detected"
  111.     .even
  112.  
  113.  
  114.     .sbttl    List of supported comm handlers
  115.  
  116. dev.ok:    .rad50    "CL "        ; use rad50 space, not zero
  117.     .rad50    "CL1"
  118.     .rad50    "CL2"
  119.     .rad50    "CL3"
  120.     .rad50    "CL4"
  121.     .rad50    "CL5"        ; test to set tsxcl flag above requires
  122.     .rad50    "CL6"        ; the first 8 here to be the CL lines!!
  123.     .rad50    "CL7"        ; add handlers below this line only
  124.     .rad50    "KM "        ; /62/
  125.     .rad50    "XC "
  126.     .rad50    "XL "
  127.     .word    0
  128.  
  129.  
  130.     .sbttl    CL handler options    ; /37/
  131.  
  132. ;    0    1    send \014 <FF>        10     400  send \015 <CR>
  133. ;    1    2    send \011 <HT>        11    1000  send CTL chars
  134. ;    2    4    send lower case        12    2000  raise DTR
  135. ;    3   10    send \012 <LF>        13    4000  accept/send 8-bit chars
  136. ;    4   20    accept \012 <LF>    14   10000  undefined
  137. ;    5   40    FF on block 0 write    15   20000      "
  138. ;    6  100    send binary output    16   40000      "
  139. ;    7  200    accept binary input    17  100000      "
  140.  
  141. cl.set:    .word    1!2!4!10!20!400!1000!2000!4000    ; /62/ spell out options
  142. cl.clr:    .word    40!100!200            ; /62/ NOLFOUT dropped
  143.  
  144.  
  145.     .sbttl    Map speed to set same (50 baud is unsupported here)
  146.  
  147. splst:    .word    75.    ,110.    ,134.    ,150.    ,300.    ,600.    ; /44/
  148.     .word    1200.    ,1800.    ,2000.    ,2400.    ,3600.    ,4800.    ; /44/
  149.     .word    7200.    ,9600.    ,19200.    ,38400.    ,0        ; /62/
  150.  
  151. spmap:    .word    1    ,2    ,3    ,4    ,5    ,6    ; /44/
  152.     .word    7    ,10    ,11    ,12    ,13    ,14    ; /44/
  153.     .word    15    ,16    ,17    ,20            ; /62/
  154.  
  155.  
  156.     .sbttl    SPFUN codes for the CL/KM/XC/XL drivers
  157.  
  158.     CLCLR    =    257        ; /37/ reset w/o dropping DTR
  159.     CLHOSE    =    265        ; /BBS/ better reset for TSX V6.0 + up
  160.     CLRDRV    =    201        ; undo XOFF, send an XON
  161.     CLRSET    =    251        ; reset CL options for TSX-Plus
  162.     CLSET    =    250        ; set CL options for TSX-Plus
  163.     CLSPEED    =    256        ; /44/ speed control
  164.     CLSTAT    ==    255        ; /BBS/ CL modem status
  165.     DTRDRV    =    206        ; RT-11 V5.2 + up, set/clear DTR
  166.     STSDRV    =    204        ; low byte status, high byte version
  167.  
  168.     XC.CONTROL ==    14        ; control channel for the driver
  169.  
  170.  
  171.     .psect    $code
  172.     .sbttl    Assign a handler as the link ; /BBS/ substantially changed..
  173.  
  174. x.assdev::save    <r2,r1>            ; mods to stop ANY bad name
  175.     mov    @r5    ,r1        ; address of the device name
  176.     strlen    r1            ; how long is it?
  177.     cmp    r0    ,#4        ; 4 is max
  178.     bgt    20$            ; too much
  179.     mov    r0    ,r2        ; copy of length for testing string
  180.     dec    r2            ; ignore colon at end
  181. 10$:    scan    (r1)+    ,#r50tbl    ; verify each char is ok
  182.     tst    r0            ; this prevents "XX::" & etc..
  183.     beq    20$            ; found a bad one..
  184.     sob    r2    ,10$        ; check next char
  185.     mov    @r5    ,r1        ; restore address
  186.     br    30$
  187.  
  188. 20$:    mov    #er$ukn    ,r0        ; unknown name
  189.     sec                ; flag error
  190.     br    90$
  191.  
  192. 30$:    call    mapxl            ; do we know about this dev?
  193.     bcs    90$            ; no, return error in r0
  194.  
  195.     tst    xl.lock            ; /62/ need to open?
  196.     bmi    40$            ; /62/ no
  197.     .lookup    #rtwork,#lun.xk,#r50dev    ; /62/ try to open the port up please
  198.     bcs    70$            ; /62/ oops
  199.     .lookup    #rtwork,#xc.control,#r50dev ; /62/ also open a control channel
  200.     bcs    70$            ; /62/ should never happen, of course
  201.     tst    xl.lock            ; /62/ locking it up?
  202.     beq    40$            ; /62/ no
  203.     com    xl.lock            ; /62/ ya, flag channels are now open
  204.     .spfun    #rtwork,#xc.control,#stsdrv,#xcsts,#0,#0 ; /62/ init queues
  205.  
  206. 40$:    tst    tsxcl            ; is it TSX and CL handler?
  207.     beq    50$            ; /62/ no, can't do this to XL
  208.     .spfun    #rtwork,#xc.control,#clset ,#cl.set,#1,#0 ; /62/ set some opts
  209.     .spfun    #rtwork,#xc.control,#clrset,#cl.clr,#1,#1 ; /62/ reset others
  210.     br    60$            ; /62/
  211. 50$:    tst    km.lock            ; /62/
  212.     bne    60$            ; /62/ KM is an 8-bit device
  213.     movb    #par$sp    ,parity        ; XL is a 7-bit handler
  214. 60$:    clr    tt$io            ; /62/ force I/O thru handler
  215.     call    x.cantyp        ; /62/ flush driver and its buffer
  216.     clr    r0            ; /62/ success
  217.     br    90$
  218.  
  219. 70$:    mov    #xcierr    ,r1        ; /62/ preset error mapping
  220.     movb    @#errbyt,r0        ; /62/ get RT-11's error code
  221.     bpl    80$            ; /62/ normal error
  222.     com    r0            ; /62/ hard error code
  223.     mov    #faterr    ,r1        ; /62/ map into the hard errors
  224. 80$:    asl    r0            ; /62/ word addressing
  225.     add    r0    ,r1        ; /62/ map the error
  226.     .purge    #xc.control        ; /62/ don't leave
  227.     .purge    #lun.xk            ; /62/ these lingering
  228.     mov    @r1    ,r0        ; /62/ restore pre-purge error
  229.  
  230. 90$:    unsave    <r1,r2>
  231.     return
  232.  
  233.  
  234.     .sbttl    Init the handler    ; /BBS/ enhanced..
  235.  
  236. ;    T T Y I N I
  237. ;
  238. ;    input:      (r5)    = TSX ^W/^B flag, only used by T.TTYINI
  239. ;    output:       r0    = is <>, error code
  240.  
  241. x.ttyini::tst    tsxsav            ; running under TSX?
  242.     beq    10$            ; /62/ no
  243.     mov    cl.pri    ,setpri+2    ; ya, load priority for using handler
  244.     mov    #setpri    ,r0        ; and bump it up,
  245.     emt    375            ; down or reload the default..
  246. 10$:    call    x.inqcd            ; carrier present?
  247.     tst    r0
  248.     bgt    20$            ; ya, don't flush buffer now
  249.     call    x.cantyp        ; no, flush driver and its buffer
  250. 20$:    mov    #2    ,cc$max        ; make ^C-ing give warning beeps first
  251.     clr    r0            ; all is well today
  252.     return
  253.  
  254.  
  255.     .sbttl    Check device by getting its physical name
  256.  
  257. mapxl:    save    <r1,r2,r3>        ; /BBS/ heavily hacked..
  258.     sub    #50    ,sp        ; /44/ allocate a buffer for new name
  259.     mov    sp    ,r2        ; /44/ and also a pointer to it
  260. 10$:    cmpb    (r1)    ,#':        ; /44/ while (*devnam != ':')
  261.     beq    20$            ; /44/   {
  262.     movb    (r1)    ,(r2)+        ; /44    *newnam++ = *devnam
  263.     beq    20$            ; /44/   if (*devnam == null) break
  264.     inc    r1            ; /44/   devnam++
  265.     br    10$            ; /44/   }
  266. 20$:    clrb    (r2)            ; /44/ *newnam = null
  267.     mov    sp    ,r2        ; /44/ newnam = newnam_base_address
  268.  
  269.     call    140$            ; get first rad50 char of name
  270.     mul    #50*50    ,r3        ; convert to rad50 value
  271.     mov    r3    ,r0        ; r0 is the accumulator
  272.     call    140$            ; get next rad50 char in name
  273.     mul    #50    ,r3        ; convert to rad50 value
  274.     beq    30$            ; null marks end, don't do junk after
  275.     add    r3    ,r0        ; add into the accumulator
  276.     call    140$            ; get possible third char of name
  277.     add    r3    ,r0        ; r0 now has rad50 name
  278. 30$:    mov    r0    ,dblk        ; save it here
  279.  
  280.     calls    fetch    ,<dblk>        ; load handler
  281.     tst    r0            ; did it work?
  282.     bne    120$            ; no
  283.  
  284.     .lookup    #rtwork,#lun.sr,#dblk    ; open chan to device
  285.     bcs    110$            ; didn't work..
  286.     .cstat    #rtwork,#lun.sr,#cstat    ; get physical name
  287.     bcs    110$            ; didn't work..
  288.     mov    cstat+12,r1        ; copy dev name
  289.     movb    cstat+10,r0        ; get unit number
  290.     beq    40$            ; if 0, use space, not "0"
  291.     add    #36    ,r0        ; convert to rad50
  292. 40$:    add    r0    ,r1        ; add unit
  293.     mov    r1    ,dblk        ; save copy of the rad50 physical name
  294.  
  295.     clr    r3            ; init index
  296. 50$:    tst    dev.ok(r3)        ; end of the list?
  297.     beq    100$            ; ya, exit with er$ukn
  298.     cmp    r1    ,dev.ok(r3)    ; find it in the list?
  299.     beq    60$            ; ya
  300.     tst    (r3)+            ; no, try next entry
  301.     br    50$
  302.  
  303. 60$:    clr    tsxcl            ; ok device, not sure it's CL yet tho
  304.     clr    xkspeed            ; don't know its speed yet
  305.     clr    b4speed            ; clear possible old fallback speed
  306.     call    170$            ; see if device is ALLOCATE-able
  307.     tst    r0            ; well?
  308.     bne    120$            ; nope, error is in r0
  309.     cmp    r3    ,#2*10        ; /62/ ya, is it a CL device?
  310.     bgt    80$            ; /62/ it's XC or XL
  311.     beq    70$            ; /62/ it's KM
  312.     mov    sp    ,tsxcl        ; ya, flag it is
  313.     mov    #16    ,xkspeed    ; CL defaults to 9600
  314.     br    90$
  315.  
  316. 70$:    inc    km.lock            ; /62/ it's KM, flag for set$speed
  317.     clr    parity            ; /62/ KM is an 8-bit device
  318. 80$:    inc    xl.lock            ; /62/ keep it, XC or XL open forever
  319.  
  320. 90$:    mov    r1    ,r50dev        ; if r50dev <> 0 then device is valid
  321.     add    #50    ,sp        ; pop local buffer
  322.     clr    r0            ; no error, also clears carry
  323.     br    130$
  324.  
  325. 100$:    mov    #er$ukn    ,r0        ; not in list
  326.     br    120$
  327. 110$:    mov    #er$dev    ,r0        ; device not responding
  328. 120$:    add    #50    ,sp        ; pop local buffer
  329.     sec                ; flag error
  330. 130$:    save    <r0>            ; save error
  331.     rol    -(sp)            ; save carry
  332.     .purge    #lun.sr            ; dump channel open for .cstat
  333.     ror    (sp)+            ; pop carry
  334.     unsave    <r0>            ; pop error
  335.     unsave    <r3,r2,r1>
  336.     return
  337.  
  338.  
  339.     .sbttl    Rad50 to ascii (legal device name chars only)
  340.  
  341. 140$:    clr    r3            ; the answer
  342.     movb    (r2)+    ,r1        ; get a byte
  343.     beq    160$            ; not there
  344.     mov    #47    ,r3        ; end of r50tbl
  345. 150$:    cmpb    r50tbl(r3),r1        ; is this it?
  346.     beq    160$            ; ya
  347.     sob    r3    ,150$        ; no, try next one
  348. 160$:    return
  349.  
  350.  
  351.     .sbttl    ALLOCATE a device
  352.  
  353. 170$:    tst    tsxsav            ; this only works with TSX
  354.     beq    180$            ; can't under RT-11
  355.     mov    #alloc    ,r0        ; try to
  356.     emt    375            ; allocate the device
  357.     bcs    200$            ; didn't work
  358.     tst    r0            ; allocated to some other job?
  359.     beq    220$            ; no, it's ok
  360.     cmp    r0    ,tsxsav        ; ya, is it this same job?
  361.     bne    190$            ; no, it's some other job
  362. 180$:    clr    r0            ; same job = no error
  363.     br    220$
  364.  
  365. 190$:    movb    #er$137    ,r0        ; no, load the appropriate error
  366.     br    220$            ; and bail out
  367.  
  368. 200$:    mov    #alloerr,r1        ; error mapping for allocate
  369.     movb    @#errbyt,r0        ; get the error code
  370.     bpl    210$            ; normal error
  371.     com    r0            ; hard error code
  372.     mov    #faterr    ,r1        ; map into the hard errors
  373. 210$:    asl    r0            ; word addressing
  374.     add    r0    ,r1        ; get the mapped error
  375.     mov    (r1)    ,r0        ; copy and exit
  376. 220$:    return
  377.  
  378.  
  379.     .sbttl    Close the link        ; /BBS/ many changes..
  380.  
  381. x.ttyfin::.twait #rtwork,#wait        ; force at least 1 tick wait
  382.     tst    cccnt            ; ^C abort?
  383.     beq    10$            ; no
  384.     clr    xcwrite            ; ya, ignore any pending output
  385. 10$:    tst    xcwrite            ; ensure ack for B packet done
  386.     bne    x.ttyfin        ; it's not done yet
  387.     call    x.inqcd            ; carrier present?
  388.     tst    r0
  389.     bgt    20$            ; ya, don't flush buffer now
  390.     call    x.cantyp        ; flush driver and its buffer
  391. 20$:    tst    tsxsav            ; running under TSX?
  392.     beq    30$            ; no
  393.     mov    defpri    ,setpri+2    ; ya, recover start-up priority
  394.     mov    #setpri    ,r0        ; and use it to
  395.     emt    375            ; reset current priority
  396. 30$:    clr    r0            ; no error is possible
  397.     return
  398.  
  399.  
  400.     .sbttl    Binary read
  401.  
  402. ;    B I N R E A
  403. ;
  404. ;    input:      (r5)    = time-out in secs, 0=max (65535 ticks), -1=one tick
  405. ;    output:    r1    = character just read
  406. ;           r0    = if <>, error code
  407.  
  408. ; /BBS/ The -1 time-out option's now used to speed up eatjunk in
  409. ;    KRTDIA.MAC's dial/redial routines.   This routine _MUST_
  410. ;    share spfun 203 with CONNECT as a pending read to XL can
  411. ;    only be dumped by exiting Kermit.
  412. ;
  413. ;    For the normal Kermit timed packet read, we post the QIO
  414. ;    and loop waiting for it to complete.  If it doesn't com-
  415. ;    plete  within the specified time, we cancel  the I/O and
  416. ;    reset the driver, except for the -1 time-out option when
  417. ;    no action is taken if no data are present.
  418.  
  419. x.xbin::mov    sp    ,rdmode        ; don't XON if no data present
  420.     br    rdcom
  421. x.binr::clr    rdmode            ; try to reset XOFF if no data show up
  422.  
  423. rdcom:    save    <r2,r3>
  424.     cmp    xkpoint    ,#xkbuff+xksize    ; ensure no buffer overflows
  425.     bhis    10$            ; gone too far, driver is %$#@!
  426.     tstb    @xkpoint        ; anything left in the read buffer?
  427.     bne    20$            ; ya
  428. 10$:    call    xxread            ; load buffer with as much as can be..
  429.     tst    r0            ; did this read succeed?
  430.     bne    30$            ; no
  431. 20$:    clr    r1            ; avoid sxt
  432.     bisb    @xkpoint,r1        ; to accommodate 8-bit data
  433.     inc    xkpoint            ; point to the next one in the buffer
  434.     clr    r0            ; say it succeeded
  435. 30$:    unsave    <r3,r2>
  436.     return
  437.  
  438. xxread:    mov    (r5)    ,r3        ; time-out in seconds here
  439.     cmp    r3    ,#-1        ; no wait?
  440.     beq    10$            ; yes
  441.     mul    clkflg    ,r3        ; no, convert time to ticks then
  442.     br    20$            ; and check on the I/O status
  443. 10$:    neg    r3            ; /62/ no wait is really one tick
  444. 20$:    call    readxk            ; read routine is shared with CONNECT
  445. 30$:    tst    xcdone            ; finished already?
  446.     bne    50$            ; /62/ no
  447. 40$:    clr    r0            ; /62/ ya, flag no error
  448.     br    70$
  449. 50$:    .twait    #rtwork,#wait        ; no, sleep for one tick
  450.     sob    r3    ,30$        ; and see if we should keep waiting
  451.     tst    xcdone            ; /62/ one last check just in case..
  452.     beq    40$            ; /62/ got something
  453.     inc    (r5)            ; /62/ don't XON
  454.     beq    60$            ; if looping without timeout
  455.     tst    rdmode            ; /45/ from CONNECT, DIAL or TRANSMIT?
  456.     bne    60$            ; /45/ yes, please don't XON then
  457.     call    x.ttxon            ; ensure interrupts ok, also send XON
  458. 60$:    mov    #er$nin    ,r0        ; no data have come in yet
  459. 70$:    return
  460.  
  461.  
  462.     .sbttl    Binary write
  463.  
  464. ;    B I N W R I
  465. ;
  466. ;    output:      r0    = if <>, error code
  467.  
  468. x.binwri::save    <r1,r2,r3,r4>
  469.     mov    2(r5)    ,r4        ; byte count for the write
  470.     beq    20$            ; /BBS/ no I/O to do..
  471.     mov    (r5)    ,r3        ; copy the data to a local buffer
  472.     mov    xklgbuf    ,r2        ; pick up pointer to a buffer
  473.     mov    r4    ,r1        ; set byte count for the copy
  474. 10$:    movb    (r3)+    ,(r2)+        ; for (i=bytecount;i>0;i--)
  475.     sob    r4    ,10$        ;   *buffer++ = *source++
  476.     clrb    (r2)+            ; *buffer++ = null
  477.     inc    r1            ; bytecount++
  478.     asr    r1            ; bytecount = bytecount/2
  479.     mov    sp    ,xcwrite    ; /BBS/ write is now pending
  480.     .writc    #xcwork,#lun.xk,xklgbuf,r1,#30$,#1 ; queue the write
  481. 20$:    clr    r0            ; success (this is never tested..)
  482.     unsave    <r4,r3,r2,r1>
  483.     return
  484.  
  485. 30$:    clr    xcwrite            ; /BBS/ .writc completion routine
  486.     return
  487.  
  488.  
  489.     .sbttl    Dump all I/O (cancel type_ahead), if possible
  490.  
  491. x.cantyp::save    <r1,r2>
  492.     cmp    rt11ver    ,#5        ; /62/ is this RT-11 V5 or above?
  493.     blt    20$            ; /62/ no, V4 can't abort I/O..
  494.     cmp    rt11upd    ,#6        ; /62/ neither can V5.6
  495.     blt    10$            ; /62/
  496.     tst    km.lock            ; /62/ determine handler type
  497.     bne    10$            ; /62/ it's KM
  498.     tst    tsxcl            ; /62/ is it CL?
  499.     beq    20$            ; /62/ not CL, thus must be XC/XL..
  500. 10$:    tst    montyp            ; /62/ if SJ monitor
  501.     blt    20$            ; /62/ .abtio = .wait so skip it !!
  502. ; /62/    .abtio    #lun.xk            ; reinit the driver
  503.     MOV    #lun.xk+<11.*^o400>,R0    ; /62/ expanded for assy under V4
  504.     EMT    ^o374            ; /62/ even though V4 can't run it
  505. 20$:    call    x.ttxon            ; /BBS/ make sure it's read-able
  506.     mov    #$allsiz,r2        ; /BBS/ loop for max possible
  507. 30$:    calls    binrea    ,<#-1>        ; try to get something
  508.     tst    r0            ; did it work?
  509.     bne    40$            ; no, exit
  510.     sob    r2    ,30$        ; yes, eat some more characters
  511. 40$:    mov    #xkbuff    ,xkpoint    ; /BBS/ reset buffer read pointer
  512.     clrb    xkbuff            ; init buffer
  513.     unsave    <r2,r1>
  514.     clr    r0            ; flag success
  515.     return
  516.  
  517.  
  518.     .sbttl    Hose the handler    ; /BBS/ routine added
  519.  
  520. x.hose::save    <r1>            ; /62/ add KM support
  521.     tst    km.lock            ; /62/ KM?
  522.     bne    10$            ; /62/ ya, it emulates spfun 257
  523.     tst    tsxcl            ; TSX and CL?
  524.     beq    30$            ; /62/ no
  525.     mov    #clhose    ,r1        ; /62/ preset for TSX V6.0 and up
  526.     cmp    tsxver    ,#600.        ; is it V6.00 or above?
  527.     bge    20$            ; /62/ ya
  528. 10$:    mov    #clclr    ,r1        ; /62/ no, do it the old way..
  529. 20$:    .spfun    #rtwork,#xc.control,r1,#0,#0,#1 ; /62/ hose CL handler
  530. 30$:    call    x.cantyp        ; /62/ hose XL or XC
  531.     .twait    #rtwork,#third        ; let things settle
  532.     unsave    <r1>            ; /62/
  533.     clr    r0            ; no error possible
  534.     return
  535.  
  536.  
  537.     .sbttl XON the handler
  538.  
  539. x.ttxon::.spfun    #rtwork,#xc.control,#clrdrv,#0,#0,#1 ; clear the driver
  540.     clr    r0            ; flag success
  541.     return
  542.  
  543.  
  544.     .sbttl    Drop DTR for 0.5 sec
  545.  
  546. x.ttyhan::save    <r1>
  547.     .spfun    #rtwork,#xc.control,#dtrdrv,#0,#0,#1 ;/62/ drop DTR
  548.     mov    clkflg    ,r1        ; /62/ number of ticks in one second
  549.     asr    r1            ; /62/ wait 0.5sec here
  550. 10$:    .twait    #rtwork,#wait        ; /BBS/ do it one tick at a time
  551.     sob    r1    ,10$        ; so it remains abort-able..
  552.     .spfun    #rtwork,#xc.control,#dtrdrv,#0,#1,#1 ;/62/ then bring DTR up
  553.     clr    r0            ; /41/ assume it worked, and assume
  554.     clr    mready            ; /BBS/ the DTR drop resets the modem
  555.     unsave    <r1>
  556.     return
  557.  
  558.  
  559.     .sbttl    Check status of DTR or DCD  ; /BBS/ added this..
  560.     .enabl    lsb
  561.  
  562. ;    I N Q C D            ; all handlers
  563. ;    I N Q D T R            ; CL or KM only
  564. ;
  565. ;    Returns:  r0 =     4  DTR or DCD is asserted
  566. ;             0  DTR or DCD is not asserted
  567. ;            -1  status is not available
  568.  
  569. x.inqcd::save    <r1>
  570.     tst    mready            ; modem must be on-line
  571.     beq    30$            ; no modem = can't do DCD..
  572.     mov    #stsdrv    ,r1        ; DCD arg
  573.     call    50$            ; goto common code..
  574.     tst    r0            ; did it work
  575.     blt    40$            ; no
  576.     tst    tsxcl            ; ya, which handler is it
  577.     bne    20$            ; CL uses bit 2
  578.     asr    r0            ; KM or XL uses bit 3, make it 2 here
  579.     br    20$            ; goto common code..
  580.  
  581. x.inqdtr::save    <r1>
  582.     tst    tsxcl            ; is this TSX and CL handler?
  583.     bne    10$            ; /62/ ya
  584.     tst    km.lock            ; /62/ is it KM?
  585.     beq    30$            ; nope..
  586. 10$:    mov    #clstat    ,r1        ; DTR argument
  587.     call    50$            ; common code
  588.     tst    r0            ; did it work?
  589.     blt    40$            ; no
  590. 20$:    bic    #^c<4>    ,r0        ; ya, hose unneeded bits
  591.     br    40$
  592. 30$:    mov    #-1    ,r0        ; DTR status not available
  593. 40$:    unsave    <r1>
  594.     return
  595.  
  596. 50$:    .spfun    #rtwork,#xc.control,r1,#xcsts,#0,#1 ; /62/ get status
  597.     bcs    60$            ; failed..
  598.     mov    xcsts    ,r0        ; return the current status
  599.     return
  600. 60$:    mov    #-1    ,r0        ; status not available
  601.     return
  602.  
  603.     .dsabl    lsb
  604.  
  605.  
  606.     .sbttl    DCD status tester    ; /62/ new..
  607.  
  608. x.dcdtst::save    <r1,r0>
  609.     mov    xcsts    ,r1        ; save prior status
  610.     tst    tsxcl            ; which handler is it?
  611.     bne    10$            ; CL uses bit 2
  612.     asr    r1            ; KM, XC and XL use bit 3, make it 2
  613. 10$:    bic    #^c<4>    ,r1        ; recover the carrier detect bit
  614.     call    x.inqcd            ; now get current DCD status
  615.     tst    r0            ; well?
  616.     blt    40$            ; it's not available, bail out..
  617.     cmp    r0    ,r1        ; any change?
  618.     beq    40$            ; no
  619.     tst    r0            ; ya, did we loose it?
  620.     bne    20$            ; no, must have just gotten it
  621.     mov    #xl.02    ,r1        ; ya, load "lost" tag
  622.     call    x.ttxon            ; clear the driver just in case
  623.     br    30$
  624. 20$:    mov    #xl.03    ,r1        ; load "detected" tag
  625. 30$:    calls    printm    ,<#2,#xl.01,r1>    ; say what's up
  626. 40$:    unsave    <r0,r1>
  627.     return
  628.  
  629.  
  630.     .sbttl    SET SPEED
  631.  
  632. ;    input:  (r5)    = desired speed
  633.  
  634. x.setspd::save    <r3>
  635.     tst    tsxcl            ; /44/ TSX+ and CL?
  636.     bne    10$            ; /62/ ya
  637.     tst    km.lock            ; /62/ KM uses the CL speed spfun..
  638.     beq    50$            ; /62/ no can do if not
  639. 10$:    clr    r3            ; /44/ match passed speed in table
  640. 20$:    tst    splst(r3)        ; /44/ end of the speed table?
  641.     beq    40$            ; /44/ yes, exit please
  642.     cmp    splst(r3),(r5)        ; /BBS/ speeds match up?
  643.     beq    30$            ; /44/ yes, exit loop
  644.     tst    (r3)+            ; /44/ no, try next entry then
  645.     br    20$            ; /44/ next please
  646. 30$:    add    #spmap    ,r3        ; /45/ for the speed
  647.     .spfun    #rtwork,#xc.control,#clspeed,r3,#1,#1 ; /62/ address NOT value
  648.     bcs    60$            ; /BBS/ oops
  649.     mov    (r3)    ,xkspeed    ; /52/ save it please
  650.     clr    r0            ; /BBS/ moved this here, say success
  651.     br    70$
  652.  
  653. 40$:    mov    #er$spe    ,r0        ; /44/ return unknown speed
  654.     br    70$
  655. 50$:    mov    #er$spx    ,r0        ; /BBS/ speed not settable
  656.     br    70$
  657. 60$:    mov    #er$wer    ,r0        ; /BBS/ device write error
  658. 70$:    unsave    <r3>
  659.     return
  660.  
  661.  
  662.  
  663.     .sbttl    Fake getting the speed
  664.  
  665. x.ttsp::tst    tsxcl            ; /54/ CL and TSX?
  666.     bne    30$            ; /62/ ya
  667.     tst    km.lock            ; /62/ KM?
  668.     beq    10$            ; /62/ no
  669.     .spfun    #rtwork,#xc.control,#clspeed,#getspd,#-1,#1 ; /62/ get speed
  670.     bcc    20$            ; /62/ got it
  671. 10$:    clr    r0            ; /62/ didn't..
  672.     br    40$            ; /62/ ..work
  673. 20$:    mov    getspd    ,xkspeed    ; /62/ ok, ensure it's the real thing
  674. 30$:    mov    xkspeed    ,r0        ; /54/ or get from last SET SPEED
  675.     asl    r0            ; /54/ word indexing
  676.     mov    splst-2(r0),r0        ; /54/ copy and exit
  677. 40$:    return
  678.  
  679.     .end
  680.