2003-11-13 00:12:56 +00:00
|
|
|
;
|
2000-05-28 13:40:48 +00:00
|
|
|
; Ullrich von Bassewitz, 31.05.1998
|
|
|
|
;
|
|
|
|
; Several small file stream functions
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.export _clearerr, _feof, _ferror, _fileno, _fflush
|
|
|
|
.import return0
|
|
|
|
.importzp ptr1
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2002-11-25 21:59:35 +00:00
|
|
|
.include "_file.inc"
|
2010-06-03 21:20:10 +00:00
|
|
|
.include "errno.inc"
|
2002-11-25 21:59:35 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
2010-06-03 21:20:10 +00:00
|
|
|
; Get the FILE* parameter, check if the file is open. Returns zero in A
|
|
|
|
; and zero flag set in case of an error.
|
|
|
|
|
|
|
|
.proc getf
|
2013-05-09 11:56:54 +00:00
|
|
|
sta ptr1
|
|
|
|
stx ptr1+1
|
|
|
|
ldy #_FILE::f_flags
|
|
|
|
lda (ptr1),y ; get f->f_flags
|
|
|
|
and #_FOPEN ; file open?
|
|
|
|
rts
|
2010-06-03 21:20:10 +00:00
|
|
|
.endproc
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
;
|
|
|
|
; void clearerr (FILE* f);
|
|
|
|
;
|
|
|
|
|
2010-06-03 21:20:10 +00:00
|
|
|
.proc _clearerr
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr getf
|
|
|
|
beq err
|
|
|
|
lda (ptr1),y
|
|
|
|
and #<~(_FEOF | _FERROR)
|
|
|
|
sta (ptr1),y
|
|
|
|
err: rts
|
2010-06-03 21:20:10 +00:00
|
|
|
.endproc
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
;
|
|
|
|
; int feof (FILE* f);
|
|
|
|
;
|
|
|
|
|
2010-06-03 21:20:10 +00:00
|
|
|
.proc _feof
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr getf
|
2010-06-03 21:20:10 +00:00
|
|
|
beq @L1 ; Return 0 on error
|
2013-05-09 11:56:54 +00:00
|
|
|
lda (ptr1),y
|
|
|
|
and #_FEOF
|
|
|
|
@L1: ldx #0
|
|
|
|
rts
|
2010-06-03 21:20:10 +00:00
|
|
|
.endproc
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
;
|
|
|
|
; int ferror (FILE* f);
|
|
|
|
;
|
|
|
|
|
2010-06-03 21:20:10 +00:00
|
|
|
.proc _ferror
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr getf
|
2010-06-03 21:20:10 +00:00
|
|
|
beq @L1 ; Return 0 on error
|
2013-05-09 11:56:54 +00:00
|
|
|
lda (ptr1),y
|
|
|
|
and #_FERROR
|
|
|
|
@L1: ldx #0
|
|
|
|
rts
|
2010-06-03 21:20:10 +00:00
|
|
|
.endproc
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
;
|
|
|
|
; int fileno (FILE* f);
|
|
|
|
;
|
|
|
|
|
2010-06-03 21:20:10 +00:00
|
|
|
.proc _fileno
|
2013-05-09 11:56:54 +00:00
|
|
|
jsr getf
|
2010-06-03 21:20:10 +00:00
|
|
|
beq error
|
2013-05-09 11:56:54 +00:00
|
|
|
ldy #_FILE::f_fd
|
|
|
|
lda (ptr1),y
|
|
|
|
ldx #0
|
|
|
|
rts
|
2000-05-28 13:40:48 +00:00
|
|
|
|
2010-06-03 21:20:10 +00:00
|
|
|
; If the file is not valid, fileno must set errno and return -1
|
|
|
|
|
|
|
|
error: lda #<EBADF
|
|
|
|
jsr __seterrno
|
|
|
|
lda #$FF
|
|
|
|
tax
|
|
|
|
rts
|
|
|
|
.endproc
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
;
|
|
|
|
; int __fastcall__ fflush (FILE* f);
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
_fflush = return0
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|