io.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 IO_KEY_LEFT/IO_KEY_RIGHT/IO_KEY_UP/IO_KEY_DOWN. */
  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. int io_poll_key(void);
  34. /* Same as io_poll_key but also reads port 0x60 when buffer empty (for full-screen programs). */
  35. int io_poll_key_with_hw(void);
  36. /* 1 when the IRQ1 storm guard masked the keyboard; the WM then polls the
  37. controller directly (every few ms) instead of relying on interrupts. */
  38. int io_keyboard_irq_masked(void);
  39. /* Queue a PS/2 set-1 scancode from a non-IRQ source (USB keyboard backend);
  40. it is then decoded by the normal io_poll_key path. */
  41. void io_inject_scancode(unsigned char sc);
  42. /* While set, the WM stops draining the keyboard ring: an inline command
  43. (e.g. `format`'s confirmation) is polling for keys itself. The WM still
  44. runs and the USB backend still queues scancodes. */
  45. void io_set_raw_keyboard(int on);
  46. int io_keyboard_raw(void);
  47. #endif