home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / mskermit / msxdm2.asm < prev    next >
Assembly Source File  |  2020-01-01  |  26KB  |  744 lines

  1.         name msxdm2
  2. ; File MSXDM2.ASM
  3. ; Last modification: 20 April 1986
  4.  
  5. ; DECmate II MS DOS Kermit module
  6. ; Add global entry point vtstat for use by Status in mssset.
  7. ; Also trimmed off trailing commas from publics. Joe R. Doupnik 12 March 1986
  8. ; Add global procedures ihosts and ihostr to handle host initialization
  9. ; when packets are to be sent or received by us,resp. 24 March 1986
  10. ; Add global procedure dtrlow (without worker serhng) to force DTR & RTS low
  11. ; in support of Kermit command Hangup. Says Not Yet Implemented. [jrd]
  12. ; Add small fixups in procedure coms. [jrd]
  13. ; Revise procedure outchr to use dos 2.x file handles rather than "punout"
  14. ; which defaults to the Printer! Make proc Clrbuf read from the comms port.
  15. ; Add global procedure Dumpscr, called by Ter in file msster, to dump screen
  16. ;  to a file. Just does a beep for now. 13 April 1986 [jrd]
  17. ; In proc Outchr add override of xon from chkxon sending routine.
  18. ;  This makes a hand typed Xoff supress the xon flow control character sent
  19. ;  automatically as the receiver buffer empties. 20 April 1986 [jrd]
  20.  
  21. PAGE 66,120
  22.  
  23.         public  serini, serrst, clrbuf, outchr, coms, vts, vtstat, dodel
  24.         public  ctlu, cmblnk, locate, lclini, prtchr, dobaud, clearl
  25.         public  dodisk, getbaud, beep
  26.         public  count, xofsnt, puthlp, putmod, clrmod, poscur
  27.         public  sendbr, term, machnam, setktab, setkhlp, showkey
  28.         public  ihosts, ihostr, dtrlow, dumpscr                 ; [jrd]
  29.         include mssdef.h
  30.  
  31. false   equ     0
  32. true    equ     1
  33. instat  equ     6
  34. rddev   equ     3fH
  35. open    equ     3dH
  36.  
  37. ; external variables used:
  38. ; drives - # of disk drives on system
  39. ; flags - global flags as per flginfo structure defined in pcdefs
  40. ; trans - global transmission parameters, trinfo struct defined in pcdefs
  41. ; portval - pointer to current portinfo structure (currently either port1
  42. ;    or port2)
  43. ; port1, port2 - portinfo structures for the corresponding ports
  44.  
  45. ; global variables defined in this module:
  46. ; xofsnt, xofrcv - tell whether we saw or sent an xoff.
  47.  
  48. datas   segment public 'datas'
  49.         extrn   drives:byte,flags:byte, trans:byte
  50.         extrn   portval:word, port1:byte, port2:byte
  51.         extrn   comand:byte, dmpname:byte                       ; [jrd]
  52.  
  53. machnam db      'DECmate II MS-DOS 2.0$'
  54. erms20  db      cr,lf,'?Warning: System has no disk drives$' ; [21a]
  55. erms40  db      cr,lf,'?Warning: Unrecognized baud rate$'
  56. erms41  db      cr,lf,'?Warning: Cannot open com port$'
  57. erms50  db      cr,lf,'Error reading from device$'
  58. hnd1    db      cr,lf,'Enter a file handle.  Check your DOS manual if you are '
  59.         db      cr,lf,'not certain what value to supply (generally 3).$'
  60. hnd2    db      cr,lf,'Handle: $'
  61. hnderr  db      cr,lf,'Warning: Handle not known.'
  62. deverr  db      cr,lf,'Any routine using the communications port will'
  63.         db      cr,lf,'probably not work.$'
  64. hndhlp  db      cr,lf,'A four digit file handle $'
  65. dev1    db      cr,lf,'Device: $'
  66. devhlp  db      cr,lf,'Name for your systems auxiliary port $'
  67. badbd   db      cr,lf,'Unimplemented baud rate$'
  68. noimp   db      cr,lf,'Command not implemented.$'
  69. hngmsg  db      cr,lf,' The phone should have hungup.',cr,lf,'$' ; [jrd]
  70. hnghlp  db      cr,lf,' The modem control lines DTR and RTS for the current'
  71.         db      ' port are forced low (off)'
  72.         db      cr,lf,' to hangup the phone. Normally, Kermit leaves them'
  73.         db      ' high (on) when it exits.'
  74.         db      cr,lf,'$'                                       ; [jrd]
  75. rdbuf   db      80 dup (?)      ; temp buf [jrd]
  76. shkmsg  db      'Not implemented.'
  77. shklen  equ     $-shkmsg
  78. setktab db      0
  79. setkhlp db      0
  80. gopos   db      esc,'['
  81. rowp    db      20 dup (?)
  82. crlf    db      cr,lf,'$'
  83. delstr  db      BS,' ',BS,'$'           ; Delete string. [21d]
  84. clrlin  db      cr,'$'                  ; Clear line (just the cr part).
  85. clreol  db      ESC,'[K$'               ; Clear line.
  86. clrseq  db      esc,'[H',esc,'[J$'      ;clear screen home cursor.
  87. telflg  db      0               ; non-zero if we're a terminal.
  88. xofsnt  db      0               ; Say if we sent an XOFF.
  89. xofrcv  db      0               ; Say if we received an XOFF.
  90. count   dw      0               ; Number of chars in int buffer.
  91. prthnd  dw      0               ; Port handle.
  92. prttab  dw      com2,com1
  93. com1    db      'COM1',0
  94. com2    db      'COM2',0
  95. tmp     db      ?,'$'
  96. temp    dw      0
  97. temp1   dw      ?               ; Temporary storage.
  98. temp2   dw      ?               ; Temporary storage.
  99. ;;;[jrd]rdbuf   db      20 dup(?)       ; Buffer for input.
  100. prtstr  db      20 dup(?)       ; Name of auxiliary device. [27d]
  101.  
  102. ; Entries for choosing communications port. [19b]
  103. comptab db      6               ; Number of options
  104.         mkeyw   '1',01H
  105.         mkeyw   '2',00H
  106.         mkeyw   'COM1',01H
  107.         mkeyw   'COM2',00H
  108.         mkeyw   'DEVICE',02H
  109.         mkeyw   'FILE-HANDLE',03H
  110.  
  111. ourarg  termarg <>
  112.  
  113. datas   ends
  114.  
  115. code    segment public 'code'
  116.         extrn   comnd:near, dopar:near, prserr:near, atoi:near, prompt:near
  117.         extrn   sleep:near                              ; [jrd]
  118.         assume  cs:code,ds:datas
  119.  
  120. ; this is called by Kermit initialization.  It checks the
  121. ; number of disks on the system, sets the drives variable
  122. ; appropriately.  Returns normally.
  123.  
  124. DODISK  PROC    NEAR
  125.         mov ah,gcurdsk                  ; Current disk value to AL.
  126.         int dos
  127.         mov dl,al                       ; Put current disk in DL.
  128.         mov ah,seldsk                   ; Select current disk.
  129.         int dos                         ; Get number of drives in AL.
  130.         mov drives,al
  131.         ret
  132. DODISK  ENDP
  133.  
  134. ; Clear the input buffer. This throws away all the characters in the
  135. ; serial interrupt buffer.  This is particularly important when
  136. ; talking to servers, since NAKs can accumulate in the buffer.
  137. ; Do nothing since we are not interrupt driven.  Returns normally.
  138.  
  139. CLRBUF  PROC    NEAR
  140.         ret
  141. CLRBUF  ENDP
  142.  
  143. ; Clear to the end of the current line.  Returns normally.
  144.  
  145. CLEARL  PROC    NEAR
  146.         push    ax              ; save regs [jrd]
  147.         push    dx
  148.         mov ah,prstr
  149.         mov dx,offset clreol
  150.         int dos
  151.         pop     dx
  152.         pop     ax
  153.         ret
  154. CLEARL  ENDP
  155.  
  156. ; Put the char in AH to the serial port.  This assumes the
  157. ; port has been initialized.  Should honor xon/xoff.  Skip returns on
  158. ; success, returns normally if the character cannot be written.
  159.  
  160. outchr: mov bp,portval
  161.         cmp ds:[bp].floflg,0    ; Are we doing flow control.
  162.         je outch2               ; No, just continue.
  163.         xor cx,cx               ; clear counter
  164.         cmp ah,byte ptr [bp].flowc      ; sending xoff? [jrd]
  165.         jne outch1              ; ne = no
  166.         mov xofsnt,false        ; supress xon from chkxon buffer routine
  167. outch1: cmp xofrcv,true         ; Are we being held?
  168.         jne outch2              ; No - it's OK to go on.
  169.         loop outch1             ; held, try for a while
  170.         mov xofrcv,false        ; timed out, force it off and fall thru.
  171. outch2: push dx                 ; Save register.
  172.         mov al,ah               ; Parity routine works on AL.
  173.         call dopar              ; Set parity appropriately.
  174.                                 ; Begin revised output routine. [jrd]
  175.         cmp prthnd,0            ; Got a handle yet? [27d]
  176.         jne outch3              ; Yup just go on. [27d]
  177.         call opnprt             ; Else 'open' the port. [27d]
  178. outch3: push    bx
  179.         mov     bx,prthnd       ; port handle
  180.         mov     cx,1            ; one byte to write
  181.         mov     dx,offset temp  ; place where data will be found
  182.         mov     byte ptr temp,al ; put data there
  183.         mov     ah,write2       ; dos 2 write to file/device
  184.         int     dos
  185.         pop     bx              ; end of revised routine
  186. ;;;     mov dl,al
  187. ;;;     mov ah,punout           ; Output char in DL to comm port.
  188. ;;;     int dos
  189.         pop dx
  190.         jmp rskp
  191.  
  192. ; This routine blanks the screen.  Returns normally.
  193.  
  194. CMBLNK  PROC    NEAR
  195.         mov ah,prstr
  196.         mov dx,offset clrseq    ;erase the screen
  197.         int dos
  198.         ret
  199. CMBLNK  ENDP
  200.  
  201. ; Homes the cursor.  Returns normally.
  202.  
  203. LOCATE  PROC    NEAR
  204.         mov dx,0                ; Go to top left corner of screen.
  205.         jmp poscur
  206. LOCATE  ENDP
  207.  
  208. ; Write a line at the bottom of the screen...
  209. ; the line is passed in dx, terminated by a $.  Returns normally.
  210. putmod  proc    near
  211.         push    dx              ; preserve message
  212.         mov     dx,1800h        ; now address line 24
  213.         call    poscur
  214.         pop     dx              ; get message back
  215.         mov     ah,prstr
  216.         int     dos             ; write it out
  217.         ret                     ; and return
  218. putmod  endp
  219.  
  220. ; clear the mode line written by putmod.  Returns normally.
  221. clrmod  proc    near
  222.         mov     dx,1800h
  223.         call    poscur          ; Go to bottom row.
  224.         call    clearl          ; Clear to end of line.
  225.         ret
  226. clrmod  endp
  227.  
  228. ; Put a help message on the screen.
  229. ; Pass the message in ax, terminated by a null.  Returns normally.
  230. puthlp  proc    near
  231.         push    dx              ; save regs [jrd]
  232.         push    si
  233.         push    ax              ; preserve this
  234.         mov     ah,prstr
  235.         mov     dx,offset crlf
  236.         int     dos
  237.         pop     si              ; point to string again
  238. puthl3: lodsb                   ; get a byte
  239.         cmp     al,0            ; end of string?
  240.         je      puthl4          ; yes, stop
  241.         mov     dl,al
  242.         mov     ah,dconio
  243.         int     dos             ; else write to screen
  244.         jmp     puthl3          ; and keep going
  245. puthl4: mov     ah,prstr
  246.         mov     dx,offset crlf
  247.         int     dos
  248.         pop     si              ; [jrd]
  249.         pop     dx
  250.         ret
  251. puthlp  endp
  252.  
  253. ; Set the baud rate for the current port, based on the value
  254. ; in the portinfo structure.  Returns normally.
  255.  
  256. DOBAUD  PROC    NEAR
  257.         mov ah,prstr
  258.         mov dx,offset noimp     ; Say it's not implemented.
  259.         int dos
  260.         push bx                 ; [jrd]
  261.         mov bx,portval
  262.         mov [bx].baud,0FFFFH    ; So it's not a recognized value.
  263.         pop bx                  ; [jrd]
  264.         ret                     ; Must be set before starting Kermit.
  265. DOBAUD  ENDP
  266.  
  267. ; Get the current baud rate from the serial card and set it
  268. ; in the portinfo structure for the current port.  Returns normally.
  269. ; This is used during initialization.
  270.  
  271. GETBAUD PROC    NEAR
  272.         ret                     ; Can't do this.
  273. GETBAUD ENDP
  274.  
  275. ; Use for DOS 2.0 and above.  Check the port status.  If no data, skip
  276. ; return.  Else, read in a char and return.
  277. ; Minor patch by [jrd]
  278. PRTCHR  PROC    NEAR
  279.         push bx
  280.         push cx
  281.         push si
  282.         push bp
  283.         cmp prthnd,0            ; Got a handle yet? [27d]
  284.         jne prtch0              ; Yup just go on. [27d]
  285.         call opnprt             ; Else 'open' the port. [27d]
  286. prtch0: call chkxon
  287.         mov bx,prthnd
  288.         mov al,instat
  289.         mov ah,ioctl
  290.         int dos
  291.         or al,al
  292.         jz prtch4               ; not ready...
  293.         mov bx,prthnd
  294.         mov ah,rddev
  295.         mov cx,1
  296.         mov dx,offset temp
  297.         int dos
  298.         jnc prtch1              ; nc = no error. [jrd]
  299.         cmp al,5                ; Error condition.
  300.         je prt3x
  301.         cmp al,6                ; Error condition
  302.         je prt3x
  303. prtch1: mov al,byte ptr temp    ; [jrd]
  304.         mov bp,portval
  305.         cmp ds:[bp].parflg,PARNON       ; no parity?
  306.         je prtch3               ; then don't strip
  307.         and al,7fh              ; else turn off parity
  308. prtch3: pop bp
  309.         pop si
  310.         pop cx
  311.         pop bx
  312.         ret
  313. prt3x:  mov ah,prstr
  314.         mov dx,offset erms50
  315.         int dos
  316. prtch4: pop bp
  317.         pop si
  318.         pop cx
  319.         pop bx
  320.         jmp rskp                ; no chars...
  321. PRTCHR  ENDP
  322.  
  323. ; Local routine to see if we have to transmit an xon
  324. chkxon  proc    near
  325.         push    bx
  326.         mov     bx,portval
  327.         cmp     [bx].floflg,0   ; doing flow control?
  328.         je      chkxo1          ; no, skip all this
  329.         cmp     xofsnt,false    ; have we sent an xoff?
  330.         je      chkxo1          ; no, forget it
  331.         mov     ax,[bx].flowc   ; ah gets xon
  332.         call    outchr          ; send it
  333.         nop
  334.         nop
  335.         nop                     ; in case it skips
  336.         mov     xofsnt,false    ; remember we've sent the xon.
  337. chkxo1: pop     bx              ; restore register
  338.         ret                     ; and return
  339. chkxon  endp
  340.  
  341. ; IHOSTS - Initialize the host by sending XON, or equivalent, and enter the
  342. ; cycle of clear input buffer, wait 1 second, test if buffer empty then exit
  343. ; else repeat cycle. Requires that the port be initialized before hand.
  344. ; Ihosts is used by the local send-file routine just after initializing
  345. ; the serial port.
  346. ; 22 March 1986 [jrd]
  347.  
  348. IHOSTS  PROC    NEAR
  349.         push    ax              ; save the registers
  350.         push    bx
  351.         push    cx
  352.         push    dx
  353.         mov     bx,portval      ; port indicator
  354.         mov     ax,[bx].flowc   ; put Go-ahead flow control char in ah
  355.         call    outchr          ; send it (release Host's output queue)
  356.          nop                    ; outchr can do skip return
  357.          nop
  358.          nop
  359. ihosts1:call    clrbuf          ; clear out interrupt buffer
  360.         mov     ax,1            ; sleep for 1 second
  361.         call    sleep           ; procedure sleep is in msscom.asm
  362.         call    prtchr          ; check for char at port
  363.          jmp    ihosts1         ; have a char in al, repeat wait/read cycle
  364.          nop                    ; prtchr does skip return on empty buffer
  365.         pop     dx              ; empty buffer. we are done here.
  366.         pop     cx
  367.         pop     bx
  368.         pop     ax
  369.         ret
  370. IHOSTS  ENDP
  371.  
  372. ; IHOSTR - initialize the remote host for our reception of a file by
  373. ; sending the flow-on character (XON typically) to release any held
  374. ; data. Called by receive-file code just after initializing the serial
  375. ; port.         22 March 1986 [jrd]
  376. IHOSTR  PROC    NEAR
  377.         push    ax              ; save regs
  378.         push    bx
  379.         push    cx
  380.         mov     bx,portval      ; port indicator
  381.         mov     ax,[bx].flowc   ; put Go-ahead flow control char in ah
  382.         call    outchr          ; send it (release Host's output queue)
  383.          nop                    ; outchr can do skip return
  384.          nop
  385.          nop
  386.         pop     cx
  387.         pop     bx
  388.         pop     ax
  389.         ret
  390. IHOSTR  ENDP
  391.  
  392. DTRLOW  PROC    NEAR            ; Global proc to Hangup the Phone by making
  393.                                 ; DTR and RTS low.
  394.         mov ah,cmtxt            ; allow text to be able to display help
  395.         mov bx,offset rdbuf     ; dummy buffer
  396.         mov dx,offset hnghlp    ; help message
  397.         call comnd              ; get a confirm
  398.          jmp r
  399. ; not yet imp.  call serhng             ; drop DTR and RTS
  400.         mov ah,prstr            ; give a nice message
  401. ; not yet imp.  mov dx,offset hngmsg
  402.         mov dx,offset noimp     ; for now
  403.         int dos
  404.         jmp rskp
  405. DTRLOW  ENDP
  406.  
  407. ; Hang up the Phone. Similar to SERRST except it just forces DTR and RTS low
  408. ; to terminate the connection. 29 March 1986 [jrd]
  409. ; Calling this twice without intervening calls to serini should be harmless.
  410. ; Returns normally.
  411. ; SERHNG is Not Yet Implemented.
  412.  
  413.  
  414. ; Send a break out the current serial port.  Returns normally.
  415. SENDBR  PROC    NEAR
  416.         push    dx              ;save the register to be used
  417.         mov     ah,03           ;class description 3 comm channel
  418.         mov     al,0bH          ;send break to port
  419.         mov     dl,1cH          ;send a 280 millisend break
  420.         int     05fH            ;call extended bios to do it
  421.         pop     dx
  422.         ret
  423. SENDBR  ENDP
  424.  
  425. ; Position the cursor according to contents of DX:
  426. ; DH contains row, DL contains column.  Returns normally.
  427. POSCUR  PROC    NEAR
  428.         add     dx,101H         ;start at column 1,1
  429.         push    ax              ; [jrd]
  430.         push    bx
  431.         push    cx
  432.         push    di
  433.         push    es
  434.         push    dx
  435.         cld
  436.         mov     ax,ds
  437.         mov     es,ax           ;address right segment
  438.         mov     di,offset rowp  ;row comes first
  439.         mov     al,dh
  440.         mov     ah,0
  441.         call    nout            ;store the characters into di
  442.         mov     al,';'          ;separated with this
  443.         stosb
  444.         pop     dx              ;get back column number
  445.         mov     al,dl
  446.         mov     ah,0
  447.         call    nout            ;store as ascii data
  448.         mov     al,'H'          ;terminator for dca
  449.         stosb
  450.         mov     byte ptr [di],'$'       ;terminate the line
  451.         mov     ah,prstr                ;print string to msdos
  452.         mov     dx,offset gopos
  453.         int     dos
  454.         pop     es              ;clean up the stack and exit
  455.         pop     di              ; [jrd]
  456.         pop     cx
  457.         pop     bx
  458.         pop     ax
  459.         ret
  460. POSCUR  ENDP
  461.  
  462. ; Delete a character from the terminal.  This works by printing
  463. ; backspaces and spaces.  Returns normally.
  464.  
  465. DODEL   PROC    NEAR
  466.         mov ah,prstr
  467.         mov dx,offset delstr    ; Erase weird character.
  468.         int dos
  469.         ret
  470. DODEL   ENDP
  471.  
  472. ; Move the cursor to the left margin, then clear to end of line.
  473. ; Returns normally.
  474.  
  475. CTLU    PROC    NEAR
  476.         mov ah,prstr
  477.         mov dx,offset clrlin
  478.         int dos
  479.         call clearl
  480.         ret
  481. CTLU    ENDP
  482.  
  483. ; Set the current port.
  484.  
  485. COMS    PROC    NEAR
  486.         mov dx,offset comptab
  487.         mov bx,0
  488.         mov ah,cmkey
  489.         call comnd
  490.          jmp r
  491.         push bx
  492.         mov ah,cmcfm
  493.         call comnd              ; Get a confirm.
  494.          jmp comx               ;  Didn't get a confirm.
  495.          nop
  496.         pop bx
  497.         cmp bl,2                ; Do they want to set device name? [27d]
  498.         je coms2                ; Yes go get name. [27d]
  499.         jg coms3                ; Else pick up file handle. [27d]
  500.         mov flags.comflg,bl     ; Set the comm port flag.
  501.         cmp flags.comflg,1      ; Using Com 1?
  502.         jne coms0               ; Nope.
  503.         mov ax,offset port1
  504.         mov portval,ax
  505.         ret
  506. coms0:  mov ax,offset port2
  507.         mov portval,ax
  508.         ret
  509. comx:   pop bx
  510.         ret
  511. coms2:  mov dx,offset dev1      ; Let user supply device name.
  512.         call prompt
  513.         mov ah,cmtxt
  514.         mov bx,offset prtstr    ; Put name here
  515.         mov dx,offset devhlp
  516.         call comnd
  517.          jmp coms21             ; Did user type ^C.
  518.          nop
  519.         mov comand.cmstat,cmcfm ;simulate a confirm has been requested. [jrd]
  520. ;[jrd]  mov al,0                ; Need a null
  521. ;[jrd]  mov [bx],al             ; To terminate string
  522.         mov dx,offset prtstr    ; Point to string
  523.         mov ah,open             ; Open port
  524.         mov al,2                ; For reading and writing
  525.         int dos
  526.         jnc coms22              ; Success
  527. coms21: mov ah,prstr
  528.         mov dx,offset erms41
  529.         int dos
  530.         mov dx,offset deverr
  531.         int dos
  532.         ret
  533. coms22: mov prthnd,ax           ; Save handle.
  534.         ret
  535. coms3:  mov dx,offset hnd2      ; Let user supply file handle.
  536.         call prompt
  537.         mov ah,cmtxt
  538.         mov bx,offset rdbuf     ; Where to put input.
  539.         mov dx,offset hndhlp    ; In case user wants help.
  540.         call comnd
  541.          jmp coms31             ; No go.
  542.          nop
  543.         cmp ah,4                ; Right amount of data?
  544.         ja coms31               ; Too many chars.
  545.         mov si,offset rdbuf
  546.         call atoi               ; Convert to real number
  547.          jmp coms31             ; Keep trying.
  548.          nop
  549.         mov prthnd,ax           ; Value returned in AX
  550.         ret
  551. coms31: mov ah,prstr            ; Else, issue a warning.
  552.         mov dx,offset hnderr
  553.         int dos
  554.         ret                     ; Yes, fail.
  555. COMS    ENDP
  556.  
  557. ; Set heath emulation on/off.
  558.  
  559. VTS     PROC    NEAR
  560.         jmp notimp
  561. VTS     ENDP
  562.  
  563. ; Save the screen to a buffer and then append buffer to a disk file. [jrd]
  564. ; Default filename is Kermit.scn; actual file can be a device too. Filename
  565. ; is determined by mssset and is passed as pointer dmpname.
  566.  
  567. DUMPSCR PROC    NEAR    ; Dumps screen contents to a file. Just Beeps here
  568.         call beep       ; [jrd]
  569.         ret
  570. DUMPSCR ENDP
  571.  
  572.  
  573. notimp: mov ah,prstr
  574.         mov dx,offset noimp
  575.         int dos
  576.         jmp prserr
  577.  
  578. VTSTAT  PROC    NEAR    ; For Status display [jrd]
  579.         ret             ; no emulator status to display
  580. VTSTAT  ENDP
  581.  
  582. ; Initialize variables to values used by the generic MS DOS version.
  583.  
  584. lclini: mov flags.vtflg,0       ; Don't to terminal emulation.
  585.         mov prthnd,3            ; No handle yet. [27d][28a d.rice]
  586. ;       call opnprt             ; Get file handle for comm port.
  587.         ret
  588.  
  589. ; Get a file handle for the communications port.  Use DOS call to get the
  590. ; next available handle.  If it fails, ask user what value to use (there
  591. ; should be a predefined handle for the port, generally 3).  The open
  592. ; will fail if the system uses names other than "COM1" or "COM2".
  593. opnprt: mov al,flags.comflg
  594.         mov ah,0
  595.         mov si,ax
  596.         shl si,1                ; double index
  597.         mov dx,prttab[si]
  598.         mov ah,open
  599.         mov al,2
  600.         int dos
  601.         jnc opnpr2
  602.         mov ah,prstr            ; It didn't like the string.
  603.         mov dx,offset erms41
  604.         int dos
  605.         mov dx,offset hnd1
  606.         int dos
  607. opnpr0: mov dx,offset hnd2      ; Ask user to supply the handle.
  608.         call prompt
  609.         mov ah,cmtxt
  610.         mov bx,offset rdbuf     ; Where to put input.
  611.         mov dx,offset hndhlp    ; In case user wants help.
  612.         call comnd
  613.          jmp opnpr3             ; Maybe user typed a ^C.
  614.          nop
  615.         mov si,offset rdbuf
  616.         call atoi               ; Convert to real number
  617.          jmp opnpr0             ; Keep trying.
  618.          nop
  619.         mov prthnd,ax           ; Value returned in AX
  620.         ret
  621. opnpr2: mov prthnd,ax           ; Call succeeded.
  622.         ret
  623. opnpr3: cmp flags.cxzflg,'C'    ; Did user type a ^C?
  624.         jne opnpr4              ; No, don't say anything.
  625.         mov ah,prstr            ; Else, issue a warning.
  626.         mov dx,offset hnderr
  627.         int dos
  628. opnpr4: ret                     ; Yes, fail.
  629.  
  630. showkey:
  631.         mov ax,offset shkmsg
  632.         mov cx,shklen
  633.         ret
  634.  
  635. ; Initialization for using serial port.  Returns normally.
  636. SERINI  PROC    NEAR
  637.         cld                     ; Do increments in string operations
  638.         call clrbuf             ; Clear input buffer.
  639.         ret                     ; We're done.
  640. SERINI  ENDP
  641.  
  642. ; Reset the serial port.  This is the opposite of serini.  Calling
  643. ; this twice without intervening calls to serini should be harmless.
  644. ; Returns normally.
  645.  
  646. SERRST  PROC    NEAR
  647.         ret                     ; All done.
  648. SERRST  ENDP
  649.  
  650. ; Produce a short beep.  The PC DOS bell is long enough to cause a loss
  651. ; of data at the port.  Returns normally.
  652.  
  653. BEEP    PROC    NEAR
  654.         mov dl,bell
  655.         mov ah,dconio
  656.         int dos
  657.         ret
  658. BEEP    ENDP
  659.  
  660. ;
  661. ;put the number in ax into the buffer pointed to by di. di is updated.
  662. ;
  663.  
  664. nout    proc    near
  665.         mov     dx,0            ;high order is always zero
  666.         mov     bx,10
  667.         div     bx              ;divide to get digit
  668.         push    dx              ;save remainder till later
  669.         or      ax,ax           ;test the quotient
  670.         jz      noutl           ;zero, no more number
  671.         call    nout            ;else call for rest of number
  672. noutl:  pop     ax              ;get digit back
  673.         add     al,'0'          ;make it displayable
  674.         stosb                   ;drop it off
  675.         ret                     ;and exit
  676. nout    endp
  677.  
  678.  
  679. ; Dumb terminal emulator.  Doesn't work too well above 1200 baud (and
  680. ; even at 1200 baud you sometimes lose the first one or two characters
  681. ; on a line).
  682. term    proc    near
  683.         mov si,ax               ; this is source
  684.         mov di,offset ourarg    ; place to store arguments
  685.         mov ax,ds
  686.         mov es,ax               ; address destination segment
  687.         mov cx,size termarg
  688.         rep movsb               ; copy into our arg blk
  689. term1:  call prtchr
  690.         jmp short term2         ; have a char...
  691.         nop
  692.         nop
  693.         jmp short term3         ; no char, go on
  694. term2:  push ax
  695.         and al,7fh              ; mask off parity for terminal
  696.         mov dl,al
  697.         mov ah,conout
  698.         int dos                 ; go print it
  699.         pop ax
  700.         test ourarg.flgs,capt   ; capturing output?
  701.         jz term3                ; no, forget it
  702.         call ourarg.captr       ; else call the routine
  703. term3:  mov ah,dconio
  704.         mov dl,0ffh
  705.         int dos
  706.         jz term1                ; no character, go on
  707.         cmp al,ourarg.escc      ; escape char?
  708.         je term4                ; yes, exit
  709.         push ax                 ; save char
  710.         mov ah,al
  711. ;[jrd]  or ah,80H               ; turn on hi bit so DOS doesn't interfere
  712.         call outchr             ; output the character
  713.         nop
  714.         nop
  715.         nop
  716.         pop ax
  717.         test ourarg.flgs,lclecho ; echoing?
  718.         jz term1                ; no, continue loop
  719.         mov dl,al
  720.         mov ah,dconio
  721.         int dos
  722.         jmp term1               ; else echo and keep going
  723. term4:  ret
  724. term    endp
  725.  
  726. ; Jumping to this location is like retskp.  It assumes the instruction
  727. ;   after the call is a jmp addr.
  728.  
  729. RSKP    PROC    NEAR
  730.         pop bp
  731.         add bp,3
  732.         push bp
  733.         ret
  734. RSKP    ENDP
  735.  
  736. ; Jumping here is the same as a ret.
  737.  
  738. R       PROC    NEAR
  739.         ret
  740. R       ENDP
  741.  
  742. code    ends
  743.         end
  744.