mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Remove kernel/serialterminal.{cpp,h}.
This commit is contained in:
parent
6d79781497
commit
c3f1550bba
7 changed files with 0 additions and 342 deletions
|
@ -127,7 +127,6 @@ refcount.o \
|
|||
resource.o \
|
||||
scheduler.o \
|
||||
segment.o \
|
||||
serialterminal.o \
|
||||
signal.o \
|
||||
string.o \
|
||||
symbol.o \
|
||||
|
|
|
@ -90,7 +90,6 @@
|
|||
#include "pipe.h"
|
||||
#include "poll.h"
|
||||
#include "resource.h"
|
||||
#include "serialterminal.h"
|
||||
#include "textterminal.h"
|
||||
#include "uart.h"
|
||||
#include "vga.h"
|
||||
|
|
|
@ -1,159 +0,0 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
serialterminal.cpp
|
||||
A terminal on a serial line.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <sortix/kernel/kernel.h>
|
||||
#include <sortix/kernel/keyboard.h>
|
||||
#include <sortix/kernel/scheduler.h>
|
||||
|
||||
#include "vga.h"
|
||||
#include "uart.h"
|
||||
#include "serialterminal.h"
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
namespace SerialTerminal
|
||||
{
|
||||
void Reset()
|
||||
{
|
||||
// Set the cursor to (0,0) and clear the screen.
|
||||
const char InitMessage[] = "\e[37m\e[40m\e[2J\e[H";
|
||||
UART::Write(InitMessage, strlen(InitMessage));
|
||||
}
|
||||
|
||||
bool isEsc;
|
||||
bool isEscDepress;
|
||||
int sigpending;
|
||||
|
||||
const bool ECHO_TO_VGA = true;
|
||||
|
||||
bool cursordisabled;
|
||||
|
||||
void Init()
|
||||
{
|
||||
Reset();
|
||||
|
||||
isEsc = isEscDepress = false;
|
||||
sigpending = -1;
|
||||
cursordisabled = false;
|
||||
}
|
||||
|
||||
void OnTick()
|
||||
{
|
||||
// TODO: Yeah, this is a bad hack.
|
||||
int c;
|
||||
while ( (c=UART::TryPopChar()) != -1 )
|
||||
{
|
||||
// TODO: Support for hooking the serial input up against the keyboard API have broken
|
||||
#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.
|
||||
|
||||
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; }
|
||||
if ( c == 145 ) // Control Depressed
|
||||
{
|
||||
if ( sigpending < 0 ) { continue; }
|
||||
if ( sigpending == 'C' - 'A' + 1 )
|
||||
{
|
||||
Scheduler::SigIntHack();
|
||||
continue;
|
||||
}
|
||||
|
||||
Keyboard::QueueKeystroke(CTRL);
|
||||
Keyboard::QueueKeystroke('A' + sigpending - 1);
|
||||
Keyboard::QueueKeystroke(CTRL | DEPRESSED);
|
||||
sigpending = -1;
|
||||
continue;
|
||||
}
|
||||
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;
|
||||
}
|
||||
if ( c == 127 ) { c = '\b'; }
|
||||
if ( c & (1<<7) )
|
||||
{
|
||||
c &= ~(1<<7); c |= DEPRESSED;
|
||||
}
|
||||
Keyboard::QueueKeystroke(c);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void OnVGAModified()
|
||||
{
|
||||
if ( !cursordisabled )
|
||||
{
|
||||
const char* msg = "\e[l";
|
||||
UART::Write(msg, strlen(msg));
|
||||
cursordisabled = true;
|
||||
}
|
||||
UART::RenderVGA((const uint16_t*) 0xB8000);
|
||||
}
|
||||
|
||||
size_t Print(void* /*user*/, const char* string, size_t stringlen)
|
||||
{
|
||||
// TODO: Echoing to the VGA terminal is broken
|
||||
#if 0
|
||||
if ( ECHO_TO_VGA ) { VGATerminal::Print(NULL, string, stringlen); }
|
||||
#endif
|
||||
if ( cursordisabled )
|
||||
{
|
||||
const char* msg = "\e[h";
|
||||
UART::Write(msg, strlen(msg));
|
||||
cursordisabled = false;
|
||||
}
|
||||
UART::Write(string, stringlen);
|
||||
return stringlen;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
|
||||
|
||||
This file is part of Sortix.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with
|
||||
Sortix. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
serialterminal.h
|
||||
A terminal on a serial line.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef SORTIX_SERIALTERMINAL_H
|
||||
#define SORTIX_SERIALTERMINAL_H
|
||||
|
||||
namespace Sortix
|
||||
{
|
||||
namespace SerialTerminal
|
||||
{
|
||||
void Init();
|
||||
void Reset();
|
||||
void OnTick();
|
||||
void OnVGAModified();
|
||||
size_t Print(void* user, const char* string, size_t stringlen);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -39,10 +39,6 @@
|
|||
#include <sortix/kernel/syscall.h>
|
||||
#include <sortix/kernel/time.h>
|
||||
|
||||
#ifdef PLATFORM_SERIAL
|
||||
#include "serialterminal.h"
|
||||
#endif
|
||||
|
||||
namespace Sortix {
|
||||
namespace Time {
|
||||
|
||||
|
|
133
kernel/uart.cpp
133
kernel/uart.cpp
|
@ -65,10 +65,6 @@ namespace Sortix
|
|||
const unsigned BASE_BAUD = 1843200/16;
|
||||
const unsigned BOTH_EMPTY = LSR_TEMT | LSR_THRE;
|
||||
|
||||
const unsigned FrameWidth = 80;
|
||||
const unsigned FrameHeight = 25;
|
||||
uint16_t VGALastFrame[FrameWidth * FrameHeight];
|
||||
|
||||
unsigned ProbeBaud(unsigned Port)
|
||||
{
|
||||
uint8_t lcr = CPU::InPortB(Port + LCR);
|
||||
|
@ -98,8 +94,6 @@ namespace Sortix
|
|||
|
||||
void Init()
|
||||
{
|
||||
InvalidateVGA();
|
||||
|
||||
Baud = ProbeBaud(Port);
|
||||
|
||||
CPU::OutPortB(Port + LCR, 0x3); // 8n1
|
||||
|
@ -187,132 +181,5 @@ namespace Sortix
|
|||
|
||||
return Result;
|
||||
}
|
||||
|
||||
void WriteNumberAsString(uint8_t Num)
|
||||
{
|
||||
if ( Num > 100 ) { WriteChar(Num / 100); }
|
||||
if ( Num > 10 ) { WriteChar(Num / 10); }
|
||||
|
||||
WriteChar(Num % 10);
|
||||
}
|
||||
|
||||
// Change from VGA color to another color system.
|
||||
unsigned ConversionTable[16] = { 0, 4, 2, 6, 1, 5, 3, 7, 0, 4, 2, 6, 1, 5, 3, 7 };
|
||||
|
||||
void InvalidateVGA()
|
||||
{
|
||||
for ( unsigned I = 0; I < FrameWidth * FrameHeight; I++ ) { VGALastFrame[I] = 0; }
|
||||
}
|
||||
|
||||
void RenderVGA(const uint16_t* Frame)
|
||||
{
|
||||
const uint16_t* Source = Frame;
|
||||
|
||||
unsigned LastColor = 1337;
|
||||
unsigned SkippedSince = 0;
|
||||
bool posundefined = true;
|
||||
|
||||
for ( unsigned Y = 0; Y < FrameHeight; Y++)
|
||||
{
|
||||
for ( unsigned X = 0; X < FrameWidth; X++ )
|
||||
{
|
||||
unsigned Index = Y * FrameWidth + X;
|
||||
|
||||
unsigned Element = Source[Index];
|
||||
unsigned OldElement = VGALastFrame[Index];
|
||||
|
||||
if ( Element == OldElement ) { continue; }
|
||||
|
||||
// Update the position if we skipped some characters.
|
||||
if ( Index - SkippedSince > 8 || posundefined )
|
||||
{
|
||||
const unsigned LineId = Y + 1;
|
||||
const unsigned ColumnId = X + 1;
|
||||
|
||||
if ( ColumnId > 1 )
|
||||
{
|
||||
UART::WriteChar('\e');
|
||||
UART::WriteChar('[');
|
||||
UART::WriteChar('0' + LineId / 10);
|
||||
UART::WriteChar('0' + LineId % 10);
|
||||
UART::WriteChar(';');
|
||||
UART::WriteChar('0' + ColumnId / 10);
|
||||
UART::WriteChar('0' + ColumnId % 10);
|
||||
UART::WriteChar('H');
|
||||
}
|
||||
else
|
||||
{
|
||||
UART::WriteChar('\e');
|
||||
UART::WriteChar('[');
|
||||
UART::WriteChar('0' + LineId / 10);
|
||||
UART::WriteChar('0' + LineId % 10);
|
||||
UART::WriteChar('H');
|
||||
}
|
||||
|
||||
SkippedSince = Index;
|
||||
posundefined = false;
|
||||
}
|
||||
|
||||
for ( unsigned Pos = SkippedSince; Pos <= Index; Pos++ )
|
||||
{
|
||||
Element = Source[Pos];
|
||||
OldElement = VGALastFrame[Pos];
|
||||
|
||||
unsigned NewColor = (ConversionTable[ (Element >> 12) & 0xF ] << 3) | (ConversionTable[ (Element >> 8) & 0xF ]);
|
||||
|
||||
// Change the color if we need to.
|
||||
if ( LastColor != NewColor )
|
||||
{
|
||||
unsigned OldFGColor = LastColor % 8;
|
||||
unsigned OldBGColor = LastColor / 8;
|
||||
unsigned FGColor = NewColor % 8;
|
||||
unsigned BGColor = NewColor / 8;
|
||||
if ( LastColor == 1337 ) { OldFGColor = 9; OldBGColor = 9; }
|
||||
|
||||
if ( (OldFGColor != FGColor) && (OldBGColor != BGColor) )
|
||||
{
|
||||
UART::WriteChar('\e');
|
||||
UART::WriteChar('[');
|
||||
UART::WriteChar('3');
|
||||
UART::WriteChar('0' + FGColor);
|
||||
UART::WriteChar(';');
|
||||
UART::WriteChar('4');
|
||||
UART::WriteChar('0' + BGColor);
|
||||
UART::WriteChar('m');
|
||||
}
|
||||
else if ( OldFGColor != FGColor )
|
||||
{
|
||||
UART::WriteChar('\e');
|
||||
UART::WriteChar('[');
|
||||
UART::WriteChar('3');
|
||||
UART::WriteChar('0' + FGColor);
|
||||
UART::WriteChar('m');
|
||||
}
|
||||
else if ( OldBGColor != BGColor )
|
||||
{
|
||||
UART::WriteChar('\e');
|
||||
UART::WriteChar('[');
|
||||
UART::WriteChar('4');
|
||||
UART::WriteChar('0' + BGColor);
|
||||
UART::WriteChar('m');
|
||||
}
|
||||
|
||||
LastColor = NewColor;
|
||||
}
|
||||
|
||||
VGALastFrame[Pos] = Element;
|
||||
|
||||
Element &= 0x7F;
|
||||
|
||||
// Filter away any non-printable characters.
|
||||
if ( Element < 32 || Element > 126 ) { Element = '?'; }
|
||||
|
||||
UART::WriteChar(Element);
|
||||
}
|
||||
|
||||
SkippedSince = Index + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,10 +34,6 @@ namespace Sortix
|
|||
void Write(const void* Buffer, size_t Size);
|
||||
void WriteChar(char C);
|
||||
int TryPopChar();
|
||||
#ifdef SORTIX_VGA_H
|
||||
void InvalidateVGA();
|
||||
void RenderVGA(const uint16_t* frame = (const uint16_t*) 0xB8000UL);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue