mousecmd.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* mouseinfo command: print mouse hardware/protocol info and exit. */
  2. #include "io.h"
  3. #include "mouse.h"
  4. static void put_uint(unsigned int n)
  5. {
  6. char buf[12];
  7. int i = 10;
  8. buf[11] = '\0';
  9. if (n == 0) {
  10. io_putchar('0');
  11. return;
  12. }
  13. while (n && i >= 0) {
  14. buf[i--] = (char)('0' + (n % 10u));
  15. n /= 10u;
  16. }
  17. io_putstr(buf + i + 1);
  18. }
  19. static void put_hex8(unsigned int x)
  20. {
  21. static const char hex[] = "0123456789ABCDEF";
  22. io_putchar(hex[(x >> 4) & 0xF]);
  23. io_putchar(hex[x & 0xF]);
  24. }
  25. void program_mouseinfo_main(void)
  26. {
  27. unsigned int id = mouse_device_id();
  28. io_putstr("mouse present ");
  29. io_putstr(mouse_is_present() ? "yes\n" : "no\n");
  30. if (!mouse_is_present())
  31. return;
  32. io_putstr("mouse id 0x");
  33. put_hex8(id & 0xFFu);
  34. io_putchar('\n');
  35. io_putstr("mouse protocol ");
  36. if (id == 0x03)
  37. io_putstr("intellimouse (wheel)\n");
  38. else if (id == 0x04)
  39. io_putstr("intellimouse explorer (5-button)\n");
  40. else
  41. io_putstr("standard ps/2\n");
  42. io_putstr("mouse packet bytes ");
  43. put_uint((id == 0x03 || id == 0x04) ? 4u : 3u);
  44. io_putchar('\n');
  45. io_putstr("mouse streaming ");
  46. io_putstr(mouse_streaming_enabled() ? "on\n" : "off\n");
  47. io_putstr("mouse cursor ");
  48. io_putstr(mouse_cursor_visible() ? "visible\n" : "hidden\n");
  49. }