Subversion Repositories HelenOS

Rev

Rev 4002 | Rev 4160 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3767 svoboda 1
/*
4154 svoboda 2
 * Copyright (c) 2006 Josef Cejka
3
 * Copyright (c) 2006 Jakub Vana
3767 svoboda 4
 * Copyright (c) 2008 Jiri Svoboda
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 *
11
 * - Redistributions of source code must retain the above copyright
12
 *   notice, this list of conditions and the following disclaimer.
13
 * - Redistributions in binary form must reproduce the above copyright
14
 *   notice, this list of conditions and the following disclaimer in the
15
 *   documentation and/or other materials provided with the distribution.
16
 * - The name of the author may not be used to endorse or promote products
17
 *   derived from this software without specific prior written permission.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 */
30
 
31
/** @addtogroup libc
32
 * @{
33
 */
34
/** @file
35
 */
36
 
37
#include <async.h>
38
#include <io/stream.h>
39
#include <ipc/console.h>
4154 svoboda 40
#include <ipc/services.h>
3767 svoboda 41
#include <console.h>
42
 
4154 svoboda 43
static int console_phone = -1;
44
 
45
void console_open(void)
46
{
47
    if (console_phone < 0) {
48
        int phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0, 0);
49
        if (phone >= 0)
50
            console_phone = phone;
51
    }
52
}
53
 
54
void console_close(void)
55
{
56
    if (console_phone >= 0) {
57
        if (ipc_hangup(console_phone) == 0) {
58
            console_phone = -1;
59
        }
60
    }
61
}
62
 
63
int console_phone_get(void)
64
{
65
    if (console_phone < 0)
66
        console_open();
67
 
68
    return console_phone;
69
}
70
 
71
void console_wait(void)
72
{
73
    while (console_phone < 0)
74
        console_open();
75
}
76
 
3768 svoboda 77
void console_clear(void)
78
{
4154 svoboda 79
    int cons_phone = console_phone_get();
3768 svoboda 80
    async_msg_0(cons_phone, CONSOLE_CLEAR);
81
}
82
 
83
void console_goto(int row, int col)
84
{
4154 svoboda 85
    int cons_phone = console_phone_get();
3768 svoboda 86
    async_msg_2(cons_phone, CONSOLE_GOTO, row, col);
87
}
88
 
4154 svoboda 89
void console_putchar(int c)
90
{
91
    int cons_phone = console_phone_get();
92
    async_msg_1(cons_phone, CONSOLE_PUTCHAR, c);
93
}
94
 
3768 svoboda 95
void console_flush(void)
96
{
4154 svoboda 97
    int cons_phone = console_phone_get();
3768 svoboda 98
    async_msg_0(cons_phone, CONSOLE_FLUSH);
99
}
100
 
101
int console_get_size(int *rows, int *cols)
102
{
4154 svoboda 103
    int cons_phone = console_phone_get();
3768 svoboda 104
    ipcarg_t r, c;
105
    int rc;
106
 
107
    rc = async_req_0_2(cons_phone, CONSOLE_GETSIZE, &r, &c);
108
 
109
    *rows = (int) r;
110
    *cols = (int) c;
111
 
112
    return rc;
113
}
114
 
3767 svoboda 115
void console_set_style(int style)
116
{
4154 svoboda 117
    int cons_phone = console_phone_get();
3767 svoboda 118
    async_msg_1(cons_phone, CONSOLE_SET_STYLE, style);
119
}
120
 
121
void console_set_color(int fg_color, int bg_color, int flags)
122
{
4154 svoboda 123
    int cons_phone = console_phone_get();
3767 svoboda 124
    async_msg_3(cons_phone, CONSOLE_SET_COLOR, fg_color, bg_color, flags);
125
}
126
 
127
void console_set_rgb_color(int fg_color, int bg_color)
128
{
4154 svoboda 129
    int cons_phone = console_phone_get();
3767 svoboda 130
    async_msg_2(cons_phone, CONSOLE_SET_RGB_COLOR, fg_color, bg_color);
131
}
132
 
3768 svoboda 133
void console_cursor_visibility(int show)
134
{
4154 svoboda 135
    int cons_phone = console_phone_get();
3768 svoboda 136
    async_msg_1(cons_phone, CONSOLE_CURSOR_VISIBILITY, show != 0);
137
}
138
 
3767 svoboda 139
/** @}
140
 */