home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / extra / nyenhuis2.arc / MSXHPX.ASM < prev   
Assembly Source File  |  1988-07-01  |  31KB  |  1,163 lines

  1.     name msxhpx
  2. ; File MSXHPX.ASM
  3. ; Edit history:
  4. ; Last edit: 4 June 1988
  5. ; 1 July 1988 Version 2.31
  6. ; 1 Jan 1988 version 2.30
  7. ; 25 May 1987 Add keyboard translator, input translation, cleanups. [jrd]
  8. ; 1 Oct 86 Version 2.29a
  9. ; 30 Sept 1986 Reject DEL char at serial port reception level to avoid
  10. ;  problems when DEL is used as a filler char (by Emacs). [jrd]
  11. ; 28 Sept 1986 Revise procedure Term to permit capturing, printer ready
  12. ;  testing, debug display. Revised other port procedures slightly too;
  13. ;  especially to set port into binary mode via ioctl. [jrd]
  14. ; 22 Sept 1986 Add modifications from Mike Mellinger: outchr, serhng.
  15. ;   Introduce COM3 as additional choice. Startup 8 bits, no parity. [jrd]
  16. ; 4 Sept 1986 Add Bob Goeke's change to move comms port table to a system
  17. ;   dependent module (typ msx---) to allow 3+ ports and localized idents. [jrd]
  18.  
  19. ; Date: 15 Oct 85
  20. ; HP Portable Kermit
  21. ;    for HP110 and HP Portable Plus
  22. ;    Port 1: Serial, Port 2: internal modem
  23. ;    Defaults: even parity, 9600 baud: serial, 1200 internal modem
  24. ;    Internal modem code only works on HP Portable Plus
  25. ;    15 Nov 85:
  26. ;       Added code to shut off serial port and modem when quitting Kermit
  27. ;    11 Jan 86;
  28. ;       change msdefs.h to mssdef.h for kermit 2.28 jrd
  29. ;
  30. ; Add global entry point vtstat for use by Status in mssset.
  31. ; Also trimmed off trailing commas in publics. Joe R. Doupnik 12 March 1986
  32. ; Add global procedures ihosts and ihostr to handle host initialization
  33. ; when packets are to be sent or received by us,resp. 24 March 1986
  34. ; Add global procedure dtrlow (without worker serhng) to force DTR & RTS low
  35. ; in support of Kermit command Hangup. Says Not Yet Implemented. [jrd]
  36. ; Add global procedure Dumpscr, called by Ter in file msster, to dump screen
  37. ;   to a file. Just does a beep for now. 13 April 1986 [jrd]
  38. ; In proc Outchr add override of xon from chkxon sending routine.
  39. ;   This makes a hand typed Xoff supress the xon flow control character sent
  40. ;   automatically as the receiver buffer empties. 20 April 1986 [jrd]
  41. ; Fix port selector table, comptab, (from original version) to properly
  42. ;   hold port name AUX. 23 April 1986 [jrd]
  43. ;
  44. ;    Fixed error in resetting the serial port, 25 April 1986
  45. ;
  46.         page    80,132
  47.      
  48. PLUS    equ    0
  49.      
  50.     public    serini, serrst, clrbuf, outchr, coms, vts, vtstat, dodel
  51.     public    ctlu, cmblnk, locate, lclini, prtchr, dobaud, clearl
  52.     public    dodisk, getbaud, beep, pcwait, termtb, shomodem, getmodem
  53.     public    xofsnt, puthlp, putmod, clrmod, poscur
  54.     public    sendbr, sendbl, term, machnam, setktab, setkhlp, showkey
  55.     public    ihosts, ihostr, dtrlow, serhng, dumpscr, comptab
  56.     public    chrout, cstatus, cquit
  57.     public    cquery, trnprs, snull, klogon, klogof, kdos
  58.  
  59.     include mssdef.h
  60.      
  61. false    equ    0
  62. true    equ    1
  63. instat    equ    6
  64. print_out equ    05h            ; dos function to print to printer
  65. prtscr    equ    80h            ; print screen pressed
  66.      
  67. ; external variables used:
  68. ; drives - # of disk drives on system
  69. ; flags - global flags as per flginfo structure defined in pcdefs
  70. ; trans - global transmission parameters, trinfo struct defined in pcdefs
  71. ; portval - pointer to current portinfo structure (currently either port1
  72. ;     or port2)
  73. ; port1, port2 - portinfo structures for the corresponding ports
  74.      
  75. ; global variables defined in this module:
  76. ; xofsnt, xofrcv - tell whether we saw or sent an xoff.
  77.      
  78. datas    segment public 'datas'
  79.     extrn    drives:byte,flags:byte, trans:byte
  80.     extrn    portval:word, port1:byte, port2:byte, dmpname:byte
  81.     extrn    port3:byte, kbdflg:byte, rxtable:byte
  82. ifdef    PLUS
  83. machnam db    'HP-PLUS$'
  84. else
  85. machnam db    'HP-110$'
  86. endif
  87. erms20    db    cr,lf,'?Warning: System has no disk drives$'
  88. erms40    db    cr,lf,'?Warning: Unrecognized baud rate$'
  89. erms41    db    cr,lf,'?Warning: Cannot open com port$'
  90. erms50    db    cr,lf,'Error reading from device$'
  91. badbd    db    cr,lf,'Unimplemented baud rate$'
  92. badpar    db    cr,lf,'Unimplemented parity$'
  93. noimp    db    cr,lf,'Command not implemented.$'
  94. hngmsg    db    cr,lf,' The phone should have hungup.',cr,lf,'$'
  95. hnghlp    db    cr,lf,' The modem control lines DTR and RTS for the current'
  96.     db    ' port are forced low (off)'
  97.     db    cr,lf,' to hangup the phone. Normally, Kermit leaves them'
  98.     db    ' high (on) when it exits.'
  99.     db    cr,lf,'$'
  100. msmsg1    db    cr,lf,' Communications port is not ready.$'
  101. msmsg2    db    cr,lf,' Communications port is ready.$'
  102. rdbuf    db    80 dup (?)        ; temp buf
  103. shkmsg    db    'Not implemented.'
  104. shklen    equ    $-shkmsg
  105. baudstr db    'SB'            ; string used in setting baud rate
  106. baudx    db    0,';'
  107. par_str db    'P'            ; string used to set parity
  108. par_x    db    4,';'            ; 4=no parity (use 0 for even parity)
  109. brk_on    db    'B1;'            ; start sending breaks
  110. brk_off db    'B0;'            ; stop sending breaks
  111. chk_msg db    0BFH,';'        ; check serial buffer
  112. $m0    db    'M0;'
  113. $m1    db    'M1;'
  114. $off_m    db    'M3;M5;'
  115. off_len equ    $-$off_m
  116. ;
  117. ini_msg db    'C2;'            ; XON/XOFF
  118.     db    'LI1;'            ; DTR on
  119.     db    'SS0;'            ; 1 Stop Bit
  120.     Db    'SW0;'            ; 8 bits ( use SW1 for 7 Bit Length)
  121. setktab db    0
  122. setkhlp db    0
  123. crlf    db    cr,lf,'$'
  124. delstr    db    BS,BS,' ',BS,'$'
  125. clrlin    db    cr,ESCAPE,'K$'
  126. clreol    db    ESCAPE,'K$'
  127. telflg    db    0        ; non-zero if we're a terminal
  128. xofsnt    db    0        ; Say if we sent an XOFF
  129. xofrcv    db    0        ; Say if we received an XOFF
  130. invseq    db    ESCAPE,'&dB$'    ; Reverse video
  131. nrmseq    db    ESCAPE,'&d@$'    ; Normal video
  132. ivlseq    db    80 dup (' '),cr,'$'    ; make line inverse video
  133. prthnd    dw    0        ; Port handle
  134. argadr    dw    ?        ; address of arg blk from msster.asm
  135. parmsk    db    ?        ; 8/7 bit parity mask, for reception
  136. flowoff    db    ?        ; flow-off char, Xoff or null (if no flow)
  137. flowon    db    ?        ; flow-on char, Xon or null
  138. captrtn    dw    ?        ; routine to call for captured output
  139. tempbuf dw    10 dup(?)
  140. prttab    dw    com1,com2,com3
  141. com1    db    'COM1',0
  142. com2    db    'AUX',0
  143. com3    db    'COM3',0
  144. blank    db    ESCAPE,'H',ESCAPE,'J$'
  145. movcur    db    ESCAPE,'&a'
  146. colno    db    20 dup(?)
  147. ten    db    10
  148. tmp    db    ?,'$'
  149. temp    dw    0
  150. temp1    dw    ?        ; Temporary storage
  151. temp2    dw    ?        ; Temporary storage
  152.      
  153. ; Entries for choosing communications port. [19b]
  154. comptab db    7        ; 7 entries. Rewritten by [jrd]
  155.     mkeyw    '1',1
  156.     mkeyw    '2',2
  157.     mkeyw    '3',2
  158.     mkeyw    'AUX',2        ; alias for com2
  159.     mkeyw    'COM1',1
  160.     mkeyw    'COM2',2
  161.     mkeyw    'COM3',3
  162.  
  163. termtb    db    tttypes            ; entries for Status, not Set
  164.     mkeyw    'Heath-19',ttheath
  165.     mkeyw    'none',ttgenrc
  166.     mkeyw    'Tek4014',tttek
  167.     mkeyw    'VT102',ttvt100        
  168.     mkeyw    'VT52',ttvt52
  169.  
  170. ;    variables for serial interupt handler
  171.      
  172. source    db    bufsiz    DUP(?)    ; buffer for data from port
  173. bufout    dw    0        ; buffer removal pointer
  174. count    dw    0        ; number of chars in int buffer
  175. bufin    dw    0        ; buffer insertion pointer
  176.      
  177.      
  178. ourarg    termarg <>
  179.      
  180. datas    ends
  181.      
  182. code    segment public 'code'
  183.     extrn    comnd:near, dopar:near, prserr:near, atoi:near, prompt:near
  184.     extrn    sleep:near
  185.     extrn    msuinit:near, keybd:near    ; in msuhpx
  186.     assume    cs:code,ds:datas
  187.      
  188. ; this is called by Kermit initialization.    It checks the
  189. ; number of disks on the system, sets the drives variable
  190. ; appropriately.  Returns normally.
  191.      
  192. DODISK    PROC    NEAR
  193.     mov    ah,gcurdsk            ; Current disk value to AL
  194.     int    dos
  195.     mov    dl,al                ; Put current disk in DL
  196.     mov    ah,seldsk            ; Select current disk
  197.     int    dos                ; Get number of drives in AL
  198.     mov    drives,al
  199.     ret
  200. DODISK    ENDP
  201.      
  202. ; Clear the input buffer. This throws away all the characters in the
  203. ; serial interrupt buffer.    This is particularly important when
  204. ; talking to servers, since NAKs can accumulate in the buffer.
  205. ; Returns normally.
  206.      
  207. CLRBUF    PROC    NEAR
  208.     cli
  209.     mov    bufin,offset source
  210.     mov    bufout,offset source
  211.     mov    count,0
  212.     sti
  213.     ret
  214. CLRBUF    ENDP
  215.      
  216. ; Clear to the end of the current line.     Returns normally.
  217.      
  218. CLEARL    PROC    NEAR
  219.     push    ax            ; save regs
  220.     push    dx
  221.     mov    ah,prstr
  222.     mov    dx,offset clreol
  223.     int    dos
  224.     pop    dx
  225.     pop    ax
  226.     ret
  227. CLEARL    ENDP
  228. ; Put the char in AH to the serial port.  This assumes the
  229. ; port has been initialized.  Should honor xon/xoff.  Skip returns on
  230. ; success, returns normally if the character cannot be written.
  231.  
  232. outchr: push cx            ; save regs
  233.     or ah,ah        ; sending a null?
  234.     jz outch2        ; z = yes
  235.     xor cx,cx        ; clear counter
  236.     cmp ah,flowoff        ; sending xoff?
  237.     jne outch1        ; ne = no
  238.     mov xofsnt,false    ; supress xon from chkxon buffer routine
  239. outch1:    cmp xofrcv,true        ; Are we being held?
  240.     jne outch2        ; No - it's OK to go on
  241.     loop outch1        ; held, try for a while
  242.     mov xofrcv,false    ; timed out, force it off and fall thru
  243. outch2:    push dx            ; Save register
  244.     mov al,ah        ; Parity routine works on AL
  245.     call dopar        ; Set parity appropriately
  246.                 ; Begin revised output routine
  247.     mov byte ptr temp,al    ; put data there
  248.     cmp prthnd,0        ; Got a handle yet?
  249.     jne outch3        ; Yup just go on
  250.     call opnprt        ; Else 'open' the port
  251. outch3:    push    bx
  252.     mov    bx,prthnd    ; port handle
  253.     mov    cx,1        ; one byte to write
  254.     mov    dx,offset temp    ; place where data will be found
  255.     mov    ah,write2    ; dos 2 write to file/device
  256.     int    dos
  257.     pop    bx        ; end of revised routine
  258.     pop dx
  259.     pop cx
  260.     jmp rskp
  261.      
  262. ; This routine blanks the screen.   Returns normally.
  263.      
  264. CMBLNK    PROC    NEAR
  265.     push    ax        ; save regs
  266.     push    dx
  267.     mov    ah,prstr
  268.     mov    dx,offset blank
  269.     int    dos
  270.     pop    dx
  271.     pop    ax
  272.     ret
  273. CMBLNK    ENDP
  274.      
  275. ; Homes the cursor.     Returns normally.
  276.      
  277. LOCATE    PROC    NEAR
  278.     mov    dx,0        ; Go to top left corner of screen
  279.     jmp    poscur
  280. LOCATE    ENDP
  281.      
  282. ; Write a line at the bottom of the screen...
  283. ; the line is passed in dx, terminated by a $.    Returns normally.
  284. putmod    proc    near
  285.     push    dx        ; preserve message
  286. ifdef    PLUS
  287.     mov    dx,1800H    ; now address line 24
  288. else
  289.     mov    dx,0F00H    ; now address line 15
  290. endif
  291.     call    poscur
  292.     mov    dx,offset invseq    ; put into inverse video
  293.     mov    ah,prstr
  294.     int    dos
  295.     pop    dx        ; get message back
  296.     int    dos        ; print it
  297.     mov    dx,offset nrmseq    ; normal video
  298.     int    dos
  299.     ret
  300. putmod    endp
  301.      
  302. ; clear the mode line written by putmod.  Returns normally.
  303. clrmod    proc    near
  304. ifdef    PLUS
  305.     mov    dx,1800H
  306. else
  307.     mov    dx,0F00H
  308. endif
  309.     call    poscur        ; Go to bottom row
  310.     call    clearl        ; Clear to end of line
  311.     ret
  312. clrmod    endp
  313.      
  314. ; Put a help message on the screen.
  315. ; Pass the message in ax, terminated by a null.     Returns normally.
  316. puthlp    proc    near
  317.     push    dx        ; save regs
  318.     push    si
  319.     push    ax        ; preserve this
  320.     mov    ah,prstr
  321.     mov    dx,offset crlf
  322.     int    dos
  323.     pop    si        ; point to string again
  324. puth0:    mov    ah,prstr
  325.     mov    dx,offset invseq    ; put into reverse video
  326.     int    dos
  327.     mov    ah,prstr
  328.     mov    dx,offset ivlseq    ; make line inverse video
  329.     int    dos
  330.     cld
  331. puth1:    lodsb            ; get a byte
  332.     cmp    al,0        ; end of string?
  333.     je    puth2
  334.     mov    dl,al
  335.     mov    ah,conout
  336.     int    dos        ; else write to screen
  337.     cmp    al,lf        ; line feed?
  338.     je    puth0        ; yes, clear the next line
  339.     jmp    puth1
  340. puth2:    mov    ah,prstr
  341.     mov    dx,offset crlf
  342.     int    dos
  343.     mov    dx,offset nrmseq    ; normal video
  344.     int    dos
  345.     pop    si
  346.     pop    dx
  347.     ret
  348. puthlp    endp
  349.      
  350. ; Set the baud rate for the current port, based on the value
  351. ; in the portinfo structure.      Returns normally.
  352.      
  353. DOBAUD    PROC    NEAR
  354.     push    ax            ; save regs
  355.     push    bx
  356.     push    dx
  357.     mov    bx,portval
  358.     mov    dx,[bx].baud        ; get baud rate from table
  359.     cmp    dx,0
  360.     jb    bd_bd
  361.     cmp    dx,10
  362.     je    bd_bd
  363.     cmp    dx,15
  364.     ja    bd_bd
  365. ;
  366.     cmp    dx,10
  367.     jb    baud_4
  368.     cmp    dx,11
  369.     jne    baud_1
  370.     mov    dl,'A'
  371.     jmp    baud_5
  372. baud_1: cmp    dx,12
  373.     jne    baud_2
  374.     mov    dx,'C'
  375.     jmp    baud_5
  376. baud_2: cmp    dx,13
  377.     jne    baud_3
  378.     mov    dx,'E'
  379.     jmp    baud_5
  380. baud_3: cmp    dx,14
  381.     jne    bd_bd
  382.     mov    dx,'F'
  383.     jmp    baud_5
  384. baud_4: add    dl,'0'            ; make # printable
  385. baud_5: mov    baudx,dl        ; put into baud rate message
  386.     mov    cx,4
  387.     mov    dx,offset baudstr    ; point to message
  388.     cmp    prthnd,0        ; is port open
  389.     je    Baud_R            ; No, skip hardware set
  390.     call    w_ioctl            ; write to ioctl of serial port
  391.     pop    dx            ; [jrd]
  392.     pop    bx
  393.     pop    ax
  394. Baud_R: ret                ; ...and return
  395. ;
  396. bd_bd:    mov    ah,prstr
  397.     mov    dx,offset badbd        ; Say it's not implemented
  398.     int    dos
  399.     mov    bx,portval
  400.     mov    [bx].baud,0FFFFH    ; So it's not a recognized value
  401.     pop    dx
  402.     pop    bx
  403.     pop    ax
  404.     ret                ; Must be set before starting Kermit
  405. DOBAUD    ENDP
  406.  
  407. ; Use hardware parity of None so software routines can do the work. [jrd]     
  408. DOPARITY PROC    NEAR
  409.     push    ax            ; save regs
  410.     push    bx
  411.     push    cx
  412.     push    dx
  413. ;;    mov    bx,portval
  414. ;;    mov    dl,[bx].parflg        ; get parity flag
  415. ;;    cmp    dl,0
  416. ;;    jne    par_1
  417. ;;    mov    dx,'0'            ; even parity
  418. ;;    jmp    par_3
  419. ;;par_1:    cmp    dl,2
  420. ;;    jne    par_2
  421.     mov    dx,'4'            ; no parity
  422. ;;    jmp    par_3
  423. ;;par_2:    cmp    dl,3
  424. ;;    jne    bd_par
  425. ;;    mov    dx,'1'            ; odd parity
  426. par_3:    mov    par_x,dl        ; set up string
  427.     mov    dx,offset par_str    ; point to string
  428.     mov    cx,3            ; 3 lettters in string
  429.     cmp    prthnd,0        ; is port open
  430.     je    Par_R            ; No, skip hardware set
  431.     call    w_ioctl            ; write to ioctl of serial port
  432.     pop    dx            ; [jrd]
  433.     pop    cx
  434.     pop    bx
  435.     pop    ax
  436. Par_R:    ret                ; ...and return
  437. bd_par: mov    bx,portval
  438.     mov    [bx].parflg,0
  439.     mov    ah,prstr
  440.     mov    dx,offset badpar
  441.     int    dos
  442.     pop    dx
  443.     pop    cx
  444.     pop    bx
  445.     pop    ax
  446.     ret
  447. DOPARITY ENDP
  448.      
  449. ; Get the current baud rate from the serial card and set it
  450. ; in the portinfo structure for the current port.   Returns normally.
  451. ; This is used during initialization.
  452.      
  453. GETBAUD PROC    NEAR
  454.     ret            ; Can't do this
  455. GETBAUD ENDP
  456.  
  457. ; SHOW MODEM - displays status of modem lines DSR, CD, CTS, in this case
  458. ; it just says whether or not the port is ready for i/o.
  459. shomodem proc    near
  460.     mov    ah,cmcfm    ; get a confirm
  461.     call    comnd
  462.      jmp    r        ; no confirm
  463.      nop
  464.     cmp    prthnd,0    ; Got a handle yet?
  465.     jne    shmod0        ; Yup just go on
  466.     call    opnprt        ; Else 'open' the port
  467. shmod0:    mov    dx,offset msmsg1 ; say port is not ready
  468.     mov    bx,prthnd
  469.     mov    al,7        ; output status command
  470.     mov    ah,ioctl    ; ask DOS to look for us
  471.     int    dos
  472.     jc    shmod1        ; c = call failed, device not ready
  473.     or    al,al
  474.     jz    shmod1        ; not ready
  475.     mov    dx,offset msmsg2 ; say port is ready
  476. shmod1:    mov    ah,prstr
  477.     int    dos
  478.     jmp    rskp
  479. shomodem endp
  480.  
  481. getmodem proc    near
  482.     mov    al,0        ; no modem status
  483.     ret
  484. getmodem endp
  485.  
  486. ;
  487. ;    write cx bytes to ioctl of serial port
  488. ;
  489. W_IOCTL PROC    NEAR
  490.     push    ax        ; save regs
  491.     push    bx
  492.     mov    ah,ioctl
  493.     mov    al,3
  494.     mov    bx,prthnd
  495.     int    dos
  496.     pop    bx
  497.     pop    ax
  498.     ret
  499. W_IOCTL ENDP
  500. ;
  501. ;    read cx bytes from ioctl of serial port to tempbuf
  502. ;
  503. R_IOCTL PROC    NEAR
  504.     push    ax            ; save regs
  505.     push    bx
  506.     mov    ah,ioctl
  507.     mov    al,2
  508.     mov    bx,prthnd
  509.     mov    dx,offset tempbuf
  510.     int    dos
  511.     pop    bx
  512.     pop    ax
  513.     ret
  514. R_IOCTL ENDP
  515. ;
  516. ;    check serial port for characters and return number in al
  517. ;
  518. CHK_BUFF PROC    NEAR
  519.     push    cx
  520.     push    dx
  521.     mov    dx,offset chk_msg
  522.     mov    cx,2
  523.     call    w_ioctl
  524.     mov    cx,1
  525.     call    r_ioctl
  526.     mov    ax,tempbuf
  527.     pop    dx
  528.     pop    cx
  529.     ret
  530. CHK_BUFF ENDP
  531.      
  532.      
  533. ; Use for DOS 2.0 and above. Check the port status. If no data, skip
  534. ; return.   Else, read in a char and return.
  535. PRTCHR    PROC    NEAR
  536.     push    bx
  537.     push    cx
  538.     push    si
  539.     cmp    prthnd,0        ; got a handle
  540.     jne    prtch1            ; ne = yes
  541.     call    opnprt            ; open port if not
  542. prtch1:    cmp    count,0            ; any chars in buffer?
  543.     jne    prtch2            ; ...yes, get one
  544.     call    chk_buff        ; any chars at port?
  545.     or    al,al
  546.     jz    prtch4            ; no, go to skip return
  547.     mov    ah,0
  548.     mov    cx,1            ; read one char
  549.     mov    count,cx
  550.     mov    bx,prthnd
  551.     mov    ah,readf2        ; DOS read from file/device
  552.     mov    dx,offset source
  553.     int    dos
  554.     jc    prt3x            ; c = failure
  555.     mov    bufout,offset source
  556. prtch2: dec    count
  557.     mov    si,bufout
  558.     cld
  559.     lodsb
  560.     mov    bufout,si
  561. prtch3: pop    si
  562.     pop    cx
  563.     pop    bx
  564.     ret                ; return success
  565. prt3x:    mov    ah,prstr
  566.     mov    dx,offset erms50
  567.     int    dos
  568. prtch4: pop    si
  569.     pop    cx
  570.     pop    bx
  571.     jmp    rskp            ; no chars
  572. PRTCHR    ENDP
  573.      
  574. ; Send a break out the current serial port.     Returns normally.
  575. SENDBR    PROC    NEAR
  576.     push    cx
  577.     push    dx
  578.     mov    dx,offset brk_on
  579.     mov    cx,3
  580.     call    w_ioctl
  581.     mov    dx,offset brk_off
  582.     mov    cx,3
  583.     call    w_ioctl
  584.     pop    dx
  585.     pop    cx
  586.     clc                ; clear carry to stay in Connect mode
  587.     ret
  588. SENDBR    ENDP
  589.  
  590. SENDBL    PROC    NEAR            ; Send a Long Break
  591.     jmp    sendbr            ; same as regular here
  592. SENDBL    ENDP    
  593.      
  594. ; IHOSTS - Initialize the host by sending XON, or equivalent, and enter the
  595. ; cycle of clear input buffer, wait 1 second, test if buffer empty then exit
  596. ; else repeat cycle. Requires that the port be initialized before hand.
  597. ; Ihosts is used by the local send-file routine just after initializing
  598. ; the serial port.
  599. ; 22 March 1986 [jrd]
  600.      
  601. IHOSTS    PROC    NEAR
  602.     push    ax        ; save the registers
  603.     push    bx
  604.     push    cx
  605.     push    dx
  606.     mov    bx,portval    ; port indicator
  607.     mov    ax,[bx].flowc    ; put Go-ahead flow control char in ah
  608.     or    ah,ah        ; don't send null if flow = none
  609.     jz    ihosts1        ; z = null
  610.     call    outchr        ; send it (release Host's output queue)
  611.      nop            ; outchr can do skip return
  612.      nop
  613.      nop
  614. ihosts1:call    clrbuf        ; clear out interrupt buffer
  615.     pop    dx        ; empty buffer. we are done here
  616.     pop    cx
  617.     pop    bx
  618.     pop    ax
  619.     ret
  620. IHOSTS    ENDP
  621.      
  622. ; IHOSTR - initialize the remote host for our reception of a file by
  623. ; sending the flow-on character (XON typically) to release any held
  624. ; data. Called by receive-file code just after initializing the serial
  625. ; port.        22 March 1986 [jrd]
  626. IHOSTR    PROC    NEAR
  627.     push    ax        ; save regs
  628.     push    bx
  629.     push    cx
  630.     mov    bx,portval    ; port indicator
  631.     mov    ax,[bx].flowc    ; put Go-ahead flow control char in ah
  632.     or    ah,ah        ; don't send null if flow = none
  633.     jz    ihostr1        ; z = null
  634.     call    outchr        ; send it (release Host's output queue)
  635.      nop            ; outchr can do skip return
  636.      nop
  637.      nop
  638. ihostr1:pop    cx
  639.     pop    bx
  640.     pop    ax
  641.     ret
  642. IHOSTR    ENDP
  643.      
  644. DTRLOW    PROC    NEAR        ; Global proc to Hangup the Phone by making
  645.                 ; DTR and RTS low.
  646.     mov ah,cmtxt        ; allow text to be able to display help
  647.     mov bx,offset rdbuf    ; dummy buffer
  648.     mov dx,offset hnghlp    ; help message
  649.     call comnd        ; get a confirm
  650.      jmp r
  651.     call serhng        ; drop DTR and RTS
  652.     mov ah,prstr        ; give a nice message
  653.     mov dx,offset hngmsg
  654.     int dos
  655.     jmp rskp
  656. DTRLOW    ENDP
  657.      
  658. ; Hang up the Phone. Similar to SERRST except it just forces DTR and RTS low
  659. ; to terminate the connection. 29 March 1986 [jrd]
  660. ; Calling this twice without intervening calls to serini should be harmless.
  661. ; Returns normally.
  662. ; Adapted from recommendation by Mike Mellinger. [jrd]
  663. SERHNG    PROC    NEAR
  664.     push    ax
  665.     push    bx
  666.     push    cx
  667.     push    dx
  668.     mov    dx,offset com2
  669.     mov    ah,open2    ; open device AUX
  670.     mov    al,1        ; for writing
  671.     int    dos
  672.     jc    serhn1        ; c = error
  673.     mov    bx,ax        ; file handle
  674.     mov    ah,write2
  675.     mov    dx,offset $off_m ; magic words to turn off DTR
  676.     mov    cx,off_len    ; their length
  677.     int    dos        ; write them
  678.     mov    ah,close2    ; close the device
  679.     int    dos
  680. serhn1:    pop    dx
  681.     pop    cx
  682.     pop    bx
  683.     pop    ax
  684.     ret
  685. SERHNG    ENDP
  686.  
  687. ; Wait for the # of milliseconds in ax, for non-IBM compatibles.
  688. ; Thanks to Bernie Eiben for this one.
  689. pcwait    proc    near
  690.     mov    cx,240        ; inner loop counter for 1 millisecond
  691. pcwai1:    sub    cx,1        ; inner loop takes 20 clock cycles
  692.     jnz    pcwai1
  693.     dec    ax        ; outer loop counter
  694.     jnz    pcwait        ; wait another millisecond
  695.     ret
  696. pcwait    endp
  697.  
  698.      
  699. ; Position the cursor according to contents of DX:
  700. ; DH contains row, DL contains column.    Returns normally.
  701. POSCUR    PROC    NEAR
  702.     push    ax            ; save regs
  703.     push    dx
  704.     push    di
  705.     mov    ax,ds
  706.     mov    es,ax            ; address data segment!!
  707.     cld
  708.     mov    di,offset colno
  709.     mov    al,dl            ; column
  710.     call    nout
  711.     mov    al,'x'
  712.     stosb
  713.     mov    al,dh            ; row
  714.     call    nout
  715.     mov    al,'Y'
  716.     stosb
  717.     mov    al,'$'
  718.     stosb
  719.     mov    dx,offset movcur
  720.     mov    ah,prstr
  721.     int    dos            ; print the sequence
  722.     pop    di
  723.     pop    dx
  724.     pop    ax
  725.     ret
  726. POSCUR    ENDP
  727.      
  728. NOUT    PROC    NEAR
  729.     cbw            ; extend the word
  730.     div    byte ptr ten    ; divide by ten
  731.     or    al,al        ; any quotient?
  732.     jz    nout1        ; no, forget this
  733.     push    ax        ; save current result
  734.     call    nout        ; output high order
  735.     pop    ax        ; restore
  736. nout1:    mov    al,ah        ; get digit
  737.     add    al,'0'        ; make printable
  738.     stosb            ; put in buffer
  739.     ret            ; and return
  740. NOUT    ENDP
  741.      
  742. ; Delete a character from the terminal.     This works by printing
  743. ; backspaces and spaces.  Returns normally.
  744.      
  745. DODEL    PROC    NEAR
  746.     push    ax            ; save regs
  747.     push    dx
  748.     mov    ah,prstr
  749.     mov    dx,offset delstr    ; Erase weird character
  750.     int    dos
  751.     pop    dx
  752.     pop    ax
  753.     ret
  754. DODEL    ENDP
  755.      
  756. ; Move the cursor to the left margin, then clear to end of line.
  757. ; Returns normally.
  758.      
  759. CTLU    PROC    NEAR
  760.     push    ax            ; save regs
  761.     push    dx
  762.     mov    ah,prstr
  763.     mov    dx,offset clrlin
  764.     int    dos
  765.     call    clearl
  766.     pop    dx
  767.     pop    ax
  768.     ret
  769. CTLU    ENDP
  770.      
  771. ; Set the current port.
  772.      
  773. COMS    PROC    NEAR
  774.     call    serr_x            ; force close on serial port
  775.     mov    dx,offset comptab    ; table of comms ports
  776.     mov    bx,0            ; use keywords as help
  777.     mov    ah,cmkey        ; parse a keyword
  778.     call    comnd
  779.      jmp     r            ; failure
  780.      nop
  781.     push    bx
  782.     mov    ah,cmcfm
  783.     call    comnd            ; Get a confirm
  784.      jmp     comx            ; Didn't get a confirm
  785.      nop
  786.     pop    bx
  787.     mov    flags.comflg,bl        ; Set the comm port flag
  788.     cmp    flags.comflg,1        ; Using Com 1?
  789.     jne    coms2            ; ne = no
  790.     mov    portval,offset port1
  791.     ret
  792. coms2:    cmp    bl,2            ; using com2?
  793.     jne    coms3            ; ne = no
  794.     mov    portval,offset port2
  795.     ret
  796. coms3:    mov    portval,offset port3
  797.     ret
  798. comx:    pop    bx
  799.     ret
  800. COMS    ENDP
  801.      
  802. ; Set heath emulation on/off.
  803.      
  804. VTS    PROC    NEAR
  805.     jmp    notimp
  806. VTS    ENDP
  807.      
  808. VTSTAT    PROC    NEAR    ; For Status display [jrd]
  809.     ret        ; no emulator status to display
  810. VTSTAT    ENDP
  811.      
  812. ; Save the screen to a buffer and then append buffer to a disk file. [jrd]
  813. ; Default filename is Kermit.scn; actual file can be a device too. Filename
  814. ; is determined by mssset and is passed as pointer dmpname.
  815.      
  816. DUMPSCR PROC    NEAR    ; Dumps screen contents to a file. Just Beeps here
  817.     call    beep
  818.     ret
  819. DUMPSCR ENDP
  820.      
  821.      
  822. notimp: mov    ah,prstr
  823.     mov    dx,offset noimp
  824.     int    dos
  825.     jmp    prserr
  826.      
  827. ; Initialize variables to values used by the generic MS DOS version.
  828.      
  829. lclini:    call    msuinit        ; init keyboard translator
  830.     mov    flags.vtflg,0    ; Don't do terminal emulation
  831.     mov    prthnd,0    ; no port handle yet. [jrd]
  832. ;;;    call    opnprt        ; Get file handle for comm port
  833.     push    bx
  834.     mov    bx,offset port1
  835.     mov    [bx].baud,B9600 ; port1 -> 9600 baud
  836.     mov    [bx].parflg,2    ;       no parity
  837.     mov    bx,offset port2
  838.     mov    [bx].baud,B1200 ; port2 -> 1200 baud
  839.     mov    [bx].parflg,2    ;       no parity
  840.     pop    bx
  841.     ret
  842.      
  843. ; Get a file handle for the communications port.  Use DOS call to get the
  844. ; next available handle.  If it fails, ask user what value to use (there
  845. ; should be a predefined handle for the port, generally 3).     The open
  846. ; will fail if the system uses names other than "COM1", "COM2", "COM3","AUX".
  847. opnprt: mov    al,flags.comflg
  848.     dec    al        ; flags.comflg = 1 for com1, 2 com2, 3 com3
  849.     mov    ah,0
  850.     mov    si,ax
  851.     shl    si,1            ; double index
  852.     mov    dx,prttab[si]
  853.     mov    ah,open2
  854.     mov    al,2
  855.     int    dos
  856.     jnc    opnpr1
  857.     mov    ah,prstr        ; It didn't like the string
  858.     mov    dx,offset erms41
  859.     int    dos
  860.     mov    prthnd,0        ; clear port file handle
  861.     stc                ; carry set for failure
  862.     ret
  863. opnpr1: mov    prthnd,ax        ; Call succeeded
  864.     mov    ah,ioctl
  865.     mov    al,00h            ; get device info
  866.     xor    dx,dx
  867.     mov    bx,prthnd        ; port's handle
  868.     int    dos
  869.     or    dl,20h            ; set binary mode in device info
  870.     mov    dh,0
  871.     mov    ah,ioctl
  872.     mov    al,01h            ; set device info
  873.     int    dos
  874.     ret                ; carry clear for success
  875.      
  876. showkey:
  877.     mov    ax,offset shkmsg
  878.     mov    cx,shklen
  879.     ret
  880.      
  881. ; Initialization for using serial port.     Returns normally.
  882. SERINI    PROC    NEAR
  883.     cld                ; Do increments in string operations
  884.     cmp    prthnd,0        ; Got Handle already?
  885.     jne    ser_x            ; ne = yes, skip open
  886.     call    opnprt            ; open handle
  887.     jc    serin2            ; carry set = failure
  888.     mov    cx,3
  889.     mov    ax,portval
  890.     cmp    ax,offset port1
  891.     jnz    seri
  892.     mov    dx,offset $m1
  893.     jmp    serx
  894. seri:    mov    dx,offset $m0
  895. serx:    call    w_ioctl
  896. ser_x:    mov    dx,offset ini_msg
  897.     mov    cx,15
  898.     call    w_ioctl
  899.     call    dobaud            ; set baud rate
  900.     call    doparity        ; set parity
  901.     push    bx
  902.     mov    bx,portval        ; get port
  903.     mov    parmsk,0ffh        ; parity mask, assume parity is None
  904.     cmp    [bx].parflg,parnon    ; is it None?
  905.     je    serin1            ; e = yes
  906.     mov    parmsk,07fh        ; no, pass lower 7 bits as data
  907. serin1:    mov    bx,[bx].flowc        ; get flow control chars
  908.     mov    flowoff,bl        ; xoff or null
  909.     mov    flowon,bh        ; xon or null
  910.     pop    bx
  911.     clc                ; carry clear for success
  912. serin2:    ret
  913. SERINI    ENDP
  914.      
  915. ; Reset the serial port.  This is the opposite of serini.   Calling
  916. ; this twice without intervening calls to serini should be harmless.
  917. ; Returns normally.
  918.      
  919. SERRST    PROC    NEAR
  920.     cmp    flags.extflg,0
  921.     jne    serr_x
  922.     ret
  923. serr_x: push    bx        ; save reg
  924.     cmp    prthnd,0    ; handle there?
  925.     je    serr_1        ; no, don't try to close
  926.     mov    cx,off_len
  927.     mov    dx,offset $off_m
  928.     call    w_ioctl
  929.     mov    bx,prthnd
  930.     mov    ah,close2
  931.     int    dos        ; close handle
  932.     mov    prthnd,0
  933. serr_1: pop    bx
  934.     ret
  935. SERRST    ENDP
  936.      
  937. ; Produce a short beep.     The PC DOS bell is long enough to cause a loss
  938. ; of data at the port.    Returns normally.
  939.      
  940. BEEP    PROC    NEAR
  941.     mov    dl,bell
  942.     mov    ah,dconio
  943.     int    dos
  944.     ret
  945. BEEP    ENDP
  946.  
  947. ; Dumb terminal emulator.  Doesn't work too well above 1200 baud (and
  948. ; even at 1200 baud you sometimes lose the first one or two characters
  949. ; on a line). Does capture (logging), local echo, debug display, tests
  950. ; for printer/logging device not ready. 27 Sept 86 [jrd]. 
  951. term    proc    near
  952.     mov    argadr,ax        ; save argument ptr
  953.     mov    si,ax            ; this is source
  954.     mov    di,offset ourarg    ; place to store arguments
  955.     push    es            ; save register
  956.     push    ds
  957.     pop    es            ; set es to datas segment
  958.     mov    cx,size termarg
  959.     cld
  960.     rep    movsb            ; copy into our arg blk
  961.     pop    es            ; restore reg
  962.     and    ourarg.flgs,not (prtscr) ; no screen printing at startup
  963.     mov    ax,ourarg.captr
  964.     mov    captrtn,ax        ; buffer capture routine
  965.  
  966.     mov    parmsk,0ffh        ; parity mask, assume parity = None
  967.     cmp    ourarg.parity,parnon    ; is parity None?
  968.     je    term1            ; e = yes, keep all 8 bits
  969.     mov    parmsk,07fh        ; else keep lower 7 bits
  970. term1:    call    portchr            ; get char from port, apply parity mask
  971.     jnc    short term2        ; nc = no char, go on
  972.     call    outtty            ; display and capture char
  973. term2:    call    keybd            ; call keyboard translator in msu
  974.     jnc    term1            ; nc = no char or have processed it
  975.                          ; carry set = quit Connect mode
  976. term4:    ret
  977. term    endp
  978.  
  979. ; put the character in al to the screen, do capture and printing,
  980. ; does translation for Set Input command.
  981. ; Adapted from msyibm.asm [jrd]
  982. outtty    proc    near
  983.     test    flags.remflg,d8bit    ; keep 8 bits for displays?
  984.     jnz    outnp8            ; nz = yes, 8 bits if possible
  985.     and    al,7fh            ; remove high bit
  986. outnp8:    cmp    rxtable+256,0        ; is translation off?
  987.     je    outnp7            ; e = yes, off
  988.     push    bx            ; Translate incoming char
  989.     mov    bx,offset rxtable    ; address of translate table
  990.     xlatb                ; new char is in al
  991.     pop    bx
  992. outnp7:
  993.     push    bx
  994.     mov    bx,argadr        ; args from msster directly
  995.     test    [bx].flgs,capt        ; capturing output? Can be shut off
  996.     pop    bx            ;  if out dev becomes not ready
  997.     jz    outnoc            ; no, forget this part
  998.     push    ax            ; save char
  999.     call    captrtn            ; give it captured character
  1000.     pop    ax            ; restore character and keep going
  1001. outnoc:    test    ourarg.flgs,prtscr    ; should we be printing?
  1002.     jz    outnop            ; no, keep going
  1003.     push    ax
  1004.     mov    ah,print_out        ; write to system printer device
  1005.     mov    dl,al
  1006.     int    dos
  1007.     pop    ax
  1008.     jnc    outnop            ; nc = successful print
  1009.     push    ax
  1010.     call    beep            ; else make a noise and
  1011.     call    trnprs            ;  turn off printing
  1012.     pop    ax
  1013. outnop:    cmp    flags.vtflg,0        ; emulating a terminal?
  1014.     jnz    outnop1            ; nz = yup, go do something smart
  1015.     test    ourarg.flgs,trnctl    ; debug? if so use dos tty mode
  1016.     jz    outnp4            ; z = no
  1017.     mov    ah,conout
  1018.     cmp    al,7fh            ; Ascii Del char or greater?
  1019.     jb    outnp1            ; b = no
  1020.     je    outnp0            ; e = Del char
  1021.     push    ax            ; save the char
  1022.     mov    dl,7eh            ; output a tilde for 8th bit
  1023.     int    dos
  1024.     pop    ax            ; restore char
  1025.     and    al,7fh            ; strip high bit
  1026. outnp0:    cmp    al,7fh            ; is char now a DEL?
  1027.     jne    outnp1            ; ne = no
  1028.     and    al,3fH            ; strip next highest bit (Del --> '?')
  1029.     jmp    outnp2            ; send, preceded by caret
  1030. outnp1:    cmp    al,' '            ; control char?
  1031.     jae    outnp3            ; ae = no
  1032.     add    al,'A'-1        ; make visible
  1033. outnp2:    push    ax            ; save char
  1034.     mov    dl,5eh            ; caret
  1035.     int    dos            ; display it
  1036.     pop    ax            ; recover the non-printable char
  1037. outnp3:    mov    dl,al
  1038.     int    dos
  1039.     ret
  1040. outnp4:    cmp    al,bell            ; bell (Control G)?
  1041.     jne    outnp5            ; ne = no
  1042.     jmp    beep            ; use short beep, avoid char loss
  1043. outnop1:
  1044. outnp5:    mov    ah,conout        ; dostty screen mode
  1045.     mov    dl,al            ; write without intervention
  1046.     int    dos            ; else let dos display char
  1047.     ret                ; and return
  1048. outtty    endp
  1049.  
  1050.  
  1051. ; send the character in al out to the serial port; handle echoing.
  1052. ; Can send an 8 bit char while displaying only 7 bits locally.
  1053. outprt    proc    near
  1054.     test    ourarg.flgs,lclecho    ; echoing?
  1055.     jz    outpr1            ; z = no, forget it
  1056.     push    ax            ; save char
  1057.     call    outtty            ; print it
  1058.     pop    ax            ; restore
  1059. outpr1:    mov    ah,al            ; this is where outchr expects it
  1060.     call    outchr            ; output to the port
  1061.      nop
  1062.      nop
  1063.      nop                ; skip returns
  1064.     ret
  1065. outprt    endp
  1066.  
  1067. ; Get a char from the serial port manager
  1068. ; returns with carry on if a character is available
  1069. portchr    proc    near
  1070.     call    prtchr            ; character at port?
  1071.      jmp    short portc1        ; yes, go handle
  1072.      nop                ; skip return is stupid
  1073. portc0:    clc                ; no carry -> no character
  1074.     ret                ; and return
  1075. portc1:    and    al,parmsk        ; apply 8/7 bit parity mask
  1076.     or    al,al            ; catch nulls
  1077.     jz    portc0            ; z = null, ignore it
  1078.     cmp    al,del            ; catch dels
  1079.     je    portc0            ; e = del, ignore it
  1080.     stc                ; have a character
  1081.     ret                ; and return
  1082. portchr    endp
  1083.  
  1084. ;; keyboard translator action routines, system dependent, called from msugen.
  1085. ; These are invoked by a jump instruction. Return carry clear for normal
  1086. ; processing, return carry set to exit Connect mode (kbdflg has transfer char)
  1087.  
  1088. chrout: call    outprt            ; put char in al to serial port
  1089.     clc                ; stay in Connect mode
  1090.     ret
  1091.  
  1092. trnprs:    push    ax            ; toggle Copy screen to printer
  1093.     test    ourarg.flgs,prtscr    ; are we currently printing?
  1094.     jnz    trnpr2            ; nz = yes, its on and going off
  1095.     mov    ah,ioctl
  1096.     mov    al,7            ; get output status of printer
  1097.     push    bx
  1098.     mov    bx,4            ; file handle for system printer
  1099.     int    dos
  1100.     pop    bx
  1101.     jc    trnpr1            ; c = printer not ready
  1102.     cmp    al,0ffh            ; Ready status?
  1103.     je    trnpr2            ; e = Ready    
  1104. trnpr1:    call    beep            ; Not Ready, complain
  1105.     jmp    trnpr3            ; and ignore request
  1106. trnpr2:    xor    ourarg.flgs,prtscr    ; flip the flag
  1107. trnpr3:    pop    ax
  1108.     clc
  1109.     ret
  1110.  
  1111. klogon    proc    near            ; resume logging (if any)
  1112.     test    flags.capflg,logses    ; session logging enabled?
  1113.     jz    klogn            ; z = no, forget it
  1114.     or    ourarg.flgs,capt    ; turn on capture flag
  1115. klogn:    clc
  1116.     ret
  1117. klogon    endp
  1118.  
  1119. klogof    proc    near            ; suspend logging (if any)
  1120.     and    argadr.flgs,not capt    ; stop capturing
  1121. klogo:    clc
  1122.     ret
  1123. klogof    endp
  1124.  
  1125. snull:    mov    ah,0            ; send a null
  1126.     call    outchr            ; send without echo or logging
  1127.      nop
  1128.      nop
  1129.      nop
  1130.     clc
  1131.     ret
  1132.  
  1133. kdos:    mov    al,'P'            ; Push to DOS
  1134.     jmp    short cmdcom
  1135. cstatus:mov    al,'S'            ; these commands exit Connect mode
  1136.     jmp    short cmdcom
  1137. cquit:    mov    al,'C'
  1138.     jmp    short cmdcom
  1139. cquery:    mov    al,'?'
  1140.     jmp    short cmdcom
  1141. cmdcom:    mov    kbdflg,al        ; pass char to msster.asm via kbdflg
  1142.     stc                ; say exit Connect mode
  1143.     ret
  1144.         
  1145. ; Jumping to this location is like retskp.    It assumes the instruction
  1146. ;    after the call is a jmp addr.
  1147.      
  1148. RSKP    PROC    NEAR
  1149.     pop    bp
  1150.     add    bp,3
  1151.     push    bp
  1152.     ret
  1153. RSKP    ENDP
  1154.      
  1155. ; Jumping here is the same as a ret.
  1156.      
  1157. R    PROC    NEAR
  1158.     ret
  1159. R    ENDP
  1160.      
  1161. code    ends
  1162.     end
  1163.