2 ; Ullrich von Bassewitz, 16.11.2002
4 ; int read (int fd, void* buf, unsigned count);
11 .import __errno, __oserror
12 .importzp ptr1, ptr2, ptr3, tmp1, tmp2
17 .include "filedes.inc"
20 ;--------------------------------------------------------------------------
21 ; initstdin: Open the stdin file descriptors for the keyboard
26 sta fdtab+STDIN_FILENO
27 lda #STDIN_FILENO + LFN_OFFS
29 stx unittab+STDIN_FILENO
32 jmp OPEN ; Will always succeed
36 ;--------------------------------------------------------------------------
49 sta ptr1+1 ; Remember -count-1
61 ; Check if we have a valid handle
65 cmp #MAX_FDS ; Is it valid?
66 bcs invalidfd ; Jump if no
68 ; Check if the LFN is valid and the file is open for writing
70 adc #LFN_OFFS ; Carry is already clear
72 lda fdtab-LFN_OFFS,x; Get flags for this handle
73 and #LFN_READ ; File open for writing?
76 ; Valid lfn. Make it the input file
81 ; Clear the byte counter
87 ; Read the status to check if we are already at the end of the file
95 beq deccount ; Branch always
100 sta tmp1 ; Save the input byte
102 jsr READST ; Read the IEEE status
104 and #%10111111 ; Check anything but the EOI bit
105 bne error5 ; Assume device not present
107 ; Store the byte just read
114 inc ptr2+1 ; *buf++ = A;
116 ; Increment the byte count
122 ; Get the status again and check the EOI bit
125 and #%01000000 ; Check for EOI
126 bne done ; Jump if end of file reached
128 ; Decrement the count
136 ; Read done, close the input channel
140 ; Return the number of chars read
146 ; Error entry, file descriptor is invalid
155 ; Error entry, file is not open
158 lda #3 ; File not open
161 ; Error entry, status not ok
163 error5: lda #5 ; Device not present