diff --git a/stdio.asm b/stdio.asm index 1c51093..c56cdb4 100644 --- a/stdio.asm +++ b/stdio.asm @@ -1574,15 +1574,17 @@ lb4 creturn 2:err * fread start temp equ 1 +p equ 5 - csubroutine (4:ptr,4:element_size,4:count,4:stream),4 + csubroutine (4:ptr,4:element_size,4:count,4:stream),8 phb phk plb stz rdTransferCount set the # of elements read stz rdTransferCount+2 - stz pbkCount no putback characters read yet + stz extraCount no putback characters read yet + stz extraCount+2 ph4 stdin+4+FILE_flag sta >stdin+4+FILE_flag jsl SYSKEYIN read the closing cr - bra lb4 + brl lb4 lb1a short M set character sta [ptr] long M @@ -1638,10 +1638,55 @@ lb1a short M set character lda rdRequestCount ora rdRequestCount+2 bne lb1 - bra lb4 + brl lb4 lb2 sta rdRefNum set the reference number - move4 ptr,rdDataBuffer set the start address + ldy #FILE_flag if the file is being read then + lda [stream],Y + bit #_IOREAD + beq lb2c +lb2a ldy #FILE_cnt while there is buffered data... + lda [stream],Y + iny + iny + ora [stream],Y + beq lb2c + lda rdRequestCount ...and the request count is not 0 + ora rdRequestCount+2 + beq lb4 + ldy #FILE_ptr get the next character + lda [stream],Y + sta p + clc + adc #1 + sta [stream],Y + iny + iny + lda [stream],Y + sta p+2 + adc #0 + sta [stream],Y + short M + lda [p] + sta [ptr] + long M + ldy #FILE_cnt dec the # chars in the buffer + sec + lda [stream],Y + sbc #1 + sta [stream],Y + bcs lb2b + iny + iny + lda [stream],Y + dec A + sta [stream],Y +lb2b inc4 ptr adjust pointer and counts + dec4 rdRequestCount + inc4 extraCount + bra lb2a + +lb2c move4 ptr,rdDataBuffer set the start address OSRead rd read the bytes bcc lb4 cmp #$4C if the error was $4C then @@ -1650,12 +1695,7 @@ lb2 sta rdRefNum set the reference number bra lb4 lb3 ph4 FILE_pbk != -1 - lda [stream],Y - inc A - ldy #FILE_cnt or stream->FILE_cnt != 0 then - ora [stream],Y - iny - iny - ora [stream],Y - beq lb1 - ph2 #SEEK_CUR fseek(stream, 0L, SEEK_CUR) - ph4 #0 - ph4