io.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* I/O library: VGA text output and PS/2 keyboard. Usable by terminal and other programs. */
  2. #ifndef IO_H
  3. #define IO_H
  4. #define IO_HEADER_ROWS 1
  5. /* Row 0: banner left, datetime right (19 chars "YYYY-MM-DD HH:MM:SS") */
  6. #define IO_DATETIME_LEN 19
  7. unsigned int io_get_cols(void);
  8. unsigned int io_get_rows(void);
  9. #define IO_VGA_COLS (io_get_cols())
  10. #define IO_VGA_ROWS (io_get_rows())
  11. #define IO_CONTENT_OFFSET (IO_HEADER_ROWS * io_get_cols())
  12. #define IO_CONTENT_ROWS (io_get_rows() - IO_HEADER_ROWS)
  13. #define IO_CONTENT_SIZE (IO_CONTENT_ROWS * io_get_cols())
  14. #define IO_DATETIME_POS (io_get_cols() - IO_DATETIME_LEN)
  15. void io_init(void);
  16. void io_putchar(char c);
  17. void io_putstr(const char *s);
  18. void io_puthex(unsigned int n); /* print n as 8 hex digits, no 0x prefix */
  19. void io_drain_keyboard(void);
  20. /* Poll keyboard; returns 0 = no key, 1..255 = ASCII, or an IO_KEY_* code. */
  21. #define IO_KEY_CTRL_C 0x03 /* Ctrl+C (ASCII ETX), kills the foreground job */
  22. #define IO_KEY_LEFT 0x100
  23. #define IO_KEY_RIGHT 0x101
  24. #define IO_KEY_UP 0x102
  25. #define IO_KEY_DOWN 0x103
  26. #define IO_KEY_PAGE_UP 0x104
  27. #define IO_KEY_PAGE_DOWN 0x105
  28. #define IO_KEY_HOME 0x106
  29. #define IO_KEY_END 0x107
  30. #define IO_KEY_DELETE 0x108
  31. #define IO_KEY_CTRL_LEFT 0x109
  32. #define IO_KEY_CTRL_RIGHT 0x10A
  33. #define IO_KEY_CTRL_DELETE 0x10B
  34. #define IO_KEY_CTRL_BACKSPACE 0x10C
  35. int io_poll_key(void);
  36. /* Same as io_poll_key but also reads port 0x60 when buffer empty (for full-screen programs). */
  37. int io_poll_key_with_hw(void);
  38. /* 1 when the IRQ1 storm guard masked the keyboard; the WM then polls the
  39. controller directly (every few ms) instead of relying on interrupts. */
  40. int io_keyboard_irq_masked(void);
  41. /* Queue a PS/2 set-1 scancode from a non-IRQ source (USB keyboard backend);
  42. it is then decoded by the normal io_poll_key path. */
  43. void io_inject_scancode(unsigned char sc);
  44. /* Raw scancode tap for diagnostics (the `keytest` kernel command). Every
  45. byte fed to the set-1 decoder is recorded with the E0-prefix state, the
  46. make/break/prefix kind and the decoded key (0 when nothing is produced). */
  47. struct io_keytap {
  48. unsigned char raw;
  49. unsigned char ext;
  50. unsigned char kind; /* 0 make, 1 break, 2 0xE0 prefix */
  51. int key;
  52. };
  53. void io_keytap_reset(void);
  54. int io_keytap_read(struct io_keytap *out);
  55. /* While set, the WM stops draining the keyboard ring: an inline command
  56. (e.g. `format`'s confirmation) is polling for keys itself. The WM still
  57. runs and the USB backend still queues scancodes. */
  58. void io_set_raw_keyboard(int on);
  59. int io_keyboard_raw(void);
  60. #endif