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

  1.     public    data, spack, rpack, rpack5, portval, port1, port2, hierr
  2.     include msdefs.h
  3.  
  4. gettim    equ    2CH        ; Get the time of day.
  5. maxlp    equ    100        ; Use as number of times to loop (in inchr).
  6. true    equ    1
  7. false    equ    0
  8. mntrgl    equ    bufsiz/4    ; Low point = 1/4 of the way full.
  9. maxpack equ    60H        ; largest packet we can handle
  10.  
  11. datas    segment public 'datas'
  12.     extrn    flags:byte, trans:byte, pack:byte, count:word, xofsnt:byte
  13.  
  14. port1    prtinfo <0FFFH,0,defpar,1,0,defhand,floxon>
  15. port2    prtinfo <0FFFH,0,defpar,1,0,defhand,floxon>
  16. portval dw    port1        ; Default is to use port 1.
  17. hierr    db    0        ; Non-ascii char (non-zero if yes).
  18. spmes    db    'Spack:  $'
  19. rpmes    db    'Rpack:  $'
  20. crlf    db    cr,lf,'$'
  21. infms0    db    'Waiting .....$'
  22. hibit    db    'Warning - Non Ascii char$'
  23. cemsg    db    'User intervention$'
  24. temp    dw    0
  25. tmp    db    ?,'$'
  26. pktptr    dw    ?        ; Position in receive packet.
  27. incnt    dw    ?        ; Number of chars read in from port.
  28. loopct    db    ?        ; Loop counter.
  29. time    dw    ?        ; When we should timeout.
  30.     dw    ?        ; Want a double word.
  31. packet    db    ?,?,?,?     ; Packet (data is part of it).
  32. data    db    5AH DUP(?)    ; Data and checksum field of packet.
  33. recpkt    db    maxpack DUP(?)    ; Receive packet storage (use the following).
  34. crctab    dw    00000H
  35.     dw    01081H
  36.     dw    02102H
  37.     dw    03183H
  38.     dw    04204H
  39.     dw    05285H
  40.     dw    06306H
  41.     dw    07387H
  42.     dw    08408H
  43.     dw    09489H
  44.     dw    0A50AH
  45.     dw    0B58BH
  46.     dw    0C60CH
  47.     dw    0D68DH
  48.     dw    0E70EH
  49.     dw    0F78FH
  50.  
  51. crctb2    dw    00000H
  52.     dw    01189H
  53.     dw    02312H
  54.     dw    0329BH
  55.     dw    04624H
  56.     dw    057ADH
  57.     dw    06536H
  58.     dw    074BFH
  59.     dw    08C48H
  60.     dw    09DC1H
  61.     dw    0AF5AH
  62.     dw    0BED3H
  63.     dw    0CA6CH
  64.     dw    0DBE5H
  65.     dw    0E97EH
  66.     dw    0F8F7H
  67. datas    ends
  68.  
  69. code    segment public
  70.     extrn    prtchr:near, clrbuf:near, outchr:near
  71.     extrn    sppos:near, stpos:near, biterr:near, intmsg:near
  72.     extrn    clearl:near, rppos:near, errpack:near
  73.     assume    cs:code, ds:datas
  74.  
  75. ;    Packet routines
  76.  
  77. ; Send_Packet
  78. ; This routine assembles a packet from the arguments given and sends it
  79. ; to the host.
  80. ;
  81. ; Expects the following:
  82. ;    AH     - Type of packet (D,Y,N,S,R,E,F,Z,T)
  83. ;    ARGBLK - Packet sequence number
  84. ;    ARGBK1 - Number of data characters
  85. ; Returns: +1 always
  86.  
  87. SPKT    PROC    NEAR
  88.  
  89. spack:    push ax         ; Save the packet type.
  90.     call clrbuf        ; Clear the input buffer. [20e]
  91.     mov bx,offset packet    ; Get address of the send packet.
  92.     mov ah,trans.ssoh    ; Get the start of header char.
  93.     mov [bx],ah        ; Put in the packet.
  94.     inc bx            ; Point to next char.
  95.     mov ax,pack.argbk1    ; Get the number of data chars.
  96.     xchg ah,al
  97.     mov al,trans.chklen    ; Length of checksum.
  98.     dec al            ; Extra length of checksum.
  99.     add ah,' '+3            ; Real packet character count made printable.
  100.     add ah,al        ; Account for checksum length in count.
  101.     mov [bx],ah        ; Put in the packet.
  102.     inc bx            ; Point to next char.
  103.     mov ch,0        ; For the 16 bit checksum.
  104.     mov cl,ah        ; Start the checksum.
  105.     mov ax,pack.argblk    ; Get the packet number.
  106.     add al,' '              ; Add a space so the number is printable.
  107.     mov [bx],al        ; Put in the packet.
  108.     inc bx            ; Point to next char.
  109.     add cx,ax        ; Add the packet number to the checksum.
  110.     pop ax            ; Get the packet type.
  111.     mov [bx],ah        ; Put in the packet.
  112.     inc bx            ; Point to next char.
  113.     mov al,0
  114.     xchg ah,al
  115.     add cx,ax        ; Add the type to the checksum.
  116.     mov dx,pack.argbk1    ; Get the packet size.
  117. spack2: cmp dx,0        ; Are there any chars of data?
  118.      jz spack3        ;  No, finish up.
  119.     dec dx            ; Decrement the char count.
  120.     mov al,[bx]        ; Get the next char.
  121.     inc bx            ; Point to next char.
  122.     mov ah,0
  123.     add cx,ax        ; Add the char to the checksum.
  124.     cmp al,0
  125.     jns spack2
  126.     cmp hierr,0ffH        ; Printed message already?
  127.     je spack2        ; Yes, then that's it.
  128.     push bx
  129.     push cx
  130.     push dx
  131.     call biterr
  132.     pop dx
  133.     pop cx
  134.     pop bx
  135.     mov hierr,0FFH        ; set err flag.
  136.     jmp spack2        ; Go try again.
  137. spack3: cmp trans.chklen,2    ; What kind of checksum are we using.
  138.     je spackx        ; 2 characters.
  139.     jg spacky        ; 3 characters.
  140.     mov ah,cl        ; 1 char: get the character total.
  141.     mov ch,cl        ; Save here too (need 'cl' for shift).
  142.     and ah,0C0H        ; Turn off all but the two high order bits.
  143.     mov cl,6
  144.     shr ah,cl        ; Shift them into the low order position.
  145.     mov cl,ch
  146.     add ah,cl        ; Add it to the old bits.
  147.     and ah,3FH        ; Turn off the two high order bits.  (MOD 64)
  148.     add ah,' '              ; Add a space so the number is printable.
  149.     mov [bx],ah        ; Put in the packet.
  150.     inc bx            ; Point to next char.
  151.     jmp spackz        ; Add EOL char.
  152. spacky: mov al,0        ; Get a null.
  153.     mov [bx],al        ; To determine end of buffer.
  154.     push bx         ; Don't lose our place.
  155.     mov bx,offset packet+1    ; First checksummed character.
  156.     call crcclc        ; Calculate the CRC.
  157.     pop bx
  158.     push cx
  159.     mov ax,cx        ; Manipulate it here.
  160.     and ax,0F000H        ; Get 4 highest bits.
  161.     mov cl,4
  162.     shr ah,cl        ; Shift them over 4 bits.
  163.     add ah,' '              ; Make printable.
  164.     mov [bx],ah        ; Add to buffer.
  165.     inc bx
  166.     pop cx            ; Get back checksum value.
  167. spackx: push cx         ; Save it for now.
  168.     and cx,0FC0H        ; Get bits 6-11.
  169.     mov ax,cx
  170.     mov cl,6
  171.     shr ax,cl        ; Shift them bits over.
  172.     add al,' '              ; Make printable.
  173.     mov [bx],al        ; Add to buffer.
  174.     inc bx
  175.     pop cx            ; Get back the original.
  176.     and cx,003FH        ; Get bits 0-5.
  177.     add cl,' '              ; Make printable.
  178.     mov [bx],cl        ; Add to buffer.
  179.     inc bx
  180. spackz: mov ah,trans.seol    ; Get the EOL the other host wants.
  181.     mov [bx],ah        ; Put in the packet.
  182.     inc bx            ; Point to next char.
  183.     mov ah,0        ; Get a null.
  184.     mov [bx],ah        ; Put in the packet.
  185.     cmp flags.debug,0    ; debug mode.
  186.     je spack4
  187.     inc bx
  188.     mov ah,'$'
  189.     mov [bx],ah
  190.     call sppos
  191.     call clearl        ; Clear to end of line.
  192.     mov dx,offset crlf
  193.     mov ah,prstr
  194.     int dos
  195.     call clearl        ; Next line too.
  196.     call sppos        ; Reposition cursor.
  197.     mov ah,prstr
  198.     mov dx,offset spmes
  199.     int dos
  200.     mov dx,offset packet
  201.     mov ah,prstr
  202.     int dos         ; debug end.
  203. spack4: call outpkt        ; Call the system dependent routine.
  204.      jmp r
  205.     jmp rskp
  206. SPKT    ENDP
  207.  
  208. ;    Write out a packet.
  209.  
  210. OUTPKT    PROC    NEAR
  211.     mov dh,trans.spad    ; Get the number of padding chars.
  212. outpk2: dec dh
  213.     cmp dh,0
  214.     jl outpk3        ; If none left proceed.
  215.     mov ah,trans.spadch    ; Get the padding char.
  216.     call outchr        ; Output it.
  217.      jmp r            ; Say we failed. [25]
  218.     jmp outpk2
  219. outpk3: mov bx,offset packet    ; Point to the packet.
  220. outlup: mov ah,[bx]        ; Get the next character.
  221.     cmp ah,0        ; Is it a null?
  222.     jnz outlp2
  223.     jmp rskp
  224. outlp2: call outchr        ; Output the character.
  225.      jmp r
  226.     inc bx            ; Increment the char pointer.
  227.     jmp outlup
  228. OUTPKT    ENDP
  229.  
  230. ; Calculate the CRC.  Returns the CRC in CX.  Destroys: BX, AX.
  231. crcclc: push dx
  232.     push si
  233.     mov dx,0        ; Initial CRC value is 0.
  234. crc0:    mov al,[bx]        ; Get the first char of the string.
  235.     cmp al,0        ; If null, then we're done.
  236.     je crc1
  237.     inc bx
  238.     xor al,dl        ; Xor input with lo order byte of CRC.
  239.     mov ah,al        ; Get a copy.
  240.     and ah,0F0H        ; Get hi 4 bits.
  241.     mov cl,4
  242.     shr ah,cl        ; Right justify.
  243.     and al,0FH        ; Get lo 4 bits.
  244.     push bx
  245.     mov si,offset crctb2    ; Low portion of CRC factor.
  246.     mov bh,0
  247.     mov bl,al
  248.     add bl,al        ; Get word index.
  249.     mov cx,[si+bx]        ; Low portion.
  250.     mov si,offset crctab    ; High portion of CRC factor.
  251.     mov bh,0
  252.     mov bl,ah
  253.     add bl,ah        ; Get word index.
  254.     mov bx,[si+bx]
  255.     xor bx,cx        ; Add the two.
  256.     mov cl,8
  257.     shr dx,cl        ; Shift CRC 8 bits to the right.
  258.     xor dx,bx        ; XOR table value and CRC.
  259.     pop bx            ; Retrieve index.
  260.     jmp crc0
  261. crc1:    mov cx,dx        ; Return it in CX.
  262.     pop si
  263.     pop dx
  264.     ret
  265.  
  266. ; Receive_Packet
  267. ; This routine waits for a packet arrive from the host.  It reads
  268. ; chars until it finds a SOH.
  269.  
  270. RPACK    PROC    NEAR
  271. rpack5: call inpkt        ; Read up to a carriage return.
  272.      jmp r            ;  Return bad.
  273. rpack0: call getchr        ; Get a character.
  274.      jmp r            ;  Hit the carriage return, return bad.
  275.     cmp al,trans.rsoh    ; Is the char the start of header char?
  276.      jne rpack0        ;  No, go until it is.
  277. rpack1: call getchr        ; Get a character.
  278.      jmp r            ;  Hit the carriage return, return bad.
  279.     cmp al,trans.rsoh    ; Is the char the start of header char?
  280.      jz rpack1        ;  Yes, then go start over.
  281.     mov ch,0        ; For 16-bit checksum.
  282.     mov cl,al        ; Start the checksum.
  283.     mov ah,0
  284.     mov pack.argbk1,ax    ; Save the data count.
  285.     call getchr        ; Get a character.
  286.      jmp r            ;  Hit the carriage return, return bad.
  287.     cmp al,trans.rsoh    ; Is the char the start of header char?
  288.      jz rpack1        ;  Yes, then go start over.
  289.     mov ah,0
  290.     add cx,ax        ; Add it to the checksum.
  291.     sub al,' '              ; Get the real packet number.
  292.     mov ah,0
  293.     mov pack.argblk,ax    ; Save the packet number.
  294.     call getchr        ; Get a character.
  295.      jmp r            ;  Hit the carriage return, return bad.
  296.     cmp al,trans.rsoh    ; Is the char the start of header char?
  297.      jz rpack1        ;  Yes, then go start over.
  298.     mov ah,0
  299.     mov temp,ax        ; Save the message type. [11]
  300.     add cx,ax        ; Add it to the checksum.
  301. ; Start of change.
  302. ; Now determine block check type for this packet.  Here we violate the layered
  303. ; nature of the protocol by inspecting the packet type in order to detect when
  304. ; the two sides get out of sync.  Two heuristics allow us to resync here:
  305. ;   a. An S packet always has a type 1 checksum.
  306. ;   b. A NAK never contains data, so its block check type is LEN-2.
  307.     push cx
  308.     mov cl,al
  309.     mov ax,pack.argbk1    ; Get back the size.
  310.     sub al,34        ; unchar(len) - 2, for SEQ & TYPE fields.
  311.     mov ah,trans.chklen    ; Checksum length we expect.
  312.     cmp cl,'S'              ; Is this an "S" packet?
  313.     jne rpk0        ; Nope.
  314.     mov ah,1        ; Yes, use 1 char checksum.
  315. rpk0:    cmp cl,'N'              ; Is this a NAK?
  316.     jne rpk1        ; Nope.
  317.     mov ah,al        ; So, len - 2 is checksum type.
  318. rpk1:    mov trans.chklen,ah    ; Then, this is the chksum length.
  319.     sub al,ah        ; Real size of data.
  320.     mov dh,al        ; Need it here.
  321.     mov ah,0
  322.     mov pack.argbk1,ax    ; And here.
  323.     pop cx
  324. ; End of change.
  325.     mov bx,offset data    ; Point to the data buffer.
  326. rpack2: dec dh            ; Any data characters?
  327.      js rpack3        ;  If not go get the checksum.
  328.     call getchr        ; Get a character.
  329.      jmp r            ;  Hit the carriage return, return bad.
  330.     cmp al,trans.rsoh    ; Is the char the start of header char?
  331.      jz rpack1        ;  Yes, then go start over.
  332.     mov [bx],al        ; Put the char into the packet.
  333.     inc bx            ; Point to the next character.
  334.     mov ah,0
  335.     add cx,ax        ; Add it to the checksum.
  336.     jmp rpack2        ; Go get another.
  337. rpack3: call getchr        ; Get a character.
  338.      jmp r            ;  Hit the carriage return, return bad.
  339.     cmp al,trans.rsoh    ; Is the char the start of header char?
  340.      jnz rpk3x
  341.      jmp rpack1        ;  Yes, then go start over.
  342. rpk3x:    sub al,' '              ; Turn the char back into a number.
  343.     cmp trans.chklen,2    ; What checksum length is in use.
  344.     je rpackx        ; Two character checksum.
  345.     jg rpacky        ; Three character CRC.
  346.     mov dh,cl        ; 1 char - get the character total.
  347.     and dh,0C0H        ; Turn off all but the two high order bits.
  348.     mov ch,cl
  349.     mov cl,6
  350.     shr dh,cl        ; Shift them into the low order position.
  351.     mov cl,ch
  352.     add dh,cl        ; Add it to the old bits.
  353.     and dh,3FH        ; Turn off the two high order bits.  (MOD 64)
  354.     cmp dh,al        ; Are they equal?
  355.      jz rpack4        ; If so finish up.
  356.     jmp rpack6        ; No, we fail.
  357. rpacky: mov tmp,al        ; Save value from packet here.
  358.     mov ah,0        ; Three character CRC.
  359.     push bx
  360.     mov bx,pktptr        ; Where we are in the packet.
  361.     dec bx
  362.     mov [bx],ah        ; Add null to signify end of buffer.
  363.     mov bx,offset recpkt+1    ; Where data for CRC is.
  364.     call crcclc        ; Calculate the CRC and put into CX.
  365.     pop bx
  366.     push cx
  367.     mov ax,cx        ; Manipulate it here.
  368.     and ax,0F000H        ; Get 4 highest bits.
  369.     mov cl,4
  370.     shr ah,cl        ; Shift them over 4 bits.
  371.     pop cx            ; Get back checksum value.
  372.     cmp ah,tmp        ; Is what we got == what we calculated?
  373.     jne rpack6
  374.     call getchr        ; Get next character of checsum.
  375.      jmp r            ; Failed.
  376.     cmp al,trans.rsoh    ; Restarting?
  377.      jz rpack7
  378.     sub al,' '              ; Get back real value.
  379. rpackx: mov tmp,al        ; Save here for now.
  380.     push cx         ; Two character checksum.
  381.     and cx,0FC0H        ; Get bits 6-11.
  382.     mov ax,cx
  383.     mov cl,6
  384.     shr ax,cl        ; Shift them bits over.
  385.     pop cx            ; Get back the original.
  386.     cmp al,tmp        ; Are they equal?
  387.      jne rpack6        ; No, we fail.
  388.     call getchr        ; Get last character of checsum.
  389.      jmp r            ; Failed.
  390.     cmp al,trans.rsoh    ; Restarting?
  391.      jz rpack7
  392.     sub al,' '              ; Get back real value.
  393.     and cx,003FH        ; Get bits 0-5.
  394.     cmp al,cl        ; Do the last chars match?
  395.     jne rpack6
  396. rpack4: mov ah,0
  397.     mov [bx],ah        ; Put a null at the end of the data.
  398.     mov ax,temp        ; Get the type.   [11]
  399.     xchg al,ah        ; Packet type should be in AH.
  400.     jmp rskp
  401. rpack6: ret
  402. rpack7: jmp rpack1        ; For the jump out of range.
  403. RPACK    ENDP
  404.  
  405.  
  406. INPKT    PROC    NEAR
  407.     mov bl,flags.cxzflg    ; Remember original value. [20b]
  408.     mov tmp,bl        ; Store it here. [20b]
  409. inpkt1: mov bx,offset recpkt    ; Point to the beginning of the packet.
  410.     mov incnt,0
  411. inpkt2: call inchr        ; Get a character.
  412.      jmp inpkt8        ;  Return failure. [20b]
  413.      nop            ;  Make it three bytes long. [20b]
  414.     mov [bx],ah        ; Put the char in the packet.
  415.     inc bx
  416.     inc incnt
  417.     cmp ah,trans.reol    ; Is it the EOL char?
  418.     je inpkt3        ; ended by eol, keep going
  419.     cmp incnt,maxpack    ; is it too big?
  420.     jbe inpkt2        ; no, keep going
  421.     jmp inpkt1        ; else just start over
  422. inpkt3: cmp incnt,1        ; Ignore bare CR.   [2 start]
  423.     je inpkt1
  424.     mov bp,portval
  425.     cmp ds:[bp].hndflg,0    ; Waiting for handshake?
  426.     jz inpkt5        ; If not then proceed.
  427. inpkt4: call inchr        ; Wait for the turn around char.
  428.      jmp inpkt8        ;  Return failure. [20b]
  429.      nop            ;  Make it three bytes long.  [20b]
  430.     mov bp,portval
  431.     cmp ah,ds:[bp].hands    ; Is it the IBM turn around character?
  432.     jne inpkt4        ; If not, go until it is.
  433. inpkt5: cmp flags.debug,0    ; In debug mode?
  434.     je inpkt6
  435.     mov ah,'$'
  436.     mov [bx],ah
  437.     call rppos
  438.     call clearl        ; Clear to end of line.
  439.     mov dx,offset crlf
  440.     mov ah,prstr
  441.     int dos
  442.     call clearl        ; Next line too.
  443.     call rppos        ; Reposition cursor.
  444.     mov ah,prstr
  445.     mov dx,offset rpmes
  446.     int dos
  447.     mov dx,offset recpkt
  448.     mov ah,prstr
  449.     int dos         ; debug end.
  450. inpkt6: mov bx,offset recpkt
  451.     mov pktptr,bx        ; Save the packet pointer.
  452.     mov bl,tmp        ; Get the original value. [20b]
  453.     cmp bl,flags.cxzflg    ; Did ^X/^Z flag change? [20b]
  454.     je inpkt7        ; If not, just return.    [20b]
  455.     cmp flags.cxzflg,'E'    ; Error packet?
  456.     je inpkt9
  457.     call intmsg        ; Else, say we saw the interrupt. [20b]
  458. inpkt7: jmp rskp        ; If so we are done.
  459. inpkt8: cmp flags.cxzflg,'C'    ; Did the user type a ^C? [25]
  460.     jne inpkt9
  461.     mov pack.state,'A'
  462.     ret
  463. inpkt9: cmp flags.cxzflg,'E'    ; How about ^E?
  464.     jne inpk10        ; No just go on.
  465.     mov bx,offset cemsg    ; Null message for error packet.
  466.     call errpack
  467.     mov pack.state,'A'
  468.     ret
  469. inpk10: mov bl,tmp        ; Get the original value. [20b]
  470.     cmp bl,flags.cxzflg    ; Did ^X/^Z flag change? [20b]
  471.     je inpk11        ; If not, just return failure.    [20b]
  472.     call intmsg        ; Else, say we saw the interrupt. [20b]
  473. inpk11: jmp r
  474. INPKT    ENDP
  475.  
  476. inchr:    cmp flags.timflg,0    ; Are timeouts turned off.
  477.     je inchr1        ; Yes, so skip this stuff.
  478.     cmp trans.stime,0    ; Don't time out?
  479.     je inchr1        ; Yes, so skip this stuff.
  480.     mov loopct,0        ; Use to check for timeout.
  481.     mov ah,gettim        ; Get the time.
  482.     int dos
  483.     mov time,cx
  484.     mov time+2,dx
  485.     mov ah,0
  486.     mov al,trans.stime    ; Timeout when getting data.
  487.     mov cl,8
  488.     shl ax,cl        ; Move timeout to seconds field.
  489.     add time+2,ax        ; If get to this time, then timeout.
  490.     jnc inchr1
  491.     inc time
  492. inchr1: call prtchr        ; Is there a character to read?
  493.      jmp inchr6        ; Got one.
  494.     mov dl,0FFH        ; To read in a char.
  495.     mov ah,dconio        ; Is a char on the console?
  496.     int dos
  497.     jz inchr2        ; If not go look for another char.
  498.     mov ah,al
  499.     cmp ah,cr        ; Is it a carriage return?
  500.     je inchr5        ; If yes, then leave.
  501.     cmp ah,'Z'-100O         ; Control-Z? [20b]
  502.     je inchr4        ; Yes - flag it. [20b]
  503.     cmp ah,'X'-100O         ; Control-X? [20b]
  504.     je inchr4        ; Yes - flag it. [20b]
  505.     cmp ah,'E'-100O         ; Control-E?
  506.     je inchr4        ; Flag it and get rest of packet.
  507.     cmp ah,'C'-100O         ; Control-C? [25]
  508.     jne inchr2        ; No, then wait for input. [25]
  509.     add ah,100O        ; Make it printable. [25]
  510.     mov flags.cxzflg,ah    ; Save it. [25]
  511.     ret            ; Return right away. [25]
  512. inchr2: cmp flags.timflg,0    ; Are timeouts turned off?
  513.     je inchr1        ; Yes, just check for more input.
  514.     cmp trans.stime,0    ; Doing time outs?
  515.     je inchr1        ; No, just go check for more input.
  516.     inc loopct
  517.     cmp loopct,maxlp    ; Times to go without checking time.
  518.     jne inchr1        ; Don't check yet.
  519.     mov ah,gettim        ; Get the current time.
  520.     int dos
  521.     mov ax,time
  522.     sub ax,cx        ; Check hours and minutes.
  523.     jl inchr5        ; Over the limit so fail.
  524.     jg inchr3        ; Under the limit, keep going.
  525.     mov ax,time+2
  526.     sub ax,dx        ; Else, check seconds and hundreds of seconds.
  527.     jle inchr5        ; Return failure.
  528. inchr3: mov loopct,0        ; Reset counter.
  529.     jmp inchr1
  530. inchr4: add ah,100O        ; Make it printable. [20b]
  531.     mov flags.cxzflg,ah    ; Remember what we saw. [20b]
  532.     jmp inchr2        ; Continue getting input. [20b]
  533. inchr5: ret
  534. inchr6: mov ah,al
  535.     mov bp,portval        ; Point to current port structure.
  536.     cmp ds:[bp].parflg,parnon    ; Is the parity none?    [10]
  537.     je inchr7        ; We're done.           [10]
  538.     and ah,7FH        ; Turn off the parity bit.
  539. inchr7: cmp ds:[bp].floflg,0    ; Doing any flow control?
  540.     jne inchr8        ; Yes, check it out.
  541.     jmp rskp        ; No, just return the data.
  542. inchr8: cmp xofsnt,true     ; Have we sent flow char (XOFF)?
  543.     je inchr9        ; Yes.
  544.     jmp rskp        ; No, just return.
  545. inchr9: cmp count,mntrgl    ; Under the low trigger point?
  546.     jb inchra        ; Yes.
  547.     jmp rskp        ; No, just return.
  548. inchra: push ax
  549.     mov bp,portval
  550.     mov ax,ds:[bp].flowc    ; Get flow control char (AH = XON, AL = XOFF).
  551.     call outchr        ; Send it (XON).
  552.     mov xofsnt,false    ; Turn off the flag.
  553.     pop ax
  554.     jmp rskp        ; Return the character.
  555.  
  556. ; Return next character in AL.
  557. GETCHR    PROC    NEAR
  558.     push bx
  559.     mov bx,pktptr        ; Get the packet pointer.
  560.     mov al,[bx]        ; Get the char.
  561.     inc bx
  562.     mov pktptr,bx
  563.     pop bx            ; Restore BX.
  564.     cmp al,trans.reol    ; Is it the EOL char?
  565.     jne getcr2        ; If not return retskp.
  566.     ret            ; If so return failure.
  567. getcr2: jmp rskp
  568. GETCHR    ENDP
  569.  
  570. ; Jumping to this location is like retskp.  It assumes the instruction
  571. ;   after the call is a jmp addr.
  572.  
  573. RSKP    PROC    NEAR
  574.     pop bp
  575.     add bp,3
  576.     push bp
  577.     ret
  578. RSKP    ENDP
  579.  
  580. ; Jumping here is the same as a ret.
  581.  
  582. R    PROC    NEAR
  583.     ret
  584. R    ENDP
  585.  
  586. code    ends
  587.     end
  588.