display.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* display command: print resolution, color depth, and other graphics info. */
  2. #include "io.h"
  3. #include "vga.h"
  4. #include "fbtext.h"
  5. static void put_uint(unsigned int n)
  6. {
  7. char buf[12];
  8. char *p = buf + sizeof(buf) - 1;
  9. *p = '\0';
  10. if (n == 0) {
  11. io_putchar('0');
  12. return;
  13. }
  14. while (n) {
  15. *--p = (char)('0' + (n % 10));
  16. n /= 10;
  17. }
  18. while (*p)
  19. io_putchar(*p++);
  20. }
  21. static void put_hex(unsigned int n)
  22. {
  23. static const char hex[] = "0123456789ABCDEF";
  24. io_putstr("0x");
  25. if (n == 0) {
  26. io_putchar('0');
  27. return;
  28. }
  29. {
  30. char buf[9];
  31. char *q = buf + 8;
  32. *q = '\0';
  33. while (n) {
  34. *--q = hex[n & 0xF];
  35. n >>= 4;
  36. }
  37. while (*q)
  38. io_putchar(*q++);
  39. }
  40. }
  41. void program_display_main(void)
  42. {
  43. io_putstr("resolution ");
  44. put_uint(vga_fb_width());
  45. io_putstr(" x ");
  46. put_uint(vga_fb_height());
  47. io_putchar('\n');
  48. io_putstr("color depth ");
  49. put_uint(vga_fb_bpp());
  50. io_putstr(" bpp\n");
  51. io_putstr("pitch ");
  52. put_uint(vga_fb_pitch());
  53. io_putstr(" bytes/line\n");
  54. io_putstr("LFB ");
  55. put_hex((unsigned int)(unsigned long)vga_fb_ptr());
  56. io_putchar('\n');
  57. io_putstr("text ");
  58. put_uint(fbtext_get_cols());
  59. io_putstr(" x ");
  60. put_uint(fbtext_get_rows());
  61. io_putstr(" chars\n");
  62. }