2 * Copyright Droids Corporation (2007)
3 * Olivier MATZ <zer0@droids-corp.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * Revision : $Id: vt100.c,v 1.1.2.1 2008-01-05 22:46:28 zer0 Exp $
30 #include <aversive/pgmspace.h>
34 static const prog_char cmd0[] = vt100_up_arr;
35 static const prog_char cmd1[] = vt100_down_arr;
36 static const prog_char cmd2[] = vt100_right_arr;
37 static const prog_char cmd3[] = vt100_left_arr;
38 static const prog_char cmd4[] = "\177";
39 static const prog_char cmd5[] = "\n";
40 static const prog_char cmd6[] = "\001";
41 static const prog_char cmd7[] = "\005";
42 static const prog_char cmd8[] = "\013";
43 static const prog_char cmd9[] = "\031";
44 static const prog_char cmd10[] = "\003";
45 static const prog_char cmd11[] = "\006";
46 static const prog_char cmd12[] = "\002";
47 static const prog_char cmd13[] = vt100_suppr;
48 static const prog_char cmd14[] = vt100_tab;
49 static const prog_char cmd15[] = "\004";
50 static const prog_char cmd16[] = "\014";
51 static const prog_char cmd17[] = "\r";
52 static const prog_char cmd18[] = "\033\177";
53 static const prog_char cmd19[] = vt100_word_left;
54 static const prog_char cmd20[] = vt100_word_right;
55 static const prog_char cmd21[] = "?";
57 const prog_char * vt100_commands[] PROGMEM = {
58 cmd0, cmd1, cmd2, cmd3, cmd4, cmd5, cmd6, cmd7,
59 cmd8, cmd9, cmd10, cmd11, cmd12, cmd13, cmd14,
60 cmd15, cmd16, cmd17, cmd18, cmd19, cmd20,
65 vt100_init(struct vt100 * vt)
67 vt->state = VT100_INIT;
72 match_command(char * buf, uint8_t size)
74 const prog_char * cmd;
77 for (i=0 ; i<sizeof(vt100_commands)/sizeof(const prog_char *) ; i++) {
79 cmd = *(vt100_commands + i);
81 cmd = (const prog_char *) pgm_read_word (vt100_commands + i);
84 if (size == strlen_P(cmd) &&
85 !strncmp_P(buf, cmd, strlen_P(cmd))) {
94 vt100_parser(struct vt100 *vt, char ch)
97 uint8_t c = (uint8_t) ch;
99 if (vt->bufpos > VT100_BUF_SIZE) {
100 vt->state = VT100_INIT;
104 vt->buf[vt->bufpos++] = c;
110 vt->state = VT100_ESCAPE;
120 vt->state = VT100_ESCAPE_CSI;
122 else if (c >= 060 && c <= 0177) { /* XXX 0177 ? */
124 vt->state = VT100_INIT;
129 case VT100_ESCAPE_CSI:
130 if (c >= 0100 && c <= 0176) {
132 vt->state = VT100_INIT;
145 return match_command(vt->buf, size);