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
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 errout ; Invalid handle, errno already set
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
69 bcc @L3 ; Branch always
74 sta tmp1 ; Save the input byte
76 jsr READST ; Read the IEEE status
78 and #%10111111 ; Check anything but the EOI bit
79 bne error5 ; Assume device not present
81 ; Store the byte just read
88 inc ptr2+1 ; *buf++ = A;
90 ; Increment the byte count
96 ; Get the status again and check the EOI bit
99 and #%01000000 ; Check for EOI
100 bne @L4 ; Jump if end of file reached
102 ; Decrement the count
108 beq done ; Branch always
110 ; Set the EOI flag and bail out
112 @L4: ldx tmp2 ; Get the handle
117 ; Read done, close the input channel
121 ; Return the number of chars read
127 ; Error entry, file is not open
130 lda #3 ; File not open
133 ; Error entry, status not ok
135 error5: lda #5 ; Device not present