1 /* Copyright (c) 2008, 2009 Nicira Networks, Inc.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
23 static void remove_elements(uint8_t *p, size_t n_elems, size_t elem_size,
25 static void insert_elements(uint8_t *p, size_t n_elems, size_t elem_size,
26 int pos, int n_insert);
27 static int range(int value, int min, int max);
30 ezio_init(struct ezio *e)
32 memset(e->icons, 0, sizeof e->icons);
35 e->show_cursor = true;
36 e->blink_cursor = false;
40 ezio_set_icon(struct ezio *e, int idx,
41 int row0, int row1, int row2, int row3,
42 int row4, int row5, int row6, int row7)
44 e->icons[idx][0] = row0;
45 e->icons[idx][1] = row1;
46 e->icons[idx][2] = row2;
47 e->icons[idx][3] = row3;
48 e->icons[idx][4] = row4;
49 e->icons[idx][5] = row5;
50 e->icons[idx][6] = row6;
51 e->icons[idx][7] = row7;
55 ezio_set_default_icon(struct ezio *e, int idx)
59 assert(idx >= 0 && idx < 8);
71 } else if (idx == 7) {
95 ezio_clear(struct ezio *e)
97 memset(e->chars, ' ', sizeof e->chars);
102 ezio_put_char(struct ezio *e, int x, int y, uint8_t c)
104 assert(x >= 0 && x <= 39);
105 assert(y >= 0 && y <= 1);
106 e->chars[y][x] = c != 0xfe ? c : 0xff;
110 ezio_line_feed(struct ezio *e)
114 ezio_scroll_up(e, 1);
119 ezio_newline(struct ezio *e)
126 ezio_delete_char(struct ezio *e, int x, int y, int n)
128 remove_elements(&e->chars[y][0], 40, 1, x, n);
132 ezio_delete_line(struct ezio *e, int y, int n)
134 remove_elements(e->chars[0], 2, 40, y, n);
138 ezio_insert_char(struct ezio *e, int x, int y, int n)
140 insert_elements(&e->chars[y][0], 40, 1, x, n);
144 ezio_insert_line(struct ezio *e, int y, int n)
146 insert_elements(&e->chars[0][0], 2, 40, y, n);
150 ezio_scroll_left(struct ezio *e, int n)
153 for (y = 0; y < 2; y++) {
154 ezio_delete_char(e, 0, y, n);
159 ezio_scroll_right(struct ezio *e, int n)
163 for (y = 0; y < 2; y++) {
164 ezio_insert_char(e, 0, y, n);
169 ezio_scroll_up(struct ezio *e, int n)
171 ezio_delete_line(e, 0, n);
175 ezio_scroll_down(struct ezio *e, int n)
177 ezio_insert_line(e, 0, n);
181 ezio_chars_differ(const struct ezio *a, const struct ezio *b, int x0, int x1,
186 x0 = range(x0, 0, 39);
187 x1 = range(x1, 1, 40);
188 for (y = 0; y < 2; y++) {
189 for (x = x0; x < x1; x++) {
190 if (a->chars[y][x] != b->chars[y][x]) {
201 remove_elements(uint8_t *p, size_t n_elems, size_t elem_size,
204 if (pos >= 0 && pos < n_elems) {
205 n_del = MIN(n_del, n_elems - pos);
206 memmove(p + elem_size * pos,
207 p + elem_size * (pos + n_del),
208 elem_size * (n_elems - pos - n_del));
209 memset(p + elem_size * (n_elems - n_del), ' ', n_del * elem_size);
214 insert_elements(uint8_t *p, size_t n_elems, size_t elem_size,
215 int pos, int n_insert)
217 if (pos >= 0 && pos < n_elems) {
218 n_insert = MIN(n_insert, n_elems - pos);
219 memmove(p + elem_size * (pos + n_insert),
221 elem_size * (n_elems - pos - n_insert));
222 memset(p + elem_size * pos, ' ', n_insert * elem_size);
227 range(int value, int min, int max)
229 return value < min ? min : value > max ? max : value;