[comp.sys.ibm.pc] Should DOS service 3F buffer input?

dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (03/29/89)

Yesterday I posted a strange problem I was having with Sidekick Plus messing
up a Fortran program.  It seemed that Fortran was never satisfied with the
input it was getting when SKPLUS was resident, and would keep asking for more.

I've since gone deep into the bowels of the Fortran .EXE, and isolated the
problem.  It seems that Fortran reads from STDIN by repeatedly using DOS service
3F to read a single byte, and only quitting when it sees a CR/LF.  What the
user sees is a single request for a line of input - presumably DOS itself is
handling the buffering.

When SKPLUS is resident, service 3F doesn't do buffering any more.  Every 
request for a byte causes a read from the terminal.  Since DOS makes it 
hard (impossible?) to return a LF, Fortran's loop goes on for a long time.

My question is:  Is the input method used by the Fortran program legal? 
I've never seen things done this way before, and found weird things happening
when I wrote a little assembler program to do input this way. (It sometimes
found characters left in DOS's buffer, sometimes didn't, and rarely gave
me what I expected.)

For anyone interested, here's my program (in A86):


;   Program to test for SKPLUS bug
;   With SKPLUS resident, always prompts for input 10 times.
;   Without it, prompts for input often enough to get 10 characters.

        jmp start

buffer  db 0d,0a,10 dup (?)

start:  mov cx,10   ; read 10 bytes
        mov di,2    ; into buffer after CR/LF

l1:     push cx
        mov  ah,03fh
        mov  bx,0   ; read from STDIN
        mov  cx,1   ; read them one at a time
        lea  dx,buffer[di]
        int  021h
        inc  di
        pop  cx
        loop l1

        mov  ah,040h
        mov  bx,1   ; write to STDOUT
        mov  cx,12  ; now print all 12 bytes 
        mov  dx,offset buffer
        int  021h
        ret

Duncan Murdoch