Select only one console when several are available, implement console_get_cursor_position() and console_get_size()

This commit is contained in:
Laurent Vivier 2007-09-11 23:03:10 +00:00
parent f5740cf4e3
commit bc78ec0127
2 changed files with 132 additions and 21 deletions

View File

@ -16,26 +16,43 @@
#include "keyboard.h"
#include "config.h"
static int vga_enabled = 0;
enum {
CONSOLE_ALL = 0,
CONSOLE_VGA,
CONSOLE_MODEM,
CONSOLE_PRINTER,
};
static int selected_console;
void
console_init(emile_l2_header_t* info)
{
if (read_config_vga(info) == 0)
{
if (vga_init())
vga_enabled = 0;
else
vga_enabled = 1;
}
selected_console = CONSOLE_ALL;
vga_init(info);
serial_init(info);
}
int console_putchar(int c)
{
if (vga_enabled)
vga_put(c);
serial_put(c);
switch(selected_console)
{
case CONSOLE_ALL:
vga_put(c);
serial_put(SERIAL_MODEM_PORT, c);
serial_put(SERIAL_PRINTER_PORT, c);
break;
case CONSOLE_VGA:
vga_put(c);
break;
case CONSOLE_MODEM:
serial_put(SERIAL_MODEM_PORT, c);
break;
case CONSOLE_PRINTER:
serial_put(SERIAL_PRINTER_PORT, c);
break;
}
return c;
}
@ -53,26 +70,84 @@ int console_keypressed(int timeout)
while (!timeout || (Ticks < time))
{
if (vga_enabled && keyboard_keypressed())
return 1;
if (serial_keypressed(SERIAL_MODEM_PORT))
return CONSOLE_MODEM;
if (serial_keypressed())
return 1;
if (serial_keypressed(SERIAL_PRINTER_PORT))
return CONSOLE_PRINTER;
if (vga_is_available() && keyboard_keypressed())
return CONSOLE_VGA;
}
return 0;
}
int
console_select(int timeout)
{
if (vga_is_available() +
serial_is_available(SERIAL_MODEM_PORT) +
serial_is_available(SERIAL_PRINTER_PORT) < 1)
return 0;
printf("Press a key on this console to select it\n");
if (console_keypressed(timeout * 60))
return 1;
if (selected_console == CONSOLE_ALL)
{
if (vga_is_available())
selected_console = CONSOLE_VGA;
else if (serial_is_available(SERIAL_MODEM_PORT))
selected_console = CONSOLE_MODEM;
else if (serial_is_available(SERIAL_PRINTER_PORT))
selected_console = CONSOLE_PRINTER;
}
return 0;
}
int console_getchar()
{
int c;
if (vga_enabled)
switch(selected_console)
{
c = keyboard_getchar();
if (c)
return c;
case CONSOLE_ALL:
if (vga_is_available())
{
c = keyboard_getchar();
if (c)
return c;
}
c = serial_getchar(SERIAL_MODEM_PORT);
if (c)
return c;
c = serial_getchar(SERIAL_PRINTER_PORT);
if (c)
return c;
break;
case CONSOLE_VGA:
if (vga_is_available())
{
c = keyboard_getchar();
if (c)
return c;
}
case CONSOLE_MODEM:
c = serial_getchar(SERIAL_MODEM_PORT);
if (c)
return c;
break;
case CONSOLE_PRINTER:
c = serial_getchar(SERIAL_PRINTER_PORT);
if (c)
return c;
break;
}
c = serial_getchar();
return c;
return 0;
}
void console_clear(void)
@ -115,8 +190,43 @@ void console_set_cursor_position(int l, int c)
printf("\033[%d;%dH", l, c);
}
void console_get_cursor_position(int *l, int *c)
{
int car;
char buf[16];
int i;
*l = *c = 0;
while(console_getchar() != 0);
printf("\033[6n");
while ( (car = console_getchar()) && (car != '\033'));
if (console_getchar() != '[')
return;
i = 0;
while ( (car = console_getchar()) != ';')
buf[i++] = car;
buf[i] = 0;
*l = strtol(buf, NULL, 10);
i = 0;
while ( (car = console_getchar()) != 'R')
buf[i++] = car;
buf[i] = 0;
*c = strtol(buf, NULL, 10);
}
void console_select_charset(char c)
{
printf("\033(%c", c);
}
void console_get_size(int *l, int *c)
{
console_cursor_save();
console_set_cursor_position(255, 255);
console_get_cursor_position(l, c);
console_cursor_restore();
}
#endif

View File

@ -28,6 +28,7 @@ extern void console_video_normal(void);
extern void console_set_cursor_position(int l, int c);
extern void console_get_cursor_position(int* l, int* c);
extern void console_get_size(int *l, int *c);
extern int console_select(int timeout);
#endif
#endif