2013-07-10 09:26:01 -04:00
|
|
|
/*******************************************************************************
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
Copyright(C) Jonas 'Sortie' Termansen 2011.
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
This file is part of Sortix.
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
Sortix is free software: you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
version.
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
details.
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
serialterminal.cpp
|
|
|
|
A terminal on a serial line.
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
*******************************************************************************/
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2012-03-21 19:52:29 -04:00
|
|
|
#include <sortix/kernel/platform.h>
|
2012-08-07 18:19:44 -04:00
|
|
|
#include <sortix/kernel/keyboard.h>
|
2013-01-09 04:47:22 -05:00
|
|
|
#include <sortix/kernel/scheduler.h>
|
|
|
|
|
2012-08-07 18:19:44 -04:00
|
|
|
#include <string.h>
|
2013-01-09 04:47:22 -05:00
|
|
|
|
2011-09-08 05:10:41 -04:00
|
|
|
#include "vga.h"
|
2011-08-05 08:25:00 -04:00
|
|
|
#include "uart.h"
|
|
|
|
#include "serialterminal.h"
|
|
|
|
|
|
|
|
namespace Sortix
|
|
|
|
{
|
|
|
|
namespace SerialTerminal
|
|
|
|
{
|
|
|
|
void Reset()
|
|
|
|
{
|
2011-08-12 11:29:45 -04:00
|
|
|
// Set the cursor to (0,0) and clear the screen.
|
2011-11-20 09:58:42 -05:00
|
|
|
const char InitMessage[] = "\e[37m\e[40m\e[2J\e[H";
|
2012-09-22 16:40:44 -04:00
|
|
|
UART::Write(InitMessage, strlen(InitMessage));
|
2011-08-05 08:25:00 -04:00
|
|
|
}
|
|
|
|
|
2011-11-20 09:58:42 -05:00
|
|
|
bool isEsc;
|
|
|
|
bool isEscDepress;
|
2011-12-05 15:14:22 -05:00
|
|
|
int sigpending;
|
2011-11-20 09:58:42 -05:00
|
|
|
|
2011-12-05 15:44:14 -05:00
|
|
|
const bool ECHO_TO_VGA = true;
|
|
|
|
|
2011-12-05 16:13:51 -05:00
|
|
|
bool cursordisabled;
|
|
|
|
|
2011-08-05 08:25:00 -04:00
|
|
|
void Init()
|
|
|
|
{
|
|
|
|
Reset();
|
2011-11-20 09:58:42 -05:00
|
|
|
|
|
|
|
isEsc = isEscDepress = false;
|
2011-12-05 15:14:22 -05:00
|
|
|
sigpending = -1;
|
2011-12-05 16:13:51 -05:00
|
|
|
cursordisabled = false;
|
2011-11-20 09:58:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnTick()
|
|
|
|
{
|
|
|
|
// TODO: Yeah, this is a bad hack.
|
|
|
|
int c;
|
|
|
|
while ( (c=UART::TryPopChar()) != -1 )
|
|
|
|
{
|
2013-06-26 11:14:07 -04:00
|
|
|
// TODO: Support for hooking the serial input up against the keyboard API have broken
|
2012-01-07 15:09:01 -05:00
|
|
|
#if 0
|
|
|
|
// TODO: This is no longer compatible with the keyboard API, so
|
|
|
|
// it has been commented out. Besides, JSSortix isn't really
|
|
|
|
// supported anyway. It'd be nice to refactor this into a
|
|
|
|
// SerialKeyboard class or something.
|
|
|
|
|
2011-11-20 09:58:42 -05:00
|
|
|
using namespace Maxsi::Keyboard;
|
|
|
|
|
|
|
|
if ( !isEsc && c == '\e' ) { isEsc = true; continue; }
|
|
|
|
if ( isEsc && c == '\e' ) { isEsc = false; }
|
|
|
|
if ( isEsc && c == '[' ) { continue; }
|
|
|
|
if ( isEsc && c == ']' ) { isEscDepress = true; continue; }
|
|
|
|
if ( isEsc && !isEscDepress && c == 'A' ) { Keyboard::QueueKeystroke(UP); }
|
|
|
|
if ( isEsc && !isEscDepress && c == 'B' ) { Keyboard::QueueKeystroke(DOWN); }
|
|
|
|
if ( isEsc && !isEscDepress && c == 'C' ) { Keyboard::QueueKeystroke(RIGHT); }
|
|
|
|
if ( isEsc && !isEscDepress && c == 'D' ) { Keyboard::QueueKeystroke(LEFT); }
|
|
|
|
if ( isEsc && isEscDepress && c == 'A' ) { Keyboard::QueueKeystroke(UP | DEPRESSED); }
|
|
|
|
if ( isEsc && isEscDepress && c == 'B' ) { Keyboard::QueueKeystroke(DOWN | DEPRESSED); }
|
|
|
|
if ( isEsc && isEscDepress && c == 'C' ) { Keyboard::QueueKeystroke(RIGHT | DEPRESSED); }
|
|
|
|
if ( isEsc && isEscDepress && c == 'D' ) { Keyboard::QueueKeystroke(LEFT | DEPRESSED); }
|
|
|
|
if ( isEsc ) { isEsc = false; isEscDepress = false; continue; }
|
|
|
|
if ( c == '\e' ) { c = ESC; }
|
|
|
|
if ( c == ('\e' | (1<<7)) ) { c = ESC | DEPRESSED; }
|
2011-12-05 15:14:22 -05:00
|
|
|
if ( c == 145 ) // Control Depressed
|
|
|
|
{
|
|
|
|
if ( sigpending < 0 ) { continue; }
|
|
|
|
if ( sigpending == 'C' - 'A' + 1 )
|
|
|
|
{
|
|
|
|
Scheduler::SigIntHack();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Keyboard::QueueKeystroke(CTRL);
|
2012-03-21 19:52:29 -04:00
|
|
|
Keyboard::QueueKeystroke('A' + sigpending - 1);
|
2011-12-05 15:14:22 -05:00
|
|
|
Keyboard::QueueKeystroke(CTRL | DEPRESSED);
|
|
|
|
sigpending = -1;
|
2012-03-21 19:52:29 -04:00
|
|
|
continue;
|
2011-12-05 15:14:22 -05:00
|
|
|
}
|
|
|
|
if ( c < 32 ) { sigpending = c; } else { sigpending = -1; }
|
|
|
|
switch ( c )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
// Ignore most unprintable characters.
|
|
|
|
if ( c < 32 ) { continue; }
|
|
|
|
case '\b':
|
|
|
|
case '\t':
|
|
|
|
case '\r':
|
|
|
|
case '\n':
|
|
|
|
case '\e':
|
|
|
|
case '\f':
|
|
|
|
break;
|
|
|
|
}
|
2011-11-20 09:58:42 -05:00
|
|
|
if ( c == 127 ) { c = '\b'; }
|
|
|
|
if ( c & (1<<7) )
|
|
|
|
{
|
|
|
|
c &= ~(1<<7); c |= DEPRESSED;
|
|
|
|
}
|
|
|
|
Keyboard::QueueKeystroke(c);
|
2012-01-07 15:09:01 -05:00
|
|
|
#endif
|
2011-11-20 09:58:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-05 15:44:14 -05:00
|
|
|
void OnVGAModified()
|
2011-11-20 09:58:42 -05:00
|
|
|
{
|
2011-12-05 16:13:51 -05:00
|
|
|
if ( !cursordisabled )
|
|
|
|
{
|
|
|
|
const char* msg = "\e[l";
|
2012-09-22 16:40:44 -04:00
|
|
|
UART::Write(msg, strlen(msg));
|
2011-12-05 16:13:51 -05:00
|
|
|
cursordisabled = true;
|
|
|
|
}
|
2011-12-05 15:44:14 -05:00
|
|
|
UART::RenderVGA((const uint16_t*) 0xB8000);
|
2011-08-05 08:25:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t Print(void* /*user*/, const char* string, size_t stringlen)
|
|
|
|
{
|
2013-06-26 11:14:07 -04:00
|
|
|
// TODO: Echoing to the VGA terminal is broken
|
2012-07-22 18:01:12 -04:00
|
|
|
#if 0
|
2011-12-05 15:44:14 -05:00
|
|
|
if ( ECHO_TO_VGA ) { VGATerminal::Print(NULL, string, stringlen); }
|
2012-07-22 18:01:12 -04:00
|
|
|
#endif
|
2011-12-05 16:13:51 -05:00
|
|
|
if ( cursordisabled )
|
|
|
|
{
|
|
|
|
const char* msg = "\e[h";
|
2012-09-22 16:40:44 -04:00
|
|
|
UART::Write(msg, strlen(msg));
|
2011-12-05 16:13:51 -05:00
|
|
|
cursordisabled = false;
|
|
|
|
}
|
2011-12-05 15:44:14 -05:00
|
|
|
UART::Write(string, stringlen);
|
2011-08-05 08:25:00 -04:00
|
|
|
return stringlen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|