File: console.c

package info (click to toggle)
emile 0.10-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,716 kB
  • ctags: 2,737
  • sloc: ansic: 18,908; makefile: 726; asm: 622; sh: 2
file content (106 lines) | stat: -rw-r--r-- 1,331 bytes parent folder | download
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
/*
 * 
 * (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
 *
 */

#include <stdio.h>

#include <macos/lowmem.h>

#include "console.h"
#include "vga.h"
#include "serial.h"
#include "keyboard.h"
#include "config.h"

static int vga_enabled = 0;

void
console_init(emile_l2_header_t* info)
{
	if (read_config_vga(info->configuration) == 0)
	{
		vga_init();
		vga_enabled = 1;
	}
	serial_init(info);
}

int console_putchar(int c)
{
	if (vga_enabled)
		vga_put(c);
	serial_put(c);

	return c;
}

void console_putstring(const char *s)
{
	while(*s)
                console_putchar(*(s++));
}

#ifdef USE_CLI
int console_keypressed(int timeout)
{
	long time = Ticks + timeout;

	while (Ticks < time)
	{
		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;
}
void console_cursor_on(void)
{
	if (vga_enabled)
	{
		vga_cursor_on();
	}
}

void console_cursor_off(void)
{
	if (vga_enabled)
	{
		vga_cursor_off();
	}
}

void console_cursor_restore(void)
{
	if (vga_enabled)
	{
		vga_cursor_restore();
	}
	serial_cursor_restore();
}

void console_cursor_save(void)
{
	if (vga_enabled)
	{
		vga_cursor_save();
	}
	serial_cursor_save();
}
#endif