2 ; Ullrich von Bassewitz, 16.11.2002
4 ; int read (int fd, void* buf, unsigned count);
10 .import SETLFS, OPEN, CHKIN, BASIN, CLRCH, READST
14 .importzp ptr1, ptr2, ptr3, tmp1, tmp2, tmp3
18 .include "filedes.inc"
21 ;--------------------------------------------------------------------------
22 ; initstdin: Open the stdin file descriptors for the keyboard
27 sta fdtab+STDIN_FILENO
28 lda #STDIN_FILENO + LFN_OFFS
30 stx unittab+STDIN_FILENO
33 jmp OPEN ; Will always succeed
37 ;--------------------------------------------------------------------------
43 jsr rwcommon ; Pop params, check handle
44 bcs errout ; Invalid handle, errno already set
46 ; Check if the LFN is valid and the file is open for writing
48 adc #LFN_OFFS ; Carry is already clear
50 lda fdtab-LFN_OFFS,x; Get flags for this handle
51 and #LFN_READ ; File open for writing?
54 ; Check the EOF flag. If it is set, don't read anything
56 lda fdtab-LFN_OFFS,x; Get flags for this handle
59 ; Valid lfn. Make it the input file
66 bcc @L3 ; Branch always
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 error5 ; 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 ; Return the number of chars read
124 ; Error entry, file is not open
127 lda #3 ; File not open
130 ; Error entry, status not ok
132 error5: lda #5 ; Device not present