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
13 .importzp sp, ptr1, ptr2, ptr3
17 .include "filedes.inc"
20 ;--------------------------------------------------------------------------
21 ; initstdout: Open the stdout and stderr file descriptors for the screen.
26 sta fdtab+STDOUT_FILENO
27 sta fdtab+STDERR_FILENO
29 sta unittab+STDOUT_FILENO
30 sta unittab+STDERR_FILENO
31 lda #STDOUT_FILENO + LFN_OFFS
33 lda #STDERR_FILENO + LFN_OFFS
34 @L1: ldx #CBMDEV_SCREEN
37 jmp OPEN ; Will always succeed
41 ;--------------------------------------------------------------------------
47 jsr rwcommon ; Pop params, check handle
48 bcs errout ; Invalid handle, errno already set
50 ; Check if the LFN is valid and the file is open for writing
52 adc #LFN_OFFS ; Carry is already clear
54 lda fdtab-LFN_OFFS,x; Get flags for this handle
55 and #LFN_WRITE ; File open for writing?
58 ; Valid lfn. Make it the output file
64 ; Output the next character from the buffer
70 inc ptr2+1 ; A = *buf++;
72 bcs error ; Bail out on errors
74 ; Count characters written
87 ; Wrote all chars, close the output channel
91 ; Return the number of chars written
97 ; Error entry, file is not open
100 lda #3 ; File not open
103 ; Error entry, status not ok
105 error5: lda #5 ; Device not present