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

  1.     public    bufpnt, buff, fcb, cpfcb, chrcnt, fixfcb, init, init1,
  2.     public    gofil, outbuf, ptchr, gtchr, gtnfil, getfil, filbuf,
  3.     public    encode, decode, nulref, nulr, decbuf, errpack, rptq,
  4.     public    origr, rptct, rptval, clrfln, cxmsg, biterr, intmsg,
  5.     public    rtpos, erpos,rppos, stpos,nppos,rprpos,nrtpos,sppos,
  6.     public    kbpos,perpos,frpos, prtscr
  7.     include msdefs.h
  8.  
  9. rptmin    equ    3        ; At least 3 of same char in a row.
  10.  
  11. ; equates for screen positioning
  12. scrfln    equ    0316H        ; Place for file name.
  13. scrkb    equ    0416H        ; Place for percent transferred.
  14. scrper    equ    0516H        ; Place for Kbytes transferred.
  15. scrst    equ    0616H        ; Place for status.
  16. scrnp    equ    0816H        ; Place for number of packets.
  17. scrnrt    equ    0916H        ; Place for number of retries.
  18. screrr    equ    0A16H        ; Place for error msgs.
  19. scrhi    equ    0B16H        ; Err when 8th bit is on.
  20. scrfr    equ    0B16H        ; Rename file.
  21. scrint    equ    0B16H        ; Acknowledge interrupt. [20b]
  22. scrsp    equ    0C00H        ; Place for send packet.
  23. scrrp    equ    0E00H        ; Place for receive packet.
  24. scrrpr    equ    1100H        ; Prompt when Kermit ends.
  25.  
  26.  
  27.  
  28. datas    segment public 'datas'
  29.     extrn    data:byte, flags:byte, trans:byte, pack:byte, hierr:byte
  30.     extrn    dosnum:byte
  31.  
  32. outlin    db    cr,lf,cr,lf
  33.     db    cr,lf,'           File name:'
  34.     db    cr,lf,'  KBytes transferred:'
  35.     db    cr,lf
  36.     db    cr,lf
  37.     db    cr,lf
  38.     db    cr,lf,'   Number of packets:'
  39.     db    cr,lf,'   Number of retries:'
  40.     db    cr,lf,'          Last error: None'
  41.     db    cr,lf,'        Last warning: None'
  42.     db    '$'
  43.  
  44. ermes4    db    'Unable to rename file$'
  45. erms10    db    '?Unable to receive data$'
  46. erms11    db    '?Disk full$'
  47. erms12    db    '?Unable to create file$'
  48. erms17    db    'Record length exceeds size of buffer$'
  49. infms5    db    'Renaming file to $'
  50. infms7    db    'File interrupt$'
  51. infms8    db    'File group interrupt$'
  52. hibit    db    'Warning - Non Ascii char$'
  53. crlf    db    cr,lf,'$'
  54. printer db    0,'LPT1       '
  55. spchar    db    24H,26H,23H,40H,21H,25H,27H,28H,29H,2DH
  56.     db    3CH,3EH,7BH,7DH,5FH,5CH,5EH,7EH,7CH,60H
  57. spclen    equ    $-spchar    ; Number of special chars.
  58. spchar2 db    24H,26H,23H,40H,21H,25H,27H,28H,29H,2DH
  59.     db    7BH,7DH,5FH,5EH,7EH,60H
  60. spc2len equ    $-spchar2
  61. next    db    0FFH        ; No next character just yet.
  62. rptval    db    0        ; Repeated character.
  63. rptct    db    1        ; Number of times it's repeated.
  64. rptq    db    drpt        ; Repeat prefix.
  65. origr    db    drpt        ; Original repeat prefix.
  66. temp1    dw    ?        ; Temporary storage.
  67. temp2    dw    ?
  68. oloc    dw    0        ; Original buffer location. [21c]
  69. osiz    dw    0        ; Original buffer size. [21c]
  70. chrcnt    dw    ?        ; Number of chars in the file buffer.
  71. outpnt    dw    ?        ; Position in packet.
  72. bufpnt    dw    ?        ; Position in file buffer.
  73. fdtpnt    dw    ?        ; Pointer to within our file.
  74. fcbptr    dw    ?        ; Position in FCB.
  75. cbfptr    dw    ?        ; Position in character buffer.
  76. filsiz    dw    0        ; Double word for filesize (in bytes.)
  77.     dw    0
  78. ofilsz    dw    0        ; Original file size percent adjusted (/100).
  79. tfilsz    dw    0        ; Bytes transferred.
  80.     dw    0
  81. oldper    dw    ?        ; old percentage
  82. oldkbt    dw    ?        ; old KB transferred.
  83. wrpmsg    db    ?        ; non-zero if we wrote percent message
  84. percnt    dw    100        ; Number to divide by for a percent.
  85. bufhex    dw    80H
  86. permsg    db    cr,' Percent transferred:$'
  87. cxzhlp    db    '^X cancels file, ^Z cancels batch'
  88.     db    ', ^E aborts protocol'
  89.     db    ', ^C aborts at once'
  90.     db    '$'
  91. asmsg    db    ' AS '
  92. asmln    equ    $-asmsg
  93. filbuf    db    60H DUP(?)    ; Character buffer.
  94. buff    db    dmasiz DUP(?)    ; Use as our DTA.
  95. fcb    db    fcbsiz DUP(?)    ; Use as our FCB.
  96. cpfcb    db    fcbsiz DUP(?)    ; Save FCB in case of "*".   [7]
  97. decbuf    db    dmasiz DUP(?)    ; For decoding incoming data.
  98. datas    ends
  99.  
  100. code    segment public
  101.     extrn    spack:near, cmblnk:near, locate:near, nout:near
  102.     extrn    putmod:near, poscur:near, clearl:near, fcbcpy:near
  103.     assume    cs:code,ds:datas
  104.  
  105. ; Position cursor for an error message.
  106.  
  107. ERPOS    PROC    NEAR
  108.     cmp flags.xflg,1    ; Packet header seen? [21c start]
  109.     jne erp0        ; No, do as normal.
  110.     mov dx,offset crlf
  111.     mov ah,prstr
  112.     int dos
  113.     ret
  114. erp0:    mov dx,screrr
  115.     jmp poscur
  116. ERPOS    ENDP
  117.  
  118. ; Position cursor for number of retries message.
  119.  
  120. RTPOS    PROC    NEAR
  121.     cmp flags.xflg,1    ; Packet header seen? [21c]
  122.     jne rtp0        ; No, do as normal.
  123.     ret
  124. rtp0:    mov dx,scrnrt
  125.     jmp poscur
  126. RTPOS    ENDP
  127.  
  128. ; Reassure user that we acknowledge his ^X/^Z.
  129.  
  130. INTMSG    PROC    NEAR
  131.     cmp flags.xflg,0    ; Writing to screen?
  132.     jne int1        ; Yes. Don't do anything.
  133.     mov dx,scrint
  134.     call poscur
  135.     call clearl
  136.     mov dx,offset infms7    ; File interrupted?
  137.     cmp flags.cxzflg,'X'    ; Yes.
  138.     je int0
  139.     mov dx,offset infms8    ; File group interrupted.
  140. int0:    mov ah,prstr
  141.     int dos
  142. int1:    ret
  143. INTMSG    ENDP
  144.  
  145. ; Print err message that found a non-standard-Ascii char in the file.
  146.  
  147. BITERR    PROC    NEAR
  148.     cmp flags.remflg,0    ; remote mode?
  149.     jne biter1        ; yes, no printing.
  150.     push bx
  151.     mov dx,scrhi
  152.     call poscur
  153.     call clearl
  154.     mov ah,prstr
  155.     mov dx,offset hibit
  156.     int dos
  157.     pop bx
  158. biter1: ret
  159. BITERR    ENDP
  160.  
  161. ;  Clear out message about interrupted file.
  162.  
  163. CXMSG    PROC    NEAR
  164.     cmp flags.xflg,0    ; Writing to screen?
  165.     jne cxm0        ; Yes. Don't do anything.
  166.     mov dx,scrint
  167.     call poscur
  168.     call clearl
  169. cxm0:    ret
  170. CXMSG    ENDP
  171.  
  172. ;  Clear out the old filename on the screen.
  173.  
  174. CLRFLN    PROC    NEAR
  175.     mov dx,scrfln
  176.     call poscur
  177.     call clearl        ; Clear to end of line. [19a]
  178.     ret
  179. CLRFLN    ENDP
  180.  
  181. ; some random screen positioning functions
  182. kbpos:    mov dx,scrkb        ; KBytes transferred.
  183.     jmp poscur
  184. perpos: mov dx,scrper        ; Percent transferred.
  185.     call poscur
  186.     jmp clearl
  187. frpos:    mov dx,scrfr        ; Say renamed file.
  188.     call poscur
  189.     jmp clearl
  190. stpos:    mov dx,scrst        ; Print status of file transfer.
  191.     call poscur
  192.     jmp clearl
  193. nppos:    mov dx,scrnp        ; Number of packets sent.
  194.     jmp poscur
  195. rprpos: mov dx,scrrpr        ; Reprompt position.
  196.     jmp poscur
  197. nrtpos: mov dx,scrnrt        ; Number of retries.
  198.     jmp poscur
  199. sppos:    mov dx,scrsp        ; Send packet location.
  200.     jmp poscur
  201. rppos:    mov dx,scrrp        ; Receive packet location.
  202.     jmp poscur
  203.  
  204.  
  205.  
  206. ;    Initialize buffers and clear line.
  207.  
  208. INIT    PROC    NEAR
  209.     call cmblnk
  210.     call locate
  211.     mov ah,prstr        ; Put statistics headers on the screen.
  212.     mov dx,offset outlin
  213.     int dos
  214.     mov dx,offset cxzhlp
  215.     call putmod        ; write mode line
  216.     mov wrpmsg,0        ; haven't printed the messsage yet.
  217.     call init1
  218.     ret
  219. INIT    ENDP
  220.  
  221. INIT1    PROC    NEAR
  222.     mov chrcnt,dmasiz           ; Number of chars left.
  223.     mov bufpnt,offset buff           ; Addr for beginning.
  224.     mov hierr,0
  225.     ret
  226. INIT1    ENDP
  227.  
  228. ;    Output the chars in a packet.
  229.  
  230. ; Called with AX = size of the data, BX = address of source.
  231.  
  232. FILEIO    PROC    NEAR
  233. ptchr:    mov cx,ax
  234.     lea ax,outbufl        ; Where to put data when buffer gets full.
  235.     jmp decode
  236.  
  237. ; CX = Size of data, BX = Address of data, AX = Routine to call to
  238. ; dump data.
  239.  
  240. decode: push si
  241.     push di
  242.     push es
  243.     push dx
  244.     push ax
  245.     mov ax,ds
  246.     mov es,ax
  247.     pop ax
  248.     mov si,bx        ; Source of data.
  249.     mov bx,ax        ; Coroutine to call.
  250.     mov di,bufpnt        ; Destination of data.
  251.     mov dh,0        ; assume no quote char
  252.     cmp trans.ebquot,'N'    ; no quoting?
  253.     je decod1        ; yes, keep going
  254.     cmp trans.ebquot,'Y'    ; or not doing it?
  255.     je decod1        ; yes, keep going
  256.     mov dh,trans.ebquot    ; otherwise use quote char
  257.  
  258. decod1: mov rptct,0        ; Reset.
  259.     mov rptval,0        ; Ditto.
  260.     dec cx
  261.     jge dcod11        ; More data.
  262.     jmp decod6        ; Else, we're through.
  263. dcod11: dec chrcnt        ; Decrement number of chars in dta.
  264.     jns decod2        ; Continue if space left.
  265.     push cx
  266.     push dx
  267.     push bx
  268.     call bx         ; Output it if full.
  269.      jmp decod5        ;  Error return if disk is full.
  270.      nop
  271.     pop bx
  272.     pop dx
  273.     pop cx
  274.     mov di,bufpnt
  275. decod2: cmp rptct,0        ; Doing a repeat?
  276.     je dcod20        ; No, so go get a character.
  277.     mov ah,0
  278.     mov al,rptval        ; Get the character we're repeating.
  279.     jmp decod4        ; And write it out to the file.
  280. dcod20: lodsb            ; Pick up a char.
  281.     cmp rptq,0        ; Doing repeat quoting?
  282.     je dcod21        ; Nope, skip this part.
  283.     cmp al,rptq        ; Did we pick up the repeat quote char?
  284.     jne dcod21        ; No, continue processing it.
  285.     lodsb            ; Get the size.
  286.     dec cx            ; Modify buffer count.
  287.     sub al,20H        ; Was made printable.
  288.     mov rptct,al        ; Remember how many repetitions.
  289.     lodsb            ; Get the char to repeat.
  290.     dec cx            ; Modify buffer count.
  291. dcod21: mov ah,00H        ; Assume no 8-bit quote char. [21b start]
  292.     cmp al,dh        ; This the 8-bit quot char?
  293.     jne decod3
  294.     lodsb            ; Get the real character.
  295.     dec cx            ; Decrement # chars in packet
  296.     mov ah,80H        ; Turn on 8-bit quot char flag. [21b end]
  297. decod3: cmp al,trans.squote    ; Is it the quote char? [21b] [21c]
  298.     jne decod4        ; If not proceed.
  299.     lodsb            ; Get the quoted character
  300.     dec cx            ; Decrement # of chars in packet.
  301.     or ah,al        ; save parity (combine with prefix)
  302.     and ah,80h        ; only parity
  303.     and al,7FH        ; Turn off the parity bit.
  304.     cmp al,trans.squote    ; Is it the quote char? [21c]
  305.     je decod4        ; If so just go write it out.
  306.     cmp al,dh        ; This the 8-bit quot char?
  307.     je  decod4        ; If so, just go write it out
  308.     cmp al,rptq        ; Is is the repeat quote character?
  309.     je decod4        ; If so, just write it out.
  310.     add al,40H        ; Make it a control char again.
  311.     and al,7FH        ; Modulo 128.
  312. decod4: or al,ah        ; or in parity
  313.     stosb            ; store the character
  314.     dec rptct        ; Repeat counter.
  315.     cmp rptct,0        ; Write out char again?
  316.     jg dcod41
  317.     jmp decod1        ; No, get next char.
  318. dcod41: mov rptval,al        ; Save the char.
  319.     jmp dcod11        ; and loop to next char.
  320. decod5: pop bx
  321.     pop dx            ; dx is pushed twice (really)
  322.     pop cx
  323.     pop dx
  324.     pop es
  325.     pop di
  326.     pop si
  327.     ret
  328. decod6: mov bufpnt,di
  329.     pop dx
  330.     pop es
  331.     pop di
  332.     pop si
  333.     jmp rskp        ; Return successfully if done.
  334.  
  335.  
  336.  
  337.     ; output the buffer, reset bufpnt and chrcnt
  338.  
  339. outbufl label    word
  340. outbuf: cmp flags.xflg,1    ; Writing to screen? [21c]
  341.     je outbf2        ; Yes, handle specially. [21c]
  342.     push bx
  343.     mov ah,writef        ; The write code.
  344.     mov dx,offset fcb
  345.     int dos         ; Write the record.
  346.     pop bx
  347.     cmp al,0        ; Successful.
  348.     jz outbf1
  349.     push ax         ; Remember the return code. [20d]
  350.     call abfil        ; Fix things up before aborting. [20d]
  351.     pop ax            ; Retrive return code. [20d]
  352.     cmp al,01
  353.     jz outbf0
  354.     call erpos
  355.     mov ah,prstr
  356.     mov dx,offset erms17    ; Record length exceeds dta.
  357.     int dos
  358.     ret
  359. outbf0: call erpos
  360.     mov ah,prstr        ; Tell about it.
  361.     mov dx,offset erms11    ; Disk full error.
  362.     int dos
  363.     ret
  364. outbf1: add tfilsz+2,80H    ; Say 128 more characters received.
  365.     adc tfilsz,0
  366.     call kbpr        ; Print the kilobytes received.
  367.     call perpr        ; Print the percent ('?' for now).
  368. outb11: mov bufpnt,offset buff    ; Addr for beginning.
  369.     mov chrcnt,dmasiz-1    ; Buffer size.
  370.     jmp rskp
  371. outbf2: mov cx,dmasiz-1     ; Number of chars to write. [21c]
  372.     sub cx,chrcnt        ; minus # of unused in buffer
  373.     mov di,offset buff    ; Where they are. [21c]
  374.     call prtscr        ; Output buffer to screen. [21c]
  375.     jmp outb11        ; Reset counter & pointer. [21c]
  376.  
  377. ;  Tidy up before aborting.    [20d]
  378. ABFIL    PROC    NEAR
  379.     mov ah,closf        ; Close the file.
  380.     mov dx,offset fcb
  381.     int dos
  382.     cmp flags.abfflg,1    ; Delete what got across or keep it?
  383.     jne abfil0        ; Nope, keep it.
  384.     mov ah,delf        ; Delete it.
  385.     mov dx,offset fcb
  386.     int dos
  387. abfil0: mov bx,offset erms10    ; Text of message to send.
  388.     call errpack        ; Send an error packet.
  389.     ret
  390. ABFIL    ENDP
  391.  
  392. ; General routine for sending an error packet.    Register BX should
  393. ; point to the text of the message being sent in the packet. [20f]
  394.  
  395. ERRPACK PROC    NEAR
  396.     mov di,offset data    ; Where to put the message.
  397.     mov al,0
  398. errp1:    mov ah,[bx]
  399.     cmp ah,'$'              ; At end of message?
  400.     je errp2
  401.     inc al            ; Remember number of chars in msg.
  402.     mov [di],ah
  403.     inc bx
  404.     inc di
  405.     jmp errp1
  406. errp2:    mov ah,0
  407.     mov pack.argbk1,ax
  408.     mov ah,'E'              ; And send an error packet.
  409.     call spack
  410.      ret            ; Return if succeed or fail.
  411.     nop
  412.     nop
  413.     ret
  414. ERRPACK ENDP
  415.  
  416. ;    Get the chars from the file.
  417.  
  418. gtchr:    cmp flags.filflg,0    ; Is there anything in the DMA?
  419.     jz gtchr0        ; Yup, proceed.
  420.     mov ah,rptq
  421.     mov origr,ah        ; Save repeat prefix here.
  422.     mov rptct,1        ; Number of times char is repeated.
  423.     mov rptval,0        ; Value of repeated char.
  424.     call inbuf
  425.      jmp gtchr1        ; No more chars, go return EOF.
  426.      nop            ; Make three bytes long.
  427. gtchr0: lea bx,inbufl
  428.     jmp encode
  429. gtchr1: mov ax,0ffffh
  430.     ret
  431.  
  432. ; encode - writes data portion of kermit packet into filbuf.
  433. ; expects BX to contain the address of a routine to refill the buffer,
  434. ; chrcnt to be the # of chars in the buffer, trans.maxdat to contain
  435. ; the maximum size of the data packet, bufpnt to contain a pointer to
  436. ; the source of the characters.
  437. ; Returns: AX/ the number of characters actually written to the buffer.
  438.  
  439. encode: mov cl,trans.maxdat    ; Maximum packet size. [21b]
  440.     mov ch,0
  441.     mov di,offset filbuf    ; Where to put the data.
  442.     mov si,bufpnt        ; pointer into source buffer
  443.     mov dl,trans.rquote    ; send quote char
  444.     mov dh,0        ; assume no 8-bit quoting
  445.     cmp trans.ebquot,'N'    ; not doing 8-bit quoting
  446.     je encod1
  447.     cmp trans.ebquot,'Y'    ; or can but won't?
  448.     je encod1
  449.     mov dh,0ffh        ; remember we have to do it
  450. encod1: dec cx            ; Decrement output buffer counter.
  451.     jge encod2        ; Go on if there is more than one left.
  452.     sub di,offset filbuf
  453.     mov ax,di
  454.     mov bufpnt,si        ; update pointer into DMA.
  455.     jmp rskp
  456. encod2: dec chrcnt        ; any data in buffer?
  457.     jge encod3        ; yes, skip over buffer refill.
  458.     call bx         ; Get another buffer full.
  459.      jmp encod8
  460.     mov si,bufpnt        ; update position in DMA.
  461.     cmp chrcnt,0        ; no characters returned?
  462.     jne encod3        ; Got some, keep going.
  463.     jmp encod8        ; none, assume eof.
  464. encod3: lodsb
  465.     cmp rptq,0        ; Are we doing repeat prefixing?
  466.     je encd3x        ; Nope, skip next part.
  467.     cmp chrcnt,0        ; Are we on the last character?
  468.     jle encd31        ; Yes, so there's no next character.
  469.     cmp rptct,94        ; Max number that we can put in a byte.
  470.     je encd31        ; Then that's it.
  471.     mov ah,[si]        ; Get the next character.
  472.     cmp al,ah        ; Is current char == next char?
  473.     jne encd31
  474.     inc rptct        ; Number of times char appears.
  475.     mov rptval,al        ; Remember the character.
  476.     inc cx            ; Repeats don't take up so much buffer space.
  477.     jmp encod1        ; Keep checking for more.
  478. encd31: cmp rptct,1        ; Were previous characters repeats?
  479.     je encd3x        ; No, so just add this char.
  480.     cmp rptct,rptmin    ; Are we within bounds for repeat prefixing?
  481.     jge encd32        ; Yes, use repeat prefixing.
  482.     mov al,rptct
  483.     mov ah,0
  484.     sub si,ax        ; Not enough characters to warrant it.
  485.     mov rptval,0        ; Clear out this value.
  486.     inc cx            ; Adjust output buffer pointer.
  487.     mov al,rptq
  488.     mov origr,al        ; Save original repeat prefix.
  489.     mov rptq,0        ; Pretend we're not doing the prefixing.
  490.     mov al,rptct
  491.     mov ah,0
  492.     add chrcnt,ax        ; Adjust input buffer pointer.
  493.     jmp encod1        ; Reprocess those characters.
  494. encd32: push ax         ; Do repeat prefixing - save data.
  495.     mov al,rptq        ; Add repeat prefix char.
  496.     stosb
  497.     dec cx            ; Account for it in buffer size.
  498.     mov al,rptct        ; Get the repeat count.
  499.     add al,20H        ; Make it printable.
  500.     stosb            ; Add to buffer.
  501.     dec cx
  502.     pop ax            ; Get back the actual character.
  503.     mov rptct,1        ; Reset repeat count.
  504.     mov rptval,0        ; And this.
  505. encd3x: cmp dh,0        ; are we doing 8-bit quoting?
  506.     je encod4        ; no, forget this.
  507.     test al,80h        ; parity on?
  508.     je encod4        ; no, don't bother with this
  509.     and al,7fh        ; turn off parity
  510.     push ax         ; save original char for a bit
  511.     dec cx            ; decrement # of chars left
  512.     mov al,trans.ebquot    ; get quote char
  513.     stosb            ; save in buffer
  514.     pop ax            ; restore character
  515. encod4: mov ah,al        ; save character
  516.     and ah,80h        ; only parity
  517.     and al,7fh        ; turn off parity in character
  518.     cmp al,' '              ; Compare to a space.
  519.     jl encod5        ; If less then its a control char.
  520.     cmp al,del        ; Is the char a delete?
  521.     jz encod5        ; Go quote it.
  522.     cmp al,dl        ; Is it the quote char?
  523.     je encod6        ; Yes - go add it. [21b start]
  524.     cmp dh,0        ; are we doing 8-bit quoting?
  525.     je encd41        ; no, don't translate it
  526.     cmp al,trans.ebquot    ; Is it the 8-bit quote char?
  527.     je encod6        ; Yes, just output with quote
  528. encd41: cmp origr,0        ; Doing repeat prefixing?
  529.     je encod7        ; No, don't check for quote char.
  530.     cmp al,origr        ; Is this the repeat quote character.
  531.     je encod6        ; Yes, then quote it.
  532.     jmp short encod7    ; else don't quote it.
  533. encod5: add al,40h        ; control char, uncontrollify
  534.     and al,7fh
  535. encod6: push ax         ; save the char
  536.     dec cx
  537.     mov al,dl
  538.     stosb
  539.     pop ax
  540. encod7: or al,ah        ; put parity back
  541.     stosb
  542.     cmp rptct,1        ; One occurence of this char?
  543.     jne encd7x
  544.     mov al,origr
  545.     mov rptq,al        ; Restore repeat quote char.
  546.     jmp encod1        ; Yes, so loop around for some more.
  547. encd7x: dec rptct        ; Add another entry of this char.
  548.     jmp encod1        ; With quoting and all.
  549.  
  550. encod8: sub di,offset filbuf
  551.     or di,di
  552.     je encod9        ; Nope.
  553.     mov ax,di
  554.     jmp rskp
  555. encod9: mov ax,0FFFFH        ; Get a minus one.
  556.     ret
  557.  
  558.  
  559. inbufl    label    word
  560. inbuf:    mov ah,flags.eoflag    ; Have we reached the end?
  561.     cmp ah,0
  562.     jz inbuf0
  563.     ret            ; Return if set.
  564. inbuf0: push si
  565.     push di
  566.     push dx
  567.     push bx
  568.     push cx
  569.     mov bx,offset buff    ; Set the r/w buffer pointer.
  570.     mov bufpnt,bx
  571.     mov ah,readf        ; Read a record.
  572.     mov dx,offset fcb
  573.     int dos
  574.     mov cx,filsiz
  575.     cmp cx,0        ; Check for 128 chars or less left.
  576.     jne inbuf1        ; Still have data left.
  577.     mov ax,ds
  578.     mov es,ax
  579.     mov si,offset filsiz+2
  580.     mov di,offset bufhex
  581.     cmps filsiz+2,es:bufhex
  582.     ja inbuf1        ; More than 128 chars.
  583.     mov flags.eoflag,0FFH    ; Set End-of-file.
  584.     mov cx,filsiz+2
  585.     cmp flags.filflg,0    ; Ever used DMA? [25]
  586.     jnz inbf01
  587.     dec cx            ; Account for DEC in caller routine.
  588. inbf01: mov chrcnt,cx        ; Return proper number of chars.
  589.     mov flags.filflg,0    ; Buffer not empty.
  590.     pop cx
  591.     pop bx
  592.     pop dx
  593.     pop di
  594.     pop si
  595.     jmp rskp
  596. inbuf1: sub filsiz+2,80H    ; Sent another 128 chars.
  597.     sbb filsiz,0        ; Account for the doubleword.
  598.     add tfilsz+2,80H    ; Book keeping for the same.
  599.     adc tfilsz,0
  600.     push ax
  601.     call kbpr        ; Print the kilobytes sent.
  602.     call perpr        ; Print the percent sent.
  603.     pop ax
  604.     mov al,80H        ; Use as counter for number of chars read.
  605.     pop cx
  606.     pop bx
  607.     pop dx
  608.     pop di
  609.     pop si
  610.     cmp flags.filflg,0    ; Ever used DMA?
  611.     jnz inbf21        ; Nope, then don't change count.
  612.     dec al            ; Fix boundary error.
  613. inbf21: mov ah,0        ; Zero the flag (buffer not empty).
  614.     mov chrcnt,ax        ; Number of chars read from file.
  615.     mov flags.filflg,0    ; Buffer not empty.
  616.     jmp rskp
  617.  
  618. nulref: mov chrcnt,0        ; No data to return.
  619.     jmp rskp
  620.  
  621. nulr:    ret
  622.  
  623. ; Print the number of Kilobytes transferred.
  624.  
  625. kbpr:    cmp flags.remflg,0    ; remote mode?
  626.     jne kbpr1        ; yes, no printing.
  627.     mov ax,tfilsz+2
  628.     mov bx,tfilsz
  629.     mov cl,10
  630.     shr ax,cl        ; divide by 1024
  631.     mov cl,6        ; high order moves 16-10 = 6 bits
  632.     shl bx,cl
  633.     or ax,bx
  634.     cmp ax,oldkbt        ; is it the same?
  635.     je kbpr1        ; yes, skip printing
  636.     mov oldkbt,ax        ; save new # of kb
  637.     push ax
  638.     call kbpos        ; Postion the cursor.
  639.     pop ax
  640.     call nout        ; Print the number of KBytes transferred.
  641. kbpr1:    ret
  642.  
  643. ; Print the percent transferred.
  644.  
  645. perpr:    cmp flags.remflg,0    ; remote mode?
  646.     jne perpr5        ; yes, no printing.
  647.     mov ax,tfilsz
  648.     or ax,tfilsz+2
  649.     cmp ax,oldper        ; same as it was before?
  650.     je perpr5        ; yes, don't bother printing.
  651.     mov oldper,ax        ; remember this for next time
  652.     cmp ofilsz,0        ; No divide by zeroes.
  653.     je perpr5        ; If not proceed.
  654.     cmp wrpmsg,0        ; did we write the percentage message?
  655.     jne perpr1        ; yes, skip this part
  656.     call perpos        ; position cursor
  657.     mov dx,offset permsg
  658.     mov ah,prstr
  659.     int dos         ; write out message
  660.     mov wrpmsg,1        ; init flag so we don't do it again
  661. perpr1: call perpos        ; Position the cursor.
  662. perpr2: mov dx,tfilsz        ; Get the high order word.
  663.     mov ax,tfilsz+2     ; Get the low order word.
  664.     div ofilsz        ; Div by percent adjusted original file size.
  665.     cmp ax,100        ; > 100% ?
  666.     jle perpr3        ; no, accept it
  667.     mov ax,100        ; else just use 100
  668. perpr3: call nout
  669.     mov dl,'%'              ; Load a percent sign.
  670. perpr4: mov ah,conout        ; Print the character.
  671.     int dos
  672. perpr5: ret
  673.  
  674. getfil: mov ah,0FFH
  675.     mov flags.filflg,ah    ; Nothing in the DMA.
  676.     mov ax,0
  677.     mov flags.eoflag,ah    ; Not the end of file.
  678.     mov bx,offset fcb+0CH
  679.     mov [bx],ax        ; Zero the current block number.
  680.     mov bx,offset fcb+0EH
  681.     mov [bx],ax        ; Ditto for Lrecl.
  682.     mov bx,offset fcb+20H
  683.     mov [bx],ah        ; Zero the current record (of block).
  684.     inc bx
  685.     mov [bx],ax        ; Same for record (of file).
  686.     mov bx,offset fcb+23H
  687.     mov [bx],ax
  688.     mov ah,openf        ; Open the file.
  689.     mov dx,offset fcb
  690.     int dos
  691.     mov dx,word ptr fcb+18    ; get file size (hi order word)
  692.     mov filsiz,dx
  693.     mov ax,word ptr fcb+16    ; lo order word
  694.     mov filsiz+2,ax
  695.     div percnt        ; Divide by 100.
  696.     mov ofilsz,ax
  697.     mov tfilsz,0        ; Set bytes sent to zero.
  698.     mov tfilsz+2,0
  699.     mov oldkbt,-1
  700.     mov oldper,-1
  701.     cmp filsiz,0        ; Null file?
  702.     jne getfl0        ; Nope.
  703.     cmp filsiz+2,0        ; Null file?
  704.     jne getfl0        ; Nope.
  705.     mov flags.eoflag,0FFH    ; Set EOF.
  706. getfl0: jmp rskp
  707.  
  708.  
  709. gtnfil: cmp flags.cxzflg,'Z'    ; Did we have a ^Z? [20b]
  710.     je gtn5         ; If yes, we're done sending files. [20b]
  711.     cmp flags.wldflg,0    ; Was there a "*"?              [7 start]
  712.     je gtn5         ; Nope.
  713.     mov bx,offset cpfcb    ; Get FCB from last check for file.
  714.     mov di,offset fcb    ; Copy to FCB.
  715.     mov cl,37        ; Size of FCB.
  716.     call fcbcpy
  717. gtn2:    mov ah,snext
  718.     mov dx,offset fcb    ; More files?
  719.     int dos
  720.     cmp al,0FFH
  721.     je gtn5
  722.     mov bx,offset fcb
  723.     mov di,offset cpfcb
  724.     mov cl,37
  725.     call fcbcpy        ; Copy from FCB.
  726.     mov di,offset fcb+1    ; Get name of next file to send.
  727.     mov bx,offset buff+1
  728.     mov cl,11
  729.     call fcbcpy
  730.     call getfil        ; Initialize
  731.      jmp r
  732.     jmp rskp
  733. gtn5:    mov flags.wldflg,0    ; Reset wild card flag.
  734.     ret                        ;  [7 end]
  735.  
  736.  
  737. ;    Get the file name (including host to micro translation)
  738.  
  739. gofil:    cmp flags.xflg,1    ; Remote command? [21c]
  740.     jne goflx        ; No.... [21c]
  741.     jmp gofla        ; Yes so skip this stuff. [21c]
  742. goflx:    cmp flags.nmoflg,1    ; Overriding name from other side? [21a]
  743.     jne gofil0        ; No - get the filename. [21a]
  744.     jmp gofil7        ; Yes, so ignore packet contents. [21a]
  745. gofil0: mov bx,offset data    ; Get the address of the file name. [21a]
  746.     mov fdtpnt,bx        ; Store the address.
  747.     mov bx,offset fcb+1    ; Address of the FCB.
  748.     mov fcbptr,bx        ; Save it.
  749.     mov ax,0
  750.     mov temp1,ax        ; Initialize the char count.
  751.     mov temp2,ax
  752.     cmp flags.droflg,1    ; Default drive? [21a]
  753.     je gofil1        ; No - don't blank out value in FCB. [21a]
  754.     mov si,offset fcb
  755.     mov [si],ah        ; Set the drive to default to current.
  756. gofil1: mov ch,' '              ; Moved the label. [21a]
  757.     mov [bx],ch        ; Blank the FCB.
  758.     inc bx
  759.     inc ah
  760.     cmp ah,0BH        ; Twelve?
  761.     jl gofil1
  762. gofil2: mov bx,fdtpnt        ; Get the NAME field.
  763.     mov ah,[bx]
  764.     inc bx
  765.     mov fdtpnt,bx
  766.     cmp ah,'.'              ; Seperator?
  767.     jne gofil3
  768.     mov bx,offset fcb+9H
  769.     mov fcbptr,bx
  770.     mov ax,temp1
  771.     mov temp2,ax
  772.     mov temp1,9H
  773.     jmp gofil6
  774. gofil3: cmp ah,0        ; Trailing null?
  775.     jz gofil7        ; Then we're done.
  776.     call verlet        ; Verify that the char is legal.
  777.     mov bx,fcbptr
  778.     mov [bx],ah
  779.     inc bx
  780.     mov fcbptr,bx
  781.     mov ax,temp1        ; Get the char count.
  782.     inc ax
  783.     mov temp1,ax
  784.     cmp ax,8H        ; Are we finished with this field?
  785.     jl gofil2
  786. gofil4: mov temp2,ax
  787.     mov bx,fdtpnt
  788.     mov ah,[bx]
  789.     inc bx
  790.     mov fdtpnt,bx
  791.     cmp ah,0
  792.     jz gofil7
  793.     cmp ah,'.'              ; Is this the terminator?
  794.     jne gofil4        ; Go until we find it.
  795. gofil6: mov bx,fdtpnt        ; Get the TYPE field.
  796.     mov ah,[bx]
  797.     inc bx
  798.     mov fdtpnt,bx
  799.     cmp ah,0        ; Trailing null?
  800.     jz gofil7        ; Then we're done.
  801.     call verlet        ; Verify that the char is legal.
  802.     mov bx,fcbptr
  803.     mov [bx],ah
  804.     inc bx
  805.     mov fcbptr,bx
  806.     inc temp1        ; Increment char count.
  807.     cmp temp1,0CH        ; Are we finished with this field?
  808.     jl gofil6
  809. gofil7: cmp flags.remflg,0    ; remote mode?
  810.     jne gofil7a        ; yes, don't print it.
  811.     call prtfn        ; Print the file name. [21a]
  812. gofil7a:cmp flags.destflg,0    ; Writing to the printer?
  813.     jne gf7y
  814.     push es
  815.     mov ax,ds
  816.     mov es,ax        ; Set this up.
  817.     mov cx,11
  818.     mov si,offset printer
  819.     mov di,offset fcb
  820.     repne movsb        ; Change name in FCB to be printer.
  821.     pop es
  822.     jmp gofil9
  823. gf7y:    mov ah,flags.flwflg    ; Is file warning on?
  824.     cmp ah,0
  825.     jnz gf7x
  826.     jmp gofil9        ; If not, just proceed.
  827. gf7x:    mov ah,openf        ; See if the file exists.
  828.     mov dx,offset fcb
  829.     int dos
  830.     cmp al,0FFH        ; Does it exist?
  831.     jnz gf8x
  832.     jmp gofil9        ; If not create it.
  833. gf8x:    cmp flags.remflg,0    ; remote mode?
  834.     jne gf8xa        ; yes, skip printing
  835.     call frpos        ; Position cursor.
  836.     mov ah,prstr        ; Inform the user we are renaming the file.
  837.     mov dx,offset infms5
  838.     int dos
  839. gf8xa:    mov ax,temp2        ; Get the number of chars in the file name.
  840.     cmp ax,0
  841.     jne gofil8
  842.     mov ax,temp1
  843.     mov temp2,ax
  844. gofil8: mov ch,0
  845.     mov cl,al
  846.     mov al,0        ; Says if first field is full.
  847.     cmp cl,9H        ; Is the first field full?
  848.     jne gofl81
  849.     mov al,0FFH        ; Set a flag saying so.
  850.     dec cl
  851. gofl81: mov bx,offset fcb    ; Get the FCB.
  852.     add bx,cx        ; Add in the character number.
  853.     mov ah,'&'
  854.     mov [bx],ah        ; Replace the char with an ampersand.
  855.     push ax
  856.     push bx
  857.     mov ah,openf        ; See if the file exists.
  858.     mov dx,offset fcb
  859.     int dos
  860.     pop bx
  861.     cmp al,0FFH        ; Does it exist?
  862.     pop ax
  863.     jz gofl89        ; If not create it.
  864.     cmp al,0        ; Get the flag.
  865.     jz gofl83
  866.     dec cl            ; Decrement the number of chars.
  867.     cmp cl,0
  868.     jz gofl88        ; If no more, die.
  869.     jmp gofl81
  870. gofl83: inc cl            ; Increment the number of chars.
  871.     cmp cl,9H        ; Are we to the end?
  872.     jl gofl81        ; If not try again ; else fail.
  873.  
  874. gofl88: cmp flags.remflg,0    ; remote mode?
  875.     jne gofl88a        ; yes, no printing
  876.     call erpos        ; Position cursor.
  877.     mov ah,prstr        ; Tell the user that we can't rename it.
  878.     mov dx,offset ermes4
  879.     int dos
  880. gofl88a:mov bx,dx        ; Tell host can't rename.  [20f]
  881.     call errpack        ; Send error packet before abort. [20f]
  882.     ret
  883.  
  884. gofl89: cmp flags.remflg,0    ; remote mode
  885.     jne gofil9        ; yes, don't have to print it
  886.     mov bx,offset fcb+0CH    ; Point past the end of the file name.
  887.     mov dh,[bx]        ; Save the present contents.
  888.     mov ah,'$'
  889.     mov [bx],ah        ; Put in a dollar sign.
  890.     push dx
  891.     mov ah,prstr        ; Print the file name.
  892.     mov dx,offset fcb+1
  893.     int dos
  894.     pop dx
  895.     mov bx,offset fcb+0CH    ; Restore over the dollar sign.
  896.     mov [bx],dh
  897. gofil9: mov ah,delf        ; Delete the file if it exists.
  898.     mov dx,offset fcb
  899.     int dos
  900.     mov ax,0
  901.     mov si,offset fcb+0CH
  902.     mov [si],ax        ; Zero current block.
  903.     mov si,offset fcb+0EH
  904.     mov [si],ax        ; Same for Lrecl.
  905.     mov si,offset fcb+20H
  906.     mov [si],ah        ; Zero the current record (within block).
  907.     inc si
  908.     mov [si],ax        ; Zero record (within file).
  909.     mov si,offset fcb+23H
  910.     mov [si],ax
  911.     mov ofilsz,0        ; File size unknown.
  912.     mov tfilsz,0        ; Set bytes received to zero.
  913.     mov tfilsz+2,0
  914.     mov oldkbt,-1
  915.     mov oldper,-1
  916.     mov ah,makef        ; Now create it.
  917.     mov dx,offset fcb
  918.     int dos
  919.     cmp al,0FFH        ; Is the disk full?
  920.     je gf9x
  921.     jmp rskp
  922. gf9x:    cmp flags.remflg,0    ; remote mode?
  923.     jne gf9xa        ; yes, don't try printing
  924.     call erpos        ; Position cursor.
  925.     mov ah,prstr        ; If so tell the user.
  926.     mov dx,offset erms12
  927.     int dos
  928.     mov bx,dx
  929. gf9xa:    call errpack        ; Send an error packet.
  930.     ret
  931. gofla:    cmp pack.argbk1,0    ; Any data in "X" packet? [21c start]
  932.     je gofla1        ; Nothing to print.
  933.     mov ah,prstr
  934.     mov dx,offset crlf
  935.     int dos
  936.     mov di,offset data    ; Where data is.
  937.     mov cx,pack.argbk1    ; How much data we have.
  938.     call prtscr        ; Print it on the screen.
  939. gofla1: mov ah,prstr
  940.     mov dx,offset crlf
  941.     int dos
  942.     jmp rskp        ; And done. [21c end]
  943. FILEIO    ENDP
  944.  
  945. ; Passed char of incoming filename in AH.  Verify that it is legal
  946. ; and if not change it to an "X".
  947. verlet: cmp ah,'0'
  948.     jl ver2         ; See if it's a legal weird char.
  949.     cmp ah,'z'+1
  950.     jns ver2
  951.     cmp ah,'9'
  952.     jle ver1        ; It's between 0-9 so it's OK.
  953.     cmp ah,'A'
  954.     jl ver2         ; Coud be a weird char.
  955.     cmp ah,'Z'
  956.     jle ver1        ; It's A-Z so it's OK.
  957.     cmp ah,'a'
  958.     jl ver2
  959.     and ah,137O        ; It's a-z, capitalize.
  960. ver1:    ret
  961.  
  962. ver2:    push es
  963.     mov cx,ds
  964.     mov es,cx        ; Scan uses ES register.
  965.     mov di,offset spchar    ; Special chars.
  966.     mov cx,spclen        ; How many of them.
  967.     cmp dosnum,0        ; Under version 2.0
  968.     je ver3
  969.     mov di,offset spchar2
  970.     mov cx,spc2len
  971. ver3:    mov al,ah        ; Char is in al.
  972.     repnz scasb        ; Search string for input char.
  973.     pop es
  974.     mov ah,al        ; Return it in AH.
  975.     cmp cx,0        ; Was it there?
  976.     jnz ver1        ; Yes, return it.
  977.     mov ah,'X'              ; If illegal, replace with "X".
  978.     mov flags.nmoflg,1
  979.     ret
  980.  
  981. ; Print incoming filename(s). [21a]
  982. PRTFN    PROC    NEAR
  983.     call clrfln        ; Position cursor & blank out the line.
  984.     mov di,offset data    ; Where to put the name.
  985.     mov bx,offset fcb    ; Where it is now.
  986.     cmp flags.droflg,0    ; Drive specified?
  987.     je prtfn1
  988.     mov dl,[bx]        ; Which one did they say?
  989.     add dl,'@'              ; Make it readable.
  990.     mov ah,dconio        ; Print the drive name.
  991.     int dos
  992.     mov dl,':'
  993.     int dos
  994. prtfn1: inc bx            ; Point to start of filename.
  995.     cmp flags.nmoflg,0    ; Is filename in packet?
  996.     je prtfn2        ; no, keep going
  997.     add di,pack.argbk1    ; bump by length of remote name
  998.     mov si,offset asmsg    ; something to put after it
  999.     mov cx,asmln        ; length of it
  1000.     rep movsb        ; add this to the buffer
  1001. prtfn2: mov cx,8        ; At most 8 letters in file name.
  1002.     mov si,bx        ; this is source now
  1003. prtfn3: lodsb            ; get a letter
  1004.     cmp al,' '              ; Done with name?
  1005.     je prtfn4        ; yes, continue
  1006.     stosb            ; else store
  1007.     loop prtfn3        ; and loop thru rest
  1008. prtfn4: mov si,offset fcb+9    ; Point to file type.
  1009.     cmp byte ptr [si],' '   ; is there a type?
  1010.     je prtfn5        ; Nope so we're done.
  1011.     mov al,'.'              ; Add the dot.
  1012.     stosb
  1013.     mov cx,3        ; At most 3 letters in file type.
  1014.     rep movsb        ; copy type (incl trailing spaces)
  1015. prtfn5: mov byte ptr [di],'$'   ; end the string
  1016.     mov ah,prstr        ; Print the file name.
  1017.     mov dx,offset data
  1018.     int dos
  1019.     mov flags.droflg,0    ; Reset flag once have the full name.
  1020.     mov flags.nmoflg,0
  1021.     ret
  1022. PRTFN    ENDP
  1023.  
  1024. ; Print data onto the screen.  If text has no "$" in it, just print
  1025. ; it.  Else, do special output for the "$".
  1026. ; Routine expects: DI = Start of buffer we are to print.
  1027. ;           CX = Number of characters to print.     [21c]
  1028.  
  1029. PRTSCR    PROC    NEAR
  1030.     mov al,'$'              ; This is what we're looking for.
  1031.     mov oloc,di        ; Remember original buffer address.
  1032.     mov osiz,cx        ; And original size.
  1033.     push es
  1034.     mov bx,ds
  1035.     mov es,bx        ; Have ES point to data area.
  1036. prts0:    repnz scasb        ; Search for "$" in the buffer.
  1037.     cmp cx,0        ; Found one?
  1038.     je prts1        ; No, do a regular DOS call.
  1039.     mov ah,prstr
  1040.     mov dx,oloc        ; Print up to the "$".
  1041.     int dos
  1042.     mov ah,dconio
  1043.     mov dl,'$'
  1044.     int dos         ; Print the "$"
  1045.     mov oloc,di        ; New starting location.
  1046.     mov osiz,cx        ; New size.
  1047.     jmp prts0
  1048. prts1:    mov bx,oloc        ; The buffer location.
  1049.     add bx,osiz        ; Point past the data.
  1050.     mov [bx],al        ; Add "$" for printing.
  1051.     mov ah,prstr
  1052.     mov dx,oloc
  1053.     int dos
  1054.     pop es
  1055.     ret
  1056. PRTSCR    ENDP
  1057.  
  1058. FIXFCB    PROC    NEAR
  1059.     push ax         ; Don't forget this.  [22]
  1060.     mov bx,offset fcb+18
  1061.     mov di,offset filsiz
  1062.     mov ax,[bx]
  1063.     mov [di],ax
  1064.     mov bx,offset fcb+16
  1065.     mov ax,[bx]
  1066.     mov 2[di],ax
  1067.     pop ax            ; Get number of chars in last buffer full. [22]
  1068.     sub filsiz+2,ax     ; Get real file size.
  1069.     sbb filsiz,0
  1070.     mov bx,offset fcb+18
  1071.     mov di,offset filsiz
  1072.     mov ax,[di]
  1073.     mov [bx],ax
  1074.     mov bx,offset fcb+16
  1075.     mov ax,2[di]
  1076.     mov [bx],ax
  1077.     ret
  1078. FIXFCB    ENDP
  1079.  
  1080. ; Jumping to this location is like retskp.  It assumes the instruction
  1081. ;   after the call is a jmp addr.
  1082.  
  1083. RSKP    PROC    NEAR
  1084.     pop bp
  1085.     add bp,3
  1086.     push bp
  1087.     ret
  1088. RSKP    ENDP
  1089.  
  1090. ; Jumping here is the same as a ret.
  1091.  
  1092. R    PROC    NEAR
  1093.     ret
  1094. R    ENDP
  1095.  
  1096. code    ends
  1097.     end
  1098.