Subversion Repositories HelenOS

Rev

Rev 2069 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2069 Rev 2071
1
/*
1
/*
2
 * Copyright (C) 2006 Josef Cejka
2
 * Copyright (c) 2006 Josef Cejka
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup console
29
/** @addtogroup console
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <screenbuffer.h>
35
#include <screenbuffer.h>
36
#include <malloc.h>
36
#include <malloc.h>
37
#include <unistd.h>
37
#include <unistd.h>
38
 
38
 
39
/** Store one character to screenbuffer. Its position is determined by
39
/** Store one character to screenbuffer. Its position is determined by
40
 * scr->position_x and scr->position_y.
40
 * scr->position_x and scr->position_y.
41
 *
41
 *
42
 * @param scr   screenbuffer
42
 * @param scr   screenbuffer
43
 * @param c stored character
43
 * @param c stored character
44
 */
44
 */
45
void screenbuffer_putchar(screenbuffer_t *scr, char c)
45
void screenbuffer_putchar(screenbuffer_t *scr, char c)
46
{
46
{
47
    keyfield_t *field;
47
    keyfield_t *field;
48
   
48
   
49
    field = get_field_at(scr, scr->position_x, scr->position_y);
49
    field = get_field_at(scr, scr->position_x, scr->position_y);
50
 
50
 
51
    field->character = c;
51
    field->character = c;
52
    field->style = scr->style;
52
    field->style = scr->style;
53
}
53
}
54
 
54
 
55
/** Initilize screenbuffer. Allocate space for screen content in accordance to given size.
55
/** Initilize screenbuffer. Allocate space for screen content in accordance to given size.
56
 * @param scr       initialized screenbuffer
56
 * @param scr       initialized screenbuffer
57
 * @param size_x    width in characters    
57
 * @param size_x    width in characters    
58
 * @param size_y    height in characters
58
 * @param size_y    height in characters
59
 * @return pointer to screenbuffer (same as scr parameter) or NULL
59
 * @return pointer to screenbuffer (same as scr parameter) or NULL
60
 */
60
 */
61
screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y)
61
screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y)
62
{
62
{
63
    scr->buffer = (keyfield_t *) malloc(sizeof(keyfield_t) * size_x * size_y);
63
    scr->buffer = (keyfield_t *) malloc(sizeof(keyfield_t) * size_x * size_y);
64
    if (!scr->buffer) {
64
    if (!scr->buffer) {
65
        return NULL;
65
        return NULL;
66
    }
66
    }
67
   
67
   
68
    scr->size_x = size_x;
68
    scr->size_x = size_x;
69
    scr->size_y = size_y;
69
    scr->size_y = size_y;
70
    scr->style.fg_color = DEFAULT_FOREGROUND;
70
    scr->style.fg_color = DEFAULT_FOREGROUND;
71
    scr->style.bg_color = DEFAULT_BACKGROUND;
71
    scr->style.bg_color = DEFAULT_BACKGROUND;
72
    scr->is_cursor_visible = 1;
72
    scr->is_cursor_visible = 1;
73
   
73
   
74
    screenbuffer_clear(scr);
74
    screenbuffer_clear(scr);
75
   
75
   
76
    return scr;
76
    return scr;
77
}
77
}
78
 
78
 
79
/** Clear screenbuffer.
79
/** Clear screenbuffer.
80
 * @param scr screenbuffer
80
 * @param scr screenbuffer
81
 */
81
 */
82
void screenbuffer_clear(screenbuffer_t *scr)
82
void screenbuffer_clear(screenbuffer_t *scr)
83
{
83
{
84
    unsigned int i;
84
    unsigned int i;
85
   
85
   
86
    for (i = 0; i < (scr->size_x * scr->size_y); i++) {
86
    for (i = 0; i < (scr->size_x * scr->size_y); i++) {
87
        scr->buffer[i].character = ' ';
87
        scr->buffer[i].character = ' ';
88
        scr->buffer[i].style = scr->style;
88
        scr->buffer[i].style = scr->style;
89
    }
89
    }
90
 
90
 
91
    scr->top_line = 0;
91
    scr->top_line = 0;
92
    scr->position_y = 0;
92
    scr->position_y = 0;
93
    scr->position_x = 0;
93
    scr->position_x = 0;
94
}
94
}
95
 
95
 
96
/** Clear one buffer line.
96
/** Clear one buffer line.
97
 * @param scr
97
 * @param scr
98
 * @param line One buffer line (not a screen line!)
98
 * @param line One buffer line (not a screen line!)
99
 */
99
 */
100
void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line)
100
void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line)
101
{
101
{
102
    unsigned int i;
102
    unsigned int i;
103
   
103
   
104
    for (i = 0; i < scr->size_x; i++) {
104
    for (i = 0; i < scr->size_x; i++) {
105
        scr->buffer[i + line * scr->size_x].character = ' ';
105
        scr->buffer[i + line * scr->size_x].character = ' ';
106
        scr->buffer[i + line * scr->size_x].style = scr->style;
106
        scr->buffer[i + line * scr->size_x].style = scr->style;
107
    }
107
    }
108
}
108
}
109
 
109
 
110
/** Copy content buffer from screenbuffer to given memory.
110
/** Copy content buffer from screenbuffer to given memory.
111
 * @param scr   source screenbuffer
111
 * @param scr   source screenbuffer
112
 * @param dest  destination
112
 * @param dest  destination
113
 */
113
 */
114
void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest)
114
void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest)
115
{
115
{
116
    unsigned int i;
116
    unsigned int i;
117
   
117
   
118
    for (i = 0; i < scr->size_x * scr->size_y; i++) {
118
    for (i = 0; i < scr->size_x * scr->size_y; i++) {
119
        dest[i] = scr->buffer[i];
119
        dest[i] = scr->buffer[i];
120
    }
120
    }
121
}
121
}
122
 
122
 
123
/** Set new cursor position in screenbuffer.
123
/** Set new cursor position in screenbuffer.
124
 * @param scr
124
 * @param scr
125
 * @param x
125
 * @param x
126
 * @param y
126
 * @param y
127
 */
127
 */
128
void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y)
128
void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y)
129
{
129
{
130
    scr->position_x = x % scr->size_x;
130
    scr->position_x = x % scr->size_x;
131
    scr->position_y = y % scr->size_y;
131
    scr->position_y = y % scr->size_y;
132
}
132
}
133
 
133
 
134
/** Set new style.
134
/** Set new style.
135
 * @param scr
135
 * @param scr
136
 * @param fg_color
136
 * @param fg_color
137
 * @param bg_color
137
 * @param bg_color
138
 */
138
 */
139
void screenbuffer_set_style(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color)
139
void screenbuffer_set_style(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color)
140
{
140
{
141
    scr->style.fg_color = fg_color;
141
    scr->style.fg_color = fg_color;
142
    scr->style.bg_color = bg_color;
142
    scr->style.bg_color = bg_color;
143
}
143
}
144
 
144
 
145
 
145
 
146
/** @}
146
/** @}
147
 */
147
 */
148
 
148