BESM6: Updated licenses missed before, TTYs use sim_putchar(), translated comments in besm6_tty.c; using "console" instead of "/dev/tty".

This commit is contained in:
Leo Broukhis 2015-01-04 23:14:51 -08:00
parent a7f05ac40c
commit aa16857edc
4 changed files with 162 additions and 143 deletions

View file

@ -1429,8 +1429,7 @@ void cpu_one_inst ()
if (RUU == 047 && PC == 04440 && RK == 067704440) { if (RUU == 047 && PC == 04440 && RK == 067704440) {
/* Если периферия простаивает, освобождаем процессор /* Если периферия простаивает, освобождаем процессор
* до следующего тика таймера. */ * до следующего тика таймера. */
if (vt_is_idle() && if (vt_is_idle()) {
printer_is_idle() && fs_is_idle()) {
check_initial_setup (); check_initial_setup ();
sim_idle (0, TRUE); sim_idle (0, TRUE);
} else if (sim_activate_time(tty_unit) > 1000*MSEC/300) { } else if (sim_activate_time(tty_unit) > 1000*MSEC/300) {

View file

@ -4,14 +4,28 @@
* Copyright (c) 2009, Serge Vakulenko * Copyright (c) 2009, Serge Vakulenko
* Copyright (c) 2009, Leonid Broukhis * Copyright (c) 2009, Leonid Broukhis
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * Permission is hereby granted, free of charge, to any person obtaining a
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * copy of this software and associated documentation files (the "Software"),
* FITNESS FOR A PARTICULAR PURPOSE. * to deal in the Software without restriction, including without limitation
* * the rights to use, copy, modify, merge, publish, distribute, sublicense,
* You can redistribute this program and/or modify it under the terms of * and/or sell copies of the Software, and to permit persons to whom the
* the GNU General Public License as published by the Free Software Foundation; * Software is furnished to do so, subject to the following conditions:
* either version 2 of the License, or (at your discretion) any later version.
* See the accompanying file "COPYING" for more details. * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SERGE VAKULENKO OR LEONID BROUKHIS BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
* OR OTHER DEALINGS IN THE SOFTWARE.
* Except as contained in this notice, the name of Leonid Broukhis or
* Serge Vakulenko shall not be used in advertising or otherwise to promote
* the sale, use or other dealings in this Software without prior written
* authorization from Leonid Broukhis and Serge Vakulenko.
* *
* This file implements three essential functions: * This file implements three essential functions:
* *

View file

@ -3,15 +3,28 @@
* *
* Copyright (c) 2009, Leo Broukhis * Copyright (c) 2009, Leo Broukhis
* Copyright (c) 2009, Serge Vakulenko * Copyright (c) 2009, Serge Vakulenko
* * Permission is hereby granted, free of charge, to any person obtaining a
* This program is distributed in the hope that it will be useful, but WITHOUT * copy of this software and associated documentation files (the "Software"),
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * to deal in the Software without restriction, including without limitation
* FITNESS FOR A PARTICULAR PURPOSE. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
* * and/or sell copies of the Software, and to permit persons to whom the
* You can redistribute this program and/or modify it under the terms of * Software is furnished to do so, subject to the following conditions:
* the GNU General Public License as published by the Free Software Foundation;
* either version 2 of the License, or (at your discretion) any later version. * The above copyright notice and this permission notice shall be included in
* See the accompanying file "COPYING" for more details. * all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* SERGE VAKULENKO OR LEONID BROUKHIS BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
* OR OTHER DEALINGS IN THE SOFTWARE.
* Except as contained in this notice, the name of Leonid Broukhis or
* Serge Vakulenko shall not be used in advertising or otherwise to promote
* the sale, use or other dealings in this Software without prior written
* authorization from Leonid Broukhis and Serge Vakulenko.
*/ */
#include "besm6_defs.h" #include "besm6_defs.h"
@ -19,10 +32,10 @@
#include "sim_tmxr.h" #include "sim_tmxr.h"
#include <time.h> #include <time.h>
#define TTY_MAX 24 /* Количество последовательных терминалов */ #define TTY_MAX 24 /* Serial TTY lines */
#define LINES_MAX TTY_MAX + 2 /* Включая параллельные интерфейсы "Консулов" */ #define LINES_MAX TTY_MAX + 2 /* Including parallel "Consul" typewriters */
/* /*
* Согласно таблице в http://ru.wikipedia.org/wiki/МТК-2 * According to a table in http://ru.wikipedia.org/wiki/МТК-2
*/ */
char * rus[] = { 0, "Т", "\r", "О", " ", "Х", "Н", "М", "\n", "Л", "Р", "Г", "И", "П", "Ц", "Ж", char * rus[] = { 0, "Т", "\r", "О", " ", "Х", "Н", "М", "\n", "Л", "Р", "Г", "И", "П", "Ц", "Ж",
"Е", "З", "Д", "Б", "С", "Ы", "Ф", "Ь", "А", "В", "Й", 0, "У", "Я", "К", 0 }; "Е", "З", "Д", "Б", "С", "Ы", "Ф", "Ь", "А", "В", "Й", 0, "У", "Я", "К", 0 };
@ -38,7 +51,7 @@ char ** reg = 0;
char * process (int sym) char * process (int sym)
{ {
/* Требуется инверсия */ /* Inversion is required for Baudot TTYs */
sym ^= 31; sym ^= 31;
switch (sym) { switch (sym) {
case 0: case 0:
@ -56,7 +69,7 @@ char * process (int sym)
return ""; return "";
} }
/* Только для последовательных линий */ /* For serial lines */
int tty_active [TTY_MAX+1], tty_sym [TTY_MAX+1]; int tty_active [TTY_MAX+1], tty_sym [TTY_MAX+1];
int tty_typed [TTY_MAX+1], tty_instate [TTY_MAX+1]; int tty_typed [TTY_MAX+1], tty_instate [TTY_MAX+1];
time_t tty_last_time [TTY_MAX+1]; time_t tty_last_time [TTY_MAX+1];
@ -74,7 +87,7 @@ uint32 CONSUL_IN[2];
uint32 CONS_CAN_PRINT[2] = { 01000, 00400 }; uint32 CONS_CAN_PRINT[2] = { 01000, 00400 };
uint32 CONS_HAS_INPUT[2] = { 04000, 02000 }; uint32 CONS_HAS_INPUT[2] = { 04000, 02000 };
/* Буфера командных строк для режима telnet. */ /* Command line buffers for TELNET mode. */
char vt_cbuf [CBUFSIZE] [LINES_MAX+1]; char vt_cbuf [CBUFSIZE] [LINES_MAX+1];
char *vt_cptr [LINES_MAX+1]; char *vt_cptr [LINES_MAX+1];
@ -121,13 +134,13 @@ REG tty_reg[] = {
}; };
/* /*
* Дескрипторы линий для мультиплексора TMXR. * Line descriptors for the TMXR multiplexor.
* Поле .conn содержит номер сокета и означает занятую линию. * The .conn field contains the socket number and denotes a used line.
* Для локальных терминалов делаем .conn = 1. * For local terminals, .conn = 1.
* Чтобы нумерация линий совпадала с нумерацией терминалов * To match line indexes with TTY numbers (1-based),
* (с единицы), нулевую линию держим занятой (.conn = 1). * line 0 is kept used (.conn = 1).
* Поле .rcve устанавливается в 1 для сетевых соединений. * The .rcve field is set to 1 for network connections.
* Для локальных терминалов оно равно 0. * For local connections, it is 0.
*/ */
TMLN tty_line [LINES_MAX+1]; TMLN tty_line [LINES_MAX+1];
TMXR tty_desc = { LINES_MAX+1, 0, 0, tty_line }; /* mux descriptor */ TMXR tty_desc = { LINES_MAX+1, 0, 0, tty_line }; /* mux descriptor */
@ -158,23 +171,24 @@ t_stat tty_reset (DEVICE *dptr)
reg = rus; reg = rus;
vt_idle = 1; vt_idle = 1;
tty_line[0].conn = 1; /* faked, always busy */ tty_line[0].conn = 1; /* faked, always busy */
/* Готовность устройства в READY2 инверсная, а устройство всегда готово */ /* In the READY2 register the ready flag for typewriters is inverted (0 means ready),
/* Провоцируем передачу */ * and the device is always ready. */
/* Forcing a ready interrupt. */
PRP |= CONS_CAN_PRINT[0] | CONS_CAN_PRINT[1]; PRP |= CONS_CAN_PRINT[0] | CONS_CAN_PRINT[1];
//return sim_activate_after (tty_unit, 1000*MSEC/300); //return sim_activate_after (tty_unit, 1000*MSEC/300);
return sim_clock_coschedule (tty_unit, tmr_poll); return sim_clock_coschedule (tty_unit, tmr_poll);
} }
/* 19 р ГРП, 300 Гц */ /* Bit 19 of GRP, should be 300 Hz */
t_stat vt_clk (UNIT * this) t_stat vt_clk (UNIT * this)
{ {
int num; int num;
/* Телетайпы работают на 10 бод */ /* Baudot TTYs work at 10 baud */
static int clk_divider = 1<<29; static int clk_divider = 1<<29;
GRP |= MGRP & GRP_SERIAL; GRP |= MGRP & GRP_SERIAL;
/* Опрашиваем сокеты на приём. */ /* Polling receiving from sockets */
tmxr_poll_rx (&tty_desc); tmxr_poll_rx (&tty_desc);
vt_print(); vt_print();
@ -183,16 +197,16 @@ t_stat vt_clk (UNIT * this)
if (! (clk_divider >>= 1)) { if (! (clk_divider >>= 1)) {
tt_print(); tt_print();
/* Прием не реализован */ /* Input from Baudot TTYs not implemented */
clk_divider = 1<<29; clk_divider = 1<<29;
} }
/* Есть новые сетевые подключения? */ /* Are there any new network connections? */
num = tmxr_poll_conn (&tty_desc); num = tmxr_poll_conn (&tty_desc);
if (num > 0 && num <= LINES_MAX) { if (num > 0 && num <= LINES_MAX) {
char buf [80]; char buf [80];
TMLN *t = &tty_line [num]; TMLN *t = &tty_line [num];
besm6_debug ("*** tty%d: новое подключение от %s", besm6_debug ("*** tty%d: a new connection from %s",
num, t->ipad); num, t->ipad);
t->rcve = 1; t->rcve = 1;
tty_unit[num].flags &= ~TTY_STATE_MASK; tty_unit[num].flags &= ~TTY_STATE_MASK;
@ -218,14 +232,17 @@ t_stat vt_clk (UNIT * this)
t->ipad); t->ipad);
tmxr_linemsg (t, buf); tmxr_linemsg (t, buf);
/* Ввод ^C, чтобы получить приглашение. */ /* Entering ^C (ETX) to get a prompt. */
t->rxb [t->rxbpi++] = '\3'; t->rxb [t->rxbpi++] = '\3';
} }
/* Опрашиваем сокеты на передачу. */ /* Polling sockets for transmission. */
tmxr_poll_tx (&tty_desc); tmxr_poll_tx (&tty_desc);
// return sim_activate_after (tty_unit, 1000*MSEC/300); /* We'll get a guaranteed interrupt rate of 250 Hz (wallclock)
* plus additional interrupts during the idle loop for speedup
* (see besm6_cpu.c).
*/
return sim_clock_coschedule (this, tmr_poll); return sim_clock_coschedule (this, tmr_poll);
} }
@ -280,10 +297,9 @@ t_stat tty_setmode (UNIT *u, int32 val, char *cptr, void *desc)
} }
/* /*
* Разрешение подключения к терминалам через telnet. * Allowing telnet connections is done with
* Делается командой: * attach tty <port>
* attach tty <порт> * Where <port> is the port number for telnet, e.g. 4199.
* Здесь <порт> - номер порта telnet, например 4199.
*/ */
t_stat tty_attach (UNIT *u, char *cptr) t_stat tty_attach (UNIT *u, char *cptr)
{ {
@ -291,39 +307,40 @@ t_stat tty_attach (UNIT *u, char *cptr)
int r, m, n; int r, m, n;
if (*cptr >= '0' && *cptr <= '9') { if (*cptr >= '0' && *cptr <= '9') {
/* Сохраняем и восстанавливаем все .conn, /* Saving and restoring all .conn,
* так как tmxr_attach() их обнуляет. */ * because tmxr_attach() zeroes them. */
for (m=0, n=1; n<=LINES_MAX; ++n) for (m=0, n=1; n<=LINES_MAX; ++n)
if (tty_line[n].conn) if (tty_line[n].conn)
m |= 1 << (LINES_MAX-n); m |= 1 << (LINES_MAX-n);
/* Неважно, какой номер порта указывать в команде задания /* The unit number is ignored for the port assignment */
* порта telnet. Можно tty, можно tty1 - без разницы. */
r = tmxr_attach (&tty_desc, &tty_unit[0], cptr); r = tmxr_attach (&tty_desc, &tty_unit[0], cptr);
for (n=1; n<=LINES_MAX; ++n) for (n=1; n<=LINES_MAX; ++n)
if (m >> (LINES_MAX-n) & 1) if (m >> (LINES_MAX-n) & 1)
tty_line[n].conn = 1; tty_line[n].conn = 1;
return r; return r;
} }
if (strcmp (cptr, "/dev/tty") == 0) {
/* Консоль. */ if (strcmp (cptr, "console") == 0) {
/* Attaching SIMH console to a particular terminal. */
u->flags &= ~TTY_STATE_MASK; u->flags &= ~TTY_STATE_MASK;
u->flags |= TTY_VT340_STATE; u->flags |= TTY_VT340_STATE;
tty_line[num].conn = 1; tty_line[num].conn = 1;
tty_line[num].rcve = 0; tty_line[num].rcve = 0;
if (num <= TTY_MAX) if (num <= TTY_MAX)
vt_mask |= 1 << (TTY_MAX - num); vt_mask |= 1 << (TTY_MAX - num);
besm6_debug ("*** консоль на T%03o", num); besm6_debug ("*** console on T%03o", num);
return 0; return 0;
} }
if (strcmp (cptr, "/dev/null") == 0) { /* Disallowing future connections to a line */
/* Запрещаем терминал. */ if (strcmp (cptr, "none") == 0) {
/* Marking the TTY as unusable. */
tty_line[num].conn = 1; tty_line[num].conn = 1;
tty_line[num].rcve = 0; tty_line[num].rcve = 0;
if (num <= TTY_MAX) { if (num <= TTY_MAX) {
vt_mask &= ~(1 << (TTY_MAX - num)); vt_mask &= ~(1 << (TTY_MAX - num));
tt_mask &= ~(1 << (TTY_MAX - num)); tt_mask &= ~(1 << (TTY_MAX - num));
} }
besm6_debug ("*** отключение терминала T%03o", num); besm6_debug ("*** turning off T%03o", num);
return 0; return 0;
} }
return SCPE_ALATT; return SCPE_ALATT;
@ -335,20 +352,20 @@ t_stat tty_detach (UNIT *u)
} }
/* /*
* Управление терминалами. * TTY control:
* set ttyN unicode - выбор кодировки UTF-8 * set ttyN unicode - selecting UTF-8 encoding
* set ttyN jcuken - выбор кодировки КОИ-7, раскладка йцукен * set ttyN jcuken - selecting KOI-7 encoding, JCUKEN layout
* set ttyN qwerty - выбор кодировки КОИ-7, раскладка яверты * set ttyN qwerty - selecting KOI-7 encoding, QWERTY layout
* set ttyN off - отключение * set ttyN off - disconnecting a line
* set ttyN tt - установка типа терминала "Телетайп" * set ttyN tt - a Baudot TTY
* set ttyN vt - установка типа терминала "Видеотон-340" * set ttyN vt - a Videoton-340 terminal
* set ttyN consul - установка типа терминала "Consul-254" * set ttyN consul - a "Consul-254" typewriter
* set ttyN destrbs - "стирающий" backspace * set ttyN destrbs - destructive (erasing) backspace
* set ttyN authbs - классический backspace * set ttyN authbs - authentic backspace (cursor left)
* set tty disconnect=N - принудительное завершение сеанса telnet * set tty disconnect=N - forceful termination of a telnet connection
* show tty - просмотр режимов терминалов * show tty - showing modes and types
* show tty connections - просмотр IP-адресов и времени соединений * show tty connections - showing IP-addresses and connection times
* show tty statistics - просмотр счетчиков переданных и принятых байтов * show tty statistics - showing TX/RX byte counts
*/ */
MTAB tty_mod[] = { MTAB tty_mod[] = {
{ TTY_CHARSET_MASK, TTY_UNICODE_CHARSET, "UTF-8 input", { TTY_CHARSET_MASK, TTY_UNICODE_CHARSET, "UTF-8 input",
@ -393,13 +410,13 @@ DEVICE tty_dev = {
void tty_send (uint32 mask) void tty_send (uint32 mask)
{ {
/* besm6_debug ("*** телетайпы: передача %08o", mask); */ /* besm6_debug ("*** TTY: transmit %08o", mask); */
TTY_OUT = mask; TTY_OUT = mask;
} }
/* /*
* Выдача символа на терминал с указанным номером. * Sending a character to a terminal with the given number.
*/ */
void vt_putc (int num, int c) void vt_putc (int num, int c)
{ {
@ -408,38 +425,29 @@ void vt_putc (int num, int c)
if (! t->conn) if (! t->conn)
return; return;
if (t->rcve) { if (t->rcve) {
/* Передача через telnet. */ /* A telnet connection. */
tmxr_putc_ln (t, c); tmxr_putc_ln (t, c);
} else { } else {
/* Вывод на консоль. */ /* Console output. */
if (t->txlog) { /* log if available */ sim_putchar(c);
fputc (c, t->txlog);
if (c == '\n')
fflush (t->txlog);
}
fputc (c, stdout);
fflush (stdout);
} }
} }
/* /*
* Выдача строки на терминал с указанным номером. * Sending a string to a terminal with the given number.
*/ */
void vt_puts (int num, const char *s) void vt_puts (int num, const unsigned char *s)
{ {
TMLN *t = &tty_line [num]; TMLN *t = &tty_line [num];
if (! t->conn) if (! t->conn)
return; return;
if (t->rcve) { if (t->rcve) {
/* Передача через telnet. */ /* A telnet connection. */
tmxr_linemsg (t, (char*) s); tmxr_linemsg (t, (char*) s);
} else { } else {
/* Вывод на консоль. */ /* Console output. */
if (t->txlog) /* log if available */ while (*s) sim_putchar(*s++);
fputs (s, t->txlog);
fputs (s, stdout);
fflush (stdout);
} }
} }
@ -450,6 +458,7 @@ const char * koi7_rus_to_unicode [32] = {
"Ь", "Ы", "З", "Ш", "Э", "Щ", "Ч", "\0x7f", "Ь", "Ы", "З", "Ш", "Э", "Щ", "Ч", "\0x7f",
}; };
/* Videoton-340 employed single byte control codes rather than ESC sequences. */
void vt_send(int num, uint32 sym, int destructive_bs) void vt_send(int num, uint32 sym, int destructive_bs)
{ {
if (sym < 0x60) { if (sym < 0x60) {
@ -473,7 +482,7 @@ void vt_send(int num, uint32 sym, int destructive_bs)
/* Left */ /* Left */
vt_puts (num, "\033["); vt_puts (num, "\033[");
if (destructive_bs) { if (destructive_bs) {
/* Стираем предыдущий символ. */ /* Erasing the previous char. */
vt_puts (num, "D \033["); vt_puts (num, "D \033[");
} }
sym = 'D'; sym = 'D';
@ -481,37 +490,35 @@ void vt_send(int num, uint32 sym, int destructive_bs)
case '\v': case '\v':
case '\033': case '\033':
case '\0': case '\0':
/* Выдаём управляющий символ. */ /* Sending the actual char */
break; break;
case '\037': case '\037':
/* Очистка экрана */ /* Clear screen */
vt_puts (num, "\033[H\033["); vt_puts (num, "\033[H\033[");
sym = 'J'; sym = 'J';
break; break;
case '\n': case '\n':
/* На VDT-340 также возвращал курсор в 1-ю позицию */ /* Also does carriage return */
vt_putc (num, '\r'); vt_putc (num, '\r');
sym = '\n'; sym = '\n';
break; break;
case '\f': case '\f':
/* Сообщение ERR при нажатии некоторых управляющих /* Home */
* клавиш выдается с использованием reverse wraparound.
*/
vt_puts(num, "\033["); vt_puts(num, "\033[");
sym = 'H'; sym = 'H';
break; break;
case '\r': case '\r':
case '\003': case '\003':
/* Неотображаемые символы */ /* Not displayed */
sym = 0; sym = 0;
break; break;
default: default:
if (sym < ' ') { if (sym < ' ') {
/* Нефункциональные ctrl-символы были видны в половинной яркости */ /* Other control chars were displayed as dimmed. */
vt_puts (num, "\033[2m"); vt_puts (num, "\033[2m");
vt_putc (num, sym | 0x40); vt_putc (num, sym | 0x40);
vt_puts (num, "\033["); vt_puts (num, "\033[");
/* Завершаем ESC-последовательность */ /* Terminating the ESC sequence */
sym = 'm'; sym = 'm';
} }
} }
@ -522,7 +529,7 @@ void vt_send(int num, uint32 sym, int destructive_bs)
} }
/* /*
* Обработка выдачи на все подключенные терминалы. * Handling output to all connected terminals.
*/ */
void vt_print() void vt_print()
{ {
@ -569,8 +576,7 @@ void vt_print()
vt_idle = 0; vt_idle = 0;
} }
/* Ввод с телетайпа не реализован; вывод работает только при использовании /* Input from Baudot TTYs not implemented. Output may require some additional work.
* модельного времени.
*/ */
void tt_print() void tt_print()
{ {
@ -615,8 +621,8 @@ void tt_print()
} }
/* /*
* Перекодировка из Unicode в КОИ-7. * Converting from Unicode to KOI-7.
* Если нет соответствия, возвращает -1. * Returns -1 if unsuccessful.
*/ */
static int unicode_to_koi7 (unsigned val) static int unicode_to_koi7 (unsigned val)
{ {
@ -820,7 +826,7 @@ static t_stat cmd_help (int32 num, char *cptr)
if (! cptr) if (! cptr)
return SCPE_INVSW; return SCPE_INVSW;
if (! *cptr) { if (! *cptr) {
/* Список всех команд. */ /* Listing all commands. */
tmxr_linemsg (t, "Commands may be abbreviated. Commands are:\r\n\r\n"); tmxr_linemsg (t, "Commands may be abbreviated. Commands are:\r\n\r\n");
for (c=cmd_table; c && c->name; c++) for (c=cmd_table; c && c->name; c++)
if (c->help) if (c->help)
@ -833,13 +839,13 @@ static t_stat cmd_help (int32 num, char *cptr)
c = lookup_cmd (gbuf); c = lookup_cmd (gbuf);
if (! c) if (! c)
return SCPE_ARG; return SCPE_ARG;
/* Описание конкретной команды. */ /* Describing a command. */
tmxr_linemsg (t, c->help); tmxr_linemsg (t, c->help);
return SCPE_OK; return SCPE_OK;
} }
/* /*
* Выполнение командной строки. * Executing a command.
*/ */
void vt_cmd_exec (int num) void vt_cmd_exec (int num)
{ {
@ -867,7 +873,7 @@ void vt_cmd_exec (int num)
} }
/* /*
* Режим управляющей командной строки. * Command line interface mode.
*/ */
void vt_cmd_loop (int num, int c) void vt_cmd_loop (int num, int c)
{ {
@ -882,11 +888,11 @@ void vt_cmd_loop (int num, int c)
case '\n': case '\n':
tmxr_linemsg (t, "\r\n"); tmxr_linemsg (t, "\r\n");
if (*cptr <= cbuf) { if (*cptr <= cbuf) {
/* Пустая строка - возврат в обычный режим. */ /* An empty line - returning to terminal emulation. */
tty_unit[num].flags &= ~TTY_CMDLINE_MASK; tty_unit[num].flags &= ~TTY_CMDLINE_MASK;
break; break;
} }
/* Выполнение. */ /* Executing. */
**cptr = 0; **cptr = 0;
vt_cmd_exec (num); vt_cmd_exec (num);
tmxr_linemsg (t, "sim>"); tmxr_linemsg (t, "sim>");
@ -894,7 +900,7 @@ void vt_cmd_loop (int num, int c)
break; break;
case '\b': case '\b':
case 0177: case 0177:
/* Стирание предыдущего символа. */ /* Backspace. */
if (*cptr <= cbuf) if (*cptr <= cbuf)
break; break;
tmxr_linemsg (t, "\b \b"); tmxr_linemsg (t, "\b \b");
@ -905,7 +911,7 @@ void vt_cmd_loop (int num, int c)
} }
break; break;
case 'U' & 037: case 'U' & 037:
/* Стирание всей строки. */ /* Erase line. */
erase_line: while (*cptr > cbuf) { erase_line: while (*cptr > cbuf) {
--*cptr; --*cptr;
if (! (**cptr & 0x80)) if (! (**cptr & 0x80))
@ -917,14 +923,14 @@ void vt_cmd_loop (int num, int c)
if (tmxr_getc_ln (t) != '[' + TMXR_VALID) if (tmxr_getc_ln (t) != '[' + TMXR_VALID)
break; break;
switch (tmxr_getc_ln (t) - TMXR_VALID) { switch (tmxr_getc_ln (t) - TMXR_VALID) {
case 'A': /* стрелка вверх */ case 'A': /* Up arrow */
if (*cptr <= cbuf) { if (*cptr <= cbuf) {
*cptr = cbuf + strlen (cbuf); *cptr = cbuf + strlen (cbuf);
if (*cptr > cbuf) if (*cptr > cbuf)
tmxr_linemsg (t, cbuf); tmxr_linemsg (t, cbuf);
} }
break; break;
case 'B': /* стрелка вниз */ case 'B': /* Down arrow */
goto erase_line; goto erase_line;
} }
break; break;
@ -938,9 +944,8 @@ void vt_cmd_loop (int num, int c)
} }
/* /*
* Ввод символа с терминала с указанным номером. * Getting a char from a terminal with the given number.
* Если нет приёма, возвращает -1. * Returns -1 if there is no char to input.
* В случае прерывания возвращает 0400 (только для консоли).
*/ */
int vt_getc (int num) int vt_getc (int num)
{ {
@ -952,7 +957,7 @@ int vt_getc (int num)
if (! t->conn) { if (! t->conn) {
/* Пользователь отключился. */ /* Пользователь отключился. */
if (t->ipad) { if (t->ipad) {
besm6_debug ("*** tty%d: отключение %s", besm6_debug ("*** tty%d: disconnecting %s",
num, num,
t->ipad); t->ipad);
t->ipad = NULL; t->ipad = NULL;
@ -962,18 +967,18 @@ int vt_getc (int num)
return -1; return -1;
} }
if (t->rcve) { if (t->rcve) {
/* Приём через telnet. */ /* A telnet line. */
c = tmxr_getc_ln (t); c = tmxr_getc_ln (t);
if (! (c & TMXR_VALID)) { if (! (c & TMXR_VALID)) {
now = time (0); now = time (0);
if (now > tty_last_time[num] + 5*60) { if (now > tty_last_time[num] + 5*60) {
++tty_idle_count[num]; ++tty_idle_count[num];
if (tty_idle_count[num] > 3) { if (tty_idle_count[num] > 3) {
tmxr_linemsg (t, "\r\nКОНЕЦ СЕАНСА\r\n"); tmxr_linemsg (t, "\r\nSIMH: END OF SESSION\r\n");
tmxr_reset_ln (t); tmxr_reset_ln (t);
return -1; return -1;
} }
tmxr_linemsg (t, "\r\nНЕ СПАТЬ!\r\n"); tmxr_linemsg (t, "\r\nSIMH: WAKE UP!\r\n");
tty_last_time[num] = now; tty_last_time[num] = now;
} }
return -1; return -1;
@ -982,22 +987,22 @@ int vt_getc (int num)
tty_last_time[num] = time (0); tty_last_time[num] = time (0);
if (tty_unit[num].flags & TTY_CMDLINE_MASK) { if (tty_unit[num].flags & TTY_CMDLINE_MASK) {
/* Продолжение режима управляющей командной строки. */ /* Continuing CLI mode. */
vt_cmd_loop (num, c & 0377); vt_cmd_loop (num, c & 0377);
return -1; return -1;
} }
if ((c & 0377) == sim_int_char) { if ((c & 0377) == sim_int_char) {
/* Вход в режим управляющей командной строки. */ /* Entering CLI mode. */
tty_unit[num].flags |= TTY_CMDLINE_MASK; tty_unit[num].flags |= TTY_CMDLINE_MASK;
tmxr_linemsg (t, "sim>"); tmxr_linemsg (t, "sim>");
vt_cptr[num] = vt_cbuf[num]; vt_cptr[num] = vt_cbuf[num];
return -1; return -1;
} }
} else { } else {
/* Ввод с клавиатуры. */ /* Console (keyboard) input. */
c = sim_poll_kbd(); c = sim_poll_kbd();
if (c == SCPE_STOP) { if (c == SCPE_STOP) {
return 0400; /* прерывание */ stop_cpu = 1; /* just in case */
} }
if (! (c & SCPE_KFLAG)) if (! (c & SCPE_KFLAG))
return -1; return -1;
@ -1006,11 +1011,9 @@ int vt_getc (int num)
} }
/* /*
* Ввод символа с клавиатуры. * Reading UTF-8, returning KOI-7.
* Перекодировка из UTF-8 в КОИ-7. * The resulting char is in the range 0..0177.
* Полученный символ находится в диапазоне 0..0177. * If no input, returns -1.
* Если нет ввода, возвращает -1.
* В случае прерывания (^E) возвращает 0400.
*/ */
static int vt_kbd_input_unicode (int num) static int vt_kbd_input_unicode (int num)
{ {
@ -1043,9 +1046,9 @@ static int vt_kbd_input_unicode (int num)
} }
/* /*
* Альтернативный вариант ввода, не требующий переключения на русскую клавиатуру. * Alternatively, entering Cyrillics can be done without switching keyboard layouts.
* Символы "точка" и "запятая" вводятся через shift, "больше-меньше" - "тильда-гравис". * Period and comma are entered with shift, less-than and greater-than are mapped to tilde-grave.
* "точка с запятой" - "закр. фиг. скобка", "апостроф" - "верт. черта". * Semicolon is }, quote is |.
*/ */
static int vt_kbd_input_koi7 (int num) static int vt_kbd_input_koi7 (int num)
{ {
@ -1108,7 +1111,7 @@ int odd_parity(unsigned char c)
} }
/* /*
* Обработка ввода со всех подключенных терминалов. * Handling input from all connected terminals.
*/ */
void vt_receive() void vt_receive()
{ {
@ -1136,18 +1139,20 @@ void vt_receive()
break; break;
} }
if (tty_typed[num] < 0) { if (tty_typed[num] < 0) {
/* TODO: обработать исключение от "неоператорского" терминала */
break; break;
} }
if (tty_typed[num] <= 0177) { if (tty_typed[num] <= 0177) {
if (tty_typed[num] == '\r' || tty_typed[num] == '\n') if (tty_typed[num] == '\r' || tty_typed[num] == '\n')
tty_typed[num] = 3; /* ^C - конец строки */ tty_typed[num] = 3; /* ETX is used as Enter */
if (tty_typed[num] == '\177') if (tty_typed[num] == '\177')
tty_typed[num] = '\b'; /* ASCII DEL -> BS */ tty_typed[num] = '\b'; /* ASCII DEL -> BS */
tty_instate[num] = 1; tty_instate[num] = 1;
TTY_IN |= mask; /* start bit */ TTY_IN |= mask; /* start bit */
GRP |= GRP_TTY_START; /* не используется ? */ GRP |= GRP_TTY_START; /* not used ? */
MGRP |= GRP_SERIAL; /* для терминалов по методу МГУ */ /* auto-enabling the interrupt just in case
* (seems to be unneeded as the interrupt is never disabled)
*/
MGRP |= GRP_SERIAL;
vt_receiving |= mask; vt_receiving |= mask;
} }
break; break;
@ -1176,7 +1181,8 @@ void vt_receive()
} }
/* /*
* Выясняем, остановлены ли терминалы. Нужно для входа в "спящий" режим. * Checking if all terminals are idle.
* SIMH should not enter idle mode until they are.
*/ */
int vt_is_idle () int vt_is_idle ()
{ {
@ -1185,7 +1191,7 @@ int vt_is_idle ()
int tty_query () int tty_query ()
{ {
/* besm6_debug ("*** телетайпы: приём");*/ /* besm6_debug ("*** TTY: query");*/
return TTY_IN; return TTY_IN;
} }

View file

@ -35,7 +35,7 @@ attach prn0 /dev/tty
; Активируем операторский терминал, ; Активируем операторский терминал,
; на который идут сообщения. ; на который идут сообщения.
; ;
attach tty1 /dev/tty attach tty1 console
; ;
; Режимы по вкусу ; Режимы по вкусу