Cursor positioning works!!

This commit is contained in:
y4my4my4m 2023-05-11 19:06:36 +09:00
parent 8afe183e24
commit e27ec865c8

View file

@ -29,17 +29,17 @@ U0 HandleControlCodes(U8 ch) {
break; break;
case 8: // BS (Backspace) case 8: // BS (Backspace)
// "%c%c%c", 8, ' ', 8; // Move cursor back, erase character, move cursor back again // "%c%c%c", 8, ' ', 8; // Move cursor back, erase character, move cursor back again
SysLog("CC Backspace happened\n");
"$$CM,-8,0$$"; "$$CM,-8,0$$";
break; break;
case 9: // HT (Horizontal Tab) case 9: // HT (Horizontal Tab)
" "; // 8 spaces // " "; // 8 spaces
// "$$CM,8,0$$"; "$$CM,8,0$$";
break; break;
case 10: // LF (Line Feed) case 10: // LF (Line Feed)
"\n"; "\n";
break; break;
case 11: // VT (Vertical Tab) case 11: // VT (Vertical Tab)
SysLog("Vertical Tab\n");
break; break;
case 12: // FF (Form Feed) case 12: // FF (Form Feed)
DocClear; DocClear;
@ -50,6 +50,7 @@ U0 HandleControlCodes(U8 ch) {
case 14: // SO (Shift Out) - Switch to an alternate character set case 14: // SO (Shift Out) - Switch to an alternate character set
case 15: // SI (Shift In) - Switch back to the default character set case 15: // SI (Shift In) - Switch back to the default character set
default: default:
SysLog("Other CC happened\n");
break; break;
} }
} }
@ -58,9 +59,15 @@ U0 HandleControlCodes(U8 ch) {
SysLog("case 127"); SysLog("case 127");
} }
if (ch == 0x24) { if (ch == 0x24) {
// ch = "//$$$$"; ch = "//$$$$";
}
if (ch >= 32 && ch < 256) // ZealOS's ASCII is up to 255
{
"%c", ch;
}
else {
"%c", '?'; // unrecognized character
} }
"%c", ch;
} }
} }
@ -254,24 +261,53 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
// Handle specific ANSI escape sequences // Handle specific ANSI escape sequences
switch (*ptr) { switch (*ptr) {
case 'n': case 'n':
SysLog("Case n\n"); SysLog("Case n, %d\n",ansi_code[0]);
if (ansi_code[0] == 5) { if (ansi_code[0] == 5) {
// Respond with terminal readiness // Respond with terminal readiness
SysLog("reported terminal readiness\n"); SysLog("reported terminal readiness\n");
TCPSocketSendString(sock, "\x1B[0n"); U8 deviceStatusResponse[5];
deviceStatusResponse[0] = ANSI_ESC;
deviceStatusResponse[1] = ANSI_CSI;
deviceStatusResponse[2] = 0x30; // '0'
deviceStatusResponse[3] = 0x6E; // 'n'
deviceStatusResponse[4] = 0x00; // Null-terminator
TCPSocketSend(sock, deviceStatusResponse, 4);
// TCPSocketSendString(sock, "\x1B[0n");
} }
else if (ansi_code[0] == 6) { else if (ansi_code[0] == 6) {
// Respond with cursor position // Respond with cursor position
// U8 response[32] = "\x1B[%d;%dR", window_width, window_height; // U8 response[32] = "\x1B[%d;%dR", window_width, window_height;
SysLog("reported cursor position\n"); SysLog("reported cursor position\n");
TCPSocketSendString(sock, "\x1B\[25;80R"); U8 cursorResponse[32];
cursorResponse[0] = ANSI_ESC;
cursorResponse[1] = ANSI_CSI;
cursorResponse[2] = 0x32;
cursorResponse[3] = 0x35;
cursorResponse[4] = 0x3B;
cursorResponse[5] = 0x38;
cursorResponse[6] = 0x30;
cursorResponse[6] = 0x52;
cursorResponse[7] = 0x00;
TCPSocketSend(sock, cursorResponse, 7);
// TCPSocketSendString(sock, "\x1B\[25;80R");
} }
ptr++; ptr++;
break; break;
case 'c': case 'c':
// Respond with device attributes // Respond with device attributes
SysLog("reported device attributes\n"); SysLog("reported device attributes\n");
TCPSocketSendString(sock, "\x1B[?1;0c"); // TCPSocketSendString(sock, "\x1B[?1;0c");
// Reports at VT101 (not sure why though)
U8 deviceAttributesResponse[8];
deviceAttributesResponse[0] = ANSI_ESC;
deviceAttributesResponse[1] = ANSI_CSI;
deviceAttributesResponse[2] = 0x3F; // '?'
deviceAttributesResponse[3] = 0x31; // '1'
deviceAttributesResponse[4] = 0x3B; // ';'
deviceAttributesResponse[5] = 0x32; // '0'
deviceAttributesResponse[6] = 0x63; // 'c'
deviceAttributesResponse[7] = 0x00; // Null-terminator
TCPSocketSend(sock, deviceAttributesResponse, 7);
ptr++; ptr++;
break; break;
case 'm': case 'm':
@ -284,8 +320,8 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
if (ansi_param_count == 0) if (ansi_param_count == 0)
{ {
switch (ansi_code[m]) { switch (ansi_code[m]) {
case 0: "$$BG$$$$FG$$"; break; // reset // case 0: "$$BG$$$$FG$$"; break; // reset
// case 0: "$$BG,TRANSPARENT$$$$WHITE$$"; break; // reset case 0: "$$BG,BLACK$$$$WHITE$$"; break; // reset
// case 1: ""; break; // TODO: bold // case 1: ""; break; // TODO: bold
// case 2: ""; break; // TODO: dim // case 2: ""; break; // TODO: dim
// case 3: ""; break; // TODO: italic // case 3: ""; break; // TODO: italic
@ -309,7 +345,7 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
// SysLog("ansi_code[%d] = %d\n", m, ansi_code[m]); // SysLog("ansi_code[%d] = %d\n", m, ansi_code[m]);
if(!isBright){ if(!isBright){
switch (ansi_code[m]) { switch (ansi_code[m]) {
case 30: "$$BLACK$$"; break; case 30: "$$DKGRAY$$"; break;
case 31: "$$RED$$"; break; case 31: "$$RED$$"; break;
case 32: "$$GREEN$$"; break; case 32: "$$GREEN$$"; break;
case 33: "$$YELLOW$$"; break; case 33: "$$YELLOW$$"; break;
@ -402,15 +438,15 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
case 'B': case 'B':
// Cursor Down // Cursor Down
SysLog("Cursor Down\n"); SysLog("Cursor Down\n");
// "$$CM+TY,0,+%d$$", ansi_code[0];
"$$CM,0,%d$$", ansi_code[0]; "$$CM,0,%d$$", ansi_code[0];
ptr++; ptr++;
break; break;
case 'C': case 'C':
// Cursor Right // Cursor Right
SysLog("Cursor Right %d %d\n", ansi_param_count, ansi_code[0]); // SysLog("Cursor Right %d %d\n", ansi_param_count, ansi_code[0]);
// "$$CM+LX,+%d,0$$", ansi_code[0];
// "$$CM,%d,0$$", ansi_code[0]; // "$$CM,%d,0$$", ansi_code[0];
// if we just move the cursor,
// you dont get the colored background since we skip over it directly
I64 C; I64 C;
for (C = 0; C < ansi_code[0]; C++) { for (C = 0; C < ansi_code[0]; C++) {
" "; " ";
@ -419,8 +455,7 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
break; break;
case 'D': case 'D':
// Cursor Left // Cursor Left
// SysLog("Cursor Left\n"); SysLog("Cursor Left\n");
// "$$CM+TY,-%d,0$$", ansi_code[0];
"$$CM,-%d,0$$", ansi_code[0]; "$$CM,-%d,0$$", ansi_code[0];
ptr++; ptr++;
break; break;
@ -428,20 +463,20 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
// Cursor Next Line // Cursor Next Line
SysLog("Cursor Next Line\n"); SysLog("Cursor Next Line\n");
// "$$CM+TY,0,+%d$$", ansi_code[0]; // "$$CM+TY,0,+%d$$", ansi_code[0];
// "\n"; "\n";
ptr++; ptr++;
break; break;
case 'F': case 'F':
// Cursor Previous Line // Cursor Previous Line
SysLog("Cursor Previous Line\n"); SysLog("Cursor Previous Line\n");
// "$$CM+LY,0,-%d$$", ansi_code[0]; "$$CM+LY,0,-%d$$", ansi_code[0];
// "\n"; // "\n";
ptr++; ptr++;
break; break;
case 'G': case 'G':
// Cursor Horizontal Absolute // Cursor Horizontal Absolute
SysLog("Cursor Horizontal Absolute\n"); SysLog("Cursor Horizontal Absolute\n");
// "$$CM,%d,0$$", ansi_code[0]; "$$CM,%d,0$$", ansi_code[0];
// "\n"; // "\n";
ptr++; ptr++;
break; break;
@ -462,16 +497,14 @@ U0 Telnet(U8 *host, U16 port=TELNET_PORT) {
SysLog("H or f AFTER row:%d, col:%d, cnt:%d\n", row, col, ansi_param_count); SysLog("H or f AFTER row:%d, col:%d, cnt:%d\n", row, col, ansi_param_count);
if (row > window_height) if (row > window_height)
row = window_height-2; row = window_height-1;
if (col > window_width) if (col > window_width)
col = window_width; col = window_width;
"$$CM+LX+TY,LE=%d,RE=%d$$", col-1, row-1;
"$$CM,%d,%d$$", row, col;
// "$$CM,LE=%d,RE=%d$$", row, col;
ptr++; ptr++;
break; break;
case 'J': case 'J':
// SysLog("J code, %d %d\n", ansi_param_count, ansi_code[0]); SysLog("J code, %d %d\n", ansi_param_count, ansi_code[0]);
// Erase in Display // Erase in Display
if (ansi_code[0] == 0) { if (ansi_code[0] == 0) {
// Erase from cursor to end of display // Erase from cursor to end of display