From 5c0764e5b9dce3ef93da43a245e7c8783866731f Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Mon, 14 May 2018 09:20:05 -0400 Subject: [PATCH] flags to initialize vt100 parameters. --- darlene.c | 16 ++++++++-------- marlene.c | 17 ++++++++--------- telnet.c | 10 +++++++--- vt100.c | 38 +++++++++++++++++++++++++++----------- vt100.gsh | 11 +++++++++++ vt100.h | 20 ++++++++++++++++++++ 6 files changed, 81 insertions(+), 31 deletions(-) create mode 100644 vt100.gsh create mode 100644 vt100.h diff --git a/darlene.c b/darlene.c index 098a5ab..b4c1c1d 100644 --- a/darlene.c +++ b/darlene.c @@ -25,9 +25,7 @@ #include #include -extern void vt100_init(void); -extern void vt100_process(const unsigned char *buffer, unsigned buffer_size); -extern void vt100_event(EventRecord *event); +#include "vt100.h" extern void screen_init(void); extern void screen_on(void); @@ -182,7 +180,7 @@ int main(int argc, char **argv) { int pid; unsigned i; Word MyID; - + unsigned vt100_flags = vtDEFAULT; Handle dpHandle = NULL; Handle shrHandle = NULL; Handle shdHandle = NULL; @@ -199,12 +197,14 @@ int main(int argc, char **argv) { for (i = 1; i < argc; ++i) { char *cp = argv[i]; if (cp[0] != '-') break; - if (strcmp(cp, "--vt52") == 0) { + if (strcmp(cp, "--") == 0) { + break; + } else if (strcmp(cp, "--vt52") == 0) { term_var.value = "\x04\x00vt52"; + vt100_flags &= ~vtDECANM; } else if (strcmp(cp, "--vt100") == 0) { term_var.value = "\x05\x00vt100"; - } else if (strcmp(cp,"--") == 0) { - break; + vt100_flags |= vtDECANM; } else { ErrWriteCString("Unknown option: "); ErrWriteCString(cp); @@ -251,7 +251,7 @@ int main(int argc, char **argv) { screen_init(); - vt100_init(); + vt100_init(vt100_flags); signal(SIGCHLD,sigchild); pid = forkpty2(&master, NULL, NULL, NULL); diff --git a/marlene.c b/marlene.c index df25a79..31f9abe 100644 --- a/marlene.c +++ b/marlene.c @@ -22,7 +22,7 @@ #include "telnet.h" #include "marinetti.h" - +#include "vt100.h" void display_pstr(const char *); void display_cstr(const char *); @@ -31,9 +31,6 @@ void display_err(Word); extern void telnet_init(void); extern void telnet_process(void); -extern void vt100_init(void); -extern void vt100_process(const unsigned char *buffer, unsigned buffer_size); -extern void vt100_event(EventRecord *event); extern void screen_init(void); extern void screen_on(void); @@ -113,7 +110,7 @@ int main(int argc, char **argv) { int mf = 0; Word MyID; Word __gno; - + unsigned vt100_flags = vtDEFAULT; __gno = false; ipid = -1; @@ -131,10 +128,12 @@ int main(int argc, char **argv) { for (i = 1; i < argc; ++i) { char *cp = argv[i]; if (cp[0] != '-') break; - if (strcmp(cp, "--vt52") == 0) { - + if (strcmp(cp, "--") == 0) { + break; + } else if (strcmp(cp, "--vt52") == 0) { + vt100_flags &= ~vtDECANM; } else if (strcmp(cp, "--vt100") == 0) { - + vt100_flags |= vtDECANM; } else { ErrWriteCString("Unknown option: "); ErrWriteCString(cp); @@ -177,7 +176,7 @@ int main(int argc, char **argv) { screen_init(); - vt100_init(); + vt100_init(vt100_flags); mf = StartUpTCP(printCallBack); if (mf < 0) { diff --git a/telnet.c b/telnet.c index 5cd9249..4fa8a68 100644 --- a/telnet.c +++ b/telnet.c @@ -108,12 +108,16 @@ void telnet_process(void) { IAC, SE }; - static unsigned char telopt_ttype[] = { + static unsigned char telopt_ttype_vt100[] = { IAC, SB, TELOPT_TTYPE, TELQUAL_IS, 'V', 'T', '1', '0', '0', IAC, SE }; - + static unsigned char telopt_ttype_vt52[] = { + IAC, SB, TELOPT_TTYPE, TELQUAL_IS, + 'V', 'T', '5', '2', + IAC, SE + }; /* don't need to process if no state, no IACs in buffer */ @@ -186,7 +190,7 @@ void telnet_process(void) { send(telopt_tspeed, sizeof(telopt_tspeed)); break; case TELOPT_TTYPE: - send(telopt_ttype, sizeof(telopt_ttype)); + send(telopt_ttype_vt100, sizeof(telopt_ttype_vt100)); break; default: diff --git a/vt100.c b/vt100.c index 4ae9243..52eb52b 100644 --- a/vt100.c +++ b/vt100.c @@ -2,11 +2,12 @@ * This handles vt100 commands. * */ -#pragma noroot #include #include +#include "vt100.h" + #define ESC "\x1b" #define send_str(x) send((const unsigned char *)x, sizeof(x)-1) @@ -63,8 +64,11 @@ static unsigned parm_count; static unsigned private; static unsigned state; -void vt100_init(void) +static unsigned initial_state = vtDEFAULT; + +void vt100_init(unsigned flags) { + __x = 0; __y = 0; saved_cursor[0] = 0; @@ -74,14 +78,26 @@ void vt100_init(void) and_mask = 0xffff; xor_mask = 0x0000; - DECANM = 1; - DECAWM = 1; - DECCKM = 0; - DECKPAM = 0; - DECCOLM = 80; - DECOM = 0; - DECSCNM = 0; - LNM = 0; + initial_state = flags; + if (flags == -1) { + DECANM = 1; + DECAWM = 1; + DECCKM = 0; + DECKPAM = 0; + DECCOLM = 80; + DECOM = 0; + DECSCNM = 0; + LNM = 0; + } else { + DECANM = flags & vtDECANM; + DECAWM = flags & vtDECAWM; + DECCKM = flags & vtDECCKM; + DECKPAM = flags & vtDECKPAM; + DECCOLM = flags & vtDECCOLM ? 132 : 80; + DECOM = flags & vtDECOM; + DECSCNM = flags & vtDECSCNM; + LNM = flags & vtLNM; + } tabs[0] = 0x8080; tabs[1] = 0x8080; @@ -521,7 +537,7 @@ void vt100_process(const unsigned char *buffer, unsigned buffer_size) { case '8': restore_cursor(); break; case '=': DECKPAM = 1; break; case '>': DECKPAM = 0; break; - case 'c': vt100_init(); ClearScreen(); break; + case 'c': vt100_init(initial_state); ClearScreen(); break; case '1': case '2': /* vt105 graphic stuff */ break; default: break; diff --git a/vt100.gsh b/vt100.gsh new file mode 100644 index 0000000..e812368 --- /dev/null +++ b/vt100.gsh @@ -0,0 +1,11 @@ +# +# +# some settings so gsh works better with vt100. +# source vt100.gsh +# +set term=vt100 +bindkey backward-delete-char "^H" +bindkey up-history "^[[A" +bindkey down-history "^[[B" +bindkey forward-char "^[[C" +bindkey backward-char "^[[D" diff --git a/vt100.h b/vt100.h new file mode 100644 index 0000000..06412f1 --- /dev/null +++ b/vt100.h @@ -0,0 +1,20 @@ +#ifndef vt100_h +#define vt100_h + +enum { + vtDECCKM = 1 << 1, /* Cursor key */ + vtDECANM = 1 << 2, /* ANSI/VT52 */ + vtDECCOLM = 1 << 3, /* Column */ + vtDECSCNM = 1 << 4, /* Screen */ + vtDECOM = 1 << 6, /* Origin */ + vtDECAWM = 1 << 7, /* Auto wrap */ + vtDECKPAM = 1 << 8, /* Keypad Application Mode */ + vtLNM = 1 << 9, /* Line Feed/New Line Mode */ + vtDEFAULT = vtDECANM | vtDECAWM, +}; + +void vt100_init(unsigned flags); +extern void vt100_process(const unsigned char *buffer, unsigned buffer_size); +extern void vt100_event(struct EventRecord *event); + +#endif \ No newline at end of file