display.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. if (vga_has_vesa()) {
  44. io_putstr("resolution ");
  45. put_uint(vga_fb_width());
  46. io_putstr(" x ");
  47. put_uint(vga_fb_height());
  48. io_putchar('\n');
  49. io_putstr("color depth ");
  50. put_uint(vga_fb_bpp());
  51. io_putstr(" bpp\n");
  52. io_putstr("pitch ");
  53. put_uint(vga_fb_pitch());
  54. io_putstr(" bytes/line\n");
  55. io_putstr("LFB ");
  56. put_hex((unsigned int)(unsigned long)vga_fb_ptr());
  57. io_putchar('\n');
  58. if (fbtext_active()) {
  59. io_putstr("text ");
  60. put_uint(fbtext_get_cols());
  61. io_putstr(" x ");
  62. put_uint(fbtext_get_rows());
  63. io_putstr(" chars\n");
  64. }
  65. } else {
  66. io_putstr("VESA not available; VGA text ");
  67. put_uint(io_get_cols());
  68. io_putstr(" x ");
  69. put_uint(io_get_rows());
  70. io_putstr(" chars\n");
  71. }
  72. }