1 //-----------------------------------------------------------------------------
2 // Borrowed initially from https://cubeatsystems.com/ntshell/index.html
3 // Copyright (C) 2010-2016 Shinichiro Nakamura (CuBeatSystems)
4 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // See LICENSE.txt for the text of the license.
17 //-----------------------------------------------------------------------------
18 // Natural Tiny Shell (NT-Shell) Version 0.3.1
19 //-----------------------------------------------------------------------------
26 //#define UART_WRITE(P, BUF, SIZ) (P)->uart_write(BUF, SIZ, (P)->extobj)
27 #define UART_WRITE(BUF) DbprintfEx(FLAG_RAWPRINT, "%s", BUF)
29 int vtsend_init(vtsend_t
*p
, VTSEND_SERIAL_WRITE uart_write
, void *extobj
) {
30 p
->uart_write
= uart_write
;
35 int vtsend_cursor_position(vtsend_t
*p
, const int column
, const int line
) {
39 buf
[2] = '0' + (line
/ 10);
40 buf
[3] = '0' + (line
% 10);
42 buf
[5] = '0' + (column
/ 10);
43 buf
[6] = '0' + (column
% 10);
46 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
50 int vtsend_cursor_up(vtsend_t
*p
, const int n
) {
54 buf
[2] = '0' + (n
/ 10);
55 buf
[3] = '0' + (n
% 10);
59 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
63 int vtsend_cursor_down(vtsend_t
*p
, const int n
) {
67 buf
[2] = '0' + (n
/ 10);
68 buf
[3] = '0' + (n
% 10);
72 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
76 int vtsend_cursor_forward(vtsend_t
*p
, const int n
) {
80 buf
[2] = '0' + (n
/ 10);
81 buf
[3] = '0' + (n
% 10);
85 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
89 int vtsend_cursor_backward(vtsend_t
*p
, const int n
) {
93 buf
[2] = '0' + (n
/ 10);
94 buf
[3] = '0' + (n
% 10);
98 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
102 int vtsend_cursor_position_save(vtsend_t
*p
) {
109 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
113 int vtsend_cursor_position_restore(vtsend_t
*p
) {
120 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
124 int vtsend_erase_display(vtsend_t
*p
) {
132 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
136 int vtsend_erase_line(vtsend_t
*p
) {
144 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
148 int vtsend_set_color_foreground(vtsend_t
*p
, const int color
) {
152 buf
[2] = '0' + ((30 + color
) / 10);
153 buf
[3] = '0' + ((30 + color
) % 10);
157 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
161 int vtsend_set_color_background(vtsend_t
*p
, const int color
) {
165 buf
[2] = '0' + ((40 + color
) / 10);
166 buf
[3] = '0' + ((40 + color
) % 10);
170 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
174 int vtsend_set_attribute(vtsend_t
*p
, const int attr
) {
178 buf
[2] = '0' + ((attr
) / 10);
179 buf
[3] = '0' + ((attr
) % 10);
183 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
187 int vtsend_set_scroll_region(vtsend_t
*p
, const int top
, const int bottom
) {
191 buf
[2] = '0' + (top
/ 10);
192 buf
[3] = '0' + (top
% 10);
194 buf
[5] = '0' + (bottom
/ 10);
195 buf
[6] = '0' + (bottom
% 10);
199 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
203 int vtsend_set_cursor(vtsend_t
*p
, const int visible
) {
214 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
225 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
230 int vtsend_reset(vtsend_t
*p
) {
236 UART_WRITE(buf
); // UART_WRITE(p, buf, sizeof(buf));
240 int vtsend_draw_box(vtsend_t
*p
, const int x1
, const int y1
, const int x2
, const int y2
) {
243 vtsend_cursor_position(p
, x1
, y1
);
244 for (i
= x1
; i
<= x2
; i
++) {
247 vtsend_cursor_position(p
, x1
, y2
);
248 for (i
= x1
; i
<= x2
; i
++) {
251 for (i
= y1
; i
<= y2
; i
++) {
252 vtsend_cursor_position(p
, x1
, i
);
254 vtsend_cursor_position(p
, x2
, i
);
260 int vtsend_fill_box(vtsend_t
*p
, const int x1
, const int y1
, const int x2
, const int y2
) {
262 for (i
= y1
; i
<= y2
; i
++) {
263 vtsend_cursor_position(p
, x1
, i
);
264 for (j
= x1
; j
<= x2
; j
++) {