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
|
|
|
|
;
|
|
|
|
|
|
|
|
.export _clearerr, _feof, _ferror, _fileno, _fflush
|
|
|
|
.import return0
|
|
|
|
.importzp ptr1
|
|
|
|
|
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
|
|
|
|
sta ptr1
|
|
|
|
stx ptr1+1
|
|
|
|
ldy #_FILE::f_flags
|
|
|
|
lda (ptr1),y ; get f->f_flags
|
|
|
|
and #_FOPEN ; file open?
|
2000-05-28 13:40:48 +00:00
|
|
|
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
|
2000-05-28 13:40:48 +00:00
|
|
|
jsr getf
|
2010-06-03 21:20:10 +00:00
|
|
|
beq err
|
2000-05-28 13:40:48 +00:00
|
|
|
lda (ptr1),y
|
2002-11-25 21:59:35 +00:00
|
|
|
and #<~(_FEOF | _FERROR)
|
2000-05-28 13:40:48 +00:00
|
|
|
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
|
|
|
|
jsr getf
|
|
|
|
beq @L1 ; Return 0 on error
|
|
|
|
lda (ptr1),y
|
|
|
|
and #_FEOF
|
|
|
|
@L1: ldx #0
|
2000-05-28 13:40:48 +00:00
|
|
|
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
|
|
|
|
jsr getf
|
|
|
|
beq @L1 ; Return 0 on error
|
2000-05-28 13:40:48 +00:00
|
|
|
lda (ptr1),y
|
2002-11-25 21:59:35 +00:00
|
|
|
and #_FERROR
|
2010-06-03 21:20:10 +00:00
|
|
|
@L1: ldx #0
|
2000-05-28 13:40:48 +00:00
|
|
|
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
|
|
|
|
jsr getf
|
|
|
|
beq error
|
2004-05-12 13:16:36 +00:00
|
|
|
ldy #_FILE::f_fd
|
2000-05-28 13:40:48 +00:00
|
|
|
lda (ptr1),y
|
|
|
|
ldx #0
|
|
|
|
rts
|
|
|
|
|
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);
|
|
|
|
;
|
|
|
|
|
|
|
|
_fflush = return0
|
|
|
|
|
|
|
|
|