2018-10-30 13:59:29 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "TTY.h"
|
|
|
|
#include "Keyboard.h"
|
|
|
|
#include "Console.h"
|
|
|
|
|
|
|
|
class VirtualConsole final : public TTY, public KeyboardClient, public ConsoleImplementation {
|
|
|
|
public:
|
|
|
|
enum InitialContents { Cleared, AdoptCurrentVGABuffer };
|
|
|
|
|
|
|
|
VirtualConsole(unsigned index, InitialContents = Cleared);
|
|
|
|
virtual ~VirtualConsole() override;
|
|
|
|
|
|
|
|
void adoptCurrentVGABuffer();
|
|
|
|
void setActive(bool);
|
|
|
|
|
|
|
|
static void switchTo(unsigned);
|
|
|
|
static void initialize();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// ^KeyboardClient
|
2018-10-30 15:33:37 +01:00
|
|
|
virtual void onKeyPress(byte) override;
|
2018-10-30 13:59:29 +01:00
|
|
|
|
|
|
|
// ^ConsoleImplementation
|
2018-10-30 15:33:37 +01:00
|
|
|
virtual void onConsoleReceive(byte) override;
|
2018-10-30 13:59:29 +01:00
|
|
|
|
2018-10-30 15:33:37 +01:00
|
|
|
// ^TTY
|
|
|
|
virtual void onTTYWrite(byte) override;
|
|
|
|
virtual String ttyName() const override;
|
|
|
|
|
|
|
|
void onChar(byte, bool shouldEmit);
|
2018-10-30 13:59:29 +01:00
|
|
|
|
|
|
|
byte* m_buffer;
|
|
|
|
unsigned m_index;
|
|
|
|
bool m_active { false };
|
|
|
|
|
2018-10-30 15:33:37 +01:00
|
|
|
void scrollUp();
|
|
|
|
void setCursor(unsigned row, unsigned column);
|
|
|
|
void putCharacterAt(unsigned row, unsigned column, byte ch);
|
|
|
|
|
2018-10-30 13:59:29 +01:00
|
|
|
void escape$H(const Vector<unsigned>&);
|
|
|
|
void escape$J(const Vector<unsigned>&);
|
|
|
|
void escape$m(const Vector<unsigned>&);
|
|
|
|
void escape$s(const Vector<unsigned>&);
|
|
|
|
void escape$u(const Vector<unsigned>&);
|
|
|
|
|
|
|
|
const byte m_rows { 25 };
|
|
|
|
const byte m_columns { 80 };
|
|
|
|
byte m_cursorRow { 0 };
|
|
|
|
byte m_cursorColumn { 0 };
|
|
|
|
byte m_savedCursorRow { 0 };
|
|
|
|
byte m_savedCursorColumn { 0 };
|
|
|
|
byte m_currentAttribute { 0x07 };
|
|
|
|
|
|
|
|
void executeEscapeSequence(byte final);
|
|
|
|
|
|
|
|
enum EscapeState {
|
|
|
|
Normal,
|
|
|
|
ExpectBracket,
|
|
|
|
ExpectParameter,
|
|
|
|
ExpectIntermediate,
|
|
|
|
ExpectFinal,
|
|
|
|
};
|
|
|
|
EscapeState m_escState { Normal };
|
|
|
|
Vector<byte> m_parameters;
|
|
|
|
Vector<byte> m_intermediates;
|
|
|
|
};
|