2 ; Ullrich von Bassewitz, 16.11.2002
4 ; int write (int fd, const void* buf, unsigned count);
8 .constructor initstdout
10 .import SETLFS, OPEN, CKOUT, BSOUT, READST, CLRCH
12 .importzp sp, ptr1, ptr2, ptr3
17 .include "filedes.inc"
20 ;--------------------------------------------------------------------------
21 ; initstdout: Open the stdout and stderr file descriptors for the screen.
28 sta fdtab+STDOUT_FILENO
29 sta fdtab+STDERR_FILENO
31 sta unittab+STDOUT_FILENO
32 sta unittab+STDERR_FILENO
33 lda #STDOUT_FILENO + LFN_OFFS
35 lda #STDERR_FILENO + LFN_OFFS
36 @L1: ldx #CBMDEV_SCREEN
39 jmp OPEN ; Will always succeed
43 ;--------------------------------------------------------------------------
50 jsr rwcommon ; Pop params, check handle
51 bcs invalidfd ; Invalid handle
53 ; Check if the LFN is valid and the file is open for writing
55 adc #LFN_OFFS ; Carry is already clear
57 lda fdtab-LFN_OFFS,x; Get flags for this handle
58 and #LFN_WRITE ; File open for writing?
61 ; Valid lfn. Make it the output file
65 @error: jmp __mappederrno ; Store into __oserror, map to errno, return -1
67 ; Output the next character from the buffer
73 inc ptr2+1 ; A = *buf++;
80 lsr a ; Bit zero is write timeout
85 ; Count characters written
98 ; Wrote all chars or disk full. Close the output channel
102 ; Clear _oserror and return the number of chars written
110 ; Error entry: Device not present
116 jmp __directerrno ; Sets _errno, clears _oserror, returns -1
118 ; Error entry: The given file descriptor is not valid or not open
122 jmp __directerrno ; Sets _errno, clears _oserror, returns -1