2001-03-21 20:59:27 +00:00
|
|
|
/*
|
|
|
|
* Marc 'BlackJack' Rintsch, 19.03.2001
|
|
|
|
*
|
|
|
|
* int cbm_read(unsigned char lfn, void* buffer, unsigned int size);
|
|
|
|
*/
|
2001-03-20 21:06:04 +00:00
|
|
|
|
|
|
|
#include <cbm.h>
|
|
|
|
|
|
|
|
extern unsigned char _oserror;
|
|
|
|
|
|
|
|
int cbm_read(unsigned char lfn, void* buffer, unsigned int size)
|
|
|
|
{
|
|
|
|
static unsigned int bytesread;
|
|
|
|
static unsigned char tmp;
|
2001-03-30 18:18:40 +00:00
|
|
|
|
|
|
|
/* if we can't change to the inputchannel #lfn then return an error */
|
2001-03-20 21:06:04 +00:00
|
|
|
if (_oserror = cbm_k_chkin(lfn)) return -1;
|
|
|
|
|
|
|
|
bytesread = 0;
|
2001-03-30 18:18:40 +00:00
|
|
|
|
2001-03-21 20:59:27 +00:00
|
|
|
while (bytesread<size && !cbm_k_readst()) {
|
2001-03-20 21:06:04 +00:00
|
|
|
tmp = cbm_k_basin();
|
2001-03-30 18:18:40 +00:00
|
|
|
|
|
|
|
/* the kernal routine BASIN sets ST to EOF if the end of file
|
|
|
|
* is reached the first time, then we have store tmp.
|
|
|
|
* every subsequent call returns EOF and READ ERROR in ST, then
|
|
|
|
* we have to exit the loop here immidiatly. */
|
2001-03-21 20:59:27 +00:00
|
|
|
if (cbm_k_readst() & 0xBF) break;
|
2001-03-30 18:18:40 +00:00
|
|
|
|
2001-03-20 21:06:04 +00:00
|
|
|
((unsigned char*)buffer)[bytesread++] = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
cbm_k_clrch();
|
|
|
|
return bytesread;
|
|
|
|
}
|