#undef __BUILD_LIB

#include <stdio.h>

#undef __read

char __conbuf[81];
char __conbufcur;
char __conbufend;
extern char __conx,__conxdim;
extern void __cput(char);

static char readchar(__reg("btmp0") long) = "\tlda\t[btmp0],z";

char __asciitopetscii(char c)
{
    if (c>=97 && c<=122 )
    {
        return c - 32;
    }

    if (c >= 65 && c <= 90)
    {
        return c + 32;
    }

    return c;
}

void __readline(void)
{
  __conbufend=0;
  __cput('_');
  while(1){
    char c;
    while((c=readchar(0xffd3610))==0);
    __asm("\tlda\t#0\n\tsta\t[btmp0],z");
    c=__asciitopetscii(c);
    if(c=='\n'){__conbuf[__conbufend++]=c;--__conx;__cput(' '); __cput(c);return;}
    else if(c==20){if(__conbufend) --__conbufend;__conx-=2;__cput('_');__cput(' ');--__conx;}
    else if(__conx==__conxdim-1||__conbufend==sizeof(__conbuf)) continue;
    else{__conbuf[__conbufend++]=c;--__conx;__cput(c);__cput('_');}
  }
}

static char __getnext(void)
{
 char c;
 if(!__conbufcur)
    __readline();
  c=__conbuf[__conbufcur];
  if(++__conbufcur==__conbufend) __conbufcur=0;
  return c;
}

__mask(1) unsigned int __read(int f,char *p,unsigned int len)
{
  unsigned int n=0;
  char c;
  do{
   *p++=c=__getnext();
    n++;
  }while(n<len&&c!='\n');
  return n;
}
