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
20 ; ------------------------------------------------------------------------
28 ; Get a pointer to the mode string
37 ; Look at the first character in mode
39 ldx #$00 ; Mode will be in X
40 lda (ptr1),y ; Get first char from mode
43 ldx #(O_WRONLY | O_CREAT | O_TRUNC)
51 ldx #(O_WRONLY | O_CREAT | O_APPEND)
53 ; Look at more chars from the mode string
58 beq modeok ; End of mode string reached
62 ora #O_RDWR ; Always do r/w in addition to anything else
66 beq @L3 ; Binary mode is ignored
72 jsr __seterrno ; Set __errno, returns zero in A
76 ; Mode string successfully parsed. Store the binary mode onto the stack in
77 ; the same place where the mode string pointer was before. Then call open()
85 ldy #4 ; Size of arguments in bytes
86 jsr _open ; Will cleanup the stack
88 ; Check the result of the open() call
94 jmp return0 ; Failure, errno/_oserror already set
103 sta (ptr1),y ; file->f_fd = fd;
106 sta (ptr1),y ; file->f_flags = _FOPEN;
108 ; Return the pointer to the file structure
116 ; ------------------------------------------------------------------------