ogetc	PROC
	push si
	mov si,ax
	mov ax,[si.ios_i]
	cmp ax,[si.ios_c]
	je ogetc_read
    ogetc_do:
	inc [si.ios_i]
	mov si,[si.ios_bp]
	add si,ax		; [0] == zero flag set!
	inc ax
	mov ah,0
	mov al,[si]
    ogetc_end:
	pop si
	ret
    ogetc_read:
	xor ax,ax
	mov [si.ios_i],ax
	mov [si.ios_c],ax
	push bx
	push cx
	push dx
	mov cx,[si.ios_size]
	mov bx,[si.ios_file]
	mov dx,[si.ios_bp]
	mov ah,3Fh
	int 21h
	pop dx
	pop cx
	pop bx
	jc ogetc_error
	mov [si.ios_c],ax
	or ax,ax
	mov ax,[si.ios_i]
	jnz ogetc_do
    ogetc_error:
	xor ax,ax
	jmp ogetc_end
ogetc	ENDP

ogets	PROC
	push si	; AX stream
	push di	; DX line buffer
	push cx	; CX buffer size
	mov si,ax
	sub cx,2
	mov di,dx
    ogets_get:
	mov ax,si
	call ogetc
	jz ogets_end
	cmp al,0Dh
	je ogets_set
	cmp al,0Ah
	je ogets_eol
	assert	al,0,jne,"gets:0"
	mov [di],al
	inc di
	dec cx
	jnz ogets_get
    ogets_set:
	mov ax,si
	call ogetc
    ogets_end:
	mov byte ptr [di],0
	pop cx
	pop di
	pop si
	ret
    ogets_eol:
	inc al
	jmp ogets_end
ogets	ENDP

