home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / mskermit / msxrmx.a86 < prev    next >
Text File  |  2020-01-01  |  37KB  |  1,082 lines

  1.         NAME    MSXRMX
  2. ; RMX System dependent module derived from Generic MS DOS Kermit module
  3.  
  4. $INCLUDE(mssdef.h86)
  5.  
  6.         public  serini, serrst, clrbuf, outchr, coms, vts, dodel, termtb, bddat
  7.         public  ctlu, cmblnk, locate, lclini, prtchr, dobaud, clearl, pcwait
  8.         public  dodisk, getbaud, beep, srcptr, sendbl, dtrtime, shomodem
  9.         public  xofsnt, puthlp, putmod, clrmod, poscur, savsi, portatt, sintok
  10.         public  sendbr, term, setktab, setkhlp, showkey, dtrlow, serhng
  11.         public  vtstat, ihosts, ihostr, dumpscr, comptab, costrt, coptr, spkout
  12.         public  chrout, chang, klogof, klogon, snull, cquit, cstatus, cquery
  13.  
  14. false   equ     0
  15. true    equ     1
  16.  
  17. ; external variables used:
  18. ; drives - # of disk drives on system
  19. ; flags - global flags as per flginfo structure defined in pcdefs
  20. ; trans - global transmission parameters, trinfo struct defined in pcdefs
  21. ; portval - pointer to current portinfo structure
  22. ; port1, port2 - portinfo structures for the corresponding ports
  23.  
  24. ; global variables defined in this module:
  25. ; xofsnt, xofrcv - tell whether we saw or sent an xoff.
  26.  
  27. datas   segment
  28. PURGE   prstr, dconio
  29.         extrn   drives:byte, flags:byte, trans:byte, citok:word, cotok:word
  30.         extrn   portval:word, prtbase:byte, oneport:byte, trmstr:byte
  31.         extrn   mbox:word, tmbox:word, sigpair:word, sematok:word, spkcnt:word
  32.         extrn   data:byte, pack:byte, combx:word, cimbx:word, termatt:word
  33.         extrn   trok:byte, rxtable:byte, kbdflg:byte, subpksz:word, source:byte
  34.         extrn   bufill:word, temp:word
  35.  
  36. erms40  db      cr,lf,'?Warning: Unrecognized baud rate',cr,lf,'$'
  37. erms60  db      cr,lf,'Port doesn''t exist, use RUN ATTACH . . .'
  38.         db      cr,lf,'& try again$'
  39. wrn1prt db
  40. &       bell,cr,lf,'Warning: No ports found, port 0 being used',cr,lf,bell,'$'
  41. badbd   db      cr,lf,'Unimplemented baud rate$'
  42. noimp   db      cr,lf,'Command not implemented.$'
  43. setktab db      0
  44. setkhlp db      0
  45. crlf    db      cr,lf,'$'
  46. delstr  db      BS,BS,' ',BS,'$'        ; Delete string.
  47. clrlin  db      cr                      ; Clear line (just the cr part).
  48. clreol  db      ESCAPE,'[0K'            ; Clear line.
  49. clscr   db      ESCAPE,'[2J'            ; clear screen
  50.  
  51. cursor  db      ESCAPE,'['              ; position cursor
  52. row     dw      ?                       ;  part
  53.         db      ';'                     ;   of
  54. col     dw      ?                       ; above
  55.         db      'H'                     ; last of above
  56.  
  57. mode    db      ESCAPE,'[24;1H',ESCAPE,'[0K'    ; put cursor on mode line & clea
  58. model   db      80 dup(?)               ; mode line contents
  59. huosc   db      ESCAPE,']M:H',ESCAPE,'\'        ; hangup OSC
  60.  
  61. xofsnt  db      0               ; Say if we sent an XOFF.
  62. xofrcv  db      0               ; Say if we received an XOFF.
  63. parmsk  db      ?               ; 8/7 bit parity mask, for reception
  64. savrflg db      ?               ; save previous remflg
  65. comstr  db      6,':COM_:'
  66. tstr    db      4,':T_:'
  67. devname db      14 dup(?)       ; :TERM:'s physical device name
  68.  
  69. ; Entries for choosing communications port. [19b]
  70. comptab db      10
  71.         %mkeyw  (%('0 (TERM)'),0)
  72.         %mkeyw  (%('1 (COM1 or T1)'),1)
  73.         %mkeyw  (%('2 (COM2 or T2)'),2)
  74.         %mkeyw  (%('3 (COM3 or T3)'),3)
  75.         %mkeyw  (%('4 (COM4 or T4)'),4)
  76.         %mkeyw  (%('5 (COM5 or T5)'),5)
  77.         %mkeyw  (%('6 (COM6 or T6)'),6)
  78.         %mkeyw  (%('7 (COM7 or T7)'),7)
  79.         %mkeyw  (%('8 (COM8 or T8)'),8)
  80.         %mkeyw  (%('9 (COM9 or T9)'),9)
  81.  
  82. ourarg  termarg <>
  83.  
  84. termtb  db      1
  85.         %mkeyw  (%('none'),ttgenrc)
  86.  
  87.         even
  88.  
  89. ten     dw      10
  90. dtrtime dw      500
  91. status  dw      ?
  92. sostrt  dw      ?
  93. soend   dw      ?
  94. sofin   dw      ?
  95. savsi   dw      source          ; points to next char in buffer
  96. srcptr  dw      source          ; points to next quadrant of buffer
  97. sintok  dw      0
  98. soutok  dw      0
  99. portptr dw      ?
  100. costrt  dw      ?
  101. coptr   dw      ?
  102. argadr  dw      ?
  103.  
  104. portatt dw      4,4,0ffh,119h   ; serial I/O port attributes for rqaspecial
  105. inbaud  dw      0,1             ; part of above
  106.  
  107. getptat dw      3,3,2 dup(?)    ; structure to read baud rate
  108. getinbd dw      ?               ; part of above
  109.  
  110. dest    db      2 dup (?)       ; outchr's buffer
  111.  
  112. ; This table is indexed by portinfo.baud.  Unsupported baud rates contain 0.
  113. bddat   label   word
  114.         dw      0               ;   45.5 baud  N/A
  115.         dw      50              ;     50 baud
  116.         dw      75              ;     75 baud
  117.         dw      110             ;    110 baud
  118.         dw      0               ;  134.5 baud  N/A
  119.         dw      150             ;    150 baud
  120.         dw      300             ;    300 baud
  121.         dw      600             ;    600 baud
  122.         dw      1200            ;   1200 baud
  123.         dw      1800            ;   1800 baud
  124.         dw      2000            ;   2000 baud
  125.         dw      2400            ;   2400 baud
  126.         dw      4800            ;   4800 baud
  127.         dw      9600            ;   9600 baud
  128.         dw      19200           ;  19200 baud
  129.         dw      38400           ;  38400 baud
  130.         dw      56800           ;  56800 baud
  131.         dw      0               ; 113600 baud  N/A
  132. datas   ends
  133.  
  134. code    segment
  135.         extrn   comnd:near, dopar:near, prserr:near, keybd:near, msuinit:near
  136.         extrn   delcon:near, crfile:near, opfile:near, writer:near
  137.         extrn   aspcl:near, prstr:near, awrite:near, rqsleep:near, flushci:near
  138.         extrn   waitio:near, sendms:near, aopen:near, aclose:near, special:near
  139.         extrn   rcvmsg:near, delseg:near, dconio:near, gfilsta:near
  140.  
  141. ; This is the HANGUP command.  It drops DTR momentarily, if the serial board
  142. ; and its driver support modem control.
  143.  
  144. dtrlow  PROC
  145. serhng: call    serrst                  ; reset & reinitialize port
  146.         call    serini
  147.         mov     ax,soutok               ; enable OSC's on output
  148.         mov     bx,offset portatt
  149.         and     word ptr[bx+4],0bfh
  150.         mov     cx,5
  151.         call    aspcl
  152.         mov     ax,soutok               ; send hangup OSC
  153.         mov     bx,offset huosc
  154.         mov     byte ptr[bx+4],'H'
  155.         mov     cx,size huosc
  156.         mov     dx,tmbox
  157.         call    awrite
  158.         mov     ax,soutok               ; wait for it
  159.         mov     bx,tmbox
  160.         call    waitio
  161.         mov     ax,dtrtime                      ; kill time
  162.         call    pcwait
  163.         mov     ax,soutok
  164.         mov     bx,offset huosc
  165.         mov     byte ptr[bx+4],'A'
  166.         mov     cx,size huosc           ; send answer OSC
  167.         mov     dx,tmbox
  168.         call    awrite
  169.         mov     ax,soutok               ; wait for it
  170.         mov     bx,tmbox
  171.         call    waitio
  172.         mov     ax,soutok               ; disable OSC's on output
  173.         mov     bx,offset portatt
  174.         or      word ptr[bx+4],40h
  175.         mov     cx,5
  176.         call    aspcl
  177.         call    serrst                  ; reset port
  178.         jmp     RSKP
  179. dtrlow  ENDP
  180.  
  181. pcwait  PROC            ; sleep for ax milliseconds (rounded up to nearest 10)
  182.         push    ax      ; too lazy to find out how much of this is necessary
  183.         push    bx
  184.         push    cx
  185.         push    dx
  186.         push    si
  187.         push    di
  188.         push    es
  189.         sub     dx,dx
  190.         add     ax,9
  191.         div     ten
  192.         push    ax
  193.         push    ds
  194.         mov     ax,offset status
  195.         push    ax
  196.         call    rqsleep
  197.         pop     es
  198.         pop     di
  199.         pop     si
  200.         pop     dx
  201.         pop     cx
  202.         pop     bx
  203.         pop     ax
  204.         ret
  205. pcwait  ENDP
  206.  
  207. ; IHOSTS - Initialize the host by sending XON, or equivalent, and enter the
  208. ; cycle of clear input buffer, test if buffer empty then exit, else repeat
  209. ; cycle. Requires that the port be initialized before hand.
  210. ; Ihosts is used by the local send-file routine just after initializing
  211. ; the serial port.
  212. ; 22 March 1986 [jrd]
  213.  
  214. IHOSTS  PROC
  215.         push    ax              ; save the registers
  216.         push    bx
  217.         push    cx
  218.         push    dx
  219.         mov     bx,portval      ; port indicator
  220.         mov     ax,[bx].flowc   ; put Go-ahead flow control char in ah
  221.         test    ah,ah           ; don't send null if flow=null
  222.         jz      ihosts1         ; z=null
  223.         call    outchr          ; send it (release Host's output queue)
  224.          nop                    ; outchr can do skip return
  225.          nop
  226.          nop
  227. ihosts1:call    clrbuf          ; clear out interrupt buffer
  228.         call    prtchr          ; check for char at port
  229.          jmp    ihosts1         ; have a char in al, repeat wait/read cycle
  230.          nop                    ; prtchr does skip return on empty buffer
  231.         pop     dx              ; empty buffer. we are done here.
  232.         pop     cx
  233.         pop     bx
  234.         pop     ax
  235.         ret
  236. IHOSTS  ENDP
  237.  
  238. ; IHOSTR - initialize the remote host for our reception of a file by
  239. ; sending the flow-on character (XON typically) to release any held
  240. ; data. Called by receive-file code just after initializing the serial
  241. ; port.         22 March 1986 [jrd]
  242. IHOSTR  PROC
  243.         push    ax              ; save regs
  244.         push    bx
  245.         push    cx
  246.         mov     bx,portval      ; port indicator
  247.         mov     ax,[bx].flowc   ; put Go-ahead flow control char in ah
  248.         test    ah,ah           ; don't send null if flow=null
  249.         jz      ihostr1         ; z=null
  250.         call    outchr          ; send it (release Host's output queue)
  251.          nop                    ; outchr can do skip return
  252.          nop
  253.          nop
  254. ihostr1:pop     cx
  255.         pop     bx
  256.         pop     ax
  257.         ret
  258. IHOSTR  ENDP
  259.  
  260. ; this is called by Kermit initialization.  It checks the
  261. ; number of disks on the system, sets the drives variable
  262. ; appropriately.  Returns normally.
  263.  
  264. DODISK  PROC
  265.         mov drives,1            ; 1 "disk".  It's $, which can be reattachfiled
  266.         ret
  267. DODISK  ENDP
  268.  
  269. ; Clear the input buffer. This throws away all the characters in the
  270. ; serial interrupt buffer.  This is particularly important when
  271. ; talking to servers, since NAKs can accumulate in the buffer.
  272. ; Returns normally.
  273.  
  274. CLRBUF  PROC
  275.         push    es
  276.         mov     ax,ds
  277.         mov     es,ax
  278.         cld
  279.         cli
  280.         mov     di,savsi                ; scan from current ptr
  281.         mov     cx,offset source+bufsiz
  282.         sub     cx,di                   ; to end of buffer for fill char
  283.         mov     al,byte ptr bufill
  284.         repne scasb
  285.         je      CLRB1                   ; jump if found
  286.         mov     di,offset source        ; scan from the beginning, if not
  287.         mov     cx,bufsiz
  288.         repne scasb
  289. CLRB1:  dec     di
  290.         mov     savsi,di                ; current ptr points to fill char
  291.         sti
  292.         pop     es
  293.         ret
  294. CLRBUF  ENDP
  295.  
  296. ; Put the char in AH to the serial port.  This assumes the
  297. ; port has been initialized.  Should honor xon/xoff.  Skip returns on
  298. ; success, returns normally if the character cannot be written.
  299.  
  300. outchr  PROC
  301.         push    bx
  302.         push    cx
  303.         push    dx
  304.         push    es
  305.         mov     al,ah
  306.         call    dopar           ; set parity, as req'd
  307.         mov     dest,al
  308.         mov     ax,soutok
  309.         mov     bx,offset dest  ; write it
  310.         mov     cx,1
  311.         sub     dx,dx
  312.         call    awrite
  313.         pop     es
  314.         pop     dx
  315.         pop     cx
  316.         pop     bx
  317.         cmp     status,0
  318.         jne     OUTCH1
  319.         jmp     RSKP            ; OK return
  320. OUTCH1: ret                     ; NG return
  321. outchr  ENDP
  322.  
  323. ; Set the baud rate for the current port, based on the value in the portinfo
  324. ; structure.  Returns normally.  Entered w/current baud rate in ax.
  325.  
  326. DOBAUD  PROC
  327.         push    bx
  328.         mov     bx,portval              ; see if new baud rate is OK
  329.         mov     si,[bx].baud
  330.         shl     si,1
  331.         mov     cx,bddat[si]
  332.         jcxz    DOBD1                   ; nope
  333.         call    serrst                  ; yeah, force serini to set it
  334.         pop     bx
  335.         ret
  336. DOBD1:  mov     [bx].baud,ax            ; restore previous baud rate
  337.         mov     dx,offset badbd         ; send bad baud msg
  338.         call    prstr
  339.         pop     bx
  340.         ret
  341. DOBAUD  ENDP
  342.  
  343. ; Get the current baud rate from the serial card and set it
  344. ; in the potinfo structure for the current port.  Returns normally.
  345. ; This is used during initialization.
  346.  
  347. GETBAUD PROC
  348.         ret                     ; It's all taken care of, so what's to do?
  349. GETBAUD ENDP
  350.  
  351.  
  352. ; Use for DOS 2.0 and above.  Check the port status.  If no data, skip return.
  353. ; Else, read in a char and return.  DX returns # chars (0 or 1 for us).
  354. PRTCHR  PROC
  355.         push    si
  356.         cmp     xofsnt,true             ; if XOF has been sent,
  357.         je      PRTCH4                  ; see if there's room in buffer for XON
  358. PRTCH1: sub     dx,dx                   ; # of chars
  359.         mov     si,savsi                ; current serial input buffer ptr
  360.         cld
  361.         lodsb
  362.         cmp     al,byte ptr bufill      ; got one?
  363.         jne     PRTCH2
  364.         pop     si                      ; nope
  365.         jmp     RSKP
  366. PRTCH2: cmp     si,offset source+bufsiz ; edge of the universe?
  367.         jb      PRTCH3                  ; no
  368.         mov     si,offset source        ; yeah, point to beginning
  369. PRTCH3: mov     savsi,si                ; update current ptr
  370.         inc     dx                      ; # chars=1
  371.         pop     si
  372.         ret                             ; got one return
  373. PRTCH4: mov     ax,srcptr               ; if next quadrant & current ptr are
  374.         sub     ax,savsi                ; 2 quadrants apart
  375.         jns     PRTCH5                  ; there's room to XON
  376.         add     ax,bufsiz
  377. PRTCH5: cmp     ax,bufsiz/2
  378.         jg      PRTCH1                  ; they aren't
  379.         push    bx                      ; send XON
  380.         mov     bx,portval
  381.         mov     ax,[bx].flowc
  382.         call    outchr
  383.          nop
  384.          nop
  385.          nop
  386.         mov     xofsnt,false            ; reset
  387.         pop     bx
  388.         jmp     PRTCH1
  389. PRTCHR  ENDP
  390.  
  391. ; Send a break out the current serial port.  Returns normally.
  392. SENDBR  PROC
  393. sendbl: mov     dx,offset noimp ; send intel's appologies
  394.         call    prstr           ; for not having OS support
  395.         ret                     ; for their hardware's capabilities
  396.  
  397. SENDBR  ENDP
  398.  
  399. ; Show modem command.  Not implemented.
  400. SHOMODEM PROC
  401.         mov     ah,cmcfm        ; get a confirm
  402.         call    comnd
  403.          ret                    ; no confirm
  404.          nop
  405.          nop
  406.         call    SENDBR          ; send not imp. msg
  407.         jmp     RSKP
  408. SHOMODEM ENDP
  409.  
  410. ; Clear to the end of the current line.  Returns normally.
  411.  
  412. CLEARL  PROC
  413.         push    bx
  414.         mov     bx,offset clreol        ; send ESC[0K
  415. SCRO1:  mov     cx,4                    ; to clear to end of line
  416. SCRO2:  push    ax
  417. SCRO3:  mov     ax,cotok
  418.         push    es
  419.         push    dx
  420.         push    si
  421.         call    writer
  422.         pop     si
  423.         pop     dx
  424.         pop     es
  425.         pop     ax
  426.         pop     bx
  427.         ret
  428. CLEARL  ENDP
  429.  
  430. ; This routine blanks the screen.  Returns normally.
  431.  
  432. CMBLNK  PROC
  433.         push    bx
  434.         mov     bx,offset clscr         ; send ESC[2J for clear screen
  435.         jmp     SCRO1
  436. CMBLNK  ENDP
  437.  
  438. ; Position the cursor according to contents of DX:
  439. ; DH contains row, DL contains column.  Returns normally.
  440. POSCUR  PROC
  441.         push    bx
  442.         push    ax
  443.         add     dx,101h         ; KERMIT starts w/0, RMX w/1
  444.         mov     al,dh           ; convert row to decimal
  445.         sub     ah,ah
  446.         mov     cl,10
  447.         div     cl
  448.         add     ax,'00'         ; covert to ASCII
  449.         mov     row,ax          ; stash in row portion of escape sequence
  450.         mov     al,dl           ; convert column to decimal
  451.         sub     ah,ah
  452.         div     cl
  453.         add     ax,'00'         ; convert to ASCII
  454.         mov     col,ax          ; to column portion of escape sequence
  455.         mov     bx,offset cursor
  456.         mov     cx,8            ; send ESC[row;colH to position cursor
  457.         jmp     SCRO3
  458. POSCUR  ENDP
  459.  
  460. ; Move the cursor to the left margin, then clear to end of line.
  461. ; Returns normally.
  462.  
  463. CTLU    PROC
  464.         push    bx
  465.         mov     bx,offset clrlin        ; send CR,ESC[0K to clear entire line
  466.         mov     cx,5
  467.         jmp     SCRO2
  468. CTLU    ENDP
  469.  
  470. ; Homes the cursor.  Returns normally.
  471.  
  472. LOCATE  PROC
  473.         mov     dx,0            ; Go to top left corner of screen.
  474.         jmp     poscur
  475. LOCATE  ENDP
  476.  
  477. ; Write a line at the bottom of the screen...
  478. ; the line is passed in dx, terminated by a $.  Returns normally.
  479. putmod  PROC
  480.         push    bx
  481.         push    ax
  482.         mov     bx,es           ; save es
  483.         mov     ax,ds
  484.         mov     es,ax
  485.         mov     di,dx
  486.         mov     cx,0ffffh       ; compute # bytes in line
  487.         mov     al,'$'
  488.         repne scasb
  489.         neg     cx
  490.         add     cx,0fffeh
  491.         mov     si,dx
  492.         mov     di,offset model
  493.         mov     dx,cx           ; save # bytes
  494.         rep movsb               ; move line after mode line escape sequence
  495.         mov     cx,size mode    ; mode line escape sequence length
  496.         add     cx,dx           ; plus line length
  497.         mov     es,bx           ; restore es
  498.         mov     bx,offset mode  ; write line prefixed w/escape sequence
  499.         jmp     SCRO3
  500. putmod  ENDP
  501.  
  502. ; clear the mode line written by putmod.  Returns normally.
  503. clrmod  PROC
  504.         push    bx
  505.         mov     bx,offset mode  ; mode line escape sequence
  506.         mov     cx,size mode    ; ESC[24;1HESC[0K
  507.         jmp     SCRO2           ; clears mode line
  508. clrmod  ENDP
  509.  
  510. ; Put a help message on the screen.
  511. ; Pass the message in ax, terminated by a null.  Returns normally.
  512. puthlp  PROC
  513.         push    dx
  514.         push    si
  515.         push    ax              ; preserve this
  516.         mov     dx,offset crlf
  517.         call    prstr
  518.         pop     si              ; point to string again
  519. puthl3: cld
  520.         lodsb                   ; get a byte
  521.         cmp     al,0            ; end of string?
  522.         je      puthl4          ; yes, stop
  523.         mov     dl,al
  524.         call    dconio          ; else write to screen
  525.         jmp     puthl3          ; and keep going
  526. puthl4: mov     dx,offset crlf
  527.         call    prstr
  528.         pop     si
  529.         pop     dx
  530.         ret
  531. puthlp  ENDP
  532.  
  533. ; Delete a character from the terminal.  This works by printing
  534. ; backspaces and spaces.  Returns normally.
  535.  
  536. DODEL   PROC
  537.         mov     dx,offset delstr
  538.         call    prstr           ; Erase weird character.
  539.         ret
  540. DODEL   ENDP
  541.  
  542. ; Set the current port.
  543. COMS    PROC
  544.         call    serrst          ; reset the old port
  545.         mov     dx,offset comptab
  546.         sub     bx,bx
  547.         mov     ah,cmkey
  548.         call    comnd           ; parse for the new one
  549.          ret
  550.          nop
  551.          nop
  552.         push    bx              ; save port #
  553.         mov     ah,cmcfm
  554.         call    comnd           ; Get a confirm.
  555.          jmp    short COMX      ; Didn't get a confirm.
  556.          nop
  557.         pop     cx              ; get port #
  558.         mov     ax,size prtinfo ; compute address of prtinfo structure
  559.         mul     cl
  560.         add     ax,offset prtbase
  561.         mov     temp,ax         ; save it
  562.         jcxz    COMS1           ; jmp if port 0 (:TERM:)
  563.         call    COMSR           ; crfile :COMn: or :Tn:
  564.         jz      COMS2           ; jmp if successful
  565.         mov     dx,offset erms60
  566.         call    prstr           ; no luck, bitch
  567.         ret
  568. COMX:   pop     bx
  569.         ret
  570. COMS1:  mov     di,offset trmstr
  571.         mov     temp+2,di       ; port name string pointer
  572.         call    crfile
  573. COMS2:  mov     bx,temp
  574.         mov     portval,bx      ; set prtinfo ptr
  575. COMS3:  mov     flags.comflg,cl ; remember port #
  576.         mov     sintok,ax       ; open port
  577.         mov     bx,1
  578.         call    aopen
  579.         call    rdbaud          ; read it's baud rate
  580.         mov     bx,portval
  581.         mov     [bx].baud,cx    ; memorize it
  582.         call    serrst          ; reset port
  583.         mov     di,temp+2       ; port name string pointer
  584.         mov     portptr,di
  585.         call    gfilsta         ; puts physical device name @temp+10
  586.         mov     ax,ds
  587.         mov     es,ax
  588.         mov     si,offset devname
  589.         mov     di,offset temp+10
  590.         mov     cx,size devname
  591.         repe cmpsb              ; is it the same as :TERM:?
  592.         je      COMS5           ; eq = yes
  593.         cmp     oneport,true    ; was it oneport?
  594.         jne     COMS4           ; ne = no, exit
  595.         mov     al,savrflg      ; yes, restore remflg to what it was before
  596.         mov     flags.remflg,al
  597.         mov     oneport,cl      ; clear oneport
  598. COMS4:  ret
  599. COMS5:  mov     al,dquiet       ; get current remflg & set to quiet mode
  600.         xchg    al,flags.remflg
  601.         cmp     oneport,true    ; if not previously one port
  602.         je      COMS4           ; save previous remflg & set oneport
  603.         mov     savrflg,al
  604.         mov     oneport,true    ; set oneport
  605.         ret
  606.  
  607. COMSR   proc
  608.         push    cx              ; save port #
  609.         add     cl,'0'          ; charify
  610.         mov     di,offset comstr
  611.         mov     temp+2,di       ; temp+2 is port name string pointer
  612.         mov     [di+5],cl       ; setup :COMn: & :Tn: strings
  613.         mov     tstr+3,cl
  614.         call    crfile          ; try COMn
  615.         jcxz    CSR1            ; OK
  616.         mov     di,offset tstr  ; try Tn
  617.         mov     temp+2,di
  618.         call    crfile
  619. CSR1:   test    cx,cx           ; return zero flag, if successful
  620.         pop     cx              ; restore port #
  621.         ret
  622. COMSR   endp
  623. COMS    ENDP
  624.  
  625. ; Reads serial port's baud rate.  Returns baud rate index in cx if recognizable
  626. ; by KERMIT, if not, cx=0ffffh.
  627.  
  628. rdbaud  PROC
  629.         push    es
  630.         mov     ax,sintok       ; use aspecial function 4 to read baud rate
  631.         mov     bx,offset getptat
  632.         mov     cx,4
  633.         call    aspcl
  634.         mov     ax,ds
  635.         mov     es,ax
  636.         mov     ax,getinbd      ; search bddat table for it
  637.         mov     cx,baudsiz
  638.         mov     di,offset bddat+2*(baudsiz-1)
  639.         std
  640.         repne scasw
  641.         cld
  642.         je      RDB1            ; found it, cx=index
  643.         mov     dx,offset erms40
  644.         call    prstr           ; not found, say so
  645.         mov     cx,0ffffh       ; return unrecognizable
  646. RDB1:   pop     es
  647.         ret
  648. rdbaud  ENDP
  649.  
  650. ; Set heath emulation on/off.
  651.  
  652. VTS     PROC
  653.         mov     dx,offset noimp
  654.         call    prstr
  655.         jmp     prserr
  656. VTS     ENDP
  657.  
  658. ; Initialize variables & find port
  659.  
  660. lclini: mov     flags.vtflg,0           ; Don't do terminal emulation.
  661.         call    msuinit
  662.  
  663.         mov     di,offset trmstr        ; get :TERM:'s physical devive name
  664.         call    gfilsta
  665.         mov     ax,ds
  666.         mov     es,ax
  667.         mov     si,offset temp+10       ; move it to devname
  668.         mov     di,offset devname
  669.         mov     cx,size devname
  670.         rep movsb
  671.  
  672.         mov     ax,offset prtbase       ; base value of prtinfo struc ptr
  673.         mov     ax,portval
  674.         mov     temp,ax                 ; save in case it ends up port 0
  675. LCL1:   add     portval,size prtinfo    ; loop thru looking for 1st of 1 to max
  676.         inc     cx                      ; 0 1st time thru
  677.         call    COMSR                   ; try crfile COMn or Tn
  678.         jz      LCL2                    ; z = success
  679.         cmp     cl,portmax-1            ; done?
  680.         jl      LCL1                    ; l = no
  681.         call    COMS1                   ; yes, go use :TERM:
  682.         mov     dx,offset wrn1prt       ; and give one port warning
  683.         call    prstr
  684.         ret
  685. LCL2:   jmp     COMS3                   ; join common code
  686.         ret
  687.  
  688. showkey:ret     ; obsolete, for ext def only
  689.  
  690. ; Initialization for using serial port.  Returns normally.
  691. SERINI  PROC
  692.         cmp     sintok,0        ; is this trip necessary?
  693.         jne     SIN3            ; no
  694.         push    bx
  695.         push    es
  696.         cmp     oneport,true    ; is it oneport?
  697.         jne     SIN1            ; ne = no
  698.         mov     ax,citok        ; yes, shut down citsk
  699.         sub     cx,cx
  700.         call    aclose
  701.         mov     ax,citok        ; reopen
  702.         mov     bx,3
  703.         call    aopen
  704.         call    flushci         ; necessary for 386
  705. SIN1:   mov     di,portptr      ; get port ptr
  706.         push    di              ; save for 2nd crfile
  707.         call    crfile          ; create it
  708.         mov     sintok,ax       ; set serial input token
  709.         mov     bx,1            ; open for reading
  710.         call    aopen
  711.  
  712.         pop     di              ; port ptr
  713.         call    crfile          ; create it
  714.         mov     soutok,ax       ; set serial output token
  715.         mov     bx,2            ; open for writing
  716.         call    aopen
  717.  
  718.         mov     bx,portval      ; prtinfo struc ptr
  719.         mov     parmsk,0ffh     ; set parmsk according to this port
  720.         cmp     [bx].parflg,parnon
  721.         je      SIN2
  722.         mov     parmsk,7fh
  723. SIN2:   mov     bx,[bx].baud    ; set baud rate according to this prot
  724.         shl     bx,1
  725.         mov     ax,bddat[bx]
  726.         mov     inbaud,ax
  727.  
  728.         mov     ax,soutok       ; set baud rate & attributes
  729.         mov     bx,offset portatt
  730.         mov     cx,5
  731.         call    aspcl
  732.  
  733.         mov     ax,mbox         ; when the message sent to mbox
  734.         mov     bx,ax           ; is the mbox token itself
  735.         call    sendms          ; it tells the serial input task
  736.         pop     es              ; to initialize & start input
  737.         pop     bx
  738. SIN3:   ret
  739. SERINI  ENDP
  740.  
  741. ; Reset the serial port.  This is the opposite of serini.  Calling
  742. ; this twice without intervening calls to serini should be harmless.
  743. ; Returns normally.
  744.  
  745. SERRST  PROC
  746.         push    bx
  747.         mov     bx,sintok       ; serial input token
  748.         test    bx,bx
  749.         jz      SERST1          ; unecessary
  750.         mov     sintok,0        ; MUST be done 1st, cuz siotsk is gonna get ints
  751.         call    delcon          ; before we get back from delete connection
  752. SERST1: mov     ax,soutok       ; serial output token
  753.         test    ax,ax
  754.         jz      SERST2          ; don't bother
  755.         push    ax              ; save for delcon
  756.         mov     cx,tmbox
  757.         push    cx              ; save for rcvmsg
  758.         call    aclose          ; let I/O complete before delcon
  759.         pop     ax
  760.         mov     bx,0ffffh
  761.         call    rcvmsg
  762.         call    delseg
  763.         pop     bx              ; soutok
  764.         mov     soutok,0        ; see above
  765.         call    delcon          ; ditto
  766.         cmp     oneport,true
  767.         jne     SERST2
  768.         call    flushci         ; necessary for 386
  769.         mov     ax,citok
  770.         mov     bx,offset termatt
  771.         mov     cx,5
  772.  
  773.         call    aspcl
  774.         mov     ax,cimbx        ; restart citsk
  775.         mov     bx,ax
  776.         call    sendms
  777. SERST2: pop     bx
  778.         ret
  779. SERRST  ENDP
  780.  
  781. ; Bell ringer
  782.  
  783. BEEP    PROC
  784.         mov     dl,bell
  785.         call    dconio
  786.         ret
  787. BEEP    ENDP
  788.  
  789. VTSTAT  PROC    ; For Status display [jrd]
  790.         ret             ; no emulator status to display
  791. VTSTAT  ENDP
  792.  
  793. ; Save the screen to a buffer and then append buffer to a disk file. [jrd]
  794. ; Default filename is Kermit.scn; actual file can be a device too. Filename
  795. ; is determined by mssset and is passed as pointer dmpname.
  796.  
  797. DUMPSCR PROC    ; Dumps screen contents to a file. Just Beeps here
  798.         jmp     beep    ; [jrd]
  799. DUMPSCR ENDP
  800.  
  801. ; Dumb terminal emulator.
  802. TERM    PROC
  803.         cmp     oneport,true            ; if oneport
  804.         jne     TERM1
  805.         mov     kbdflg,'C'              ; force exit connect mode
  806.         jmp     BEEP
  807. TERM1:  mov     si,ax                   ; this is source
  808.         mov     di,offset ourarg        ; place to store arguments
  809.         mov     ax,ds
  810.         mov     es,ax                   ; address destination segment
  811.         mov     cx,size termarg
  812.         cld
  813.         rep movsb                       ; copy into our arg blk
  814.         mov     parmsk,0ffh
  815.         cmp     ourarg.parity,parnon
  816.         je      TERM2
  817.         mov     parmsk,7fh
  818. TERM2:  mov     ax,citok                ; shut down citsk & reopen citok
  819.         call    aclose
  820.         mov     ax,citok
  821.         mov     bx,3
  822.         call    aopen
  823.  
  824.         sub     ax,ax                   ; turn off control C trap
  825.         mov     sigpair,ax
  826.         mov     ax,citok
  827.         mov     bx,offset sigpair
  828.         mov     cx,6
  829.         call    aspcl
  830.  
  831.         push    termatt+6               ; save
  832.         cmp     trok,true
  833.         je      TERM3
  834.         and     termatt+6,0fdffh        ; turn off translation
  835. TERM3:  push    termatt+4               ; save
  836.         or      termatt+4,0e0h          ; disable OSC's & output ctrl chars
  837.         mov     ax,cotok                ; make it transparent as all get out
  838.         mov     bx,offset termatt       ; during terminal emulation
  839.         mov     cx,5
  840.         call    special
  841.         mov     ax,citok
  842.         mov     bx,offset termatt
  843.         mov     cx,5
  844.         call    aspcl
  845.  
  846.         mov     ax,cimbx                ; start citsk & cotsk
  847.         mov     bx,ax
  848.         call    sendms
  849.         mov     ax,combx
  850.         mov     bx,ax
  851.         call    sendms
  852.  
  853.         mov     ax,ds
  854.         mov     es,ax
  855.  
  856. TERM4:  call    PORTCHR                 ; get char from port
  857.          call   OUTTTY                  ; if char, output it
  858.         call    KEYBD                   ; check keyboard
  859.         jnc     TERM4                   ; carry=exit Connect mode
  860.  
  861.         pop     termatt+4               ; restore
  862.         pop     termatt+6               ; restore
  863.  
  864.         mov     ax,combx                ; shut down cotsk
  865.         mov     bx,ax
  866.         call    sendms
  867.  
  868.         mov     ax,citok                ; shut down citsk & reopen citok
  869.         call    aclose
  870.         mov     ax,citok
  871.         mov     bx,3
  872.         call    aopen
  873.  
  874.         mov     ax,sematok              ; restore control C trap
  875.         mov     sigpair,ax
  876.         mov     ax,citok
  877.         mov     bx,offset sigpair
  878.         mov     cx,6
  879.         call    aspcl
  880.  
  881.         mov     ax,cotok                ; reopen cotok
  882.         mov     bx,3
  883.         mov     cx,bx
  884.         call    opfile
  885.  
  886.         mov     ax,citok                ; restore terminal attributes
  887.         mov     bx,offset termatt
  888.         mov     cx,5
  889.         call    aspcl
  890.         mov     ax,cotok
  891.         mov     bx,offset termatt
  892.         mov     cx,5
  893.         call    special
  894.  
  895.         mov     ax,cimbx                ; restart citsk
  896.         mov     bx,ax
  897.         call    sendms
  898.  
  899.         ret
  900. TERM    ENDP
  901.  
  902. ;; keyboard translator action routines, system dependent, called from msurmx.
  903. ; These are invoked by a jump instruction. Return carry clear for normal
  904. ; processing, return carry set exit Connect mode (kbdflg has transfer char).
  905.  
  906. klogon  proc                            ; resume logging (if any)
  907.         test    flags.capflg,logses     ; session logging enabled?
  908.         jz      klogn                   ; z = no, forget it
  909.         or      argadr.flgs,capt        ; turn on capture flag
  910.         or      ourarg.flgs,capt        ; turn on local capture flag as well
  911. klogn:  clc
  912.         ret
  913. klogon  endp
  914.  
  915. klogof  proc                            ; suspend logging (if any)
  916.         and     argadr.flgs,not capt    ; stop capturing
  917.         and     ourarg.flgs,not capt    ; rest local as well
  918.         clc
  919.         ret
  920. klogof  endp
  921.  
  922. snull:  mov     ah,0                    ; send a null
  923.         call    outchr                  ; send without echo or logging
  924.          nop
  925.          nop
  926.          nop
  927.         clc
  928.         ret
  929.  
  930. cmdcom: mov     kbdflg,al               ; pass char to msster.asm via kbdflg
  931.         stc                             ; say exit Connect mode
  932.         ret
  933. cstatus:mov     al,'S'                  ; these commands exit Connect mode
  934.         jmp     cmdcom
  935. cquit:  mov     al,'C'
  936.         jmp     cmdcom
  937. cquery: mov     al,'?'
  938.         jmp     cmdcom
  939. chang:  mov     al,'H'
  940.         jmp     cmdcom
  941.  
  942. ;; end of action routines
  943.  
  944. OUTTTY  PROC
  945.         cmp     rxtable+256,0           ; translation turned off?
  946.         je      OTY1                    ; e = yes, no translation
  947.         push    bx
  948.         mov     bx,offset rxtable       ; address of translate table [jrd]
  949.         xlatb                           ; new char is in al
  950.         pop     bx
  951. OTY1:   test    ourarg.flgs,capt        ; capturing output?
  952.         jz      OTY2                    ; no, forget it
  953.         push    ax
  954.         call    ourarg.captr            ; else call the routine
  955.         pop     ax
  956. OTY2:   test    ourarg.flgs,trnctl      ; debugging?  nz=yes
  957.         jnz     OTY3                    ; bypass translation & do debug display
  958.         test    flags.remflg,d8bit      ; keep 8 bits for displays?
  959.         jnz     OUTONE                  ; nz = yes, 8 bits if possible
  960.         and     al,7fh                  ; remove high bit
  961.  
  962. OUTONE  PROC
  963.         mov     di,coptr                ; CO buffer pointer
  964.         sub     di,costrt               ; is buffer full?
  965.         cmp     di,cobufl
  966.         je      OUTONE                  ; eq=yes, wait for room
  967.  
  968.         cli                             ; disable ints during
  969.         mov     di,coptr                ; these 3
  970.         stosb                           ; critical
  971.         mov     coptr,di                ; instructions
  972.         sti
  973.  
  974.         ret
  975. OUTONE  ENDP
  976.  
  977. OTY3:   test    al,al                   ; is high bit on?
  978.         jns     OTY4                    ; ns=no
  979.         mov     ah,al                   ; save it
  980.         mov     al,'~'                  ; output tilde
  981.         call    OUTONE
  982.         mov     al,ah                   ; restore it & turn off high bit
  983.         and     al,7fh
  984. OTY4:   cmp     al,7fh                  ; is it rubout?
  985.         jne     OTY5                    ; ne=no
  986.         and     al,3fh                  ; convert to ?
  987.         jmp     short OTY6              ; to display ^? for rubout
  988. OTY5:   cmp     al,' '                  ; is it a control character?
  989.         jae     OUTONE                  ; ae=no, just output it
  990.         add     al,'@'                  ; make printable
  991. OTY6:   mov     ah,al                   ; save
  992.         mov     al,'^'                  ; output ^
  993.         call    OUTONE
  994.         mov     al,ah                   ; restore & output
  995.         jmp     OUTONE
  996. OUTTTY  ENDP
  997.  
  998. CHROUT  PROC
  999.         test    ourarg.flgs,lclecho     ; echoing?
  1000.         jz      CHRO1                   ; no, don't bother
  1001.         push    ax
  1002.         call    OUTTTY
  1003.         pop     ax
  1004. CHRO1:  mov     ah,al
  1005.         call    outchr                  ; output the character
  1006.          nop
  1007.          nop
  1008.          nop
  1009.         ret
  1010. CHROUT  ENDP
  1011.  
  1012. SPKOUT  PROC
  1013.         inc     spkcnt          ; bump ctr
  1014.         cmp     ah,trans.ssoh
  1015.         je      SPK4            ; eq = start of packet
  1016.         cmp     bx,soend
  1017.         je      SPK1            ; eq = enough to write
  1018.         clc
  1019.         ret
  1020.  
  1021. SPK1:   push    cx
  1022.         push    bx
  1023.         push    ax
  1024.         push    dx
  1025.         mov     cx,bx           ; bx is last byte+1
  1026.         xchg    bx,sostrt       ; bx = current 1st byte, sostrt = next 1st byte
  1027.         sub     cx,bx           ; cx = # bytes
  1028.  
  1029.         mov     ax,soutok       ; call rqawrite(soutok,ds:bx,cx,0,@status)
  1030.         sub     dx,dx
  1031.         call    awrite
  1032.         pop     dx
  1033.         pop     ax
  1034.         mov     bx,sostrt
  1035.         mov     cx,sofin
  1036. SPK2:   add     bx,subpksz      ; next time to write (soend) =
  1037.         cmp     bx,cx           ; min{sofin,(sostrt + subpksz)}
  1038.         jb      SPK3
  1039.         mov     bx,cx
  1040. SPK3:   mov     soend,bx
  1041.         pop     bx
  1042.         pop     cx
  1043.         clc
  1044.         ret
  1045.  
  1046. SPK4:   push    cx
  1047.         push    bx              ; start of packet
  1048.         dec     bx              ; point to soh
  1049.         mov     sostrt,bx       ; set sub-packet start ptr
  1050.         sub     cx,cx
  1051.         mov     cl,trans.chklen
  1052.         add     cx,offset data
  1053.         add     cx,pack.argbk1
  1054.         inc     cx
  1055.         mov     sofin,cx        ; sofin = end of packet ptr
  1056.         jmp     SPK2
  1057. SPKOUT  ENDP
  1058.  
  1059. PORTCHR PROC
  1060.         call    prtchr          ; get char from port
  1061.          jmp    short PORCH1    ; got one
  1062.          nop
  1063.         jmp     short RSKP      ; don't got
  1064. PORCH1: and     al,parmsk       ; apply 8/7 bit parity mask
  1065.         jz      RSKP            ; filter nulls
  1066.         cmp     al,del          ; filter rubouts
  1067.         je      RSKP
  1068.         ret
  1069. PORTCHR ENDP
  1070.  
  1071. ; Jumping to this location is like retskp.  It assumes the instruction
  1072. ;   after the call is a jmp addr.
  1073.  
  1074. RSKP    PROC
  1075.         pop     bp
  1076.         add     bp,3
  1077.         jmp     bp
  1078. RSKP    ENDP
  1079.  
  1080. code    ends
  1081.         end
  1082.