3 * @author CuBeatSystems
4 * @author Shinichiro Nakamura
6 * ===============================================================
7 * Natural Tiny Shell (NT-Shell) Version 0.3.1
8 * ===============================================================
9 * Copyright (c) 2010-2016 Shinichiro Nakamura
11 * Permission is hereby granted, free of charge, to any person
12 * obtaining a copy of this software and associated documentation
13 * files (the "Software"), to deal in the Software without
14 * restriction, including without limitation the rights to use,
15 * copy, modify, merge, publish, distribute, sublicense, and/or
16 * sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following
20 * The above copyright notice and this permission notice shall be
21 * included in all copies or substantial portions of the Software.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30 * OTHER DEALINGS IN THE SOFTWARE.
38 //#define UART_WRITE(P, BUF, SIZ) (P)->uart_write(BUF, SIZ, (P)->extobj)
39 #define UART_WRITE(BUF) DbprintfEx(FLAG_RAWPRINT, "%s", BUF)
41 int vtsend_init(vtsend_t
*p
, VTSEND_SERIAL_WRITE uart_write
, void *extobj
) {
42 p
->uart_write
= uart_write
;
47 int vtsend_cursor_position(vtsend_t
*p
, const int column
, const int line
) {
51 buf
[2] = '0' + (line
/ 10);
52 buf
[3] = '0' + (line
% 10);
54 buf
[5] = '0' + (column
/ 10);
55 buf
[6] = '0' + (column
% 10);
58 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
62 int vtsend_cursor_up(vtsend_t
*p
, const int n
) {
66 buf
[2] = '0' + (n
/ 10);
67 buf
[3] = '0' + (n
% 10);
71 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
75 int vtsend_cursor_down(vtsend_t
*p
, const int n
) {
79 buf
[2] = '0' + (n
/ 10);
80 buf
[3] = '0' + (n
% 10);
84 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
88 int vtsend_cursor_forward(vtsend_t
*p
, const int n
) {
92 buf
[2] = '0' + (n
/ 10);
93 buf
[3] = '0' + (n
% 10);
97 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
101 int vtsend_cursor_backward(vtsend_t
*p
, const int n
) {
105 buf
[2] = '0' + (n
/ 10);
106 buf
[3] = '0' + (n
% 10);
110 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
114 int vtsend_cursor_position_save(vtsend_t
*p
) {
121 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
125 int vtsend_cursor_position_restore(vtsend_t
*p
) {
132 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
136 int vtsend_erase_display(vtsend_t
*p
) {
144 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
148 int vtsend_erase_line(vtsend_t
*p
) {
156 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
160 int vtsend_set_color_foreground(vtsend_t
*p
, const int color
) {
164 buf
[2] = '0' + ((30 + color
) / 10);
165 buf
[3] = '0' + ((30 + color
) % 10);
169 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
173 int vtsend_set_color_background(vtsend_t
*p
, const int color
) {
177 buf
[2] = '0' + ((40 + color
) / 10);
178 buf
[3] = '0' + ((40 + color
) % 10);
182 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
186 int vtsend_set_attribute(vtsend_t
*p
, const int attr
) {
190 buf
[2] = '0' + ((attr
) / 10);
191 buf
[3] = '0' + ((attr
) % 10);
195 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
199 int vtsend_set_scroll_region(vtsend_t
*p
, const int top
, const int bottom
) {
203 buf
[2] = '0' + (top
/ 10);
204 buf
[3] = '0' + (top
% 10);
206 buf
[5] = '0' + (bottom
/ 10);
207 buf
[6] = '0' + (bottom
% 10);
211 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
215 int vtsend_set_cursor(vtsend_t
*p
, const int visible
) {
226 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
237 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
242 int vtsend_reset(vtsend_t
*p
) {
248 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
252 int vtsend_draw_box(vtsend_t
*p
, const int x1
, const int y1
, const int x2
, const int y2
) {
255 vtsend_cursor_position(p
, x1
, y1
);
256 for (i
= x1
; i
<= x2
; i
++) {
259 vtsend_cursor_position(p
, x1
, y2
);
260 for (i
= x1
; i
<= x2
; i
++) {
263 for (i
= y1
; i
<= y2
; i
++) {
264 vtsend_cursor_position(p
, x1
, i
);
266 vtsend_cursor_position(p
, x2
, i
);
272 int vtsend_fill_box(vtsend_t
*p
, const int x1
, const int y1
, const int x2
, const int y2
) {
274 for (i
= y1
; i
<= y2
; i
++) {
275 vtsend_cursor_position(p
, x1
, i
);
276 for (j
= x1
; j
<= x2
; j
++) {