forked from audetto/AppleWin
/
Debugger_Console.h
343 lines (295 loc) · 9.47 KB
/
Debugger_Console.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#ifndef DEBUGGER_CONSOLE_H
#define DEBUGGER_CONSOLE_H
#include <cstdarg>
enum
{
// Basic Symbol table has > 600 symbols
// Lines, was 128, but need ~ 256+16 for PROFILE LIST
// Output
CONSOLE_HEIGHT = 768,
CONSOLE_WIDTH = 80,
// need min 256+ lines for "profile list"
CONSOLE_BUFFER_HEIGHT = CONSOLE_HEIGHT,
// Input
HISTORY_HEIGHT = 128,
HISTORY_WIDTH = 128,
CONSOLE_FIRST_LINE = 1, // where ConsoleDisplay is pushed up from
};
// Color ____________________________________________________________________
// typedef unsigned char conchar_t;
typedef short conchar_t;
// NOTE: Keep in sync ConsoleColors_e g_anConsoleColor !
enum ConsoleColors_e
{
CONSOLE_COLOR_K, // 0
CONSOLE_COLOR_x = 0, // default console foreground
CONSOLE_COLOR_R, // 1 Red
CONSOLE_COLOR_G, // 2 Green
CONSOLE_COLOR_Y, // 3 Yellow
CONSOLE_COLOR_B, // 4 Blue
CONSOLE_COLOR_M, // 5 Magenta/Purple
CONSOLE_COLOR_C, // 6 Cyan
CONSOLE_COLOR_W, // 7 White
CONSOLE_COLOR_O, // 8 Orange
CONSOLE_COLOR_k, // 9 Grey
CONSOLE_COLOR_b, // : Light Blue
NUM_CONSOLE_COLORS
};
extern COLORREF g_anConsoleColor[ NUM_CONSOLE_COLORS ];
// Note: THe ` ~ key should always display ~ to prevent rendering errors
#define CONSOLE_COLOR_ESCAPE_CHAR '`'
#define _CONSOLE_COLOR_MASK 0x7F
/* Help Colors
*/
#if 1 // USE_APPLE_FONT
// TODO: char *g_aColorTextStrings[] = ""
// TODO: replace with CT_STRINGS[0]
// TODO: CT_COMMA
// TODO: CT_COLON
// TODO: CT_PAREN_L
// TODO: CT_PAREN_R
// Console Help Color
#define CHC_DEFAULT "`0"
#define CHC_USAGE "`3"
#define CHC_CATEGORY "`6"
#define CHC_COMMAND "`2" // Green
#define CHC_KEY "`1" // Red
#define CHC_ARG_MAND "`7" // < >
#define CHC_ARG_OPT "`4" // [ ]
#define CHC_ARG_SEP "`9" // | grey
#define CHC_NUM_DEC "`:" // Lite Blue looks better then yellow (_SearchMemoryDisplay), S D000:FFFF A9 00, PROFILE, HELP BP
#define CHC_NUM_HEX "`3"
#define CHC_SYMBOL "`2" // Symbols
#define CHC_ADDRESS "`8" // Hex Address
#define CHC_ERROR "`1" // Red
#define CHC_WARNING "`8" // Orange
#define CHC_INFO "`3" // Yellow
#define CHC_STRING "`6" //
#define CHC_EXAMPLE "`:"
#define CHC_PATH "`:" // Light Blue
#else
#define CHC_DEFAULT ""
#define CHC_USAGE ""
#define CHC_COMMAND ""
#define CHC_KEY ""
#define CHC_ARG_MAND ""
#define CHC_ARG_OPT ""
#define CHC_ARG_SEP ""
#define CHC_NUMBER ""
#define CHC_SYMBOL ""
#define CHC_ADDRESS ""
#define CHC_ERROR ""
#define CHC_STRING ""
#define CHC_EXAMPLE ""
#endif
// ascii markup
inline bool ConsoleColor_IsCharMeta( unsigned char c )
{
if (CONSOLE_COLOR_ESCAPE_CHAR == c)
return true;
return false;
}
inline bool ConsoleColor_IsCharColor( unsigned char c )
{
if ((c >= '0') && ((c - '0') < NUM_CONSOLE_COLORS))
return true;
return false;
}
// Console "Native" Chars
//
// There are a few different ways of encoding color chars & mouse text
// Simplist method is to use a user-defined ESCAPE char to shift
// into color mode, or mouse text mode. The other solution
// is to use a wide-char, simulating unicode16.
//
// C1C0 char16 of High Byte (c1) and Low Byte (c0)
// 1) --?? Con: Colors chars take up extra chars.
// Con: String Length is complicated.
// Pro: simple to parse
//
// <-- WE USE THIS
// 2) ccea Pro: Efficient packing of plain text and mouse text
// Pro: Color is optional (only record new color)
// Con: need to provide char8 and char16 API
// Con: little more difficult to parse/convert plain text
// i.e.
// ea = 0x20 - 0x7F ASCII
// 0x80 - 0xFF Mouse Text '@'-'Z' -> 0x00 - 0x1F
// cc = ASCII '0' - '9' (color)
// 3) ??cc Con: Colors chars take up extra chars
// 4) f?? Con: Colors chars take up extra chars
//
// Legend:
// f Flag
// -- Not Applicable (n/a)
// ?? ASCII (0x20 - 0x7F)
// ea Extended ASCII with High-Bit representing Mouse Text
// cc Encoded Color / Mouse Text
//
inline bool ConsoleColor_IsColorOrMouse( conchar_t g )
{
if (g > _CONSOLE_COLOR_MASK)
return true;
return false;
}
inline bool ConsoleColor_IsColor( conchar_t g )
{
return ConsoleColor_IsCharColor (g >> 8);
}
inline COLORREF ConsoleColor_GetColor( conchar_t g )
{
const int iColor = (g >> 8) - '0';
if (iColor < NUM_CONSOLE_COLORS)
return g_anConsoleColor[ iColor ];
return g_anConsoleColor[ 0 ];
}
inline char ConsoleColor_GetMeta( conchar_t g )
{
return ((g >> 8) & _CONSOLE_COLOR_MASK);
}
inline char ConsoleChar_GetChar( conchar_t g )
{
return (g & _CONSOLE_COLOR_MASK);
}
inline char ConsoleColor_MakeMouse( unsigned char c )
{
return ((c - '@') + (_CONSOLE_COLOR_MASK + 1));
}
inline conchar_t ConsoleColor_MakeMeta( unsigned char c )
{
conchar_t g = (ConsoleColor_MakeMouse(c) << 8);
return g;
}
inline conchar_t ConsoleColor_MakeColor( unsigned char color, unsigned char text )
{
conchar_t g = (color << 8) | text;
return g;
}
// Return the string length without the markup
inline int ConsoleColor_StringLength( const char *pText )
{
const char *pSrc = pText;
/* */ int nLen = 0;
if( pText )
{
while( *pSrc )
{
if( ConsoleColor_IsCharMeta( *pSrc ) )
pSrc++;
else
nLen++;
pSrc++;
}
}
return nLen;
}
// Globals __________________________________________________________________
// Buffer
extern bool g_bConsoleBufferPaused;
extern int g_nConsoleBuffer;
extern conchar_t g_aConsoleBuffer[ CONSOLE_BUFFER_HEIGHT ][ CONSOLE_WIDTH ]; // TODO: std::vector< line_t >
// Cursor
extern char g_sConsoleCursor[];
// Display
extern char g_aConsolePrompt[];// = TEXT(">!"); // input, assembler // NUM_PROMPTS
extern char g_sConsolePrompt[];// = TEXT(">"); // No, NOT Integer Basic! The nostalgic '*' "Monitor" doesn't look as good, IMHO. :-(
extern int g_nConsolePromptLen;
extern bool g_bConsoleFullWidth;// = false;
extern int g_iConsoleDisplayStart ; // to allow scrolling
extern int g_nConsoleDisplayTotal ; // number of lines added to console
extern int g_nConsoleDisplayLines ;
extern int g_nConsoleDisplayWidth ;
extern conchar_t g_aConsoleDisplay[ CONSOLE_HEIGHT ][ CONSOLE_WIDTH ];
// Input History
extern int g_nHistoryLinesStart;// = 0;
extern int g_nHistoryLinesTotal;// = 0; // number of commands entered
extern char g_aHistoryLines[ HISTORY_HEIGHT ][ HISTORY_WIDTH ];// = {TEXT("")};
// Input Line
// Raw input Line (has prompt)
extern char g_aConsoleInput[ CONSOLE_WIDTH ];
// Cooked input line (no prompt)
extern int g_nConsoleInputChars ;
extern char * g_pConsoleInput ; // points to past prompt
extern const char * g_pConsoleFirstArg ; // points to first arg
extern bool g_bConsoleInputQuoted ;
extern char g_nConsoleInputSkip ;
// Prototypes _______________________________________________________________
// Console
// Buffered
bool ConsolePrint( const char * pText );
bool ConsolePrintVa( char* buf, size_t bufsz, const char* pFormat, va_list va );
template<size_t _BufSz>
inline bool ConsolePrintVa( char (&buf)[_BufSz], const char* pFormat, va_list va )
{
return ConsolePrintVa(buf, _BufSz, pFormat, va);
}
inline bool ConsolePrintFormat( char* buf, size_t bufsz, const char* pFormat, ... )
{
va_list va;
va_start(va, pFormat);
bool const r = ConsolePrintVa(buf, bufsz, pFormat, va);
va_end(va);
return r;
}
template<size_t _BufSz>
inline bool ConsolePrintFormat( char(&buf)[_BufSz], const char* pFormat, ... )
{
va_list va;
va_start(va, pFormat);
bool const r = ConsolePrintVa(buf, pFormat, va);
va_end(va);
return r;
}
void ConsoleBufferToDisplay ();
const conchar_t* ConsoleBufferPeek ();
void ConsoleBufferPop ();
bool ConsoleBufferPush( const char * pString );
bool ConsoleBufferPushVa( char* buf, size_t bufsz, const char* pFormat, va_list va );
template<size_t _BufSz>
inline bool ConsoleBufferPushVa( char (&buf)[_BufSz], const char* pFormat, va_list va )
{
return ConsoleBufferPushVa(buf, _BufSz, pFormat, va);
}
inline bool ConsoleBufferPushFormat( char* buf, size_t bufsz, const char* pFormat, ... )
{
va_list va;
va_start(va, pFormat);
bool const r = ConsoleBufferPushVa(buf, bufsz, pFormat, va);
va_end(va);
return r;
}
template<size_t _BufSz>
inline bool ConsoleBufferPushFormat( char(&buf)[_BufSz], const char* pFormat, ... )
{
va_list va;
va_start(va, pFormat);
bool const r = ConsoleBufferPushVa(buf, pFormat, va);
va_end(va);
return r;
}
void ConsoleConvertFromText( conchar_t * sText, const char * pText );
// Display
Update_t ConsoleDisplayError ( const char * pTextError );
void ConsoleDisplayPause ();
void ConsoleDisplayPush ( const char * pText );
void ConsoleDisplayPush ( const conchar_t * pText );
Update_t ConsoleUpdate ();
void ConsoleFlush ();
// Input
void ConsoleInputToDisplay ();
const char *ConsoleInputPeek ();
bool ConsoleInputClear ();
bool ConsoleInputBackSpace ();
bool ConsoleInputChar ( TCHAR ch );
void ConsoleInputReset ();
int ConsoleInputTabCompletion ();
void ConsoleUpdateCursor( char ch );
Update_t ConsoleBufferTryUnpause (int nLines);
// Scrolling
Update_t ConsoleScrollHome ();
Update_t ConsoleScrollEnd ();
Update_t ConsoleScrollUp ( int nLines );
Update_t ConsoleScrollDn ( int nLines );
Update_t ConsoleScrollPageUp ();
Update_t ConsoleScrollPageDn ();
#endif