home *** CD-ROM | disk | FTP | other *** search
- include compiler.inc
-
- ttl FGETC, 1.06, 11-20-86, cr
-
- ;single character stream input
-
- dseg
-
- cseg
-
- xtfs <read,$strhand>
-
- MODE equ byte ptr 2[si]
- CRFLG equ byte ptr 3[si]
-
- alias fgetc,getc
-
- procdef fgetc, <<streamp, ptr>>
- locs <<bufp,word>>
- pushreg
- pushds
-
- xor di,di ;blank local buffer
-
- callit $strhand <<streamp,ptr>>
- inc ax
- jnz tmp1
- jmp reteof ;bad pointer...
- tmp1:
- dec ax ;ax holds handle
- ldptr si, streamp
-
- test bl,1 ;bl holds MODE
- jz seterr ;not open for reading
- test bl,18h
- jnz reteof ;already set
- inc cx ;test for UGC
- jz lfloop ;no char waiting
- dec cx
- mov di,cx ;had one in UGC
- mov word ptr [si],-1
- jmp short gotbyt
- ;
- lfloop:
- push ax ;save handle
- push ds
- mov bx,1 ;get one byte
- lea cx,bufp ;address of buffer
- callit read,<<bx,reg>,<cx,preg,ss>,<ax,reg>>
- mov di,bufp
- and di,0ffh
-
- pop ds
- pop dx ;recover handle in DX!!
- or ax,ax
- jz seteof ;nothing returned - set EOF
- inc ax
- jnz gotbyt
- seterr:
- or MODE,10h ;set error flag
- jmp short seteof
- gotbyt:
- test MODE,4 ;have a byte in DI
- jnz getval ;not in raw mode
- mov ax,di
- cmp al,0dh ;was it CR
- jnz notcr
- mov CRFLG,1 ;yes, set flag
- mov ax,0ah
- jmp short fini ;and return LF
- ;
- notcr: cmp al,0ah ;was it LF
- jnz notlf
- test CRFLG,1 ;CR flag set?
- jz getval ;no
- mov CRFLG,0 ;yes, clear it
- mov ax,dx ; restore handle
- jmp lfloop ;and get next byte
- ;
- notlf: cmp al,1ah ;was it CPMEOF
- jnz notef
- seteof:
- or MODE,08h ;yes, set EOF
- reteof:
- mov ax,-1
- jmp short fini
- ;
- notef:
- mov CRFLG,0 ;clear CR flag
- getval:
- mov ax,di ;and return byte
- xor ah,ah ;as unsigned
- fini:
- pret
-
- pend fgetc
-
- finish
-