home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / extra / nyenhuis2.arc / MSXHP1.ASM < prev    next >
Assembly Source File  |  1988-07-01  |  23KB  |  898 lines

  1.     name msxhp1
  2. ; File MSXHP1.ASM
  3. ; System dependent module for HP150.
  4. ; Use with file MSUHP1.ASM (keyboard translator)
  5. ; Last edit: 12 June 1988
  6. ; 1 July 1988 Version 2.31
  7. ; 11 Jan 1988 update to 2.30 consistency level.
  8. ; 1 Jan 1988 version 2.30
  9.  
  10.     public    serini, serrst, clrbuf, outchr, coms, vts, vtstat, dodel, ctlu
  11.     public    cmblnk, locate, prtchr, dobaud, clearl, lclini
  12.     public    dodisk, getbaud, beep, setkhlp, setktab
  13.     public    machnam, xofsnt, term, poscur, termtb, shomodem, getmodem
  14.     public    clrmod, putmod, puthlp, sendbr, sendbl, showkey, pcwait
  15.     public    ihosts, ihostr, dtrlow, serhng, dumpscr, comptab
  16.     public    chrout, cstatus, cquit
  17.     public    cquery, trnprs, snull, klogon, klogof, kdos
  18.  
  19.     include mssdef.h
  20.  
  21. false    equ    0
  22. true    equ    1
  23. instat    equ    6
  24. print_out equ    05h            ; dos function to print to printer
  25. prtscr    equ    80h            ; print screen pressed
  26.  
  27. wrdev    equ    40H
  28. rddev    equ    3fH
  29. open    equ    3dH
  30. close    equ    3eH
  31. rdchan    equ    2
  32. e_send_break equ 6
  33. e_ioctl    equ    44h        ; DOS i/o control function
  34. passall    equ    0803h        ; Port transparency mode [WHM]
  35.  
  36. datas     segment    public 'datas'
  37.     extrn    drives:byte, flags:byte, trans:byte
  38.     extrn    portval:word, port1:byte, port2:byte, dmpname:byte
  39.     extrn    kbdflg:byte, rxtable:byte
  40.  
  41. machnam    db    'HP-150$'
  42. erms20    db    cr,lf,'?Warning: System has no disk drives$'
  43. erms40    db    cr,lf,'?Warning: Unrecognized baud rate$'
  44. erms41    db    cr,lf,'?Warning: Cannot open com port$'
  45. noimp    db    cr,lf,'Command not implemented.$'
  46. hngmsg    db    cr,lf,' The phone should have hungup.',cr,lf,'$'
  47. hnghlp    db    cr,lf,' The modem control lines DTR and RTS for the current'
  48.     db    ' port are forced low (off)'
  49.     db    cr,lf,' to hangup the phone. Normally, Kermit leaves them'
  50.     db    ' high (on) when it exits.'
  51.     db    cr,lf,'$'
  52. msmsg1    db    cr,lf,' Communications port is not ready.$'
  53. msmsg2    db    cr,lf,' Communications port is ready.$'
  54. rdbuf    db    80 dup (?)    ; temp buf
  55. setktab    db    0
  56. setkhlp    db    0
  57. shkmsg    db    '?Not implemented.'
  58. shklen    equ    $-shkmsg
  59. crlf    db      cr,lf,'$'
  60. delstr  db      BS,BS,'  ',BS,BS,'$'     ; Delete string
  61. clrlin  db      cr,ESCAPE,'K$'
  62. xofsnt    db    0        ; Say if we sent an XOFF
  63. xofrcv    db    0        ; Say if we received an XOFF
  64. invseq    db    ESCAPE,'&dB$'    ; Reverse video
  65. nrmseq    db    ESCAPE,'&d@$'    ; Normal mode
  66. ivlseq    db    80 dup (' '),ESCAPE,'A','$' ; [ak] Make a line inverse video
  67. tmp    db    ?,'$'
  68. temp    dw    0
  69. temp1   dw      ?               ; Temporary storage
  70. temp2   dw      ?               ; Temporary storage
  71.  
  72. ; Entries for choosing communications port
  73.  
  74. comptab    db    4            ; four entries
  75.     mkeyw    '1',1
  76.     mkeyw    '2',2
  77.     mkeyw    'COM1',1
  78.     mkeyw    'COM2',2
  79.  
  80. termtb    db    tttypes            ; entries for Status, not Set
  81.     mkeyw    'Heath-19',ttheath
  82.     mkeyw    'none',ttgenrc
  83.     mkeyw    'Tek4014',tttek
  84.     mkeyw    'VT102',ttvt100        
  85.     mkeyw    'VT52',ttvt52
  86.  
  87. ; variables for serial interrupt handler
  88.  
  89. source    db    bufsiz DUP(?)    ; Buffer for data from port
  90. bufout    dw    0        ; buffer removal ptr
  91. count    dw    0        ; Number of chars in int buffer
  92. bufin    dw    0        ; buffer insertion ptr
  93. telflg    db    0        ; Are we acting as a terminal
  94. clreol    db    ESCAPE,'K$'
  95. prttab    dw    com1,com2    ; rationalized by [jrd]
  96. com1    db    'COM1',0
  97. com2    db    'COM2',0
  98. blank    db    ESCAPE,'H',ESCAPE,'J$'
  99. movcur    db    ESCAPE,'&a'
  100. colno    db    20 dup (?)
  101. ten    db    10
  102. prthnd    dw    0
  103. argadr    dw    ?        ; address of arg blk from msster.asm
  104. parmsk    db    ?        ; 8/7 bit parity mask, for reception
  105. flowoff    db    ?        ; flow-off char, Xoff or null (if no flow)
  106. flowon    db    ?        ; flow-on char, Xon or null
  107. captrtn    dw    ?        ; routine to call for captured output
  108. tempbuf dw    10 dup(?)
  109. ourarg    termarg    <>
  110. datas    ends
  111.  
  112. code    segment    public 'code'
  113.     extrn    comnd:near, dopar:near, prserr:near, atoi:near, prompt:near
  114.     extrn    sleep:near
  115.     extrn    msuinit:near, keybd:near        ; in msuhp1.asm
  116.     assume    cs:code, ds:datas, es:nothing
  117.  
  118. ; See how many disk drives we have
  119. DODISK    PROC    NEAR
  120.     mov ah,gcurdsk            ; Current disk value to AL
  121.     int dos
  122.     mov dl,al            ; Put current disk in DL
  123.     mov ah,seldsk            ; Select current disk
  124.     int dos                ; Get number of drives in AL
  125.     mov drives,al
  126.     ret
  127. DODISK    ENDP
  128.  
  129. ; Clear the input buffer before sending a packet
  130.  
  131. CLRBUF    PROC    NEAR
  132.     cli
  133.     mov ax,offset source
  134.     mov bufin,ax
  135.     mov bufout,ax
  136.     mov count,0
  137.     sti
  138.     cmp prthnd,0        ; have a port handle yet?
  139.     jne clrb1        ; ne = yes, read chars
  140.     ret            ; else just return
  141. clrb1:    call prtchr        ; get a character
  142.      jmp clrb1        ; until there aren't any more
  143.      nop
  144.     ret
  145. CLRBUF    ENDP
  146.  
  147. ; Common routine to clear to end-of-line
  148.  
  149. CLEARL    PROC    NEAR
  150.     push    ax        ; save regs
  151.     push    dx
  152.     mov    dx,offset clreol
  153.     mov    ah,prstr
  154.     int    dos
  155.     pop    dx        ; restore regs
  156.     pop    ax
  157.     ret
  158. CLEARL    ENDP
  159.  
  160. dobaud    proc    near        ; updated by [jrd] to set baud
  161.     mov ah,prstr
  162.     mov dx,offset noimp    ; Say it's not implemented
  163.     int dos
  164.     push bx            ; save reg
  165.     mov bx,portval
  166.     mov [bx].baud,0FFFFH    ; So it's not a recognized value
  167.     pop bx
  168.     ret            ; Must be set before starting Kermit
  169. dobaud    endp
  170.  
  171. ; Send the break signal out data comm
  172. sendbl:                    ; long break (same as regular here)
  173. sendbr:    mov    al,e_send_break        ; regular break
  174.     call    dc_ioctl
  175.     clc                ; clear carry bit (stay in Connect)
  176.     ret
  177.  
  178. ; Set some data comm ioctl option.  AL has function code
  179. dc_ioctl proc    near
  180.     push    ax            ; save regs
  181.     push    bx
  182.     push    cx
  183.     push    dx
  184.     mov    ah,8h
  185.     mov    tempbuf,ax
  186.     mov    dx,offset tempbuf
  187.     mov    ah,e_ioctl
  188.     mov    al,3
  189.     mov    bx,prthnd
  190.     mov    cx,2
  191.     int    dos
  192.     pop    dx            ; restore regs
  193.     pop    cx
  194.     pop    bx
  195.     pop    ax
  196.     ret
  197. dc_ioctl endp
  198.  
  199. shomodem proc    near
  200.     mov    ah,cmcfm    ; get a confirm
  201.     call    comnd
  202.      jmp    r        ; no confirm
  203.      nop
  204.     cmp    prthnd,0    ; Got a handle yet?
  205.     jne    shmod0        ; Yup just go on
  206.     call    opnprt        ; Else 'open' the port
  207. shmod0:    mov    dx,offset msmsg1 ; say port is not ready
  208.     mov    bx,prthnd
  209.     mov    al,7        ; output status command
  210.     mov    ah,ioctl    ; ask DOS to look for us
  211.     int    dos
  212.     jc    shmod1        ; c = call failed, device not ready
  213.     or    al,al
  214.     jz    shmod1        ; not ready
  215.     mov    dx,offset msmsg2 ; say port is ready
  216. shmod1:    mov    ah,prstr
  217.     int    dos
  218.     jmp    rskp
  219. shomodem endp
  220.  
  221. getmodem proc near
  222.     mov    al,0
  223.     ret
  224. getmodem endp
  225.  
  226. ; Put the char in AH to the serial port.  This assumes the
  227. ; port has been initialized.  Should honor xon/xoff.  Skip returns on
  228. ; success, returns normally if the character cannot be written
  229.  
  230. outchr: push    cx        ; save regs
  231.     or    ah,ah        ; sending a null?
  232.     jz    outch2        ; z = yes
  233.     xor    cx,cx        ; clear counter
  234.     cmp    ah,flowoff    ; sending xoff?
  235.     jne    outch1        ; ne = no
  236.     mov    xofsnt,false    ; supress xon from chkxon buffer routine
  237. outch1:    cmp    xofrcv,true    ; Are we being held?
  238.     jne    outch2        ; No - it's OK to go on
  239.     loop    outch1        ; held, try for a while
  240.     mov    xofrcv,false    ; timed out, force it off and fall thru
  241. outch2:    push    dx        ; Save register
  242.     mov    al,ah        ; Parity routine works on AL
  243.     call    dopar        ; Set parity appropriately
  244.                 ; Begin revised output routine
  245.     mov    byte ptr temp,al ; put data there
  246.     cmp    prthnd,0    ; Got a handle yet?
  247.     jne    outch3        ; Yup just go on
  248.     call    opnprt        ; Else 'open' the port
  249. outch3:    push    bx
  250.     mov    bx,prthnd    ; port handle
  251.     mov    cx,1        ; one byte to write
  252.     mov    dx,offset temp    ; place where data will be found
  253.     mov    ah,write2    ; dos 2 write to file/device
  254.     int    dos
  255.     pop    bx        ; end of revised routine
  256.     pop    dx
  257.     pop    cx
  258.     jmp    rskp
  259.  
  260. ; Get a file handle for the communications port.  Use DOS call to get the
  261. ; next available handle.  If it fails, ask user what value to use (there
  262. ; should be a predefined handle for the port, generally 3).  The open
  263. ; will fail if the system uses names other than "COM1" or "COM2".
  264. opnprt:    mov al,flags.comflg
  265.     dec al            ; flags.comflg is 1 for com1, 2 for com2
  266.     mov ah,0
  267.     push si
  268.     mov si,ax
  269.     shl si,1        ; double index
  270.     mov dx,prttab[si]
  271.     pop si
  272.     mov ah,open2
  273.     mov al,2
  274.     int dos
  275.     jnc opnpr2
  276.     mov ah,prstr        ; It didn't like the string
  277.     mov dx,offset erms41
  278.     int dos
  279.     ret
  280. opnpr2:    mov prthnd,ax        ; Call succeeded
  281.     mov ah,ioctl
  282.     mov al,00h        ; get device info
  283.     xor dx,dx
  284.     mov bx,prthnd        ; port's handle
  285.     int dos
  286.     or dl,20h        ; set binary mode in device info
  287.     mov dh,0
  288.     mov ah,ioctl
  289.     mov al,01h        ; set device info
  290.     int dos
  291.     ret
  292.  
  293. ; This routine blanks the screen.
  294.  
  295. CMBLNK    PROC    NEAR        ; This is stolen from the IBM example
  296.     push ax
  297.     push dx
  298.     mov ah,prstr
  299.     mov dx,offset blank
  300.     int dos
  301.     pop dx
  302.     pop ax
  303.     ret
  304. CMBLNK  ENDP
  305.  
  306. LOCATE  PROC    NEAR
  307.     mov dx,0        ; Go to top left corner of screen
  308.     jmp poscur        ; callret
  309. LOCATE  ENDP
  310.  
  311. GETBAUD    PROC    NEAR
  312.     ret
  313. GETBAUD    ENDP
  314.  
  315.  
  316. ; skip returns if no character available at port,
  317. ; otherwise returns with char in al, # of chars in buffer in dx.
  318.  
  319. PRTCHR    PROC    NEAR
  320.     push bx
  321.     push cx
  322.     push si
  323.     cmp prthnd,0        ; have a handle yet?
  324.     jne prtch1        ; yes, keep going
  325.     call opnprt
  326. prtch1:    cmp count,0        ; no characters?
  327.     jne prtch2        ; no, go fill buffer
  328.     mov bx,prthnd
  329.     mov al,rdchan
  330.     mov ah,ioctl
  331.     mov dx,offset source    ; buffer to read into
  332.     mov cx,bufsiz        ; length of buffer
  333.     int dos
  334.     jc prtch4        ; c = error
  335.     mov count,ax        ; reset count
  336.     mov dx,ax        ; needed to obey rules
  337.     or ax,ax
  338.     jz prtch4        ; still no chars
  339.     mov bufout,offset source ; this is output ptr
  340. prtch2:    dec count
  341.     mov dx,count        ; return count in dx
  342.     mov si,bufout
  343.     cld
  344.     lodsb            ; get character
  345.     mov bufout,si        ; update ptr
  346. prtch3:    pop si
  347.     pop cx
  348.     pop bx
  349.     ret            ; exit success
  350. prtch4:    pop si
  351.     pop cx
  352.     pop bx
  353.     jmp rskp        ; no chars
  354. PRTCHR  ENDP
  355.  
  356. ; IHOSTS - Initialize the host by sending XON, or equivalent, and enter the
  357. ; cycle of clear input buffer, wait 1 second, test if buffer empty then exit
  358. ; else repeat cycle. Requires that the port be initialized before hand.
  359. ; Ihosts is used by the local send-file routine just after initializing
  360. ; the serial port.
  361. ; 22 March 1986 [jrd]
  362.  
  363. IHOSTS    PROC    NEAR
  364.     push    ax        ; save the registers
  365.     push    bx
  366.     push    cx
  367.     push    dx
  368.     mov    bx,portval    ; port indicator
  369.     mov    ax,[bx].flowc    ; put Go-ahead flow control char in ah
  370.     or    ah,ah        ; don't send null if flow = none
  371.     jz    ihosts1        ; z = null
  372.     call    outchr        ; send it (release Host's output queue)
  373.      nop            ; outchr can do skip return
  374.      nop
  375.      nop
  376. ihosts1:call    clrbuf        ; clear out interrupt buffer
  377.     pop    dx            ; empty buffer. we are done here
  378.     pop    cx
  379.     pop    bx
  380.     pop    ax
  381.     ret
  382. IHOSTS    ENDP
  383.  
  384. ; IHOSTR - initialize the remote host for our reception of a file by
  385. ; sending the flow-on character (XON typically) to release any held
  386. ; data. Called by receive-file code just after initializing the serial
  387. ; port.        22 March 1986 [jrd]
  388. IHOSTR    PROC    NEAR
  389.     push    ax        ; save regs
  390.     push    bx
  391.     push    cx
  392.     mov    bx,portval    ; port indicator
  393.     mov    ax,[bx].flowc    ; put Go-ahead flow control char in ah
  394.     or    ah,ah        ; don't send null if flow = none
  395.     jz    ihostr1        ; z = null
  396.     call    outchr        ; send it (release Host's output queue)
  397.      nop            ; outchr can do skip return
  398.      nop
  399.      nop
  400. ihostr1:pop    cx
  401.     pop    bx
  402.     pop    ax
  403.     ret
  404. IHOSTR    ENDP
  405.  
  406. DTRLOW    PROC    NEAR        ; Global proc to Hangup the Phone by making
  407.                 ; DTR and RTS low.
  408.     mov ah,cmtxt        ; allow text to be able to display help
  409.     mov bx,offset rdbuf    ; dummy buffer
  410.     mov dx,offset hnghlp    ; help message
  411.     call comnd        ; get a confirm
  412.      jmp r
  413. ; not yet imp.    call serhng        ; drop DTR and RTS
  414.     mov ah,prstr        ; give a nice message
  415. ; not yet imp.    mov dx,offset hngmsg
  416.     mov dx,offset noimp    ; for now
  417.     int dos
  418.     clc
  419.     jmp rskp
  420. DTRLOW    ENDP
  421.  
  422. ; Hang up the Phone. Similar to SERRST except it just forces DTR and RTS low
  423. ; to terminate the connection. 29 March 1986 [jrd]
  424. ; Calling this twice without intervening calls to serini should be harmless.
  425. ; Returns normally.
  426. ; SERHNG is Not Yet Implemented.
  427. SERHNG    PROC    NEAR
  428.     ret
  429. SERHNG    ENDP
  430.  
  431. ; Position the cursor according to contents of DX
  432.  
  433. POSCUR    PROC    NEAR
  434.     push    ax            ; save regs
  435.     push    dx
  436.     push    di
  437.     push    es
  438.     mov    ax,ds
  439.     mov    es,ax            ; address data segment
  440.     cld
  441.     mov    di,offset colno
  442.     mov    al,dl            ; column
  443.     call    nout
  444.     mov    al,'c'
  445.     stosb
  446.     mov    al,dh            ; row
  447.     call    nout
  448.     mov    al,'Y'
  449.     stosb
  450.     mov    al,'$'
  451.     stosb
  452.     mov    dx,offset movcur
  453.     mov    ah,prstr
  454.     int    dos            ; print the sequence
  455.     pop    es            ; restore regs
  456.     pop    di
  457.     pop    dx
  458.     pop    ax
  459.     ret
  460. POSCUR    ENDP
  461.  
  462. NOUT    PROC    NEAR
  463.     cbw            ; extend to word
  464.     div    byte ptr ten    ; divide by 10
  465.     or    al,al        ; any quotient?
  466.     jz    nout1        ; no, forget this
  467.     push    ax        ; save current result
  468.     call    nout        ; output high order
  469.     pop    ax        ; restore
  470. nout1:    mov    al,ah        ; get digit
  471.     add    al,'0'        ; make printable
  472.     stosb
  473.     ret            ; put in buffer and return
  474. NOUT    endp
  475.  
  476. ; Write a line in inverse video at the bottom of the screen...
  477. ; the line is passed in dx, terminated by a $.  Returns normally.
  478. putmod    proc    near
  479.     push    dx        ; preserve message
  480.     mov    dx,24 * 100H    ; line 24
  481.     call    poscur
  482.     mov    dx,offset invseq ; put into inverse video
  483.     mov    ah,prstr
  484.     int    dos
  485.     pop    dx
  486.     int     dos
  487.     mov    dx,offset nrmseq ; normal videw
  488.     int    dos
  489.     ret            ; and return
  490. putmod    endp
  491.  
  492. ; Clear the mode line written by putmod.  Returns normally.
  493. clrmod    proc    near
  494.     mov    dx,24 * 100H
  495.     call    poscur
  496.     call    clearl
  497.     ret
  498. clrmod    endp
  499.  
  500. ; Put a help message one the screen in reverse video.  Pass
  501. ; the message in AX, terminated by a null.  Returns normally.
  502. ; The message is put wherever the cursor currently is located.
  503. puthlp    proc    near
  504.     push ax            ; save some regs
  505.     push si
  506.     push dx
  507.     push ax
  508.     mov ah,prstr        ; Leave some room before the message
  509.     mov dx,offset crlf
  510.     int dos
  511.     pop si            ; Put message address here
  512. puth0:    mov ah,prstr
  513.     mov dx,offset invseq    ; Put into reverse video
  514.     int dos
  515.     mov ah,prstr
  516.     mov dx,offset ivlseq    ; Make line inverse video
  517.     int dos
  518.     cld
  519. puth1:    lodsb
  520.     cmp al,0        ; Terminated with a null
  521.     je puth2
  522.     mov dl,al
  523.     mov ah,conout
  524.     int dos    
  525.     cmp al,lf        ; Line feed?
  526.     je puth0        ; Yes, clear the next line
  527.     jmp puth1        ; Else, just keep on writing
  528. puth2:    mov dx,offset crlf
  529.     mov ah,prstr
  530.     int dos
  531.     mov dx,offset nrmseq        ; Normal video
  532.     int dos
  533.     pop si                ; restore regs
  534.     pop dx
  535.     pop ax
  536.     ret
  537. puthlp    endp
  538.  
  539. ; Perform a delete.
  540.  
  541. DODEL    PROC    NEAR
  542.     push ax
  543.     push dx
  544.     mov ah,prstr
  545.     mov dx,offset delstr        ; Erase weird character
  546.     int dos
  547.     pop dx
  548.     pop ax            
  549.     ret
  550. DODEL    ENDP
  551.  
  552. ; Perform a Control-U.
  553.  
  554. CTLU    PROC    NEAR
  555.     push ax
  556.     push dx
  557.     mov ah,prstr
  558.     mov dx,offset clrlin
  559.     int dos
  560.     pop dx
  561.     pop ax
  562.     ret
  563. CTLU    ENDP
  564.  
  565. COMS    PROC    NEAR
  566.         mov dx,offset comptab        ; comms port table
  567.         mov bx,0            ; use keywords as help
  568.         mov ah,cmkey            ; parse keyword
  569.         call comnd
  570.          jmp r                ; failed
  571.         push bx
  572.         mov ah,cmcfm
  573.         call comnd            ; Get a confirm
  574.          jmp comx            ;  Didn't get a confirm
  575.      nop
  576.         pop bx
  577.         mov flags.comflg,bl        ; Set the comm port flag
  578.     cmp flags.comflg,1        ; Using Com 1?
  579.     jne coms2            ; Nope
  580.     mov portval,offset port1
  581.     ret
  582. coms2:    mov portval,offset port2    ; use Com2
  583.     ret
  584. comx:    pop bx
  585.     ret
  586. COMS    ENDP
  587.  
  588. VTS    PROC    NEAR            ; Set Term code
  589.     jmp notimp
  590. VTS    ENDP
  591.  
  592.  
  593. VTSTAT    PROC    NEAR    ; For Status display [jrd]
  594.     ret        ; no emulator status to display
  595. VTSTAT    ENDP 
  596.  
  597. ; Save the screen to a buffer and then append buffer to a disk file. [jrd]
  598. ; Default filename is Kermit.scn; actual file can be a device too. Filename
  599. ; is determined by mssset and is passed as pointer dmpname.
  600.  
  601. DUMPSCR    PROC    NEAR    ; Dumps screen contents to a file. Just Beeps here
  602.     call    beep
  603.     ret
  604. DUMPSCR    ENDP
  605.  
  606.  
  607. notimp:    mov    ah,prstr
  608.     mov    dx,offset noimp
  609.     int    dos
  610.     jmp    prserr
  611.  
  612. lclini:    mov    flags.vtflg,0        ; no terminal emulation. [jrd]
  613.     mov    prthnd,0        ; no port handle yet. [jrd]
  614.     call    msuinit            ; initialize keyboard module msugen
  615.     ret
  616.  
  617.  
  618. showkey:
  619.     mov    ax,offset shkmsg
  620.     mov    cx,shklen
  621.     ret
  622.  
  623. ; Wait for the # of milliseconds in ax, for non-IBM compatibles.
  624. ; Thanks to Bernie Eiben for this one.
  625. pcwait    proc    near
  626.     mov    cx,240        ; inner loop counter for 1 millisecond
  627. pcwai1:    sub    cx,1        ; inner loop takes 20 clock cycles
  628.     jnz    pcwai1
  629.     dec    ax        ; outer loop counter
  630.     jnz    pcwait        ; wait another millisecond
  631.     ret
  632. pcwait    endp
  633.  
  634. ; Initialization for using serial port.  Returns normally.
  635. ; Attempts to put port device in binary mode. [jrd]
  636. SERINI    PROC    NEAR
  637.     cld            ; Do increments in string operations
  638.     cmp prthnd,0        ; Got a handle yet?
  639.     jne serin0        ; ne = yes, just go on
  640.     push bx
  641.     call opnprt        ; Else 'open' the port
  642.     mov ax,passall        ; set for transparency mode [WHM]
  643.     call dc_ioctl        ; use DOS function [WHM]
  644.     pop bx
  645. serin0:    push bx
  646.     mov bx,portval        ; get port [jrd]
  647.     mov parmsk,0ffh        ; parity mask, assume parity is None
  648.     cmp [bx].parflg,parnon    ; is it None?
  649.     je serin1        ; e = yes
  650.     mov parmsk,07fh        ; no, pass lower 7 bits as data
  651. serin1:    mov bx,[bx].flowc    ; get flow control chars
  652.     mov flowoff,bl        ; xoff or null
  653.     mov flowon,bh        ; xon or null
  654.     pop bx
  655.     clc            ; carry clear for success
  656.     ret
  657. SERINI    ENDP
  658.  
  659. SERRST    PROC    NEAR
  660.     push bx            ; save reg
  661.     mov bx,prthnd
  662.     cmp bx,0        ; none there?
  663.     je serrs1        ; no, don't try to close
  664.     mov ah,close
  665.     int dos            ; close handle
  666.     mov prthnd,0
  667. serrs1: pop bx
  668.     ret            ; All done
  669. SERRST    ENDP
  670.  
  671. ; Generate a short beep.
  672.  
  673. BEEP    PROC    NEAR
  674.     mov dl,bell
  675.     mov ah,conout
  676.     int dos    
  677.     ret
  678. BEEP    ENDP 
  679.  
  680. ; Dumb terminal emulator.  Doesn't work too well above 1200 baud (and
  681. ; even at 1200 baud you sometimes lose the first one or two characters
  682. ; on a line). Does capture (logging), local echo, debug display, tests
  683. ; for printer/logging device not ready. 27 Sept 86 [jrd]. 
  684. term    proc    near
  685.     mov argadr,ax        ; save argument ptr
  686.     mov si,ax        ; this is source
  687.     mov di,offset ourarg    ; place to store arguments
  688.     push es            ; save register
  689.     push ds
  690.     pop es            ; make es point to datas segment
  691.     mov cx,size termarg
  692.     cld
  693.     rep movsb        ; copy into our arg blk
  694.     pop es            ; recover reg
  695.     and ourarg.flgs,not (prtscr) ; no screen printing at startup
  696.     mov ax,ourarg.captr
  697.     mov captrtn,ax        ; buffer capture routine
  698.  
  699.     mov parmsk,0ffh        ; parity mask, assume parity = None
  700.     cmp ourarg.parity,parnon ; is parity None?
  701.     je term1        ; e = yes, keep all 8 bits
  702.     mov parmsk,07fh        ; else keep lower 7 bits
  703. term1:    call portchr        ; get char from port, apply parity mask
  704.     jnc short term2        ; nc = no char, go on
  705.     call outtty        ; display and capture char
  706. term2:    call    keybd        ; call keyboard translator in msu
  707.     jnc    term1        ; nc = no char or have processed it
  708.                      ; carry set = quit Connect mode
  709. term4:    ret
  710. term    endp
  711.  
  712.  
  713. ; put the character in al to the screen, do capture and printing,
  714. ; does translation for Set Input command.
  715. ; Adapted from msyibm.asm [jrd]
  716. outtty    proc    near
  717.     test    flags.remflg,d8bit    ; keep 8 bits for displays?
  718.     jnz    outnp8            ; nz = yes, 8 bits if possible
  719.     and    al,7fh            ; remove high bit
  720. outnp8:    cmp    rxtable+256,0        ; is translation off?
  721.     je    outnp7            ; e = yes, off
  722.     push    bx            ; Translate incoming char
  723.     mov    bx,offset rxtable    ; address of translate table
  724.     xlatb                ; new char is in al
  725.     pop    bx
  726. outnp7:
  727.     push    bx
  728.     mov    bx,argadr        ; args from msster directly
  729.     test    [bx].flgs,capt        ; capturing output? Can be shut off
  730.     pop    bx            ;  if out dev becomes not ready
  731.     jz    outnoc            ; no, forget this part
  732.     push    ax            ; save char
  733.     call    captrtn            ; give it captured character
  734.     pop    ax            ; restore character and keep going
  735. outnoc:    test    ourarg.flgs,prtscr    ; should we be printing?
  736.     jz    outnop            ; no, keep going
  737.     push    ax
  738.     mov    ah,print_out        ; write to system printer device
  739.     mov    dl,al
  740.     int    dos
  741.     pop    ax
  742.     jnc    outnop            ; nc = successful print
  743.     push    ax
  744.     call    beep            ; else make a noise and
  745.     call    trnprs            ;  turn off printing
  746.     pop    ax
  747. outnop:    cmp    flags.vtflg,0        ; emulating a terminal?
  748.     jnz    outnop1            ; nz = yup, go do something smart
  749.     test    ourarg.flgs,trnctl    ; debug? if so use dos tty mode
  750.     jz    outnp4            ; z = no
  751.     mov    ah,conout
  752.     cmp    al,7fh            ; Ascii Del char or greater?
  753.     jb    outnp1            ; b = no
  754.     je    outnp0            ; e = Del char
  755.     push    ax            ; save the char
  756.     mov    dl,7eh            ; output a tilde for 8th bit
  757.     int    dos
  758.     pop    ax            ; restore char
  759.     and    al,7fh            ; strip high bit
  760. outnp0:    cmp    al,7fh            ; is char now a DEL?
  761.     jne    outnp1            ; ne = no
  762.     and    al,3fH            ; strip next highest bit (Del --> '?')
  763.     jmp    outnp2            ; send, preceded by caret
  764. outnp1:    cmp    al,' '            ; control char?
  765.     jae    outnp3            ; ae = no
  766.     add    al,'A'-1        ; make visible
  767. outnp2:    push    ax            ; save char
  768.     mov    dl,5eh            ; caret
  769.     int    dos            ; display it
  770.     pop    ax            ; recover the non-printable char
  771. outnp3:    mov    dl,al
  772.     int    dos
  773.     ret
  774. outnp4:    cmp    al,bell            ; bell (Control G)?
  775.     jne    outnp5            ; ne = no
  776.     jmp    beep            ; use short beep, avoid char loss
  777. outnop1:
  778. outnp5:    mov    ah,conout        ; dostty screen mode
  779.     mov    dl,al            ; write without intervention
  780.     int    dos            ; else let dos display char
  781.     ret                ; and return
  782. outtty    endp
  783.  
  784.  
  785. ; send the character in al out to the serial port; handle echoing.
  786. ; Can send an 8 bit char while displaying only 7 bits locally.
  787. outprt    proc    near
  788.     test    ourarg.flgs,lclecho    ; echoing?
  789.     jz    outpr1            ; z = no, forget it
  790.     push    ax            ; save char
  791.     call    outtty            ; print it
  792.     pop    ax            ; restore
  793. outpr1:    mov    ah,al            ; this is where outchr expects it
  794.     call    outchr            ; output to the port
  795.      nop
  796.      nop
  797.      nop                ; skip returns
  798.     ret
  799. outprt    endp
  800.  
  801. ; Get a char from the serial port manager
  802. ; returns with carry on if a character is available
  803. portchr    proc    near
  804.     call    prtchr            ; character at port?
  805.      jmp    short portc1        ; yes, go handle
  806.      nop                ; skip return is stupid
  807. portc0:    clc                ; no carry -> no character
  808.     ret                ; and return
  809. portc1:    and    al,parmsk        ; apply 8/7 bit parity mask
  810.     or    al,al            ; catch nulls
  811.     jz    portc0            ; z = null, ignore it
  812.     cmp    al,del            ; catch dels
  813.     je    portc0            ; e = del, ignore it
  814.     stc                ; have a character
  815.     ret                ; and return
  816. portchr    endp
  817.  
  818. ;; keyboard translator action routines, system dependent, called from msugen.
  819. ; These are invoked by a jump instruction. Return carry clear for normal
  820. ; processing, return carry set to exit Connect mode (kbdflg has transfer char)
  821.  
  822. chrout: call    outprt            ; put char in al to serial port
  823.     clc                ; stay in Connect mode
  824.     ret
  825.  
  826. trnprs:    push    ax            ; toggle Copy screen to printer
  827.     test    ourarg.flgs,prtscr    ; are we currently printing?
  828.     jnz    trnpr2            ; nz = yes, its on and going off
  829.     mov    ah,ioctl
  830.     mov    al,7            ; get output status of printer
  831.     push    bx
  832.     mov    bx,4            ; file handle for system printer
  833.     int    dos
  834.     pop    bx
  835.     jc    trnpr1            ; c = printer not ready
  836.     cmp    al,0ffh            ; Ready status?
  837.     je    trnpr2            ; e = Ready    
  838. trnpr1:    call    beep            ; Not Ready, complain
  839.     jmp    trnpr3            ; and ignore request
  840. trnpr2:    xor    ourarg.flgs,prtscr    ; flip the flag
  841. trnpr3:    pop    ax
  842.     clc
  843.     ret
  844.  
  845. klogon    proc    near            ; resume logging (if any)
  846.     test    flags.capflg,logses    ; session logging enabled?
  847.     jz    klogn            ; z = no, forget it
  848.     or    ourarg.flgs,capt    ; turn on capture flag
  849. klogn:    clc
  850.     ret
  851. klogon    endp
  852.  
  853. klogof    proc    near            ; suspend logging (if any)
  854.     and    argadr.flgs,not capt    ; stop capturing
  855. klogo:    clc
  856.     ret
  857. klogof    endp
  858.  
  859. snull:    mov    ah,0            ; send a null
  860.     call    outchr            ; send without echo or logging
  861.      nop
  862.      nop
  863.      nop
  864.     clc
  865.     ret
  866.  
  867. kdos:    mov    al,'P'            ; Push to DOS
  868.     jmp    short cmdcom
  869. cstatus:mov    al,'S'            ; these commands exit Connect mode
  870.     jmp    short cmdcom
  871. cquit:    mov    al,'C'
  872.     jmp    short cmdcom
  873. cquery:    mov    al,'?'
  874.     jmp    short cmdcom
  875. cmdcom:    mov    kbdflg,al        ; pass char to msster.asm via kbdflg
  876.     stc                ; say exit Connect mode
  877.     ret
  878.                     ;; end of action routines
  879.  
  880. ; Jumping to this location is like retskp.  It assumes the instruction
  881. ;   after the call is a jmp addr.
  882.  
  883. RSKP    PROC    NEAR
  884.     pop    bp
  885.     add    bp,3
  886.     push    bp
  887.         ret
  888. RSKP    ENDP
  889.  
  890. ; Jumping here is the same as a ret.
  891.  
  892. R       PROC    NEAR
  893.         ret
  894. R       ENDP
  895.  
  896. code    ends 
  897.     end
  898.