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, CLRCH
12 .import __errno, __oserror
13 .importzp sp, ptr1, ptr2, ptr3
18 .include "filedes.inc"
21 ;--------------------------------------------------------------------------
22 ; initstdout: Open the stdout and stderr file descriptors for the screen.
27 sta fdtab+STDOUT_FILENO
28 sta fdtab+STDERR_FILENO
30 sta unittab+STDOUT_FILENO
31 sta unittab+STDERR_FILENO
32 lda #STDOUT_FILENO + LFN_OFFS
34 lda #STDERR_FILENO + LFN_OFFS
35 @L1: ldx #CBMDEV_SCREEN
38 jmp OPEN ; Will always succeed
42 ;--------------------------------------------------------------------------
48 jsr rwcommon ; Pop params, check handle
49 bcs invalidfd ; Branch if handle not ok
51 ; Check if the LFN is valid and the file is open for writing
53 adc #LFN_OFFS ; Carry is already clear
55 lda fdtab-LFN_OFFS,x; Get flags for this handle
56 and #LFN_WRITE ; File open for writing?
59 ; Valid lfn. Make it the output file
65 ; Output the next character from the buffer
71 inc ptr2+1 ; A = *buf++;
73 bcs error ; Bail out on errors
75 ; Count characters written
88 ; Wrote all chars, close the output channel
92 ; Return the number of chars written
98 ; Error entry, file descriptor is invalid
107 ; Error entry, file is not open
110 lda #3 ; File not open
113 ; Error entry, status not ok
115 error5: lda #5 ; Device not present