flags to initialize vt100 parameters.

This commit is contained in:
Kelvin Sherlock 2018-05-14 09:20:05 -04:00
parent 58e63dc252
commit 5c0764e5b9
6 changed files with 81 additions and 31 deletions

View File

@ -25,9 +25,7 @@
#include <gno/gno.h> #include <gno/gno.h>
#include <gno/kerntool.h> #include <gno/kerntool.h>
extern void vt100_init(void); #include "vt100.h"
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_init(void);
extern void screen_on(void); extern void screen_on(void);
@ -182,7 +180,7 @@ int main(int argc, char **argv) {
int pid; int pid;
unsigned i; unsigned i;
Word MyID; Word MyID;
unsigned vt100_flags = vtDEFAULT;
Handle dpHandle = NULL; Handle dpHandle = NULL;
Handle shrHandle = NULL; Handle shrHandle = NULL;
Handle shdHandle = NULL; Handle shdHandle = NULL;
@ -199,12 +197,14 @@ int main(int argc, char **argv) {
for (i = 1; i < argc; ++i) { for (i = 1; i < argc; ++i) {
char *cp = argv[i]; char *cp = argv[i];
if (cp[0] != '-') break; 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"; term_var.value = "\x04\x00vt52";
vt100_flags &= ~vtDECANM;
} else if (strcmp(cp, "--vt100") == 0) { } else if (strcmp(cp, "--vt100") == 0) {
term_var.value = "\x05\x00vt100"; term_var.value = "\x05\x00vt100";
} else if (strcmp(cp,"--") == 0) { vt100_flags |= vtDECANM;
break;
} else { } else {
ErrWriteCString("Unknown option: "); ErrWriteCString("Unknown option: ");
ErrWriteCString(cp); ErrWriteCString(cp);
@ -251,7 +251,7 @@ int main(int argc, char **argv) {
screen_init(); screen_init();
vt100_init(); vt100_init(vt100_flags);
signal(SIGCHLD,sigchild); signal(SIGCHLD,sigchild);
pid = forkpty2(&master, NULL, NULL, NULL); pid = forkpty2(&master, NULL, NULL, NULL);

View File

@ -22,7 +22,7 @@
#include "telnet.h" #include "telnet.h"
#include "marinetti.h" #include "marinetti.h"
#include "vt100.h"
void display_pstr(const char *); void display_pstr(const char *);
void display_cstr(const char *); void display_cstr(const char *);
@ -31,9 +31,6 @@ void display_err(Word);
extern void telnet_init(void); extern void telnet_init(void);
extern void telnet_process(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_init(void);
extern void screen_on(void); extern void screen_on(void);
@ -113,7 +110,7 @@ int main(int argc, char **argv) {
int mf = 0; int mf = 0;
Word MyID; Word MyID;
Word __gno; Word __gno;
unsigned vt100_flags = vtDEFAULT;
__gno = false; __gno = false;
ipid = -1; ipid = -1;
@ -131,10 +128,12 @@ int main(int argc, char **argv) {
for (i = 1; i < argc; ++i) { for (i = 1; i < argc; ++i) {
char *cp = argv[i]; char *cp = argv[i];
if (cp[0] != '-') break; 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) { } else if (strcmp(cp, "--vt100") == 0) {
vt100_flags |= vtDECANM;
} else { } else {
ErrWriteCString("Unknown option: "); ErrWriteCString("Unknown option: ");
ErrWriteCString(cp); ErrWriteCString(cp);
@ -177,7 +176,7 @@ int main(int argc, char **argv) {
screen_init(); screen_init();
vt100_init(); vt100_init(vt100_flags);
mf = StartUpTCP(printCallBack); mf = StartUpTCP(printCallBack);
if (mf < 0) { if (mf < 0) {

View File

@ -108,12 +108,16 @@ void telnet_process(void) {
IAC, SE IAC, SE
}; };
static unsigned char telopt_ttype[] = { static unsigned char telopt_ttype_vt100[] = {
IAC, SB, TELOPT_TTYPE, TELQUAL_IS, IAC, SB, TELOPT_TTYPE, TELQUAL_IS,
'V', 'T', '1', '0', '0', 'V', 'T', '1', '0', '0',
IAC, SE 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 */ /* 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)); send(telopt_tspeed, sizeof(telopt_tspeed));
break; break;
case TELOPT_TTYPE: case TELOPT_TTYPE:
send(telopt_ttype, sizeof(telopt_ttype)); send(telopt_ttype_vt100, sizeof(telopt_ttype_vt100));
break; break;
default: default:

38
vt100.c
View File

@ -2,11 +2,12 @@
* This handles vt100 commands. * This handles vt100 commands.
* *
*/ */
#pragma noroot
#include <Event.h> #include <Event.h>
#include <ctype.h> #include <ctype.h>
#include "vt100.h"
#define ESC "\x1b" #define ESC "\x1b"
#define send_str(x) send((const unsigned char *)x, sizeof(x)-1) #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 private;
static unsigned state; static unsigned state;
void vt100_init(void) static unsigned initial_state = vtDEFAULT;
void vt100_init(unsigned flags)
{ {
__x = 0; __x = 0;
__y = 0; __y = 0;
saved_cursor[0] = 0; saved_cursor[0] = 0;
@ -74,14 +78,26 @@ void vt100_init(void)
and_mask = 0xffff; and_mask = 0xffff;
xor_mask = 0x0000; xor_mask = 0x0000;
DECANM = 1; initial_state = flags;
DECAWM = 1; if (flags == -1) {
DECCKM = 0; DECANM = 1;
DECKPAM = 0; DECAWM = 1;
DECCOLM = 80; DECCKM = 0;
DECOM = 0; DECKPAM = 0;
DECSCNM = 0; DECCOLM = 80;
LNM = 0; 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[0] = 0x8080;
tabs[1] = 0x8080; tabs[1] = 0x8080;
@ -521,7 +537,7 @@ void vt100_process(const unsigned char *buffer, unsigned buffer_size) {
case '8': restore_cursor(); break; case '8': restore_cursor(); break;
case '=': DECKPAM = 1; break; case '=': DECKPAM = 1; break;
case '>': DECKPAM = 0; 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; case '1': case '2': /* vt105 graphic stuff */ break;
default: default:
break; break;

11
vt100.gsh Normal file
View File

@ -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"

20
vt100.h Normal file
View File

@ -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