2004-02-15 20:46:45 +00:00
|
|
|
/*
|
|
|
|
*
|
2007-05-30 22:05:10 +00:00
|
|
|
* (c) 2004-2007 Laurent Vivier <Laurent@lvivier.info>
|
2004-02-15 20:46:45 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-05-23 17:09:48 +00:00
|
|
|
#include <stdio.h>
|
2007-06-06 13:21:52 +00:00
|
|
|
#include <stdlib.h>
|
2007-09-03 17:51:12 +00:00
|
|
|
#include <sys/types.h>
|
2005-05-23 17:09:48 +00:00
|
|
|
|
2005-11-08 02:06:40 +00:00
|
|
|
#include <macos/lowmem.h>
|
2004-02-15 20:46:45 +00:00
|
|
|
|
2004-06-22 21:21:32 +00:00
|
|
|
#include "vga.h"
|
2007-05-30 22:05:10 +00:00
|
|
|
#include "console.h"
|
2004-06-25 11:15:16 +00:00
|
|
|
#include "serial.h"
|
2005-08-27 15:48:13 +00:00
|
|
|
#include "keyboard.h"
|
2005-11-28 23:21:00 +00:00
|
|
|
#include "config.h"
|
2004-06-25 11:15:16 +00:00
|
|
|
|
|
|
|
static int vga_enabled = 0;
|
2004-02-15 20:46:45 +00:00
|
|
|
|
|
|
|
void
|
2004-06-22 21:21:32 +00:00
|
|
|
console_init(emile_l2_header_t* info)
|
2004-02-15 20:46:45 +00:00
|
|
|
{
|
2007-05-16 20:54:50 +00:00
|
|
|
if (read_config_vga(info) == 0)
|
2005-11-28 23:21:00 +00:00
|
|
|
{
|
2005-12-12 22:31:05 +00:00
|
|
|
if (vga_init())
|
|
|
|
vga_enabled = 0;
|
|
|
|
else
|
|
|
|
vga_enabled = 1;
|
2005-11-28 23:21:00 +00:00
|
|
|
}
|
2005-11-27 22:31:07 +00:00
|
|
|
serial_init(info);
|
2004-02-15 20:46:45 +00:00
|
|
|
}
|
|
|
|
|
2005-11-08 02:06:40 +00:00
|
|
|
int console_putchar(int c)
|
2004-02-15 20:46:45 +00:00
|
|
|
{
|
2004-06-25 11:15:16 +00:00
|
|
|
if (vga_enabled)
|
|
|
|
vga_put(c);
|
|
|
|
serial_put(c);
|
2005-05-23 17:09:48 +00:00
|
|
|
|
|
|
|
return c;
|
2004-02-15 20:46:45 +00:00
|
|
|
}
|
|
|
|
|
2005-05-25 06:26:00 +00:00
|
|
|
void console_putstring(const char *s)
|
2004-02-15 20:46:45 +00:00
|
|
|
{
|
|
|
|
while(*s)
|
2005-05-25 06:26:00 +00:00
|
|
|
console_putchar(*(s++));
|
2004-02-15 20:46:45 +00:00
|
|
|
}
|
2005-08-27 15:48:13 +00:00
|
|
|
|
|
|
|
#ifdef USE_CLI
|
|
|
|
int console_keypressed(int timeout)
|
|
|
|
{
|
|
|
|
long time = Ticks + timeout;
|
|
|
|
|
2007-08-18 13:32:30 +00:00
|
|
|
while (!timeout || (Ticks < time))
|
2005-08-27 15:48:13 +00:00
|
|
|
{
|
|
|
|
if (vga_enabled && keyboard_keypressed())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (serial_keypressed())
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int console_getchar()
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
if (vga_enabled)
|
|
|
|
{
|
|
|
|
c = keyboard_getchar();
|
|
|
|
if (c)
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
c = serial_getchar();
|
|
|
|
return c;
|
|
|
|
}
|
2007-05-30 22:05:10 +00:00
|
|
|
|
|
|
|
void console_clear(void)
|
|
|
|
{
|
|
|
|
printf("\033[2J");
|
|
|
|
}
|
|
|
|
|
2005-08-28 21:41:31 +00:00
|
|
|
void console_cursor_on(void)
|
|
|
|
{
|
2007-05-30 22:05:10 +00:00
|
|
|
printf("\033[?25h");
|
2005-08-28 21:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void console_cursor_off(void)
|
|
|
|
{
|
2007-05-30 22:05:10 +00:00
|
|
|
printf("\033[?25l");
|
2005-08-28 21:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void console_cursor_restore(void)
|
|
|
|
{
|
2007-05-30 22:05:10 +00:00
|
|
|
printf("\0338");
|
2005-08-28 21:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void console_cursor_save(void)
|
|
|
|
{
|
2007-05-30 22:05:10 +00:00
|
|
|
printf("\0337");
|
|
|
|
}
|
|
|
|
|
|
|
|
void console_video_inverse(void)
|
|
|
|
{
|
|
|
|
printf("\033[7m");
|
|
|
|
}
|
|
|
|
|
|
|
|
void console_video_normal(void)
|
|
|
|
{
|
|
|
|
printf("\033[27m");
|
2005-08-28 21:41:31 +00:00
|
|
|
}
|
2007-06-01 20:48:44 +00:00
|
|
|
|
2007-06-06 13:21:52 +00:00
|
|
|
void console_set_cursor_position(int l, int c)
|
2007-06-01 20:48:44 +00:00
|
|
|
{
|
2007-06-06 13:21:52 +00:00
|
|
|
printf("\033[%d;%dH", l, c);
|
2007-06-01 20:48:44 +00:00
|
|
|
}
|
2007-08-12 20:43:28 +00:00
|
|
|
|
|
|
|
void console_select_charset(char c)
|
|
|
|
{
|
|
|
|
printf("\033(%c", c);
|
|
|
|
}
|
2005-08-27 15:48:13 +00:00
|
|
|
#endif
|