]> git.sur5r.net Git - cc65/blob - libsrc/cbm/cbm_read.c
Added mouse module from C64
[cc65] / libsrc / cbm / cbm_read.c
1 /*
2  * Marc 'BlackJack' Rintsch, 19.03.2001
3  *
4  * int cbm_read(unsigned char lfn, void* buffer, unsigned int size);
5  */
6
7 #include <cbm.h>
8
9 extern unsigned char _oserror;
10
11 int cbm_read(unsigned char lfn, void* buffer, unsigned int size)
12 {
13     static unsigned int bytesread;
14     static unsigned char tmp;
15
16     /* if we can't change to the inputchannel #lfn then return an error */
17     if (_oserror = cbm_k_chkin(lfn)) return -1;
18     
19     bytesread = 0;
20
21     while (bytesread<size && !cbm_k_readst()) {
22         tmp = cbm_k_basin();
23         
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;
29         
30         ((unsigned char*)buffer)[bytesread++] = tmp;
31     }
32     
33     cbm_k_clrch();
34     return bytesread;
35 }