io.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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_clear_screen(void);
  17. int io_did_scroll(void); /* returns 1 once after a scroll, then 0 until next scroll */
  18. void io_putchar(char c);
  19. void io_putstr(const char *s);
  20. void io_puthex(unsigned int n); /* print n as 8 hex digits, no 0x prefix */
  21. unsigned int io_get_cursor(void);
  22. void io_set_cursor(unsigned int pos);
  23. void io_cursor_show_block(void);
  24. void io_cursor_hide_block(void);
  25. void io_vga_write(unsigned int pos, unsigned short value);
  26. void io_drain_keyboard(void);
  27. /* Poll keyboard; returns 0 = no key, 1..255 = ASCII, or an IO_KEY_* code. */
  28. #define IO_KEY_CTRL_C 0x03 /* Ctrl+C (ASCII ETX), kills the foreground job */
  29. #define IO_KEY_LEFT 0x100
  30. #define IO_KEY_RIGHT 0x101
  31. #define IO_KEY_UP 0x102
  32. #define IO_KEY_DOWN 0x103
  33. #define IO_KEY_PAGE_UP 0x104
  34. #define IO_KEY_PAGE_DOWN 0x105
  35. #define IO_KEY_HOME 0x106
  36. #define IO_KEY_END 0x107
  37. #define IO_KEY_DELETE 0x108
  38. int io_poll_key(void);
  39. /* Same as io_poll_key but also reads port 0x60 when buffer empty (for full-screen programs). */
  40. int io_poll_key_with_hw(void);
  41. /* 1 when the IRQ1 storm guard masked the keyboard; the WM then polls the
  42. controller directly (every few ms) instead of relying on interrupts. */
  43. int io_keyboard_irq_masked(void);
  44. /* Queue a PS/2 set-1 scancode from a non-IRQ source (USB keyboard backend);
  45. it is then decoded by the normal io_poll_key path. */
  46. void io_inject_scancode(unsigned char sc);
  47. /* While set, the WM stops draining the keyboard ring: an inline command
  48. (e.g. `format`'s confirmation) is polling for keys itself. The WM still
  49. runs and the USB backend still queues scancodes. */
  50. void io_set_raw_keyboard(int on);
  51. int io_keyboard_raw(void);
  52. #endif