home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / asm / MSKERMIT.ZIP / MSTERM.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-05-17  |  12.2 KB  |  453 lines

  1.     public    clscpt, defkey, cptfcb, inicpt, clscpi, telnet
  2.     public    dopar, shokey, prkey
  3.     include msdefs.h
  4.  
  5. datas    segment public 'datas'
  6.     extrn    flags:byte, trans:byte, buff:byte, portval:word
  7.  
  8. targ    termarg <0,1,80,24,cptchr,2dch,0,scntab,deftab,0,,parnon>
  9. ssp    dw    0        ; Save SP in Telnet.
  10. crlf    db    cr,lf,'$'
  11. tmp    db    ?,'$'
  12. temp    dw    0
  13. temp1    dw    ?        ; Temporary storage.
  14. temp2    dw    ?        ; Temporary storage.
  15. tmsg1    db    cr,lf,'[Connecting to host, type $'
  16. tmsg3    db    ' C to return to PC]',cr,lf,cr,lf,cr,lf,'$'
  17. tmsg2    db    cr,lf,'[Back at micro]',cr,lf,'$'
  18. erms22    db    cr,lf,'?No capture file open$' ;[jd]
  19. esctl    db    'Control-$'         ; [6]
  20.  
  21. inthlp    db    cr,lf,' ?  This message'
  22.     db    cr,lf,' C  Close the connection'
  23.     db    cr,lf,' S  Status of the connection'
  24.     db    cr,lf,' B  Send a break'
  25.     db    cr,lf,' M  Toggle mode line'
  26.     db    cr,lf,' Q  Quit logging'
  27.     db    cr,lf,' R  Resume logging'
  28.     db    cr,lf,' 0  Send a null'
  29.     db    cr,lf,' Typing the escape character will send it to the host'
  30.     db    0
  31.  
  32. intprm    db    'Command>$'
  33.  
  34. CPTFCB    DB    25H DUP (?)
  35. CAPBUF    DB    200 DUP (?)
  36. CAPBP    DW    ?
  37. CAPLFT    DB    ?
  38.  
  39. SCNTLEN EQU    200        ; MAX # OF DEFINITIONS ONE can have
  40. defbsiz equ    400        ; combined length of all definitions...
  41. scntab    dw    scntlen dup (?) ; scan codes redefined
  42. deftab    dw    scntlen dup (?) ; pointer to definition strings
  43. defbuf    db    defbsiz dup (?)
  44. defptr    dw    defbuf        ; pointer starts at beginning
  45. deflen    dw    defbsiz     ; amt of space left in buffer
  46. sttmsg    db    'Type space to continue$'
  47. shkmsg    db    cr,lf,'Press key: $'
  48. datas    ends
  49.  
  50. code    segment public
  51.     extrn    comnd:near, outchr:near, stat0:near
  52.     extrn    escprt:near, clrbuf:near, term:near
  53.     extrn    cmblnk:near, locate:near, prtchr:near
  54.     extrn    beep:near, puthlp:near
  55.     extrn    serini:near,serrst:near, sendbr:near, showkey:near
  56.     assume    cs:code, ds:datas
  57.  
  58. ; the show key command.
  59.  
  60. shokey    proc    near
  61.     mov    ah,cmcfm        ; confirm with carriage return
  62.     call    comnd
  63.      jmp    r            ; uh oh...
  64.     mov    dx,offset shkmsg
  65.     mov    ah,prstr
  66.     int    dos            ; print a prompt for it
  67.     mov    ax,offset targ        ; give it terminal arg block.
  68.     call    showkey         ; show them the key definition
  69.     push    ax
  70.     push    cx            ; save results
  71.     mov    dx,offset crlf
  72.     mov    ah,prstr
  73.     int    dos
  74.     pop    cx
  75.     pop    ax
  76.     call    prkey            ; print the buffer
  77.     mov    dx,offset crlf
  78.     mov    ah,prstr
  79.     int    dos
  80.     jmp    rskp            ; and return
  81. shokey    endp
  82.  
  83. ; pass a string pointer in ax, length in cx.
  84. ; Prints the string, quoting any unprintables, except crlf.
  85.  
  86. prkey    proc    near
  87.     mov    si,ax            ; copy string ptr
  88.     jcxz    prke6            ; no string, stop here
  89. prke1:    push    cx            ; save counter
  90.     lodsb                ; get a byte
  91.     and    al,7fH            ; only consider low-order 7 bits.
  92.     cmp    al,' '                  ; printable?
  93.     jb    prke2            ; no, print the hard way
  94.     cmp    al,7fH            ; maybe a delete?
  95.     jne    prke4            ; no, can just put into string
  96. prke2:    jcxz    prke3            ; last char, can't be crlf
  97.     cmp    al,cr            ; carriage return?
  98.     jne    prke3            ; no, go on
  99.     cmp    byte ptr [si],lf    ; followed by linefeed?
  100.     jne    prke3
  101.     mov    ah,prstr
  102.     mov    dx,offset crlf
  103.     int    dos            ; else just print crlf
  104.     inc    si            ; skip over lf
  105.     pop    cx            ; careful...
  106.     dec    cx
  107.     push    cx
  108.     jmp    short prke5
  109. prke3:    push    ax            ; preserve the char
  110.     mov    ah,conout
  111.     mov    dl,'\'
  112.     int    dos            ; print the quote character
  113.     pop    ax
  114.     call    proct            ; print the octal byte
  115.     jmp    short prke5
  116. prke4:    mov    dl,al            ; normal char, just print it
  117.     mov    ah,conout
  118.     int    dos
  119. prke5:    pop    cx            ; restore count
  120.     loop    prke1
  121. prke6:    ret                ; and return
  122. prkey    endp
  123.  
  124. ; print the byte in al as an octal number
  125. proct    proc    near
  126.     mov    dl,al            ; get the byte
  127.     and    dl,7h            ; keep low-order byte
  128.     mov    cl,3
  129.     shr    al,cl            ; shift to get next digit
  130.     jz    proc1            ; 0, no more to print
  131.     push    dx            ; else save current digit
  132.     call    proct            ; print rest
  133.     pop    dx
  134. proc1:    mov    ah,conout
  135.     add    dl,'0'                  ; make printable
  136.     int    dos
  137.     ret
  138. proct    endp
  139.  
  140. ;    This is the CONNECT command.
  141.  
  142. TELNET    PROC    NEAR
  143.     mov ah,cmcfm
  144.     call comnd        ; Get a confirm.
  145.      jmp r            ;  Didn't get a confirm.
  146.     mov ah,prstr        ; Output
  147.     mov dx,offset crlf    ; a crlf.
  148.     int dos
  149.     call domsg        ; Reassure user. [19b]
  150.     mov al,targ.flgs    ; get present flags
  151.     and al,modoff        ; this is only one we can keep around
  152.     or al,havtt        ; defaults (!)
  153.     cmp flags.debug,0    ; debug mode?
  154.     jz tel0         ; no, keep going
  155.     or al,trnctl        ; yes, show control chars
  156. tel0:    cmp flags.vtflg,0    ; vt52 emulation?
  157.     jz tel1
  158.     or al,emheath
  159. tel1:    mov bx,portval
  160.     cmp [bx].ecoflg,0    ; echoing?
  161.     jz tel2
  162.     or al,lclecho
  163. tel2:    mov targ.flgs,al    ; store flags
  164.     mov ah,flags.comflg
  165.     mov targ.prt,ah     ; Port 1 or 2
  166.     mov ah,trans.escchr
  167.     mov targ.escc,ah
  168.     mov ah,[bx].parflg
  169.     mov targ.parity,ah
  170.     mov ax,[bx].baud
  171.     mov targ.baudb,al
  172.     mov ah,flags.capflg
  173.     and ah,capt
  174.     or targ.flgs,ah
  175.     call serini        ; init serial port
  176. tem:    mov ax,offset targ    ; Point to terminal arguments
  177.     call term
  178.     or targ.flgs,scrsam    ; assume screen is the same.
  179. intchr: mov ah,dconio        ; Direct console I/O.
  180.     mov dl,0FFH        ; Input.
  181.     int dos         ; Get a char.
  182.     jz intchr        ; no char, keep looking
  183.     mov ah,al
  184.     jz intchr        ; If so, go until we get a char.
  185.     cmp ah,' '              ; space - ignore it
  186.     je tem
  187.     mov bh,ah        ; Save the actual char.
  188.     and ah,not ('a'-'A')    ; Convert to upper case.
  189.     or ah,40H        ; convert ctl-char to actual char.
  190.     cmp ah,'C'              ; Is it close?
  191.     jne intch1
  192.     call serrst        ; reset serial port
  193.     jmp rskp        ; and return
  194. intch1: cmp ah,'S'              ; Is it status?
  195.     jnz intch2
  196.     call stat0        ; If so, call stat0.
  197.     call puthlp        ; put help on screen
  198.     mov dx,offset sttmsg
  199.     mov ah,prstr
  200.     int dos
  201. intch1a:mov ah,8        ; console input, no echo
  202.     int dos
  203.     cmp al,' '              ; space?
  204.     jne intch1a
  205.     and targ.flgs,not scrsam ; remember screen changed.
  206.     jmp tem
  207. intch2: cmp ah,'B'              ; Send a break? [20g]
  208.     jne intch3        ; No. [20g]
  209.     call sendbr        ; Yes, so send a break. [20g]
  210.     jmp tem         ; And return.  [20g]
  211. intch3: cmp ah,'M'              ; mode line?
  212.     jne intch4
  213.     xor targ.flgs,modoff    ; toggle mode line
  214.     jmp tem         ; and reconnect
  215. intch4: cmp bh,'?'              ; Is it help?
  216.     jne intch5        ; If not, go to the next check.
  217.     mov ax,offset inthlp    ; If so, get the address of the help message.
  218.     call puthlp        ; write help msg
  219.     mov dx,offset intprm
  220.     mov ah,prstr        ; Print it.
  221.     int dos
  222.     and targ.flgs,not scrsam ; remember screen changed
  223.     jmp intchr        ; Get another char.
  224. intch5: cmp bh,trans.escchr    ; Is it the escape char?
  225.     jne intch7        ; If not, go send a beep to the user.
  226. intch6: mov ah,al
  227.     call outchr
  228.     nop
  229.     nop
  230.     nop
  231.     jmp tem         ; Return, we are done here.
  232. intch7: cmp ah,'Q'              ; maybe want to stop logging?
  233.     jne intch8
  234.     test targ.flgs,capt    ; not capturing, can't do this
  235.     jz intc10
  236.     and targ.flgs,not capt ; stop capturing
  237.     jmp tem         ; and resume
  238. intch8: cmp ah,'R'              ; maybe resume?
  239.     jne intch9        ; no, keep going
  240.     cmp flags.capflg,0    ; can we capture?
  241.     jz intc10        ; no, forget it
  242.     test targ.flgs,capt    ; already capturing?
  243.     jnz intc10        ; yes, can't toggle back on then
  244.     or targ.flgs,capt    ; else turn flag on
  245.     jmp tem         ; and resume
  246. intch9: cmp bh,'0'              ; perhaps want a null (note original chr in bh)
  247.     jne intc10
  248.     mov ah,0
  249.     call outchr
  250.     nop
  251.     nop
  252.     nop
  253.     jmp tem
  254. intc10: call beep
  255.     jmp tem
  256. TELNET    ENDP
  257.  
  258. ; Reassure user about connection to the host.  Tell him what escape
  259. ; sequence to use to return and the communications port and baud
  260. ; rate being used.   [19b]
  261.  
  262. DOMSG    PROC    NEAR
  263.     mov ah,prstr
  264.     mov dx,offset tmsg1
  265.     int dos
  266.     call escprt
  267.     mov ah,prstr
  268.     mov dx,offset tmsg3
  269.     int dos
  270.     ret
  271. DOMSG    ENDP
  272.  
  273.  
  274. ; Set parity for character in Register AL.
  275.  
  276. dopar:    push bx
  277.     mov bx,portval
  278.     cmp [bx].parflg,parnon    ; No parity?            [10 start]
  279.     je parret        ; Just return
  280.     cmp [bx].parflg,parevn    ; Even parity?
  281.     jne dopar0
  282.     and al,07FH        ; Strip parity.
  283.     jpe parret        ; Already even, leave it.
  284.     or al,080H        ; Make it even parity.
  285.     jmp parret
  286. dopar0: cmp [bx].parflg,parmrk    ; Mark parity?
  287.     jne dopar1
  288.     or al,080H        ; Turn on the parity bit.
  289.     jmp parret
  290. dopar1: cmp [bx].parflg,parodd    ; Odd parity?
  291.     jne dopar2
  292.     and al,07FH        ; Strip parity.
  293.     jpo parret        ; Already odd, leave it.
  294.     or al,080H        ; Make it odd parity.
  295.     jmp parret
  296. dopar2: and al,07FH        ; Space parity - turn off parity bit.
  297. parret: pop bx
  298.     ret                    ; [10 end]
  299.  
  300. inicpt    proc    near
  301.     mov    capbp,offset capbuf
  302.     mov    caplft,128        ; init buffer ptr & chrs left
  303.     ret                ; and return
  304. inicpt    endp
  305.  
  306.  
  307. cptchr    proc    near            ; capture routine, char in al
  308.     push    di
  309.     mov    di,capbp
  310.     mov    byte ptr [di],al
  311.     inc    di
  312.     mov    capbp,di        ; restore pointer
  313.     pop    di
  314.     dec    caplft            ; decrement chars remaining
  315.     jnz    cptch1            ; more room, forget this part
  316.     call    cptdmp            ; dump the info
  317.     call    inicpt            ; re-init ptrs.
  318. cptch1: ret                ; and return
  319. cptchr    endp
  320.  
  321. cptdmp    proc    near            ; empty the capture buffer
  322.     push    ax
  323.     push    dx
  324.     mov    ah,setdma
  325.     mov    dx,offset capbuf    ; the capture routine buffer
  326.     int    dos
  327.     mov    ah,writef
  328.     mov    dx,offset cptfcb
  329.     int    dos            ; write out the block
  330. ;*** must be fixed... check error returns, disable capturing,
  331. ;*** figure out how to put dma address back
  332.     mov    dx,offset buff
  333.     mov    ah,setdma
  334.     int    dos            ; put dma back
  335.     pop    dx
  336.     pop    ax
  337.     ret
  338. cptdmp    endp
  339.  
  340. clscpt    proc    near
  341.     test    flags.capflg,0FFH    ; doing capture
  342.     jnz    clscp1            ; yes, go ahead
  343.     mov    dx,offset erms22
  344.     mov    ah,prstr
  345.     int    dos
  346.     jmp    rskp
  347. clscp1: mov    ah,cmcfm
  348.     call    comnd
  349.      jmp    r
  350. clscpi: mov    al,'Z'-64               ; control-z for eof...
  351.     call    cptchr            ; output to file
  352.     mov    al,caplft
  353.     cmp    al,128            ; is buffer empty?
  354.     je    clscp2            ; yes, forget this stuff
  355.     call    cptdmp            ; dump buffer (preserves registers)
  356. clscp2: mov    ah,0
  357.     sub    word ptr cptfcb+16,ax    ; subtract remaining from low filsize
  358.     sbb    word ptr cptfcb+18,0    ; and from high size (with borrow)
  359.     mov    ah,closf
  360.     mov    dx,offset cptfcb
  361.     int    dos            ; close up file
  362.     mov    flags.capflg,0        ; no longer capturing...
  363.     jmp    rskp            ; and return
  364. clscpt    endp
  365.  
  366. ; enter with ax/scan code to define, si/ pointer to definition, cx/ length
  367. ; of definition.  Defines it in definition table.
  368. ;*** somewhere should check for overflow etc of defbuf, and of scntab
  369. defkey    proc    near
  370.     push    ax        ; save scan code
  371.     mov    ax,ds
  372.     mov    es,ax        ; address data segment
  373.     mov    di,defptr    ; this is where the def gets built
  374.     inc    di        ; leave a byte for length
  375. defk1:    lodsb            ; get a byte from the source
  376.     cmp    al,'\'          ; escape?
  377.     jne    defk2        ; no, just deposit him
  378.     dec    cx        ; count available is one less
  379.     call    trnesc        ; translate the escape sequence
  380.     inc    cx        ; account for '\' (loop will decrement again).
  381. defk2:    stosb            ; drop off character
  382.     loop    defk1        ; and keep going while we have more
  383.     mov    ax,di        ; get ptr to end
  384.     dec    ax        ; back up pointer to end
  385.     mov    si,defptr    ; pick up old ptr value
  386.     sub    ax,si        ; this is actual length used
  387.     mov    byte ptr [si],al ; fill in length of entry
  388.     mov    defptr,di    ; this is next free byte
  389. ; definition address is in si
  390.     pop    ax        ; recover scan code
  391.     mov    cx,targ.klen    ; length of scan table
  392.     jcxz    defk4        ; not there, just go add it
  393.     mov    di,offset scntab ; the scan code table
  394.     repne    scasw        ; look for this one
  395.     jne    defk4        ; not defined already
  396.     sub    di,offset scntab + 2 ; compute index into table
  397.     mov    deftab[di],si    ; fill in address
  398.     ret            ; and return
  399. defk4:    mov    di,targ.klen    ; get length again
  400.     inc    di
  401.     cmp    di,scntlen
  402.     ja    defk5        ;** ignore def if over size
  403.     mov    targ.klen,di    ; update length
  404.     shl    di,1        ; double for word index
  405.     mov    scntab[di-2],ax ; put scan code into table
  406.     mov    deftab[di-2],si ; and fill in definition
  407. defk5:    ret            ; that's it
  408. defkey    endp
  409.  
  410. ; enter with si/ source pointer, cx/ count
  411. ; converts an escape sequence, updates all pointers
  412. trnesc    proc    near
  413.     push    bx
  414.     push    dx        ; preserve these
  415.     mov    al,0        ; this is current accumulation
  416.     jcxz    trnes2        ; empty string, forget it
  417.     mov    bl,3        ; this is max # of digits to use
  418.     mov    bh,8        ; this is radix
  419. trnes1: mov    dl,[si]
  420.     cmp    dl,'0'
  421.     jb    trnes2        ; out of range, stop here
  422.     cmp    dl,'7'
  423.     ja    trnes2
  424.     inc    si        ; accept character
  425.     sub    dl,'0'          ; convert to binary
  426.     mul    bh        ; shift accumulation
  427.     add    al,dl        ; add to accumulation
  428.     dec    bl        ; decrement digit counter
  429.     loopnz    trnes1        ; and keep trying
  430. trnes2: pop    dx
  431.     pop    bx
  432.     ret            ; and return
  433. trnesc    endp
  434.  
  435. ; Jumping to this location is like retskp.  It assumes the instruction
  436. ;   after the call is a jmp addr.
  437.  
  438. RSKP    PROC    NEAR
  439.     pop bp
  440.     add bp,3
  441.     push bp
  442.     ret
  443. RSKP    ENDP
  444.  
  445. ; Jumping here is the same as a ret.
  446.  
  447. R    PROC    NEAR
  448.     ret
  449. R    ENDP
  450.  
  451. code    ends
  452.     end
  453.