#include <stdio.h>
#include "libsys.h"

extern FILE __files[FOPEN_MAX+3];

int OSBGET(__reg("a") char)=
"\tinline\n"
"\ttay\n"
"\tjsr\t$ffd7\n"
"\tldx\t#0\n"
"\tbcc\t.noerr\n"
"\tdex\n"
"\ttxa\n"
".noerr:\n"
"\teinline";

unsigned int __readfile(__reg("r0") char f,__reg("r2/r3") char *p,__reg("r4/r5") unsigned int len)
{
  unsigned int n=0;
  int c;
  do{
   c=OSBGET(f);
   if(c==EOF) break;
   *p++=c;
   n++;
  }while(n<len);
  return n;
}
