io.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #define IO_KEY_ALT_TAB 0x10D /* Alt+Tab (Shift+Alt+Tab is separate) */
  36. #define IO_KEY_ALT_SHIFT_TAB 0x10E
  37. int io_poll_key(void);
  38. /* 1 while either Alt key is held. The WM uses it to end an Alt+Tab
  39. switcher session when Alt is released. */
  40. int io_alt_down(void);
  41. /* Same as io_poll_key but also reads port 0x60 when buffer empty (for full-screen programs). */
  42. int io_poll_key_with_hw(void);
  43. /* 1 when the IRQ1 storm guard masked the keyboard; the WM then polls the
  44. controller directly (every few ms) instead of relying on interrupts. */
  45. int io_keyboard_irq_masked(void);
  46. /* Queue a PS/2 set-1 scancode from a non-IRQ source (USB keyboard backend);
  47. it is then decoded by the normal io_poll_key path. */
  48. void io_inject_scancode(unsigned char sc);
  49. /* Raw scancode tap for diagnostics (the `keytest` kernel command). Every
  50. byte fed to the set-1 decoder is recorded with the E0-prefix state, the
  51. make/break/prefix kind and the decoded key (0 when nothing is produced). */
  52. struct io_keytap {
  53. unsigned char raw;
  54. unsigned char ext;
  55. unsigned char kind; /* 0 make, 1 break, 2 0xE0 prefix */
  56. int key;
  57. };
  58. void io_keytap_reset(void);
  59. int io_keytap_read(struct io_keytap *out);
  60. /* While set, the WM stops draining the keyboard ring: an inline command
  61. (e.g. `format`'s confirmation) is polling for keys itself. The WM still
  62. runs and the USB backend still queues scancodes. */
  63. void io_set_raw_keyboard(int on);
  64. int io_keyboard_raw(void);
  65. #endif