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
78 ; Mode string successfully parsed. Store the binary mode onto the stack in
79 ; the same place where the mode string pointer was before. The call open()
87 ldy #4 ; Size of arguments in bytes
88 jsr _open ; Will cleanup the stack
90 ; Check the result of the open() call
96 jmp return0 ; Failure, errno/_oserror already set
105 sta (ptr1),y ; file->f_fd = fd;
108 sta (ptr1),y ; file->f_flags = _FOPEN;
110 ; Return the pointer to the file structure
118 ; ------------------------------------------------------------------------