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

  1.     .title    k11prt    pro/rt XC/XL interface
  2.     .ident    /1.0.01/
  3.  
  4. ;    13-Oct-84  11:02:39  Brian Nelson
  5. ;
  6. ;    6-May-85             Basically had to add in checks for xl and tsx
  7. ;                            and then roll in some of the code from k11tsx
  8. ;                            in order to properly use the cl lines under
  9. ;                            TSX.  (Ned W. Rhodes)
  10. ;
  11. ;    04-Nov-85  13:59:39  Mods suggested by Chuck Sandoian for TSX (BDN)
  12. ;                 All such edits marked by /37/
  13. ;
  14. ;    31-Dec-85  04:25:02  Added DTR control for RT11 5.2 and XC/XL
  15. ;    02-Sep-86  09:31:48  Fix SET SPEED for TSX+, edit /54/
  16. ;
  17. ;    Copyright (C) 1984 1985 Change Software, Inc.
  18.  
  19.  
  20.  
  21.  
  22. ;    NOTICE: !!!!!!
  23. ;
  24. ;     To operate  properly with Kermits at high speed and with Kermits
  25. ;    not supporting xon/xoff flow control, the PRO/RT11 device handler
  26. ;    for XC: MUST be modified to increase the internal buffer size and
  27. ;    to  repress XON/XOFF  transmission within a packet.  This is very
  28. ;    easy to do.  In the file XL.MAC  from your PRO/RT kit, change the
  29. ;    line
  30. ;    from:        BUFSIZ    = 64.
  31. ;    to:        BUFSIZ    = 220.
  32. ;
  33. ;    and the line
  34. ;    from:        STPSIZ    = BUFSIZ/4
  35. ;    to:        STPSIZ    = BUFSIZ/2
  36. ;
  37. ;     To recreate  XCX.SYS, first copy XC.MAC, XM.MAC, XL.MAC, XM.ANS
  38. ;    and SYSGEN.COM to DK: and then type  IND SYSGEN.  Tell it to use
  39. ;    the saved answer file  XM.ANS.  When SYSGEN exits,  it will have
  40. ;    created, among other files, a file called XM.CND which is needed
  41. ;    for the driver assembly.
  42. ;
  43. ;    Then:
  44. ;
  45. ;    assign dk: src:
  46. ;    copy xcx.sys xcx.old
  47. ;     ren/nopro xcx.sys xcx.sys
  48. ;    unlo xc:
  49. ;    rem xc:
  50. ;    macro/obj:xcx (xm,xm.cnd,xc)
  51. ;    link/exe:xcx.sys xcx
  52. ;    ins xc:
  53.  
  54.  
  55.  
  56.  
  57.     .if ndf, K11INC
  58.     .ift
  59.     .include    /IN:K11MAC.MAC/
  60.     .endc
  61.  
  62.     .psect
  63.  
  64.     .mcall    .ABTIO    ,.READW    ,.WRITW    ,.SPFUN    ,.TTINR    ,.TTYIN    ,.TTYOU
  65.     .mcall    .MRKT    ,.CMKT    ,.TWAIT    ,.WRITC
  66.     .mcall    .LOOKUP    ,.DSTAT    ,.FETCH    ,.CLOSE
  67.     .mcall    .PRINT    ,.GVAL    ,.HRESET,.RELEAS
  68.     .enabl    gbl
  69.  
  70.     .psect    XCRW    ,rw,d,lcl,rel,con
  71. xcwork:    .blkw    12            ; for asynch calls to the XC driver
  72. xcsts:    .word    0,0            ; /51/ Saved from STSDRV
  73. second:    .word    0,60.            ; wait a full second
  74. third:    .word    0,20.
  75. tenth:    .word    0,6            ; wait 1/10 second
  76. break:    .word    0,17.            ; for sending breaks, .283 seconds
  77. wait:    .word    0,1            ; wait one tick (1/60 second)
  78. dtrlow:    .word    0,60.*1            ; /41/ 2 second DTR drop
  79. nobinar:.word    1            ; /37/ assume XL/XC (no binary I/O)
  80. r50dev::.word    0,0,0,0            ; /37/ save name in rad50
  81. devnam:    .word    0,0,0,0,0,0,0,0,0,0,0,0    ; save the device name
  82. ttctlc:    .blkw    1            ; for control C things in connect mode
  83. xoffed:    .word    0            ; flag that we xoffed the other kermit
  84. xcpoint:.word    xcrdbf            ; current pointer into XCRDBF
  85. xcsize:    .word    0            ; size of last XC read (not used)
  86. xcdone:    .word    0            ; read is complete
  87. xcwdon:    .word    0            ; writc is complete
  88. timwrk:    .blkw    4
  89.     .even
  90. xcrdbf:    .blkb    102            ; for a local read buffer, always asciz
  91. xcrdsi    =    100            ; size of XCRDBF
  92.  
  93. m.tsxs:    .byte    35,'S            ; Single Character
  94.     .BYTE    35,'W            ; Tape mode on
  95.     .BYTE    35,'U            ; No wait
  96.     .BYTE    35,'Y            ; High efficiency
  97.     .BYTE    35,'R
  98.     .BYTE    0
  99.     .even
  100. m.tsxr:    .byte    35,'T            ; Single character off
  101.     .byte    35,'X            ; Tape mode off
  102.     .byte    35,'Z            ; Line feed echo
  103.     .byte    0
  104.     .even
  105. hieff:    .byte    0,120            ; Turn hi eff off
  106.  
  107.  
  108. ;    Edit 37 04-Nov-85  13:45:32  Brian Nelson
  109. ;
  110. ; /37/     Conversations with Chuck Sandoian, (Compuserve 76703,414) have
  111. ;    determined that (1) the CL handler can run in 8bit mode  (NULLS
  112. ;    will, of course, not be passed). This is enabled by setting bit
  113. ;    11 in the .SPFUN code 250. Also, the CL driver DROPS DTR if the
  114. ;    driver is passed an  .SPFUN OFFDRV (code 205).  Ned Rhodes  had
  115. ;    the code for 250 set to 1427. With the release of v5 and v6, we
  116. ;    caln now use 8bit mode and control DTR,  so now it's 7427.  The
  117. ;    meaning of the bits follow:
  118. ;
  119. ;    0    Pass \014 <FF>        8    Send \015 <CR>
  120. ;    1    Pass \011 <HT>        9    Send CTL chars
  121. ;    2    Enable lower case    10    Raise DTR
  122. ;    3    Pass \012 <LF>        11    Enable 8bit mode
  123. ;    4    Accept \012        12    unknown
  124. ;    5    N/A            13    ...ditto
  125. ;    6    Binary output        14    ......and so on
  126. ;    7    Binary input        15    .........
  127.  
  128. xlset:    .word    7427            ; /37/ Options to set (was 1427)
  129. xlset2:    .word    40!10            ; /44/ NOLFOUT and NOFORM0
  130. xlset3:    .word    10            ; /45/ Put LFOUT back in
  131.  
  132. ;    The following tables are used for:
  133. ;
  134. ;    (1) On TSX+, map decimal speeds into .SPFUN speeds for setting
  135. ;        speed on DH/DHV/DHU and DZ/DZV interfaces.
  136. ;    (2) At some future time when either TSX+ or RT supports it get
  137. ;        the interface speed from  the exec and  insert a .TWAIT in
  138. ;        front of the .SPFUN read call to reduce cpu usage at lower
  139. ;        line speeds. For now, default to one tick unless a SET SPE
  140. ;        command was given on TSX+.
  141.  
  142.     .word    0
  143. splst:    .word    75.    ,110.    ,134.    ,150.    ,300.    ,600.    ; /44/
  144.     .word    1200.    ,1800.    ,2000.    ,2400.    ,3600.    ,4800.    ; /44/
  145.     .word    7200.    ,9600.    ,19200.    ,0            ; /44/
  146.  
  147. spmap:    .word    1    ,2    ,3    ,4    ,5    ,6    ; /44/
  148.     .word    7    ,10    ,11    ,12    ,13    ,14    ; /44/
  149.     .word    15    ,16    ,17                ; /44/
  150.                                 ;
  151. waitti:    .byte    1                        ; /52/
  152.     .byte    6    ,6    ,6    ,6    ,6    ,4    ; /52/
  153.     .byte    3    ,2    ,2    ,2    ,2    ,1    ; /52/
  154.     .byte    1    ,1    ,0    ,0    ,0    ,0    ; /52/
  155.     .even                            ; /52/
  156. waitarg:.word    0,0                        ; /52/
  157. xkspeed:.word    0                        ; /52/
  158.  
  159.     .psect    $CODE
  160.  
  161.     ERRBYT    =    52
  162.     JSW    =    44
  163.  
  164.  
  165. ;    .SPFUN    codes for the XC/XL driver
  166.  
  167.     CLRDRV    ==    201        ; undo xon, reset the driver
  168.     BRKDRV    ==    202        ; wc=0, end break else break
  169.     SRDDRV    ==    203        ; special read, wc is max # of bytes
  170.                     ; to read, always returns at least one
  171.                     ; byte, up to max if data is there.
  172.     STSDRV    ==    204        ; driver status, high byte is driver
  173.                     ; version, low byte is:
  174.                     ; bit 0 = 1 if sent xoff to host
  175.                     ; bit 1 = 1 if rec xoff from host
  176.                     ; bit 2 = 1 if CTS is ok
  177.     OFFDRV    =    205        ; disable interupts at program exit
  178.  
  179.     DTRDRV    =    206        ; rt 5.2, set/clear DTR. If WC <> 0
  180.                     ; then turn it on else turn it off.
  181.     
  182.     CLSET    =    250        ; Set cl options for TSX-Plus
  183.     CLRSET    =    251        ; Reset cl option for TSX-Plus
  184.     CLSPEED    =    256        ; /44/ Speed control
  185.     CLCLR    =    257        ; /37/ Reset w/o dropping DTR
  186.  
  187.     XC.CONTROL ==     14        ; channel for controlling the driver
  188.     XC.AUX       =    15        ; /41/ Ditto
  189.  
  190.  
  191.     .iif ndf, XON      , XON = 'Q&37
  192.     .iif ndf, XOFF      , XOFF= 'S&37
  193.  
  194.  
  195.     .sbttl    assign and init the XC/XL port
  196.     .enabl    lsb
  197.  
  198.     .mcall    .SERR    ,.HERR        ; /51/
  199.  
  200. x.ttysav::
  201. x.ttyrst::
  202. x.deadev::
  203.     mov    r1    ,-(sp)        ; /45/
  204.     br    10$            ; /45/
  205. x.assdev::
  206.     mov    r1    ,-(sp)        ; /44/ Save a register please
  207.     mov    @r5    ,r1        ; /44/ Address of the devname
  208.     call    mapxl            ; /44/ Do we know about this dev?
  209.     bcs    110$            ; /44/ No, return error in R0
  210. 10$:    .SERR                ; /51/
  211.     tst    tsxcl            ; Under tsx and using cl line?
  212.     beq    100$            ; Nope
  213.     mov    #hieff,r0        ; Get emt parameter block
  214.     emt    375            ; Turn off hi efficiency
  215.     .PRINT    #m.tsxr            ; Reset some terminal parameters
  216. 100$:    .HERR                ; /51/
  217.     clr    r0            ; Success
  218. 110$:    mov    (sp)+    ,r1        ; /44/ Restore
  219.     return                ; not needed for PRO/RT
  220.  
  221.  
  222.     .dsabl    lsb
  223.  
  224.  
  225. ;    T T Y I N I
  226. ;
  227. ;    input:    @r5    device name
  228. ;        2(r5)    LUN
  229. ;        4(r5)    modifiers
  230. ;
  231. ;    output:    r0    error code
  232.  
  233.  
  234. x.TTYINi::
  235.     save    <r1,r2,r3,r4>        ; /37/ always save temps please
  236.     mov    @r5    ,r1        ; get the device name address
  237.     mov    2(r5)    ,r0        ; copy the device name please
  238.     asl    r0            ; lun times two please
  239.     movb    (r1)    ,devnam(r0)    ; save it please
  240.     movb    1(r1)    ,devnam+1(r0)    ; both ascii characters please
  241.     clr    r0            ; assume success
  242.     tstb    @r1            ; perhaps the console ?
  243.     beq    100$            ; yes, don't do anything
  244.     cmpb    @r1    ,#'T&137    ; TT: ?
  245.     beq    100$            ; do nothing then
  246.  
  247. 1$:    clr    xoffed            ; reset 'sent an XOFF' flag
  248.     mov    #xcrdbf    ,xcpoint    ; a pointer into the XC: buffer
  249.     mov    #xcrdbf    ,r2        ; xc device, zero the buffer
  250.     mov    #xcrdsi+2,r0        ; the size of the buffer
  251. 5$:    clrb    (r2)+            ; clear it out
  252.     sob    r0    ,5$        ; next please
  253.  
  254.     call    mapxl            ; /44/ See if XL/XC or CLn passed
  255.     bcs    95$            ; /44/ No, exit with ER$UKN
  256.     mov    r0    ,r2        ; /44/ Point to RAD50 device name
  257. 10$:    calls    fetch    ,<@r2>        ; get the device loaded ?
  258.     tst    r0            ; did it work ?
  259.     bne    95$            ; no
  260. 20$:    clr    xcdone            ; nothing pending to read from XC:
  261.     mov    r2    ,r3        ; /37/ get pointer to rad50 of dev
  262.     mov    #r50dev    ,r4        ; /37/ where to save r50 of name
  263.     mov    (r3)+    ,(r4)+        ; /37/ copy rad50 of device name
  264.     mov    (r3)+    ,(r4)+        ; /37/ copy rad50 of device name
  265.     mov    (r3)+    ,(r4)+        ; /37/ copy rad50 of device name
  266.     mov    (r3)+    ,(r4)+        ; /37/ copy rad50 of device name
  267.     .LOOKUP    #rtwork,2(r5),r2    ; try to open the port up please
  268.     bcs    60$            ; oops
  269.     .LOOKUP    #rtwork,#XC.CONTROL,r2    ; also open a control channel
  270.     bcs    60$            ; should never happen, of course
  271.     call    200$            ; /51/ Extra for driver version
  272.     call    tsxopt            ; /37/ set CLn: if it's TSX+
  273.     tst    nobinary        ; can we do binary i/o to XC: ?
  274.     beq    30$            ; yes
  275.     cmpb    parity    ,#par$no    ; currently PARITY NONE ?
  276.     bne    30$            ; no
  277.     movb    #par$sp    ,parity        ; set space parity to fake it
  278. 30$:    clr    r0            ; all is well today
  279.     br    100$            ; exit with sucess
  280.  
  281.  
  282.  
  283. 60$:    mov    #xcierr    ,r0        ; open error on X?0: device
  284.     br    90$            ; map it to a global error
  285. 70$:    mov    #xcspfun,r0        ; .SPFUN error for X?0:
  286.     br    90$            ; map it to a global error
  287.  
  288. 90$:    clr    r1            ; now map to the global error code
  289.     movb    @#ERRBYT,r1        ; get RT11's error code
  290.     asl    r1            ; times 2 for word indexing
  291.     add    r0    ,r1        ; point to the global error code
  292.     mov    @r1    ,r0        ; and get it
  293. 95$:    mov    2(r5)    ,r1        ; clear the saved device name
  294.     asl    r1            ; times two please
  295.     clr    devnam(r1)        ; simple
  296. 100$:    unsave    <r4,r3,r2,r1>        ; /37/ pop scratch registers and exit
  297.     return                ; bye
  298.  
  299.  
  300. 200$:    .SPFUN    #rtwork,#XC.CONTROL,#STSDRV,#xcsts,#0,#1
  301.     .SPFUN    #rtwork,#XC.CONTROL,#CLRDRV,#0,#0,#1
  302.     bit    #1    ,xcsts        ; Did we ever xoff the host?
  303.     beq    210$            ; No
  304.     .WRITC    #rtwork,2(r5),#$xon,#1,#290$,#1
  305. 210$:    return
  306.  
  307. 290$:    return                ; .WRTIC completion
  308.  
  309.     .save
  310.     .psect    $pdata    ,ro,d,lcl,rel,con
  311.     .even
  312. $xon:    .byte    'Q&37,0
  313.     .even
  314.     .restore
  315.  
  316.  
  317.  
  318.     .sbttl    TSX+ things
  319.  
  320.  
  321. tsxopt:    tst    tsxcl            ; /37/ TSX+ and CL:
  322.     beq    100$            ; /37/ No
  323.     cmp    nobinary,#1        ; /37/ currently set to default?
  324.     bne    10$            ; /37/ no, don't change it
  325.     clr    nobinary        ; /37/ Yes, we can do 8BIT I/O on CL
  326. 10$:    .GVAL    #rtwork,#-4        ; get tsx leadin
  327.     movb    r0,m.tsxr        ; set in place
  328.     movb    r0,m.tsxr+2        ; set in place
  329.     movb    r0,m.tsxr+4        ; set in place
  330.     movb    r0,m.tsxs        ; set in place
  331.     movb    r0,m.tsxs+2        ; set in place
  332.     movb    r0,m.tsxs+4        ; set in place
  333.     movb    r0,m.tsxs+6        ; set in place
  334.     movb    r0,m.tsxs+8.        ; set in place
  335.     .PRINT    #m.tsxs            ; set the options
  336.     .SPFUN    #rtwork,#xc.control,#clset,#xlset,#1,#0
  337.                     ; set some cl options
  338.     .SPFUN    #rtwork,#xc.control,#clrset,#xlset2,#1,#0
  339.                     ; reset some cl options
  340.     bis    #40000!10000!100,@#JSW    ; lower case, no wait, and special
  341. 100$:    return                ; back to caller
  342.  
  343.  
  344.  
  345. mapxl:    save    <r1,r2,r3>        ; /44/ Save these please
  346.     clr    r3            ; /44/ Current index
  347.     sub    #50    ,sp        ; /44/ Allocate a buffer for new name
  348.     mov    sp    ,r2        ; /44/ And also a pointer to it
  349. 5$:    cmpb    (r1)    ,#':        ; /44/ While ( *devnam != ':' )
  350.     beq    6$            ; /44/   {
  351.     movb    (r1)    ,(r2)+        ; /44    *newnam++ = *devnam
  352.     beq    6$            ; /44/   if ( *devnam == NULL) break
  353.     inc    r1            ; /44/   devnam++
  354.     br    5$            ; /44/   } ;
  355. 6$:    clrb    (r2)            ; /44/ *newnam = NULL
  356.     mov    sp    ,r2        ; /44/ newnam = newnam_base_address
  357.  
  358. 10$:    tst    200$(r3)        ; /44/ End of the list yet ?
  359.     beq    90$            ; /44/ Yes, exit with ER$UKN
  360.     strcmp    r2    ,200$(r3)    ; /44/ Find a device name match?
  361.     tst    r0            ; /44/ Well ?
  362.     beq    20$            ; /44/ Yes
  363.     tst    (r3)+            ; /44/ No, try the next entry
  364.     br    10$            ; /44/ ....
  365. 20$:    mov    #310$    ,r0        ; /44/ Success, copy r50 devicename
  366.     mov    300$(r3),@r0        ; /44/ Just copy over first word
  367.     add    #50    ,sp        ; /44/ Pop local buffer....
  368.     clc                ; /44/ No errors
  369.     br    100$            ; /44/ Exit
  370. 90$:    mov    #ER$UKN    ,r0        ; /44/ Return error and exit
  371.     add    #50    ,sp        ; /44/ Pop local buffer....
  372.     sec                ; /44/ Flag error
  373. 100$:    unsave    <r3,r2,r1>        ; /44/ Exit
  374.     return
  375.  
  376.  
  377. 200$:    .word    201$,202$,203$,204$
  378.     .word    210$,211$,212$,213$,214$,215$,216$,217$
  379.     .word    220$,221$
  380.     .word    0
  381. 201$:    .asciz    /XC/
  382. 202$:    .asciz    /XL/
  383. 203$:    .asciz    /XC0/
  384. 204$:    .asciz    /XL0/
  385. 210$:    .asciz    /CL0/
  386. 211$:    .asciz    /CL1/
  387. 212$:    .asciz    /CL2/
  388. 213$:    .asciz    /CL3/
  389. 214$:    .asciz    /CL4/
  390. 215$:    .asciz    /CL5/
  391. 216$:    .asciz    /CL6/
  392. 217$:    .asciz    /CL7/
  393. 220$:    .asciz    /KL/
  394. 221$:    .asciz    /KL0/
  395.     .even
  396. 300$:    .rad50    /XC /
  397.     .rad50    /XL /
  398.     .rad50    /XC /
  399.     .rad50    /XL /
  400.     .rad50    /CL0/
  401.     .rad50    /CL1/
  402.     .rad50    /CL2/
  403.     .rad50    /CL3/
  404.     .rad50    /CL4/
  405.     .rad50    /CL5/
  406.     .rad50    /CL6/
  407.     .rad50    /CL7/
  408.     .rad50    /KL /
  409.     .rad50    /KL0/
  410. 310$:    .rad50    /   /
  411.     .rad50    /   /
  412.     .rad50    /   /
  413.     .rad50    /   /
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.     .sbttl    close the line up
  421.     .enabl    lsb
  422.  
  423. x.ttyfin::
  424.     save    <r1,r2>            ; /37/ save temps please
  425.     .TWAIT    #rtwork,#third        ; /37/ insure ack for B packet done
  426.     tst    tsxcl            ; /45/ Tsx+ and CLn?
  427.     beq    1$            ; /45/ No
  428.     .SPFUN    #rtwork,#xc.control,#clset,#xlset3,#1,#0 ; /45/ Yes, SET LFOUT
  429. 1$:    clr    wasxc            ; was not xc/xl and pure RT
  430.     mov    2(r5)    ,r1        ; get the internal lun
  431.     asl    r1            ; map it
  432.     cmpb    devname(r1),#'C&137    ; /44/ CLn: and TSX+ ?
  433.     beq    2$            ; /44/ Yes, let it through
  434.     cmpb    devname(r1),#'X&137    ; see if the device was X?:
  435.     bne    10$            ; no, then do nothing
  436. 2$:    call    clrxc            ; reset the driver
  437.     mov    #CLCLR    ,r2        ; /37/ assume TSX CL function 257
  438.     tst    tsxcl            ; tsx and cl?
  439.     bne    5$            ; yes
  440.     mov    sp    ,wasxc        ; flag for .exit that this was XC/XL
  441.     mov    #OFFDRV    ,r2        ; /37/ No, was real RT11 today
  442. 5$:    .SPFUN    #rtwork,#XC.CONTROL,r2,#0,#0,#1 ;disable interupts at exit
  443.     .ABTIO    2(r5)            ; try to stop all i/o please
  444.     .ABTIO    #XC.CONTROL        ; /51/
  445.     .CLOSE    2(r5)            ; yes, was XC/XL, thus close it
  446.     .CLOSE    #XC.CONTROL        ; and close the controller port
  447.     clr    xcwdone            ; nothing as far as writes either
  448.     clr    xcdone            ; nothing pending to read from XC:
  449.     mov    #xcrdbf    ,xcpoint    ; reset the pointer to the buffer
  450.     clrb    @xcpoint        ; stuff a null in please
  451. 10$:    clr    devnam(r1)        ; no device active now
  452.     clr    r0            ; no error are possible
  453.     unsave    <r2,r1>            ; /37/ pop temp and exit
  454.     return                ; bye
  455.  
  456.     .dsabl    lsb
  457.  
  458.  
  459. x.finrt::                ; /37/ clear the line for good
  460.     tst    r50dev            ; /37/ anything ever opened up ?
  461.     beq    10$            ; /37/ no
  462.     .LOOKUP    #rtwork,#XC.CONTROL,#r50dev          ; /37/ yes, open it
  463.     .SPFUN    #rtwork,#XC.CONTROL,#OFFDRV,#0,#0,#1 ; /37/ and kill it
  464. 10$:    tst    wasxc            ; /37/ need a .HRESET ?
  465.     beq    20$            ; /37/ no
  466.     .ABTIO    #XC.CONTROL        ; /51/
  467.     .CLOSE    #XC.CONTROL        ; /51/
  468.     .HRESET                ; /51/
  469.     br    100$            ; /51/ And exit
  470.                     ;
  471. 20$:    .CLOSE    #XC.CONTROL        ; /37/
  472. 100$:    clr    r0            ; /37/ bye
  473.     return
  474.  
  475.  
  476.     .save
  477.     .psect    XCDATA    ,rw,d,lcl,rel,con
  478. XCNAME:    .rad50    /XC /
  479.     .rad50    /   /
  480.     .rad50    /   /
  481.     .rad50    /   /
  482. XLNAME:    .rad50    /XL /
  483.     .rad50    /   /
  484.     .rad50    /   /
  485.     .rad50    /   /
  486.     .restore
  487.  
  488.  
  489.  
  490.  
  491.  
  492.     .sbttl    binrea    read binary
  493.  
  494.  
  495. ;    B I N R E A
  496. ;
  497. ;    input:    @r5    LUN
  498. ;        2(r5)    timeout
  499. ;    output:    r0    error code
  500. ;        r1    character just read
  501. ;
  502. ;    To avoid rewriting the terminal emulation code, the case
  503. ;    where we get passed a timeout of -1 is used to do a  qio
  504. ;    to the XC port and then subsequent calls simply check to
  505. ;    see if it completed. If so, get whats in the buffer.  If
  506. ;    it's not done, exit and check  next time.  This  is only
  507. ;    done from the connect code,  so perhaps later I will get
  508. ;    around to rewriting it.
  509. ;
  510. ;    For the normal Kermit timed packet read, we post the qio
  511. ;    and loop waiting for it to complete. If it does not com-
  512. ;    plete  within the specified time, we cancel  the i/o and
  513. ;    reset the driver.
  514. ;    For proper operation, the XC driver must be modified  as
  515. ;    described at the beginning of the file.
  516.  
  517. rdmode:    .word    0
  518.  
  519. x.xbin::mov    sp    ,rdmode
  520.     br    rdcom
  521. x.binr::clr    rdmode
  522. rdcom:    save    <r2,r3,r4>        ; we may want to use these here
  523.     mov    @r5    ,r2        ; get the lun to use
  524.     asl    r2            ; if TT: then do it different
  525.     cmpb    devnam(r2),#'C&137    ; /44/ CLn: and TSX+ ?
  526.     beq    10$            ; /44/ Yes, let it through
  527.     cmpb    devnam(r2),#'X&137    ; XC: ?
  528.     beq    10$            ; yes (or at least assume so)
  529.     call    ttread            ; yes, get from the console tt
  530.     br    100$            ; bye
  531.  
  532. 10$:    cmp    xcpoint    ,#xcrdbf+xcrdsi    ; insure no buffer overflows
  533.     bhis    20$            ; gone too far, XC driver is %$#@!
  534.     tstb    @xcpoint        ; anything left in the readbuffer?
  535.     bne    30$            ; no
  536. 20$:    mov    #xcrdbf    ,xcpoint    ; reset the pointer to the buffer
  537.     clrb    @xcpoint        ; stuff a null in please
  538.     call    xxread            ; load the buffer with as much as can
  539.     tst    r0            ; did this read succeed ?
  540.     bne    100$            ; no
  541. 30$:    clr    r1            ; avoid sxt even if the fubar XC
  542.     bisb    @xcpoint,r1        ; driver always drops bit 7 (future?)
  543.     inc    xcpoint            ; point to the next one in the buffer
  544.     clr    r0            ; insure success and exit
  545.  
  546. 100$:    unsave    <r4,r3,r2>
  547.     return
  548.  
  549.  
  550. xxread:    mov    2(r5)    ,r3        ; timeout in seconds here
  551.     bne    10$            ;
  552.     inc    r3            ; convert nothing to one second
  553. 10$:    cmp    r3    ,#-1        ; no wait ?
  554.     beq    15$            ; yes
  555.     mul    #60.    ,r3        ; no, convert time to ticks then
  556.     br    20$            ; and check on the i/o status
  557. 15$:    mov    #1    ,r3        ; no wait (really, one tick)
  558.  
  559. 20$:    tst    xcdone            ; no timout, last read ever finish?
  560.     bmi    30$            ; no, keep waiting then
  561.     mov    #-1    ,xcdone        ; read without waiting for it
  562.     mov    xkspeed    ,r1        ; /52/ Get current line speed
  563.     movb    waitti(r1),waitarg+2    ; /52/ Insert the desired delay now
  564.     .TWAIT    #rtwork,#waitarg    ; /52/ Now delay processing a moment
  565.     .SPFUN    #xcwork,@r5,#SRDDRV,#xcrdbf,#xcrdsi,#1,#200$
  566.  
  567. 30$:    tst    xcdone            ; return that fast (?)
  568.     bgt    40$            ; yes
  569.     tst    clkflg            ; /37/ system have a clock?
  570.     bne    34$            ; /37/ yes
  571.     cpuwait    #1            ; /37/ no, loop to wait
  572.     br    35$            ; /37/ next please
  573. 34$:    .TWAIT    #rtwork,#wait        ; no, sleep for 1/60 second
  574. 35$:    sob    r3    ,30$        ; and see if we should keep waiting
  575.     tst    xcdone            ; got it from the XC buffer now?
  576.     bmi    50$            ; no, return no data and exit
  577.  
  578. 40$:    clr    r1            ; all done, get character and exit
  579.     bisb    xcrdbf    ,r1        ; and set the error code to zero
  580.     clr    xcdone            ; que a new read next time called
  581.     clr    r0            ; in r0
  582.     br    100$            ; bye
  583.  
  584. 50$:    cmp    2(r5)    ,#-1        ; no xon's if we are looping no tmo
  585.     beq    60$            ;
  586.     tst    rdmode            ; /45/ From CONNECT or DIAL ?
  587.     bne    60$            ; /45/ Yes, please drop XON's then
  588.     call    clrxc            ; insure interupts are ok, also XON
  589. 60$:    mov    #ER$NIN    ,r0        ; no data has come it yet
  590.     br    100$            ; exit
  591.  
  592. 100$:    return
  593.  
  594.  
  595. 200$:    mov    #1    ,xcdone        ; flag a read completion and exit
  596.     return                ; so we will break the .TWAIT loop
  597.  
  598.  
  599.  
  600.  
  601.     .sbttl    raw i/o from the console TT
  602.  
  603.  
  604. ttread:    bis    #40000!10000!100,@#JSW    ; lower case, no wait
  605.     cmp    2(r5)    ,#-1        ; read without any wait ?
  606.     bne    10$            ; no
  607.     .TTINR                ; one char from the console tt:
  608.     bcs    80$            ; it worked
  609.     mov    r0    ,r1        ; and exit with success
  610.     clr    r0            ; bye
  611.     br    100$            ; exit at last
  612.  
  613. 10$:    mov    2(r5)    ,r1        ; get the timeout in seconds
  614.     mul    #60.    ,r1        ; into ticks now
  615. 20$:    .TTINR                ; try a character from TT:
  616.     bcc    30$            ; it worked, get the ch into r1
  617.     dec    r1            ; been here too long ?
  618.     beq    80$            ; yes, exit with error
  619.     .TWAIT    #rtwork,#wait        ; sleep a moment please
  620.     br    20$            ; and try again please
  621.  
  622. 30$:    clr    r1            ; it worked, get the character and exit
  623.     bisb    r0    ,r1        ; simple
  624.     clr    r0            ; success
  625.     br    100$            ; and exit
  626.  
  627. 80$:    mov    #ER$NIN    ,r0        ; no data today
  628.     clr    r1            ; same here, return a null
  629. 100$:
  630.     tst    tsxcl            ; tsx and cl
  631.     bne    101$            ; yes
  632.     bic    #40000!10000!100,@#JSW    ; reset some tt options
  633. 101$:    return
  634.  
  635.  
  636.  
  637.  
  638.     .sbttl    binary write
  639.  
  640.  
  641.  
  642. ;    B I N W R I
  643. ;
  644. ;    binwri( %loc buffer, %val buffer_size, %val lun )
  645. ;
  646. ;    output:    r0    error code
  647.  
  648.     $XLV51    =    16.
  649.     $XLV52    =    17.
  650.  
  651.  
  652. x.binwri::
  653.     save    <r1,r2,r3,r4>
  654.     clr    r0            ; presume no errors
  655.     tst    2(r5)            ; any i/o to do at all?
  656.     beq    100$            ; no
  657.     mov    4(r5)    ,r4        ; check for TT: please
  658.     asl    r4            ; by indexing to DEVNAM:
  659.     cmpb    devnam(r4),#'T&137    ; TT: ?
  660.     bne    20$            ; no
  661.     mov    @r5    ,r4        ; simple
  662.     mov    2(r5)    ,r2        ; number of characters to write
  663. 15$:    .TTYOUT    (r4)+            ; dump via .TTYOU to avoid .PRINT's
  664.     sob    r2    ,15$        ; problems with 8bit characters please
  665.     clr    r0            ; and exit
  666.     br    100$            ; bye
  667.  
  668. 20$:    mov    #-1    ,xcwdone    ; Done yet?
  669.     mov    (r5)    ,r3        ; Copy the data to a local buffer
  670.     mov    xklgbuf    ,r2        ; Pick up pointer to a buffer
  671.     mov    2(r5)    ,r4        ; The byte count for the write
  672.     mov    r4    ,r1        ; Set byte count for the copy.
  673. 25$:    movb    (r3)+    ,(r2)+        ; for (i=bytecount;i>0;i--)
  674.     sob    r4    ,25$        ;   *buffer++ = *source++
  675.     mov    r1    ,r4        ; restore  the byte count
  676.     dec    r4            ; if bytecount <> 1
  677.     beq    40$            ;  then
  678.     cmpb    -(r3)    ,#CR        ;    if lastcharacter == CR
  679.     bne    30$            ;     then
  680.     movb    #LF    ,(r2)+        ;       *bufffer++ = NULL
  681.     inc    r1            ;       bytecount++
  682. 30$:    clr    xoffed            ;    xoffed = false ;
  683. ;-    tst    rtflow            ;    if (needflowcontrol)
  684. ;-    beq    35$            ;     then
  685. ;-    movb    #XOFF    ,(r2)+        ;      *buffer++ = XOFF
  686. ;-    inc    r1            ;      bytecount++
  687. ;-    mov    sp    ,xoffed        ;      xoffed = true
  688. 35$:
  689.  
  690. 40$:    clrb    (r2)+            ; *buffer++ = NULL ;
  691.     inc    r1            ; bytecount++ 
  692.     asr    r1            ; bytecount = bytecount/2
  693.     .WRITC    #xcwork,4(r5),xklgbuf,r1,#200$,#1
  694.     mov    #10.*60.,r3        ; wait at most 10 seconds (?)
  695.  
  696. 50$:    tst    xcwdone            ; ast completion as of yet ?
  697.     bne    60$            ; yes
  698.     tst    clkflg            ; A clock?
  699.     bne    55$            ; Yes
  700.     CPUWAIT    #1            ; No, loop and fall thru, twait is NOP
  701. 55$:    .TWAIT    #rtwork,#wait        ; still not complete, wait a tick
  702.     sob    r3    ,50$        ; and check again
  703.     call    clrxc            ; clear the driver out, send XON
  704.     clr    r0
  705.     br    100$            ; exit
  706.  
  707. 60$:    tst    r4            ; was that a single character i/o?
  708.     beq    70$            ; yes
  709.     tst    xoffed            ; in case a virgin xcdriver, wait.
  710.     beq    70$            ; no, skip the wait and xon then.
  711.     .TWAIT    #rtwork,#tenth        ; no, sleep for a moment please
  712.     .TWAIT    #rtwork,#tenth        ; at 9600, we need this one also
  713.     call    300$            ; xon the other side please
  714. 70$:    clr    r0            ; success
  715.     clr    xcwdone            ; reset the i/o in progress flag
  716.  
  717. 100$:    unsave    <r4,r3,r2,r1>        ; pop registers and exit
  718.     return                ; bye
  719.  
  720.  
  721. 200$:    mov    #1    ,xcwdone    ; flag ast level completion
  722.     return                ; and exit
  723.  
  724.  
  725. 300$:    tst    xoffed            ; did we xoff the other side?
  726.     beq    310$            ; no
  727.     .WRITC    #xcwork,4(r5),#320$,#1,#0,#1 ; synch i/o this time please
  728. 310$:    clr    xoffed            ; say no xoff's anymore please
  729.     return
  730.  
  731. 320$:    .byte    XON,0
  732.  
  733.  
  734. clrxc:    .SPFUN    #rtwork,#XC.CONTROL,#CLRDRV,#0,#0,#1 ; clear the driver
  735.     return
  736.  
  737.  
  738.     .sbttl    cantyp    try to dump all typeahead
  739.  
  740.  
  741. x.cantyp::
  742.     save    <r1,r2>            ; save temps
  743.     mov    #200    ,r2        ; loop for no more than 128 characters
  744.     mov    #xcrdbf    ,xcpoint    ; reset the pointer to the buffer
  745.     clrb    @xcpoint        ; stuff a null in please
  746. 10$:    calls    binrea    ,<2(r5),#-1>    ; try to get something
  747.     tst    r0            ; did it work ?
  748.     bne    20$            ; no, exit
  749.     sob    r2    ,10$        ; yes, eat somemore characters
  750. 20$:    .ABTIO    2(r5)            ; try to reinit the driver and exit
  751.     call    clrxc            ; this also please
  752. 100$:    unsave    <r2,r1>            ; pop temp and exit
  753.     clr    r0
  754.     return                ; bye
  755.  
  756.  
  757. x.ttxon::
  758.     call    clrxc            ; get the driver to clear xoff status
  759.     return
  760.  
  761.  
  762. x.senbrk::
  763.     .SPFUN    #rtwork,#XC.CONTROL,#BRKDRV,#0,#1,#1
  764.     tst    brklen            ; /43/ User set a BREAK length?
  765.     beq    10$            ; /43/ No
  766.     mov    brklen    ,break+2    ; /43/ Yes, use it
  767. 10$:    .MRKT    #timwrk,#break,#20$,#20
  768.     clr    r0
  769.     return
  770.  
  771. 20$:    .SPFUN    #rtwork,#XC.CONTROL,#BRKDRV,#0,#0,#1
  772.     clr    r0
  773.     return
  774.  
  775.  
  776. ;    Drop dtr for a moment, For RT11 5.2 only
  777. ;    Added 31-Dec-85  03:46:44 Edit 2.41
  778.  
  779.     .enabl    lsb
  780.  
  781. x.ttyhan::
  782. x.ttydtr::
  783.     save    <r1>            ; /41/ Save a register
  784.     mov    (r5)    ,r1        ; /44/ Get device name address in R1
  785.     call    mapxl            ; /44/ See if device names maps
  786.     bcs    100$            ; /44/ No, so exit
  787.     mov    r0    ,r1        ; /44/ Point to it
  788. 10$:    calls    fetch    ,<@r1>        ; /41/ Insure handler is loaded
  789.     .LOOKUP    #rtwork,#XC.AUX,r1    ; /41/ Now open it up
  790.     bcs    90$            ; /41/ Oops, should not happen
  791.     .SPFUN    #rtwork,#XC.AUX,#DTRDRV,#0,#0,#1 ;/41/ Now DROP DTR
  792.     .TWAIT    #rtwork,#dtrlow             ;/41/ And let it stay low for
  793.     .TWAIT    #rtwork,#dtrlow             ;/41/ And let it stay low for
  794.     .TWAIT    #rtwork,#dtrlow             ;/41/ And let it stay low for
  795.     .SPFUN    #rtwork,#XC.AUX,#DTRDRV,#0,#1,#1 ;/41/ while, then bring it up
  796.     .CLOSE    #XC.AUX            ; /41/ Close controlling channel
  797.     br    100$
  798. 90$:    movb    @#52    ,r1
  799.     message    <Error from .lookup >
  800.     decout    r1
  801.     message
  802. 100$:    unsave    <r1>            ; /41/ Pop saved register
  803.     clr    r0            ; /41/ Assume that it worked
  804.     return                ; /41/ And exit
  805.  
  806.     .dsabl    lsb
  807.  
  808.  
  809.     .sbttl    parse terminal unit
  810.  
  811.  
  812. ;    T T P A R S
  813. ;
  814. ;    input:    @r5    address of RT11 Multiple terminal service unit string
  815. ;    output:    r0    unit in binary
  816.  
  817.  
  818. x.ttpars::
  819.     clr    r0            ; always unit zero for PRO/RT
  820.     return
  821.  
  822.  
  823.  
  824.     .sbttl    GTTNAM    get MT unit of current console (set tt:consol=nn)
  825.  
  826. ;    G T T N A M
  827. ;
  828. ;    input:    @r5    address of console name to be written
  829. ;    output:    @r5    current console name
  830. ;        consave    same thing
  831.  
  832. x.gttnam::
  833.     mov    @r5    ,r0        ; for PRO/RT, always return TT:
  834.     movb    #'T&137    ,@r0
  835.     movb    (r0)+    ,consave
  836.     movb    #'T&137    ,@r0
  837.     movb    (r0)+    ,consave+1
  838.     movb    #':    ,@r0
  839.     movb    (r0)+    ,consave+2
  840.     clrb    @r0
  841.     clrb    consave+3
  842.     clr    r0
  843.     return
  844.  
  845.  
  846.     global    <consave>
  847.  
  848.  
  849.  
  850.     .sbttl    terminal i/o things we don't need, can't do or haven't done yet
  851.  
  852. ;    Edit:    /54/ Remove ASL R3 to get correct speed indexing
  853.  
  854. x.setspd::
  855.     clr    xkspeed            ; /52/ No saved speed now
  856.     tst    tsxcl            ; /44/ TSX+ and CL ?
  857.     beq    110$            ; /44/ No can do if not
  858.     save    <r1,r2,r3>        ; /44/ Save a register or three
  859.     clr    r3            ; /44/ Match passed speed in table
  860. 10$:    tst    splst(r3)        ; /44/ End of the speed table ?
  861.     beq    90$            ; /44/ Yes, exit please
  862.     cmp    splst(r3),2(r5)        ; /44/ Speeds match up ?
  863.     beq    20$            ; /44/ Yes, exit loop
  864.     tst    (r3)+            ; /44/ No, try next entry then
  865.     br    10$            ; /44/ Next please
  866. 20$:    mov    (r5)    ,r1        ; /44/ Get device name address in R1
  867.     call    mapxl            ; /44/ See if device names maps
  868.     bcs    100$            ; /44/ No, so exit
  869.     mov    r0    ,r1        ; /44/ Point to it
  870.     calls    fetch    ,<@r1>        ; /44/ Insure handler is loaded
  871.     .LOOKUP    #rtwork,#XC.AUX,r1    ; /44/ Now open it up
  872.     bcs    100$            ; /44/ Oops, should not happen
  873.     add    #spmap    ,r3        ; /45/ for the speed
  874.     .SPFUN    #rtwork,#XC.AUX,#CLSPEED,r3,#1,#0 ; /45/ Address NOT value
  875.     bcs    40$            ; /52/ Oops
  876.     mov    (r3)    ,xkspeed    ; /52/ Save it please
  877. 40$:    .CLOSE    #XC.AUX            ; /44/ Close controlling channel
  878.     br    100$            ; /44/ Exit
  879. 90$:    mov    #ER$SPE    ,r0        ; /44/ Return UNKNOWN speed
  880. 100$:    unsave    <r3,r2,r1>        ; /44/ Pop saved registers
  881.     clr    r0            ; /44/ Assume that it worked
  882.     return                ; /44/ And exit
  883.  
  884. 110$:    mov    #377    ,r0
  885.     return
  886.  
  887.  
  888.  
  889.  
  890. x.ttsp::clr    r0            ; /54/ Presume failure
  891.     tst    tsxcl            ; /54/ CL and TSX+
  892.     beq    100$            ; /54/ No
  893.     mov    xkspeed    ,r0        ; /54/ Get from last SET SPEED
  894.     asl    r0            ; /54/ Word indexing
  895.     mov    splst-2(r0),r0        ; /54/ Copy and exit
  896. 100$:    return                ; /54/ Bye
  897.  
  898. x.ttset::
  899. x.ttrfin::
  900. x.ttrini::
  901.     clr    r0
  902.     return
  903.  
  904.  
  905.  
  906.     .mcall    .TTYIN
  907.     jsw    =    44
  908.  
  909. x.kbread::
  910.     mov    r2    ,-(sp)
  911.     mov    r3    ,-(sp)
  912.     bis    #40000    ,@#jsw        ; enable lower case tt: input
  913.     tst    tsxcl            ; tsx and cl?
  914.     beq    5$            ; nope
  915.     bic    #10000!100,@#jsw    ; ditch single ch input and wait
  916.     br    7$            ; jump ahead
  917.  
  918. 5$:    bic    #10000    ,@#jsw        ; ditch single ch input please
  919.  
  920. 7$:    mov    @r5    ,r1        ; a buffer to put the chars
  921.     mov    #80.    ,r3        ; size of the buffer here
  922. ;10$:    .SCCA    #area    ,#kmonbf    ; so we can catch control Z
  923. 10$:    .TTYIN                ; read a character please
  924.     tstb    r0
  925.     beq    15$            ; a null
  926.     cmpb    r0    ,#'Z&37        ; control Z ?
  927.     beq    20$            ; yes
  928.     cmpb    r0    ,#'C&37        ; control C ?
  929.     beq    20$            ; yep
  930.     cmpb    r0    ,#15        ; carriage return ?
  931.     beq    30$            ; yep
  932.     movb    r0    ,(r1)+        ; return what we just got
  933.     cmpb    r0    ,#14        ; form feed ?
  934.     beq    40$            ; yep
  935. 15$:    sob    r3    ,10$        ; next please
  936. 20$:    mov    #ER$EOF    ,r0        ; say read error and exit
  937.     br    100$            ; bye
  938. 30$:    movb    #cr    ,(r1)+        ; return all terminators please
  939.     movb    #lf    ,(r1)+        ; simple
  940.     .TTYIN                ; eat the line feed now
  941. 40$:    clrb    @r1
  942.     sub    @r5    ,r1        ; the length
  943.     clr    r0
  944. 100$:    mov    (sp)+    ,r3
  945.     mov    (sp)+    ,r2
  946.     return
  947.  
  948.  
  949.  
  950.     .end
  951.