MIFARE Plus 4b UID: fix signature check
[RRG-proxmark3.git] / armsrc / vtsend.c
blob725df35d689281f5cd682e6b45adb116f9919e17
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.
5 //
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 //-----------------------------------------------------------------------------
21 #include "vtsend.h"
22 #include "pm3_cmd.h"
23 #include "dbprint.h"
25 #define ESC (0x1B)
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;
31 p->extobj = extobj;
32 return 0;
35 int vtsend_cursor_position(vtsend_t *p, const int column, const int line) {
36 char buf[1 + 8];
37 buf[0] = ESC;
38 buf[1] = '[';
39 buf[2] = '0' + (line / 10);
40 buf[3] = '0' + (line % 10);
41 buf[4] = ';';
42 buf[5] = '0' + (column / 10);
43 buf[6] = '0' + (column % 10);
44 buf[7] = 'H';
45 buf[8] = '\0';
46 UART_WRITE(buf); // UART_WRITE(p, buf, sizeof(buf));
47 return 0;
50 int vtsend_cursor_up(vtsend_t *p, const int n) {
51 char buf[1 + 5];
52 buf[0] = ESC;
53 buf[1] = '[';
54 buf[2] = '0' + (n / 10);
55 buf[3] = '0' + (n % 10);
56 buf[4] = 'A';
57 buf[5] = '\0';
59 UART_WRITE(buf); // UART_WRITE(p, buf, sizeof(buf));
60 return 0;
63 int vtsend_cursor_down(vtsend_t *p, const int n) {
64 char buf[1 + 5];
65 buf[0] = ESC;
66 buf[1] = '[';
67 buf[2] = '0' + (n / 10);
68 buf[3] = '0' + (n % 10);
69 buf[4] = 'B';
70 buf[5] = '\0';
72 UART_WRITE(buf); // UART_WRITE(p, buf, sizeof(buf));
73 return 0;
76 int vtsend_cursor_forward(vtsend_t *p, const int n) {
77 char buf[1 + 5];
78 buf[0] = ESC;
79 buf[1] = '[';
80 buf[2] = '0' + (n / 10);
81 buf[3] = '0' + (n % 10);
82 buf[4] = 'C';
83 buf[5] = '\0';
85 UART_WRITE(buf); // UART_WRITE(p, buf, sizeof(buf));
86 return 0;
89 int vtsend_cursor_backward(vtsend_t *p, const int n) {
90 char buf[1 + 5];
91 buf[0] = ESC;
92 buf[1] = '[';
93 buf[2] = '0' + (n / 10);
94 buf[3] = '0' + (n % 10);
95 buf[4] = 'D';
96 buf[5] = '\0';
98 UART_WRITE(buf); // UART_WRITE(p, buf, sizeof(buf));
99 return 0;
102 int vtsend_cursor_position_save(vtsend_t *p) {
103 char buf[1 + 3];
104 buf[0] = ESC;
105 buf[1] = '[';
106 buf[2] = 's';
107 buf[3] = '\0';
109 UART_WRITE(buf); // UART_WRITE(p, buf, sizeof(buf));
110 return 0;
113 int vtsend_cursor_position_restore(vtsend_t *p) {
114 char buf[1 + 3];
115 buf[0] = ESC;
116 buf[1] = '[';
117 buf[2] = 'u';
118 buf[3] = '\0';
120 UART_WRITE(buf); // UART_WRITE(p, buf, sizeof(buf));
121 return 0;
124 int vtsend_erase_display(vtsend_t *p) {
125 char buf[1 + 4];
126 buf[0] = ESC;
127 buf[1] = '[';
128 buf[2] = '2';
129 buf[3] = 'J';
130 buf[4] = '\0';
132 UART_WRITE(buf); // UART_WRITE(p, buf, sizeof(buf));
133 return 0;
136 int vtsend_erase_line(vtsend_t *p) {
137 char buf[1 + 4];
138 buf[0] = ESC;
139 buf[1] = '[';
140 buf[2] = '2';
141 buf[3] = 'K';
142 buf[4] = '\0';
144 UART_WRITE(buf); // UART_WRITE(p, buf, sizeof(buf));
145 return 0;
148 int vtsend_set_color_foreground(vtsend_t *p, const int color) {
149 char buf[1 + 5];
150 buf[0] = ESC;
151 buf[1] = '[';
152 buf[2] = '0' + ((30 + color) / 10);
153 buf[3] = '0' + ((30 + color) % 10);
154 buf[4] = 'm';
155 buf[5] = '\0';
157 UART_WRITE(buf); // UART_WRITE(p, buf, sizeof(buf));
158 return 0;
161 int vtsend_set_color_background(vtsend_t *p, const int color) {
162 char buf[1 + 5];
163 buf[0] = ESC;
164 buf[1] = '[';
165 buf[2] = '0' + ((40 + color) / 10);
166 buf[3] = '0' + ((40 + color) % 10);
167 buf[4] = 'm';
168 buf[5] = '\0';
170 UART_WRITE(buf); // UART_WRITE(p, buf, sizeof(buf));
171 return 0;
174 int vtsend_set_attribute(vtsend_t *p, const int attr) {
175 char buf[1 + 5];
176 buf[0] = ESC;
177 buf[1] = '[';
178 buf[2] = '0' + ((attr) / 10);
179 buf[3] = '0' + ((attr) % 10);
180 buf[4] = 'm';
181 buf[5] = '\0';
183 UART_WRITE(buf); // UART_WRITE(p, buf, sizeof(buf));
184 return 0;
187 int vtsend_set_scroll_region(vtsend_t *p, const int top, const int bottom) {
188 char buf[1 + 8];
189 buf[0] = ESC;
190 buf[1] = '[';
191 buf[2] = '0' + (top / 10);
192 buf[3] = '0' + (top % 10);
193 buf[4] = ';';
194 buf[5] = '0' + (bottom / 10);
195 buf[6] = '0' + (bottom % 10);
196 buf[7] = 'r';
197 buf[8] = '\0';
199 UART_WRITE(buf); // UART_WRITE(p, buf, sizeof(buf));
200 return 0;
203 int vtsend_set_cursor(vtsend_t *p, const int visible) {
204 if (visible) {
205 char buf[1 + 6];
206 buf[0] = ESC;
207 buf[1] = '[';
208 buf[2] = '?';
209 buf[3] = '2';
210 buf[4] = '5';
211 buf[5] = 'h';
212 buf[6] = '\0';
214 UART_WRITE(buf); // UART_WRITE(p, buf, sizeof(buf));
215 } else {
216 char buf[1 + 6];
217 buf[0] = ESC;
218 buf[1] = '[';
219 buf[2] = '?';
220 buf[3] = '2';
221 buf[4] = '5';
222 buf[5] = 'l';
223 buf[6] = '\0';
225 UART_WRITE(buf); // UART_WRITE(p, buf, sizeof(buf));
227 return 0;
230 int vtsend_reset(vtsend_t *p) {
231 char buf[1 + 2];
232 buf[0] = ESC;
233 buf[1] = 'c';
234 buf[2] = '\0';
236 UART_WRITE(buf); // UART_WRITE(p, buf, sizeof(buf));
237 return 0;
240 int vtsend_draw_box(vtsend_t *p, const int x1, const int y1, const int x2, const int y2) {
241 int i;
243 vtsend_cursor_position(p, x1, y1);
244 for (i = x1; i <= x2; i++) {
245 UART_WRITE("-");
247 vtsend_cursor_position(p, x1, y2);
248 for (i = x1; i <= x2; i++) {
249 UART_WRITE("-");
251 for (i = y1; i <= y2; i++) {
252 vtsend_cursor_position(p, x1, i);
253 UART_WRITE("|");
254 vtsend_cursor_position(p, x2, i);
255 UART_WRITE("|");
257 return 0;
260 int vtsend_fill_box(vtsend_t *p, const int x1, const int y1, const int x2, const int y2) {
261 int i, j;
262 for (i = y1; i <= y2; i++) {
263 vtsend_cursor_position(p, x1, i);
264 for (j = x1; j <= x2; j++) {
265 UART_WRITE(" ");
268 return 0;