2 ; Ullrich von Bassewitz, 16.11.2002
4 ; int read (int fd, void* buf, unsigned count);
10 .import SETLFS, OPEN, CHKIN, BASIN, CLRCH, READST
13 .importzp ptr1, ptr2, ptr3, tmp1, tmp2, tmp3
18 .include "filedes.inc"
21 ;--------------------------------------------------------------------------
22 ; initstdin: Open the stdin file descriptors for the keyboard
29 sta fdtab+STDIN_FILENO
30 lda #STDIN_FILENO + LFN_OFFS
32 stx unittab+STDIN_FILENO
35 jmp OPEN ; Will always succeed
39 ;--------------------------------------------------------------------------
46 jsr rwcommon ; Pop params, check handle
47 bcs invalidfd ; Invalid handle
49 ; Check if the LFN is valid and the file is open for writing
51 adc #LFN_OFFS ; Carry is already clear
53 lda fdtab-LFN_OFFS,x; Get flags for this handle
54 and #LFN_READ ; File open for writing?
57 ; Check the EOF flag. If it is set, don't read anything
59 lda fdtab-LFN_OFFS,x; Get flags for this handle
62 ; Valid lfn. Make it the input file
65 bcc @L3 ; Branch if ok
66 jmp __mappederrno ; Store into __oserror, map to errno, return -1
71 sta tmp1 ; Save the input byte
73 jsr READST ; Read the IEEE status
75 and #%10111111 ; Check anything but the EOI bit
76 bne devnotpresent ; Assume device not present
78 ; Store the byte just read
85 inc ptr2+1 ; *buf++ = A;
87 ; Increment the byte count
93 ; Get the status again and check the EOI bit
96 and #%01000000 ; Check for EOI
97 bne @L4 ; Jump if end of file reached
105 beq done ; Branch always
107 ; Set the EOI flag and bail out
109 @L4: ldx tmp2 ; Get the handle
114 ; Read done, close the input channel
118 ; Clear _oserror and return the number of chars read
126 ; Error entry: Device not present
130 jmp __directerrno ; Sets _errno, clears _oserror, returns -1
132 ; Error entry: The given file descriptor is not valid or not open
136 jmp __directerrno ; Sets _errno, clears _oserror, returns -1