2 ; Ullrich von Bassewitz, 22.11.2002
4 ; FILE* __fastcall__ _fopen (const char* name, const char* mode, FILE* f);
5 ; /* Open the specified file and fill the descriptor values into f */
11 .import pushax, incsp4, return0
21 ; ------------------------------------------------------------------------
29 ; Get a pointer to the mode string
38 ; Look at the first character in mode
40 ldx #$00 ; Mode will be in X
41 lda (ptr1),y ; Get first char from mode
44 ldx #(O_WRONLY | O_CREAT | O_TRUNC)
52 ldx #(O_WRONLY | O_CREAT | O_APPEND)
54 ; Look at more chars from the mode string
59 beq modeok ; End of mode string reached
63 ora #O_RDWR ; Always do r/w in addition to anything else
67 beq @L3 ; Binary mode is ignored
73 jsr __seterrno ; Set __errno, returns zero in A
77 ; Mode string successfully parsed. Store the binary mode onto the stack in
78 ; the same place where the mode string pointer was before. Then call open()
86 lda #<(S_IREAD|S_IWRITE)
87 ldx #>(S_IREAD|S_IWRITE)
88 jsr pushax ; Push the "mode" argument onto the stack
89 ldy #6 ; Size of arguments in bytes
90 jsr _open ; Will cleanup the stack
92 ; Check the result of the open() call
98 jmp return0 ; Failure, errno/_oserror already set
100 ; Open call succeeded
107 sta (ptr1),y ; file->f_fd = fd;
110 sta (ptr1),y ; file->f_flags = _FOPEN;
112 ; Return the pointer to the file structure
120 ; ------------------------------------------------------------------------