1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#include "ansiesc.h"
#include "etherboot.h"
#include "start32.h"
#include "misc.h"
#if ANSIMODE==-1
static int ansion = 0;
#endif
/**************************************************************************
SLEEP
**************************************************************************/
void sleep(int secs)
{
unsigned long tmo;
for (tmo = currticks()+secs*TICKS_PER_SEC; currticks() < tmo; )
/* Nothing */;
}
int getdec(unsigned char **ptr)
{
char *p = *ptr;
int ret=0;
if ((*p < '0') || (*p > '9')) return(-1);
while ((*p >= '0') && (*p <= '9')) {
ret = ret*10 + (*p - '0');
p++;
}
*ptr = p;
return(ret);
}
#if ANSIMODE==-1
void
ansiswitch(int i)
{
ansion = i;
}
#endif
void
putchar(int c)
{
#ifdef CONSOLE_CRT
#if ANSIMODE==-1 /* choose by variable */
if (ansion)
ansi_putc(c);
else {
if (c == '\n')
console_putc('\r');
console_putc(c);
}
#elif ANSIMODE==1 /* always ANSI */
ansi_putc(c);
#else /* always console */
if (c == '\n')
console_putc('\r');
console_putc(c);
#endif
#endif
#ifdef CONSOLE_SERIAL
if (c == '\n')
serial_putc('\r');
serial_putc(c);
#endif
}
/**************************************************************************
GETCHAR - Read the next character from input device WITHOUT ECHO
**************************************************************************/
int getchar(void)
{
int c = 256;
do {
#ifdef POWERSAVE
/* Doze for a while (until the next interrupt). This works
* fine, because the keyboard is interrupt-driven, and the
* timer interrupt (approx. every 50msec) takes care of the
* serial port, which is read by polling. This reduces the
* power dissipation of a modern CPU considerably, and also
* makes Etherboot waiting for user interaction waste a lot
* less CPU time in a VMware session. */
cpu_nap();
#endif /* POWERSAVE */
#ifdef CONSOLE_CRT
if (console_ischar())
c = console_getc();
#endif
#ifdef CONSOLE_SERIAL
if (serial_ischar())
c = serial_getc();
#endif
} while (c==256);
if (c == '\r')
c = '\n';
return c;
}
int iskey(void)
{
#ifdef CONSOLE_CRT
if (console_ischar())
return 1;
#endif
#ifdef CONSOLE_SERIAL
if (serial_ischar())
return 1;
#endif
return 0;
}
|