/* $Header: cons.c,v 1.3 89/04/11 20:00:15 mar Exp $
 *
 * Initialize console devices, and choose one.  Getc and putc will
 * use the first one found of: qvss, sm, qdss, or serial line.
 */

int qv_init(), sm_init(), qd_init(), sl_init();

int (*cons_inits[])() = { qv_init, sm_init, qd_init,/* plx_init,*/ sl_init, 0 };

int (*v_putc)(), (*v_getc)(), (*v_getct)(), slputc();
extern int cpu, sid_ext;

init_cons()
{
    int (**fp)(), (*t)(), x;
    v_putc = v_getc = v_getct = (int (*)())0;

    for (fp = cons_inits; *fp; fp++)
      if ((**fp)())
	break;
}

/* Generic console putc */

putchar(c)
{
    if (v_putc) {
	(*v_putc)(c);
	if (c == '\n')
	  (*v_putc)('\r');
    }
}

/* Generic console getc */

int getchar()
{
    register int c = 0;

    if (v_getc) {
	c = (*v_getc)();
	if (c=='\r')
	  c = '\n';
	if (c != '\b' && c != '\177')
	  putchar(c);
    }
    return(c);
}

/* Generic console getc with timeout.  The timeout value is expressed in
 * tenths of a second.  Either the character received will be returned or
 * -1 if timeout occurs.
 */

int getchart(timeo)
{
    register int c;

    if (v_getct) {
	if ((c = (*v_getct)(timeo)) == -1)
	  return(c);
	if (c=='\r')
	  c = '\n';
	if (c != '\b' && c != '\177')
	  putchar(c);
	return(c);
    } else
      return(getchar());
}
