Console.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. m_logbuffer.enqueue(ch);
  47. if (m_implementation)
  48. m_implementation->on_sysconsole_receive(ch);
  49. }
  50. ConsoleImplementation::~ConsoleImplementation()
  51. {
  52. }