2 ; Ullrich von Bassewitz, 22.06.2002
4 ; Original C code by Marc 'BlackJack' Rintsch, 19.03.2001
6 ; int __fastcall__ cbm_read (unsigned char lfn, void* buffer, unsigned int size)
7 ; /* Reads up to "size" bytes from a file to "buffer".
8 ; * Returns the number of actually read bytes, 0 if there are no bytes left
9 ; * (EOF) or -1 in case of an error. _oserror contains an errorcode then (see
13 ; static unsigned int bytesread;
14 ; static unsigned char tmp;
16 ; /* if we can't change to the inputchannel #lfn then return an error */
17 ; if (_oserror = cbm_k_chkin(lfn)) return -1;
21 ; while (bytesread<size && !cbm_k_readst()) {
22 ; tmp = cbm_k_basin();
24 ; /* the kernal routine BASIN sets ST to EOF if the end of file
25 ; * is reached the first time, then we have store tmp.
26 ; * every subsequent call returns EOF and READ ERROR in ST, then
27 ; * we have to exit the loop here immidiatly. */
28 ; if (cbm_k_readst() & 0xBF) break;
30 ; ((unsigned char*)buffer)[bytesread++] = tmp;
41 .import CHKIN, READST, BASIN, CLRCH
42 .importzp ptr1, ptr2, ptr3, tmp1
52 sta ptr1+1 ; Save -size-1
56 stx ptr2+1 ; Save buffer
61 bcs @E1 ; Branch on error
68 beq @L3 ; Branch always
76 jsr BASIN ; Read next char from file
77 sta tmp1 ; Save it for later
85 sta (ptr2),y ; Save read byte
89 inc ptr2+1 ; ++buffer;
93 inc ptr3+1 ; ++bytesread;
103 ldx ptr3+1 ; return bytesread;