2018-10-21 19:59:43 +00:00
|
|
|
#include "Console.h"
|
2018-10-23 11:02:38 +00:00
|
|
|
#include "IO.h"
|
2018-10-27 21:42:20 +00:00
|
|
|
#include "kprintf.h"
|
2018-10-23 11:02:38 +00:00
|
|
|
|
|
|
|
// Bytes output to 0xE9 end up on the Bochs console. It's very handy.
|
|
|
|
#define CONSOLE_OUT_TO_E9
|
2018-10-21 19:59:43 +00:00
|
|
|
|
|
|
|
static Console* s_the;
|
|
|
|
|
|
|
|
Console& Console::the()
|
|
|
|
{
|
2018-10-30 22:01:48 +00:00
|
|
|
ASSERT(s_the);
|
2018-10-21 19:59:43 +00:00
|
|
|
return *s_the;
|
|
|
|
}
|
|
|
|
|
|
|
|
Console::Console()
|
2018-10-30 12:59:29 +00:00
|
|
|
: CharacterDevice(5, 1)
|
2018-10-21 19:59:43 +00:00
|
|
|
{
|
|
|
|
s_the = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Console::~Console()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-15 23:10:13 +00:00
|
|
|
bool Console::can_read(Process&) const
|
2018-10-25 11:07:59 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-01-15 23:20:38 +00:00
|
|
|
ssize_t Console::read(Process&, byte*, size_t)
|
2018-10-21 19:59:43 +00:00
|
|
|
{
|
|
|
|
// FIXME: Implement reading from the console.
|
|
|
|
// Maybe we could use a ring buffer for this device?
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-15 23:20:38 +00:00
|
|
|
ssize_t Console::write(Process&, const byte* data, size_t size)
|
2018-10-27 21:42:20 +00:00
|
|
|
{
|
2018-10-30 12:59:29 +00:00
|
|
|
if (!size)
|
|
|
|
return 0;
|
|
|
|
if (!m_implementation)
|
|
|
|
return 0;
|
|
|
|
for (size_t i = 0; i < size; ++i)
|
2018-12-03 00:38:22 +00:00
|
|
|
put_char(data[i]);
|
2018-11-12 00:28:46 +00:00
|
|
|
return size;
|
2018-10-27 21:42:20 +00:00
|
|
|
}
|
|
|
|
|
2018-12-03 00:38:22 +00:00
|
|
|
void Console::put_char(char ch)
|
2018-10-21 20:11:46 +00:00
|
|
|
{
|
2018-10-23 11:02:38 +00:00
|
|
|
#ifdef CONSOLE_OUT_TO_E9
|
2018-10-27 21:42:20 +00:00
|
|
|
//if (ch != 27)
|
2018-10-23 11:02:38 +00:00
|
|
|
IO::out8(0xe9, ch);
|
|
|
|
#endif
|
2018-10-30 12:59:29 +00:00
|
|
|
if (m_implementation)
|
2018-12-02 23:39:25 +00:00
|
|
|
m_implementation->on_sysconsole_receive(ch);
|
2018-10-21 20:11:46 +00:00
|
|
|
}
|
2018-10-21 19:59:43 +00:00
|
|
|
|
2018-10-30 12:59:29 +00:00
|
|
|
ConsoleImplementation::~ConsoleImplementation()
|
2018-10-21 19:59:43 +00:00
|
|
|
{
|
|
|
|
}
|