Console.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "Console.h"
  2. #include "IO.h"
  3. #include "kprintf.h"
  4. // Bytes output to 0xE9 end up on the Bochs console. It's very handy.
  5. #define CONSOLE_OUT_TO_E9
  6. static Console* s_the;
  7. Console& Console::the()
  8. {
  9. ASSERT(s_the);
  10. return *s_the;
  11. }
  12. Console::Console()
  13. : CharacterDevice(5, 1)
  14. {
  15. s_the = this;
  16. }
  17. Console::~Console()
  18. {
  19. }
  20. bool Console::can_read(Process&) const
  21. {
  22. return false;
  23. }
  24. ssize_t Console::read(Process&, byte*, size_t)
  25. {
  26. // FIXME: Implement reading from the console.
  27. // Maybe we could use a ring buffer for this device?
  28. return 0;
  29. }
  30. ssize_t Console::write(Process&, const byte* data, size_t size)
  31. {
  32. if (!size)
  33. return 0;
  34. if (!m_implementation)
  35. return 0;
  36. for (size_t i = 0; i < size; ++i)
  37. put_char(data[i]);
  38. return size;
  39. }
  40. void Console::put_char(char ch)
  41. {
  42. #ifdef CONSOLE_OUT_TO_E9
  43. //if (ch != 27)
  44. IO::out8(0xe9, ch);
  45. #endif
  46. if (m_implementation)
  47. m_implementation->on_sysconsole_receive(ch);
  48. }
  49. ConsoleImplementation::~ConsoleImplementation()
  50. {
  51. }