home *** CD-ROM | disk | FTP | other *** search
/ Phoenix CD 2.0 / Phoenix_CD.cdr / 01e / msk230s2.zip / MSXGEN.ASM < prev    next >
Assembly Source File  |  1988-02-12  |  39KB  |  981 lines

  1.         name    msxgen
  2. ; File MSXGEN.ASM
  3. ; Generic MS DOS Kermit module, does i/o via DOS calls.
  4. ; Use with file MSUGEN.ASM (Generic keyboard translator)
  5. ;
  6. ; Last edit: 8 Jan 1988
  7. ; 8 Jan 1988 Update 8 bit display in outtty. [jrd]
  8. ; 1 Jan 1988 version 2.30
  9. ; 10 Dec 1987 Add Showmodem command.
  10. ; 12 Sept 1987 version 2.30
  11. ; 18 July 1987 Remove redundant rxtable test (Tnx to Jack Bryans), pass all
  12. ;  incoming serial port chars (except flow control) when Debug is on. [jrd]
  13. ; 25 May 1987 add keyboard translator, input translation, cleanups. [jrd]
  14. ; 1 Oct 86 Version 2.29a
  15. ; 30 Sept 1986 Reject DEL char at serial port reception level to avoid
  16. ;  problems when DEL is used as a filler char (by Emacs). [jrd]
  17. ; 27 Sept 1986 Revise procedure Term to permit capturing, printer ready
  18. ;  testing, debug display. Revised other port procedures slightly too;
  19. ;  especially to set port into binary mode via ioctl. [jrd]
  20. ; 4 Sept 1986 Add Bob Goeke's change to move comms port table to a system
  21. ;  dependent module (typ msx---) to allow 3+ ports and localized idents. [jrd]
  22. ; 26 May 1986 Make default display mode be Serial. [jrd]
  23. ;
  24. ; Note: the biggest difficulty using this Generic Kermit is loss of one
  25. ; or two incoming characters when the screen must scroll. IBM PC's and
  26. ; relatives do this. If possible, replace the DOS screen write with faster
  27. ; calls specific to your system. Procedure Sleep call (uses system time of
  28. ; day clock) is commented out below for systems lacking such a clock. [jrd]
  29.  
  30.         public  serini, serrst, clrbuf, outchr, coms, vts, vtstat, dodel
  31.         public  ctlu, cmblnk, locate, lclini, prtchr, dobaud, clearl
  32.         public  dodisk, getbaud, beep, trnprs, pcwait, shomodem, termtb
  33.         public  count, xofsnt, puthlp, putmod, clrmod, poscur
  34.         public  sendbr, sendbl, term, machnam, setktab, setkhlp, showkey
  35.         public  ihosts, ihostr, dtrlow, serhng, dumpscr, comptab
  36.         public  chrout, cstatus, cquit, cquery, chang   ; kbd action verbs
  37.         public  snull, kdos, klogof, klogon
  38.         include mssdef.h
  39.  
  40. false   equ     0
  41. true    equ     1
  42. instat  equ     6
  43. print_out equ   05h                     ; dos function to print to printer
  44. prtscr  equ     80h                     ; print screen pressed
  45.  
  46. ; external variables used:
  47. ; drives - # of disk drives on system
  48. ; flags - global flags as per flginfo structure defined in pcdefs
  49. ; trans - global transmission parameters, trinfo struct defined in pcdefs
  50. ; portval - pointer to current portinfo structure (currently either port1
  51. ;    or port2)
  52. ; port1, port2 - portinfo structures for the corresponding ports
  53.  
  54. ; global variables defined in this module:
  55. ; xofsnt, xofrcv - tell whether we saw or sent an xoff.
  56.  
  57. datas   segment public 'datas'
  58.         extrn   drives:byte,flags:byte, trans:byte
  59.         extrn   portval:word, port1:byte, port2:byte, port3:byte, port4:byte
  60.         extrn   comand:byte, dmpname:byte                       ; [jrd]
  61.         extrn   kbdflg:byte, rxtable:byte
  62.  
  63. machnam db      'Generic MS-DOS 2.0$'
  64. erms20  db      cr,lf,'?Warning: System has no disk drives$'
  65. erms40  db      cr,lf,'?Warning: Unrecognized baud rate$'
  66. erms41  db      cr,lf,'?Warning: Cannot open com port$'
  67. erms50  db      cr,lf,'Error reading from device$'
  68. hnd1    db      cr,lf,'Enter a file handle.  Check your DOS manual if you are '
  69.         db      cr,lf,'not certain what value to supply (generally 3).$'
  70. hnd2    db      cr,lf,'Handle: $'
  71. hnderr  db      cr,lf,'Warning: Handle not known.'
  72. deverr  db      cr,lf,'Any routine using the communications port will'
  73.         db      cr,lf,'probably not work.$'
  74. hndhlp  db      cr,lf,'A one to four digit file handle $'
  75. dev1    db      cr,lf,'Device: $'
  76. devhlp  db      cr,lf,'Name for your systems auxiliary port $'
  77. badbd   db      cr,lf,'Unimplemented baud rate$'
  78. noimp   db      cr,lf,'Command not implemented.$'
  79. hngmsg  db      cr,lf,' The phone should have hungup.',cr,lf,'$'
  80. hnghlp  db      cr,lf,' The modem control lines DTR and RTS for the current'
  81.         db      ' port are forced low (off)'
  82.         db      cr,lf,' to hangup the phone. Normally, Kermit leaves them'
  83.         db      ' high (on) when it exits.'
  84.         db      cr,lf,'$'
  85. msmsg1  db      cr,lf,' Communications port is not ready.$'
  86. msmsg2  db      cr,lf,' Communications port is ready.$'
  87. rdbuf   db      80 dup (?)      ; temp buf [jrd]
  88.  
  89. shkmsg  db      'Not implemented.'
  90. shklen  equ     $-shkmsg
  91. setktab db      0
  92. setkhlp db      0
  93. crlf    db      cr,lf,'$'
  94. delstr  db      BS,BS,'  ',BS,BS,'$'    ; Delete string
  95. ; If delete code moves cursor then BS over code, BS over bad char, space
  96. ; over both to erase from screen, BS twice to restore cursor position.
  97. clrlin  db      cr,'$'                  ; Clear line (just the cr part).
  98. clreol  db      '^U',cr,lf,'$'          ; Clear line.
  99. telflg  db      0               ; non-zero if we're a terminal.
  100. argadr  dw      ?               ; address of arg blk from msster.asm
  101. parmsk  db      ?               ; 8/7 bit parity mask, for reception
  102. flowoff db      ?               ; flow-off char, Xoff or null (if no flow)
  103. flowon  db      ?               ; flow-on char, Xon or null
  104. captrtn dw      ?               ; routine to call for captured output
  105. xofsnt  db      0               ; Say if we sent an XOFF.
  106. xofrcv  db      0               ; Say if we received an XOFF.
  107. count   dw      0               ; Number of chars in int buffer.
  108. prthnd  dw      0               ; Port handle.
  109. prttab  dw      com1,com2
  110. com1    db      'COM1',0
  111. com2    db      'COM2',0
  112. tmp     db      ?,'$'
  113. temp    dw      0
  114. temp1   dw      ?               ; Temporary storage.
  115. temp2   dw      ?               ; Temporary storage.
  116. prtstr  db      20 dup(?)       ; Name of auxiliary device
  117.  
  118. ; Entries for choosing communications port
  119. comptab db      6               ; Number of options
  120.         mkeyw   '1',1
  121.         mkeyw   '2',2
  122.         mkeyw   'COM1',1
  123.         mkeyw   'COM2',2
  124.         mkeyw   'Device',3
  125.         mkeyw   'File-handle',4
  126.  
  127. ourarg  termarg <>
  128.  
  129. termtb  db      tttypes                 ; entries for Status, not Set
  130.         mkeyw   'Heath-19',ttheath
  131.         mkeyw   'none',ttgenrc
  132.         mkeyw   'Tek4014',tttek
  133.         mkeyw   'VT102',ttvt100
  134.         mkeyw   'VT52',ttvt52
  135.  
  136. datas   ends
  137.  
  138. code    segment public 'code'
  139.         extrn   comnd:near, dopar:near, prserr:near, atoi:near, prompt:near
  140.         extrn   sleep:near, msuinit:near, keybd:near
  141.         assume  cs:code,ds:datas
  142.  
  143.  
  144. ; this is called by Kermit initialization.  It checks the
  145. ; number of disks on the system, sets the drives variable
  146. ; appropriately.  Returns normally.
  147.  
  148. DODISK  PROC    NEAR
  149.         mov ah,gcurdsk                  ; Current disk value to AL.
  150.         int dos
  151.         mov dl,al                       ; Put current disk in DL.
  152.         mov ah,seldsk                   ; Select current disk.
  153.         int dos                         ; Get number of drives in AL.
  154.         mov drives,al
  155.         ret
  156. DODISK  ENDP
  157.  
  158. ; Clear the input buffer. This throws away all the characters in the
  159. ; serial interrupt buffer.  This is particularly important when
  160. ; talking to servers, since NAKs can accumulate in the buffer.
  161. ; Do nothing since we are not interrupt driven.  Returns normally.
  162.  
  163. CLRBUF  PROC    NEAR            ; rewritten by [jrd]
  164.         cmp prthnd,0            ; got a port handle yet?
  165.         jne clrbu1              ; ne = yes
  166.         ret                     ; else just return
  167. clrbu1: call prtchr             ; read from comms port
  168.          jmp clrbu1             ;  returns when data available
  169.          nop
  170.         ret                     ; skip returns on no data
  171. CLRBUF  ENDP
  172.  
  173. ; Clear to the end of the current line.  Returns normally.
  174.  
  175. CLEARL  PROC    NEAR
  176.         push ax
  177.         push dx
  178.         mov ah,prstr
  179.         mov dx,offset clreol
  180.         int dos
  181.         pop dx
  182.         pop ax
  183.         ret
  184. CLEARL  ENDP
  185.  
  186. shomodem proc   near
  187.         mov     ah,cmcfm        ; get a confirm
  188.         call    comnd
  189.          jmp    r               ; no confirm
  190.          nop
  191.         cmp     prthnd,0        ; Got a handle yet?
  192.         jne     shmod0          ; Yup just go on
  193.         call    opnprt          ; Else 'open' the port
  194. shmod0: mov     dx,offset msmsg1 ; say port is not ready
  195.         mov     bx,prthnd
  196.         mov     al,7            ; output status command
  197.         mov     ah,ioctl        ; ask DOS to look for us
  198.         int     dos
  199.         jc      shmod1          ; c = call failed, device not ready
  200.         or      al,al
  201.         jz      shmod1          ; not ready...
  202.         mov     dx,offset msmsg2 ; say port is ready
  203. shmod1: mov     ah,prstr
  204.         int     dos
  205.         jmp     rskp
  206. shomodem endp
  207.  
  208. ; Put the char in AH to the serial port.  This assumes the
  209. ; port has been initialized.  Should honor xon/xoff.  Skip returns on
  210. ; success, returns normally if the character cannot be written.
  211.  
  212. OUTCHR  PROC    NEAR
  213.         push    cx              ; save regs
  214.         or      ah,ah           ; sending a null?
  215.         jz      outch2          ; z = yes
  216.         xor     cx,cx           ; clear counter
  217.         cmp     ah,flowoff      ; sending xoff?
  218.         jne     outch1          ; ne = no
  219.         mov     xofsnt,false    ; supress xon from chkxon buffer routine
  220. outch1: cmp     xofrcv,true     ; Are we being held?
  221.         jne     outch2          ; No - it's OK to go on.
  222.         loop    outch1          ; held, try for a while
  223.         mov     xofrcv,false    ; timed out, force it off and fall thru.
  224. outch2: push    dx              ; Save register.
  225.         mov     al,ah           ; Parity routine works on AL.
  226.         call    dopar           ; Set parity appropriately.
  227.                                 ; Begin revised output routine
  228.         mov     byte ptr temp,al ; put data there
  229.         cmp     prthnd,0        ; Got a handle yet?
  230.         jne     outch3          ; Yup just go on
  231.         call    opnprt          ; Else 'open' the port
  232. outch3: push    bx
  233.         mov     bx,prthnd       ; port handle
  234.         mov     cx,1            ; one byte to write
  235.         mov     dx,offset temp  ; place where data will be found
  236.         mov     ah,write2       ; dos 2 write to file/device
  237.         int     dos
  238.         pop     bx              ; end of revised routine
  239.         pop     dx
  240.         pop     cx
  241.         jmp     rskp
  242. OUTCHR  ENDP
  243.  
  244. ; This routine blanks the screen.  Returns normally.
  245.  
  246. CMBLNK  PROC    NEAR
  247.         push ax                 ; save some registers
  248.         push dx
  249.         mov ah,prstr
  250.         mov dx,offset crlf      ; carriage return plus line feed.
  251.         pop dx
  252.         pop ax
  253.         ret
  254. CMBLNK  ENDP
  255.  
  256. ; Homes the cursor.  Returns normally.
  257.  
  258. LOCATE  PROC    NEAR
  259.         mov dx,0                ; Go to top left corner of screen.
  260.         jmp poscur
  261. LOCATE  ENDP
  262.  
  263. ; Write a line at the bottom of the screen...
  264. ; the line is passed in dx, terminated by a $.  Returns normally.
  265. putmod  proc    near
  266.         push    dx              ; preserve message
  267.         mov     dx,1800h        ; now address line 24
  268.         call    poscur
  269.         pop     dx              ; get message back
  270.         mov     ah,prstr
  271.         int     dos             ; write it out
  272.         ret                     ; and return
  273. putmod  endp
  274.  
  275. ; clear the mode line written by putmod.  Returns normally.
  276. clrmod  proc    near
  277.         mov     dx,1800h
  278.         call    poscur          ; Go to bottom row.
  279.         call    clearl          ; Clear to end of line.
  280.         ret
  281. clrmod  endp
  282.  
  283. ; Put a help message on the screen.
  284. ; Pass the message in ax, terminated by a null.  Returns normally.
  285. puthlp  proc    near
  286.         push    dx              ; save regs
  287.         push    si
  288.         push    ax              ; preserve this
  289.         mov     ah,prstr
  290.         mov     dx,offset crlf
  291.         int     dos
  292.         pop     si              ; point to string again
  293.         cld
  294. puthl3: lodsb                   ; get a byte
  295.         cmp     al,0            ; end of string?
  296.         je      puthl4          ; yes, stop
  297.         mov     dl,al
  298.         mov     ah,dconio
  299.         int     dos             ; else write to screen
  300.         jmp     puthl3          ; and keep going
  301. puthl4: mov     ah,prstr
  302.         mov     dx,offset crlf
  303.         int     dos
  304.         pop     si
  305.         pop     dx
  306.         ret
  307. puthlp  endp
  308.  
  309. ; Set the baud rate for the current port, based on the value
  310. ; in the portinfo structure.  Returns normally.
  311.  
  312. DOBAUD  PROC    NEAR
  313.         mov ah,prstr
  314.         mov dx,offset noimp     ; Say it's not implemented.
  315.         int dos
  316.         push bx                 ; save reg
  317.         mov bx,portval
  318.         mov [bx].baud,0FFFFH    ; So it's not a recognized value.
  319.         pop bx
  320.         ret                     ; Must be set before starting Kermit.
  321. DOBAUD  ENDP
  322.  
  323. ; Get the current baud rate from the serial card and set it
  324. ; in the portinfo structure for the current port.  Returns normally.
  325. ; This is used during initialization.
  326.  
  327. GETBAUD PROC    NEAR
  328.         ret                     ; Can't do this.
  329. GETBAUD ENDP
  330.  
  331. ; Use for DOS 2.0 and above.  Check the port status.  If no data, skip
  332. ; return.  Else, read in a char and return.
  333. ; Note added by [jrd]: The test for char-at-input-port is int 21h function
  334. ; 44h (ioctl) sub function 6 (get input status). On many systems an FFH will
  335. ; be reported (meaning Ready) even though no char is available; the Ready
  336. ; indication is misleading. In such cases the system will wait for a char
  337. ; and will appear to be hung. A preferrable method is to use the ROM Bios
  338. ; call int 14H function 3 (get port status) and if the lsb of the returned
  339. ; 8 bits in AH is 1 then a char is availble at the port; this assumes that
  340. ; the machine emulates this ROM Bios operation.
  341. ; Lastly, if the current code is used and the system hangs then reboot
  342. ; and say  ECHO Hello >COM1  before running Kermit; this should make MSDOS
  343. ; truely aware of the port's actual status. Dark grey magic. Good luck! [jrd]
  344. PRTCHR  PROC    NEAR
  345.         push    bx
  346.         push    cx
  347.         cmp     prthnd,0        ; Got a handle yet?
  348.         jne     prtch0          ; Yup just go on
  349.         call    opnprt          ; Else 'open' the port
  350. prtch0: call    chkxon
  351.         mov     bx,prthnd
  352.         mov     al,instat       ; input status command
  353.         mov     ah,ioctl        ; see note above
  354.         int     dos
  355.         jc      prtch4          ; c = call failed, device not ready
  356.         or      al,al
  357.         jz      prtch4          ; not ready...
  358.         mov     bx,prthnd       ; the file handle
  359.         mov     ah,readf2       ; read file/device
  360.         mov     cx,1            ; want just one character
  361.         mov     dx,offset rdbuf ; where to store it
  362.         int     dos
  363.         jnc     prtch1          ; nc = no error
  364.         cmp     al,5            ; Error condition.
  365.         je      prt3x
  366.         cmp     al,6            ; Error condition
  367.         je      prt3x
  368.         jmp     prtch4          ; else report no char present.
  369. prtch1:;;;mov   count,0         ; update count (always 0 for one char reads)
  370.         mov     dx,ax           ; needed to obey rules
  371.         or      ax,ax           ; reading from end of file?
  372.         jz      prtch4          ; z = yes
  373.         mov     al,rdbuf        ; recover char
  374. prtch3: pop     cx
  375.         pop     bx
  376.         ret                     ; return success (char is in al)
  377. prt3x:  mov     ah,prstr
  378.         mov     dx,offset erms50
  379.         int     dos
  380. prtch4: pop     cx
  381.         pop     bx
  382.         jmp     rskp            ; no chars...
  383. PRTCHR  ENDP
  384.  
  385. ; Local routine to see if we have to transmit an xon
  386. chkxon  proc    near
  387.         push    bx
  388.         mov     bx,portval
  389.         cmp     [bx].floflg,0   ; doing flow control?
  390.         je      chkxo1          ; no, skip all this
  391.         cmp     xofsnt,false    ; have we sent an xoff?
  392.         je      chkxo1          ; no, forget it
  393.         mov     ax,[bx].flowc   ; ah gets xon
  394.         call    outchr          ; send it
  395.         nop
  396.         nop
  397.         nop                     ; in case it skips
  398.         mov     xofsnt,false    ; remember we've sent the xon.
  399. chkxo1: pop     bx              ; restore register
  400.         ret                     ; and return
  401. chkxon  endp
  402.  
  403. ; IHOSTS - Initialize the host by sending XON, or equivalent, and enter the
  404. ; cycle of clear input buffer, wait 1 second, test if buffer empty then exit
  405. ; else repeat cycle. Requires that the port be initialized before hand.
  406. ; Ihosts is used by the local send-file routine just after initializing
  407. ; the serial port.
  408. ; 22 March 1986 [jrd]
  409.  
  410. IHOSTS  PROC    NEAR
  411.         push    ax              ; save the registers
  412.         push    bx
  413.         push    cx
  414.         push    dx
  415.         mov     bx,portval      ; port indicator
  416.         mov     ax,[bx].flowc   ; put Go-ahead flow control char in ah
  417.         or      ah,ah           ; don't send null if flow = none
  418.         jz      ihosts1         ; z = null
  419.         call    outchr          ; send it (release Host's output queue)
  420.          nop                    ; outchr can do skip return
  421.          nop
  422.          nop
  423. ihosts1:call    clrbuf          ; clear out interrupt buffer
  424.         mov     ax,1            ; sleep for 1 second
  425. ; NOTE: for systems with a time-of-day clock uncomment the line below
  426. ; (call sleep) to provide an interval for the host to respond.
  427.  
  428. ;;;     call    sleep           ; procedure sleep is in msscom.asm
  429.         call    prtchr          ; check for char at port
  430.          jmp    ihosts1         ; have a char in al, repeat wait/read cycle
  431.          nop                    ; prtchr does skip return on empty buffer
  432.         pop     dx              ; empty buffer. we are done here.
  433.         pop     cx
  434.         pop     bx
  435.         pop     ax
  436.         ret
  437. IHOSTS  ENDP
  438.  
  439. ; IHOSTR - initialize the remote host for our reception of a file by
  440. ; sending the flow-on character (XON typically) to release any held
  441. ; data. Called by receive-file code just after initializing the serial
  442. ; port.         22 March 1986 [jrd]
  443. IHOSTR  PROC    NEAR
  444.         push    ax              ; save regs
  445.         push    bx
  446.         push    cx
  447.         mov     bx,portval      ; port indicator
  448.         mov     ax,[bx].flowc   ; put Go-ahead flow control char in ah
  449.         or      ah,ah           ; don't send null if flow = null
  450.         jz      ihostr1         ; z = null
  451.         call    outchr          ; send it (release Host's output queue)
  452.          nop                    ; outchr can do skip return
  453.          nop
  454.          nop
  455. ihostr1:pop     cx
  456.         pop     bx
  457.         pop     ax
  458.         ret
  459. IHOSTR  ENDP
  460.  
  461. DTRLOW  PROC    NEAR            ; Global proc to Hangup the Phone by making
  462.                                 ; DTR and RTS low.
  463.         mov ah,cmtxt            ; allow text to be able to display help
  464.         mov bx,offset rdbuf     ; dummy buffer
  465.         mov dx,offset hnghlp    ; help message
  466.         call comnd              ; get a confirm
  467.          jmp r
  468. ; not yet imp.  call serhng             ; drop DTR and RTS
  469.         mov ah,prstr            ; give a nice message
  470. ; not yet imp.  mov dx,offset hngmsg
  471.         mov dx,offset noimp     ; for now
  472.         int dos
  473.         jmp rskp
  474. DTRLOW  ENDP
  475.  
  476. ; Hang up the Phone. Similar to SERRST except it just forces DTR and RTS low
  477. ; to terminate the connection. 29 March 1986 [jrd]
  478. ; Calling this twice without intervening calls to serini should be harmless.
  479. ; Returns normally.
  480. ; SERHNG is Not Yet Implemented.
  481.  
  482. SERHNG  PROC NEAR
  483.         ret
  484. SERHNG  ENDP
  485.  
  486. ; Wait for the # of milliseconds in ax, for non-IBM compatibles.
  487. ; Based on 4.77 Mhz 8088 processor speeds.
  488. ; Thanks to Bernie Eiben for this one.
  489. pcwait  proc    near
  490.         mov     cx,240          ; inner loop counter for 1 millisecond
  491. pcwai1: sub     cx,1            ; inner loop takes 20 clock cycles
  492.         jnz     pcwai1
  493.         dec     ax              ; outer loop counter
  494.         jnz     pcwait          ; wait another millisecond
  495.         ret
  496. pcwait  endp
  497.  
  498.  
  499. ; Send a break out the current serial port.  Returns normally.
  500. SENDBR  PROC    NEAR            ; Normal Break
  501.         ret
  502. SENDBR  ENDP
  503. SENDBL  PROC    NEAR            ; Long Break
  504.         ret
  505. SENDBL  ENDP
  506.  
  507. ; Position the cursor according to contents of DX:
  508. ; DH contains row, DL contains column.  Returns normally.
  509. POSCUR  PROC    NEAR
  510.         ret
  511. POSCUR  ENDP
  512.  
  513. ; Delete a character from the terminal.  This works by printing
  514. ; backspaces and spaces.  Returns normally.
  515.  
  516. DODEL   PROC    NEAR
  517.         mov ah,prstr
  518.         mov dx,offset delstr    ; Erase weird character.
  519.         int dos
  520.         ret
  521. DODEL   ENDP
  522.  
  523. ; Move the cursor to the left margin, then clear to end of line.
  524. ; Returns normally.
  525.  
  526. CTLU    PROC    NEAR
  527.         mov ah,prstr
  528.         mov dx,offset clrlin
  529.         int dos
  530.         call clearl
  531.         ret
  532. CTLU    ENDP
  533.  
  534. ; Set the current port.
  535.  
  536. COMS    PROC    NEAR
  537.         mov dx,offset comptab   ; the table to examine
  538.         mov bx,0                ; use keywords as help
  539.         mov ah,cmkey            ; parse keyword from comptab
  540.         call comnd
  541.          jmp r                  ; no match
  542.         push bx                 ; value following the located keyword
  543.         mov ah,cmcfm
  544.         call comnd              ; Get a confirm.
  545.          jmp comx               ;  Didn't get a confirm.
  546.          nop
  547.         pop bx
  548.         cmp bl,3                ; Do they want to set device name?
  549.         je coms3                ; e = Yes go get name
  550.         jg coms4                ; g = pick up file handle
  551.         mov flags.comflg,bl     ; Set the comm port flag.
  552.         cmp bl,1                ; Using Com 1?
  553.         jne coms2               ; Nope.
  554.         mov portval,offset port1
  555.         ret
  556. coms2:  cmp flags.comflg,2      ; using Com2?
  557.         jne coms3               ; ne = no
  558.         mov portval,offset port2
  559.         ret
  560. comx:   pop bx
  561.         ret
  562. coms3:  mov dx,offset dev1      ; Let user supply device name.
  563.         call prompt
  564.         mov ah,cmtxt            ; parse string, returns asciiz string
  565.         mov bx,offset prtstr    ; Put name here
  566.         mov dx,offset devhlp    ; help message if user types question mark
  567.         call comnd
  568.          jmp coms31             ; Did user type ^C.
  569.          nop
  570.         mov comand.cmstat,cmcfm ; simulate a confirm has been requested
  571.         mov dx,offset prtstr    ; Point to string
  572.         mov ah,open2            ; Open port as a file
  573.         mov al,2                ; For reading and writing
  574.         int dos
  575.         jc coms31               ; c = failure
  576.         mov portval,offset port3 ; port info structure
  577.         mov flags.comflg,3      ; set port ident
  578.         jmp short coms32        ; Success
  579. coms31: mov ah,prstr
  580.         mov dx,offset erms41
  581.         int dos
  582.         mov dx,offset deverr
  583.         int dos
  584.         ret
  585. coms32: mov prthnd,ax           ; Save handle.
  586.         mov ah,ioctl
  587.         mov al,00h              ; get device info
  588.         xor dx,dx
  589.         mov bx,prthnd           ; port's handle
  590.         int dos
  591.         jc coms41               ; c = error
  592.         or dl,20h               ; set binary mode in device info
  593.         mov dh,0
  594.         mov ah,ioctl
  595.         mov al,01h              ; set device info
  596.         int dos
  597.         jc coms41               ; c = error
  598.         ret
  599. coms4:  mov dx,offset hnd2      ; Let user supply file handle.
  600.         call prompt
  601.         mov ah,cmtxt
  602.         mov bx,offset rdbuf     ; Where to put input.
  603.         mov dx,offset hndhlp    ; In case user wants help.
  604.         call comnd
  605.          jmp coms41             ; No go.
  606.          nop
  607.         cmp ah,4                ; Right amount of data?
  608.         ja coms41               ; Too many chars.
  609.         mov comand.cmstat,cmcfm ; simulate a confirm has been requested
  610.         mov si,offset rdbuf
  611.         call atoi               ; Convert to real number in ax
  612.          jmp coms41             ; Keep trying.
  613.          nop
  614.         mov portval,offset port4 ; port info structure
  615.         mov flags.comflg,4      ; set port ident
  616.         jmp coms32              ; go complete processing
  617. coms41: mov ah,prstr            ; Else, issue a warning.
  618.         mov dx,offset hnderr
  619.         int dos
  620.         ret                     ; Yes, fail.
  621. COMS    ENDP
  622.  
  623. ; Set heath emulation on/off.
  624.  
  625. VTS     PROC    NEAR
  626.         jmp notimp
  627. VTS     ENDP
  628.  
  629.  
  630. VTSTAT  PROC    NEAR    ; For Status display [jrd]
  631.         ret             ; no emulator status to display
  632. VTSTAT  ENDP
  633.  
  634. ; Save the screen to a buffer and then append buffer to a disk file. [jrd]
  635. ; Default filename is Kermit.scn; actual file can be a device too. Filename
  636. ; is determined by mssset and is passed as pointer dmpname.
  637.  
  638. DUMPSCR PROC    NEAR    ; Dumps screen contents to a file. Just Beeps here
  639.         call beep
  640.         ret
  641. DUMPSCR ENDP
  642.  
  643. notimp: mov ah,prstr
  644.         mov dx,offset noimp
  645.         int dos
  646.         jmp prserr
  647.  
  648. ; Initialize variables to values used by the generic MS DOS version.
  649.  
  650. lclini: mov flags.vtflg,0       ; Don't to terminal emulation.
  651.         mov prthnd,0            ; No handle yet
  652.         mov flags.remflg,dserial ; set serial display mode
  653. ;;      call opnprt             ; Get file handle for comm port.
  654.         call msuinit            ; declare keyboard translator present
  655.         ret
  656.  
  657. ; Get a file handle for the communications port.  Use DOS call to get the
  658. ; next available handle.  If it fails, ask user what value to use (there
  659. ; should be a predefined handle for the port, generally 3).  The open
  660. ; will fail if the system uses names other than "COM1" or "COM2".
  661. opnprt: mov al,flags.comflg
  662.         dec al                  ; com1 is 1, com2 is 2, etc
  663.         mov ah,0
  664.         push si
  665.         mov si,ax
  666.         shl si,1                ; double index
  667.         mov dx,prttab[si]       ; table of port names
  668.         pop si
  669.         mov ah,open2            ; open file/device
  670.         mov al,2                ; for reading/writing
  671.         int dos
  672.         jnc opnpr2              ; nc = no error so far
  673.         mov ah,prstr            ; It didn't like the string.
  674.         mov dx,offset erms41
  675.         int dos
  676.         mov dx,offset hnd1
  677.         int dos
  678. opnpr0: mov dx,offset hnd2      ; Ask user to supply the handle.
  679.         call prompt
  680.         mov ah,cmtxt
  681.         mov bx,offset rdbuf     ; Where to put input.
  682.         mov dx,offset hndhlp    ; In case user wants help.
  683.         call comnd
  684.          jmp opnpr3             ; Maybe user typed a ^C.
  685.          nop
  686.         mov si,offset rdbuf
  687.         call atoi               ; Convert to real number
  688.          jmp opnpr0             ; Keep trying.
  689.          nop
  690.         mov prthnd,ax           ; Value returned in AX
  691.         ret
  692. opnpr2: mov prthnd,ax           ; Call succeeded.
  693.         mov ah,ioctl
  694.         mov al,00h              ; get device info
  695.         xor dx,dx
  696.         mov bx,prthnd           ; port's handle
  697.         int dos
  698.         or dl,20h               ; set binary mode in device info
  699.         mov dh,0
  700.         mov ah,ioctl
  701.         mov al,01h              ; set device info
  702.         int dos
  703.         ret
  704. opnpr3: cmp flags.cxzflg,'C'    ; Did user type a ^C?
  705.         jne opnpr4              ; No, don't say anything.
  706.         mov ah,prstr            ; Else, issue a warning.
  707.         mov dx,offset hnderr
  708.         int dos
  709. opnpr4: ret                     ; Yes, fail.
  710.  
  711. showkey:
  712.         mov ax,offset shkmsg
  713.         mov cx,shklen
  714.         ret
  715.  
  716. ; Initialization for using serial port.  Returns normally.
  717. ; Attempts to put port device in binary mode. [jrd]
  718. SERINI  PROC    NEAR
  719.         cld                     ; Do increments in string operations
  720.         cmp     prthnd,0        ; Got a handle yet?
  721.         jne     serin0          ; ne = yes, just go on
  722.         push    bx
  723.         call    opnprt          ; Else 'open' the port
  724.         pop     bx
  725. serin0:;;;;     call clrbuf     ; Clear input buffer.
  726.         push    bx
  727.         mov     bx,portval      ; get port
  728.         mov     parmsk,0ffh     ; parity mask, assume parity is None
  729.         cmp     [bx].parflg,parnon ; is it None?
  730.         je      serin1          ; e = yes
  731.         mov     parmsk,07fh     ; no, pass lower 7 bits as data
  732. serin1: mov     bx,[bx].flowc   ; get flow control chars
  733.         mov     flowoff,bl      ; xoff or null
  734.         mov     flowon,bh       ; xon or null
  735.         pop     bx
  736.         ret                     ; We're done.
  737. SERINI  ENDP
  738.  
  739. ; Reset the serial port.  This is the opposite of serini.  Calling
  740. ; this twice without intervening calls to serini should be harmless.
  741. ; Returns normally.
  742.  
  743. SERRST  PROC    NEAR
  744.         ret                     ; All done.
  745. SERRST  ENDP
  746.  
  747. ; Produce a short beep.  The PC DOS bell is long enough to cause a loss
  748. ; of data at the port.  Returns normally.
  749.  
  750. BEEP    PROC    NEAR
  751.         mov dl,bell
  752.         mov ah,dconio
  753.         int dos
  754.         ret
  755. BEEP    ENDP
  756. ;
  757.  
  758.  
  759. ; Dumb terminal emulator.  Doesn't work too well above 1200 baud (and
  760. ; even at 1200 baud you sometimes lose the first one or two characters
  761. ; on a line). Does capture (logging), local echo, debug display, tests
  762. ; for printer/logging device not ready. Uses keyboard translator
  763. ; 20 March 1987 [jrd].
  764. term    proc    near
  765.         mov     argadr,ax               ; save argument ptr
  766.         mov     si,ax                   ; this is source
  767.         mov     di,offset ourarg        ; place to store arguments
  768.         mov     ax,ds
  769.         mov     es,ax                   ; address destination segment
  770.         mov     cx,size termarg
  771.         cld
  772.         rep     movsb                   ; copy into our arg blk
  773.         and     ourarg.flgs,not (prtscr) ; no screen printing at startup
  774.         mov     ax,ourarg.captr
  775.         mov     captrtn,ax              ; buffer capture routine
  776.         mov     parmsk,0ffh             ; parity mask, assume parity = None
  777.         cmp     ourarg.parity,parnon    ; is parity None?
  778.         je      term1                   ; e = yes, keep all 8 bits
  779.         mov     parmsk,07fh             ; else keep lower 7 bits
  780. term1:  call    portchr         ; get char from port, apply parity mask
  781.         jnc     short term2     ; nc = no char, go on
  782.         call    outtty          ; display and capture char
  783.         jmp     term1           ; do quick loop back for more
  784. term1b: call    outtty          ; display and capture char
  785. term2:  call    keybd           ; keyboard translator to read and send text
  786.         jnc     term1           ; nc = do not exit Connect mode
  787. term4:  ret
  788. term    endp
  789.  
  790. ;; keyboard translator action routines, system dependent, called from msugen.
  791. ; These are invoked by a jump instruction. Return carry clear for normal
  792. ; processing, return carry set exit Connect mode (kbdflg has transfer char).
  793.  
  794. chrout: call    outprt                  ; put char in al to serial port
  795.         clc                             ; stay in Connect mode
  796.         ret
  797.  
  798. trnprs: push    ax                      ; toggle Copy screen to printer
  799.         test    ourarg.flgs,prtscr      ; are we currently printing?
  800.         jnz     trnpr2                  ; nz = yes, its on and going off
  801.         mov     ah,ioctl
  802.         mov     al,7                    ; get output status of printer
  803.         push    bx
  804.         mov     bx,4                    ; file handle for system printer
  805.         int     dos
  806.         pop     bx
  807.         jc      trnpr1                  ; c = printer not ready
  808.         cmp     al,0ffh                 ; Ready status?
  809.         je      trnpr2                  ; e = Ready
  810. trnpr1: call    beep                    ; Not Ready, complain
  811.         jmp     trnpr3                  ; and ignore request
  812. trnpr2: xor     ourarg.flgs,prtscr      ; flip the flag
  813. trnpr3: pop     ax
  814.         clc
  815.         ret
  816.  
  817.  
  818. klogon  proc    near                    ; resume logging (if any)
  819.         test    flags.capflg,logses     ; session logging enabled?
  820.         jz      klogn                   ; z = no, forget it
  821.         or      ourarg.flgs,capt        ; turn on capture flag
  822. klogn:  clc
  823.         ret
  824. klogon  endp
  825.  
  826. klogof  proc    near                    ; suspend logging (if any)
  827.         and     argadr.flgs,not capt    ; stop capturing
  828. klogo:  clc
  829.         ret
  830. klogof  endp
  831.  
  832. snull:  mov     ah,0                    ; send a null
  833.         call    outchr                  ; send without echo or logging
  834.          nop
  835.          nop
  836.          nop
  837.         clc
  838.         ret
  839.  
  840. kdos:   mov     al,'P'                  ; Push to DOS
  841.         jmp     short cmdcom
  842. cstatus:mov     al,'S'                  ; these commands exit Connect mode
  843.         jmp     short cmdcom
  844. cquit:  mov     al,'C'
  845.         jmp     short cmdcom
  846. cquery: mov     al,'?'
  847.         jmp     short cmdcom
  848. chang:  mov     al,'H'                  ; Hangup, drop DTR & RTS
  849. ;;;     jmp     short cmdcom
  850. cmdcom: mov     kbdflg,al               ; pass char to msster.asm via kbdflg
  851.         stc                             ; say exit Connect mode
  852.         ret
  853.                                         ;; end of action routines
  854.  
  855. ; put the character in al to the screen, do capture and printing,
  856. ; does translation for Set Input command.
  857. ; Adapted from msyibm.asm [jrd]
  858. outtty  proc    near
  859.         test    flags.remflg,d8bit      ; keep 8 bits for displays?
  860.         jnz     outnp8                  ; nz = yes, 8 bits if possible
  861.         and     al,7fh                  ; remove high bit
  862. outnp8: cmp     rxtable+256,0           ; is translation off?
  863.         je      outnp7                  ; e = yes, off
  864.         push    bx                      ; Translate incoming char
  865.         mov     bx,offset rxtable       ; address of translate table
  866.         xlatb                           ; new char is in al
  867.         pop     bx
  868. outnp7:
  869.         push    bx
  870.         mov     bx,argadr               ; args from msster directly
  871.         test    [bx].flgs,capt          ; capturing output? Can be shut off
  872.         pop     bx                      ;  if out dev becomes not ready.
  873.         jz      outnoc                  ; no, forget this part
  874.         push    ax                      ; save char
  875.         call    captrtn                 ; give it captured character
  876.         pop     ax                      ; restore character and keep going
  877. outnoc: test    ourarg.flgs,prtscr      ; should we be printing?
  878.         jz      outnop                  ; no, keep going
  879.         push    ax
  880.         mov     ah,print_out            ; write to system printer device
  881.         mov     dl,al
  882.         int     dos
  883.         pop     ax
  884.         jnc     outnop                  ; nc = successful print
  885.         push    ax
  886.         call    beep                    ; else make a noise and
  887.         call    trnprs                  ;  turn off printing
  888.         pop     ax
  889. outnop: cmp     flags.vtflg,0           ; emulating a terminal?
  890.         jnz     outnop1                 ; nz = yup, go do something smart
  891.         test    ourarg.flgs,trnctl      ; debug? if so use dos tty mode
  892.         jz      outnp4                  ; z = no
  893.         mov     ah,conout
  894.         cmp     al,7fh                  ; Ascii Del char or greater?
  895.         jb      outnp1                  ; b = no
  896.         je      outnp0                  ; e = Del char
  897.         push    ax                      ; save the char
  898.         mov     dl,7eh                  ; output a tilde for 8th bit
  899.         int     dos
  900.         pop     ax                      ; restore char
  901.         and     al,7fh                  ; strip high bit
  902. outnp0: cmp     al,7fh                  ; is char now a DEL?
  903.         jne     outnp1                  ; ne = no
  904.         and     al,3fH                  ; strip next highest bit (Del --> '?')
  905.         jmp     outnp2                  ; send, preceded by caret
  906. outnp1: cmp     al,' '                  ; control char?
  907.         jae     outnp3                  ; ae = no
  908.         add     al,'A'-1                ; make visible
  909. outnp2: push    ax                      ; save char
  910.         mov     dl,5eh                  ; caret
  911.         int     dos                     ; display it
  912.         pop     ax                      ; recover the non-printable char
  913. outnp3: mov     dl,al
  914.         int     dos
  915.         ret
  916. outnp4: cmp     al,bell                 ; bell (Control G)?
  917.         jne     outnp5                  ; ne = no
  918.         jmp     beep                    ; use short beep, avoid char loss.
  919. outnop1:
  920. outnp5: test    flags.remflg,d8bit      ; keep 8 bits for displays?
  921.         jnz     outnp9                  ; nz = yes, 8 bits if possible
  922.         and     al,7fh                  ; remove high bit
  923. outnp9: mov     ah,conout               ; dostty screen mode
  924.         mov     dl,al                   ; write without intervention.
  925.         int     dos                     ; else let dos display char
  926.         ret                             ; and return
  927. outtty  endp
  928.  
  929.  
  930. ; send the character in al out to the serial port; handle echoing.
  931. ; Can send an 8 bit char while displaying only 7 bits locally.
  932. outprt  proc    near
  933.         test    ourarg.flgs,lclecho     ; echoing?
  934.         jz      outpr1                  ; z = no, forget it
  935.         push    ax                      ; save char
  936.         call    outtty                  ; print it
  937.         pop     ax                      ; restore
  938. outpr1: mov     ah,al                   ; this is where outchr expects it
  939.         call    outchr                  ; output to the port
  940.          nop
  941.          nop
  942.          nop                            ; skip returns...
  943.         ret
  944. outprt  endp
  945.  
  946. ; Get a char from the serial port manager
  947. ; returns with carry on if a character is available
  948. portchr proc    near
  949.         call    prtchr                  ; character at port?
  950.          jmp    short portc1            ; yes
  951.          nop
  952. portc0: clc                             ; no carry -> no character
  953.         ret                             ; and return...
  954. portc1: and     al,parmsk               ; apply 8/7 bit parity mask
  955.         or      al,al                   ; catch nulls
  956.         jz      portc0                  ; z = null, ignore it
  957.         cmp     al,del                  ; catch dels
  958.         je      portc0                  ; e = del, ignore it
  959. portc2: stc                             ; have a character
  960.         ret                             ; and return
  961. portchr endp
  962.  
  963. ; Jumping to this location is like retskp.  It assumes the instruction
  964. ;   after the call is a jmp addr.
  965.  
  966. RSKP    PROC    NEAR
  967.         pop     bp
  968.         add     bp,3
  969.         push    bp
  970.         ret
  971. RSKP    ENDP
  972.  
  973. ; Jumping here is the same as a ret.
  974.  
  975. R       PROC    NEAR
  976.         ret
  977. R       ENDP
  978.  
  979. code    ends
  980.         end
  981.