2 ; Ullrich von Bassewitz, 16.11.2002
4 ; int write (int fd, const void* buf, unsigned count);
8 .constructor initstdout
11 .importzp sp, ptr1, ptr2, ptr3
16 .include "filedes.inc"
19 ;--------------------------------------------------------------------------
20 ; initstdout: Open the stdout and stderr file descriptors for the screen.
26 lda #STDOUT_FILENO + LFN_OFFS
28 lda #STDERR_FILENO + LFN_OFFS
29 @L1: ldx #CBMDEV_SCREEN
32 jmp OPEN ; Will always succeed
36 ;--------------------------------------------------------------------------
43 jsr rwcommon ; Pop params, check handle
44 bcs invalidfd ; Invalid handle
46 ; Check if the LFN is valid and the file is open for writing
48 adc #LFN_OFFS ; Carry is already clear
50 lda fdtab-LFN_OFFS,x; Get flags for this handle
51 and #LFN_WRITE ; File open for writing?
54 ; Valid lfn. Make it the output file
58 @error: jmp __mappederrno ; Store into __oserror, map to errno, return -1
60 ; Output the next character from the buffer
66 inc ptr1+1 ; A = *buf++;
73 lsr a ; Bit zero is write timeout
78 ; Count characters written
91 ; Wrote all chars or disk full. Close the output channel
95 ; Clear _oserror and return the number of chars written
103 ; Error entry: Device not present
109 jmp __directerrno ; Sets _errno, clears _oserror, returns -1
111 ; Error entry: The given file descriptor is not valid or not open
115 jmp __directerrno ; Sets _errno, clears _oserror, returns -1