3 * - By John Hodge (thePowersGang)
6 * - VT100/xterm Emulation
10 #include "include/vt100.h"
11 #include "include/display.h"
12 #include <ctype.h> // isalpha
13 #include <acess/sys.h> // _SysDebug
15 const uint32_t caVT100Colours[] = {
16 // Black, Red, Green, Yellow, Blue, Purple, Cyan, Gray
17 // Same again, but bright
18 0x000000, 0x770000, 0x007700, 0x777700, 0x000077, 0x770077, 0x007777, 0xAAAAAAA,
19 0xCCCCCC, 0xFF0000, 0x00FF00, 0xFFFF00, 0x0000FF, 0xFF00FF, 0x00FFFF, 0xFFFFFFF
22 int Term_HandleVT100_Long(int Len, const char *Buf);
24 static inline int min(int a, int b)
29 int Term_HandleVT100(int Len, const char *Buf)
31 #define MAX_VT100_ESCAPE_LEN 16
32 static char inc_buf[MAX_VT100_ESCAPE_LEN];
33 static int inc_len = 0;
35 if( inc_len > 0 || *Buf == '\x1b' )
37 // Handle VT100 (like) escape sequence
38 int new_bytes = min(MAX_VT100_ESCAPE_LEN - inc_len, Len);
39 int ret = 0, old_inc_len = inc_len;
40 memcpy(inc_buf + inc_len, Buf, new_bytes);
45 return 1; // Skip 1 character (the '\x1b')
49 case '[': // Multibyte, funtime starts
50 ret = Term_HandleVT100_Long(inc_len-2, inc_buf+2);
62 ret -= old_inc_len; // counter cached bytes
70 Display_MoveCursor(-1, 0);
71 Display_AddText(1, " ");
72 Display_MoveCursor(-1, 0);
73 // TODO: Need to handle \t and ^A-Z
76 // TODO: tab (get current cursor pos, space until multiple of 8)
82 Display_MoveCursor(INT_MIN, 0);
99 int Term_HandleVT100_Long(int Len, const char *Buffer)
103 int args[6] = {0,0,0,0,0,0};
104 int bQuestionMark = 0;
107 if(j == Len) return 0;
111 if(j == Len) return 0;
114 if( '0' <= c && c <= '9' )
118 if(j == Len) return 0;
121 while('0' <= c && c <= '9') {
124 if(j == Len) return 0;
134 _SysDebug("Unexpected char 0x%x in VT100 escape code", c);
144 _SysDebug("Unknown VT100 extended escape char 0x%x", c);
155 Display_ClearLine(0);
156 else if( args[0] == 2 )
157 Display_ClearLines(0); // Entire screen!
159 _SysDebug("TODO: VT100 %i J", args[0]);
169 for( i = 0; i < argc; i ++ )
175 else if( 30 <= args[i] && args[i] <= 37 )
178 Display_SetForeground( caVT100Colours[ args[i]-30 ] );
180 else if( 40 <= args[i] && args[i] <= 47 )
183 Display_SetBackground( caVT100Colours[ args[i]-30 ] );
189 _SysDebug("Unknown VT100 escape char 0x%x", c);