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 int new_bytes = min(MAX_VT100_ESCAPE_LEN - inc_len, Len);
39 memcpy(inc_buf + inc_len, Buf, new_bytes);
41 // Handle VT100 (like) escape sequence
43 _SysDebug("inc_len = %i, new_bytes = %i", inc_len, new_bytes);
46 return 1; // Skip 1 character (the '\x1b')
50 case '[': // Multibyte, funtime starts
51 ret = Term_HandleVT100_Long(inc_len-2, inc_buf+2);
69 Display_MoveCursor(-1, 0);
72 // TODO: tab (get current cursor pos, space until multiple of 8)
78 // TODO: Carriage return
79 Display_MoveCursor(INT_MIN, 0);
96 int Term_HandleVT100_Long(int Len, const char *Buffer)
100 int args[6] = {0,0,0,0,0,0};
101 int bQuestionMark = 0;
104 if(j == Len) return 0;
108 if(j == Len) return 0;
111 if( '0' <= c && c <= '9' )
115 if(j == Len) return 0;
118 while('0' <= c && c <= '9') {
121 if(j == Len) return 0;
131 _SysDebug("Unexpected char 0x%x in VT100 escape code", c);
141 _SysDebug("Unknown VT100 extended escape char 0x%x", c);
152 Display_ClearLine(0);
153 else if( args[0] == 2 )
154 Display_ClearLines(0); // Entire screen!
156 _SysDebug("TODO: VT100 %i J", args[0]);
166 for( i = 0; i < argc; i ++ )
172 else if( 30 <= args[i] && args[i] <= 37 )
175 Display_SetForeground( caVT100Colours[ args[i]-30 ] );
177 else if( 40 <= args[i] && args[i] <= 47 )
180 Display_SetBackground( caVT100Colours[ args[i]-30 ] );
186 _SysDebug("Unknown VT100 escape char 0x%x", c);