3 * @author Shinichiro Nakamura
4 * @brief VT100 Senderの実装。
8 * ===============================================================
9 * Natural Tiny Shell (NT-Shell)
11 * ===============================================================
12 * Copyright (c) 2010-2011 Shinichiro Nakamura
14 * Permission is hereby granted, free of charge, to any person
15 * obtaining a copy of this software and associated documentation
16 * files (the "Software"), to deal in the Software without
17 * restriction, including without limitation the rights to use,
18 * copy, modify, merge, publish, distribute, sublicense, and/or
19 * sell copies of the Software, and to permit persons to whom the
20 * Software is furnished to do so, subject to the following
23 * The above copyright notice and this permission notice shall be
24 * included in all copies or substantial portions of the Software.
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
28 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
30 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
31 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
32 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
33 * OTHER DEALINGS IN THE SOFTWARE.
34 * ===============================================================
42 vtsend_t *p, int (*uart_write)(const char *buf, const int siz))
44 p->uart_write = uart_write;
48 int vtsend_cursor_position(vtsend_t *p, const int column, const int line)
53 buf[2] = '0' + (line / 10);
54 buf[3] = '0' + (line % 10);
56 buf[5] = '0' + (column / 10);
57 buf[6] = '0' + (column % 10);
59 p->uart_write(buf, 8);
63 int vtsend_cursor_up(vtsend_t *p, const int n)
68 buf[2] = '0' + (n / 10);
69 buf[3] = '0' + (n % 10);
71 p->uart_write(buf, 5);
75 int vtsend_cursor_down(vtsend_t *p, const int n)
80 buf[2] = '0' + (n / 10);
81 buf[3] = '0' + (n % 10);
83 p->uart_write(buf, 5);
87 int vtsend_cursor_forward(vtsend_t *p, const int n)
92 buf[2] = '0' + (n / 10);
93 buf[3] = '0' + (n % 10);
95 p->uart_write(buf, 5);
99 int vtsend_cursor_backward(vtsend_t *p, const int n)
104 buf[2] = '0' + (n / 10);
105 buf[3] = '0' + (n % 10);
107 p->uart_write(buf, 5);
111 int vtsend_cursor_position_save(vtsend_t *p)
117 p->uart_write(buf, 3);
121 int vtsend_cursor_position_restore(vtsend_t *p)
127 p->uart_write(buf, 3);
131 int vtsend_erase_display(vtsend_t *p)
138 p->uart_write(buf, 4);
142 int vtsend_erase_line(vtsend_t *p)
148 p->uart_write(buf, 3);
152 int vtsend_set_color_foreground(vtsend_t *p, const int color)
157 buf[2] = '0' + ((30 + color) / 10);
158 buf[3] = '0' + ((30 + color) % 10);
160 p->uart_write(buf, 5);
164 int vtsend_set_color_background(vtsend_t *p, const int color)
169 buf[2] = '0' + ((40 + color) / 10);
170 buf[3] = '0' + ((40 + color) % 10);
172 p->uart_write(buf, 5);
176 int vtsend_set_attribute(vtsend_t *p, const int attr)
181 buf[2] = '0' + ((attr) / 10);
182 buf[3] = '0' + ((attr) % 10);
184 p->uart_write(buf, 5);
188 int vtsend_set_scroll_region(vtsend_t *p, const int top, const int bottom)
193 buf[2] = '0' + (top / 10);
194 buf[3] = '0' + (top % 10);
196 buf[5] = '0' + (bottom / 10);
197 buf[6] = '0' + (bottom % 10);
199 p->uart_write(buf, 8);
203 int vtsend_set_cursor(vtsend_t *p, const int visible)
213 p->uart_write(buf, 6);
222 p->uart_write(buf, 6);
227 int vtsend_reset(vtsend_t *p)
232 p->uart_write(buf, 2);
238 const int x1, const int y1, const int x2, const int y2)
242 vtsend_cursor_position(p, x1, y1);
243 for (i = x1; i <= x2; i++) {
244 p->uart_write(" ", 1);
246 vtsend_cursor_position(p, x1, y2);
247 for (i = x1; i <= x2; i++) {
248 p->uart_write(" ", 1);
250 for (i = y1; i <= y2; i++) {
251 vtsend_cursor_position(p, x1, i);
252 p->uart_write(" ", 1);
253 vtsend_cursor_position(p, x2, i);
254 p->uart_write(" ", 1);
261 const int x1, const int y1, const int x2, const int y2)
264 for (i = y1; i <= y2; i++) {
265 vtsend_cursor_position(p, x1, i);
266 for (j = x1; j <= x2; j++) {
267 p->uart_write(" ", 1);