videomode.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #include <efi.h>
  2. #define MAX_RECURSION 6
  3. #define SCREEN_MIN_WIDTH 800
  4. #define SCREEN_MIN_HEIGHT 600
  5. #define STR_SIZE 256
  6. /* mode = a number between 0 and GOP->Mode->MaxMode-1 */
  7. struct sysinfo
  8. {
  9. int gfxMode, fbSize, fbX, fbY;
  10. void *fb;
  11. /* mem map */
  12. };
  13. struct coord
  14. {
  15. int x, y;
  16. };
  17. struct colour
  18. {
  19. uint8_t r, g, b;
  20. };
  21. struct colour white;
  22. /* -------------------------------------------------------------- */
  23. int valid(CHAR16 str[])
  24. {
  25. ...
  26. return 0;
  27. }
  28. int possible(int c)
  29. {
  30. ...
  31. return 0;
  32. }
  33. int numFromStr(CHAR16 str[])
  34. {
  35. int count, i;
  36. count = 0;
  37. i = 0;
  38. do
  39. {
  40. i = (i * 10) + str[count] - '0';
  41. count++;
  42. }
  43. while(str[count] != '\0');
  44. return count;
  45. }
  46. void askForMode(EFI_SYSTEM_TABLE ST, struct sysinfo *si)
  47. {
  48. CHAR16 s[STR_SIZE];
  49. do
  50. {
  51. do
  52. {
  53. do
  54. {
  55. ST->ConOut->OutputString(ST->ConOut,
  56. L"Enter graphics mode:");
  57. ST->ConIn->Input(ST->ConIn, s); wrong???
  58. }
  59. while(!valid(s));
  60. si->gfxMode = numFromStr(s);
  61. }
  62. while(!possible(si->gfxMode));
  63. si->fb = GOP->FramebufferBase;
  64. si->fbSize = GOP->FramebufferSize;
  65. si->fbX = ...;
  66. si->fbY = ...;
  67. }
  68. while(si->fbX < SCREEN_MIN_WIDTH || si->fbY <SCREEN_MIN_HEIGHT);
  69. }
  70. /* -------------------------------------------------------------- */
  71. void sierpinski(struct coord c1, struct coord c2, int step)
  72. {
  73. struct coord targetC1, targetC2, targetC3, c3, rectSize;
  74. int midX, midY, diffX, diffY;
  75. rectSize.x = RECT_X_SIZE;
  76. rectSize.y = RECT_Y_SIZE;
  77. midX = (c1.x + c2.x)/2;
  78. midY = (c1.y + c2.y)/2;
  79. diffX = F*(c2.x - c1.x)/2;
  80. diffY = F*(c2.y - c1.y)/2;
  81. if (step == MAX_RECURSION)
  82. {
  83. c3.x = midX + diffX;
  84. c3.y = midY - diffX;
  85. DrawTriangle(c1, c2, c3);
  86. }
  87. else
  88. {
  89. targetC1.x = midX;
  90. targetC1.y = midY;
  91. targetC2.x = (3 * c1.x + c2.x) / 4 + diffY;
  92. targetC2.y = (3 * c1.y + c2.y) / 4 - diffX;
  93. targetC3.x = (c1.x + 3 * c2.x) / 4 + diffY;
  94. targetC3.y = (c1.y + 3 * c2.y) / 4 - diffX;
  95. sierpinski(c1, targetC1, step+1);
  96. sierpinski(targetC1, c2, step+1);
  97. sierpinski(targetC2, targetC3, step+1);
  98. }
  99. }
  100. void gfxDemo()
  101. {
  102. white.r = 255;
  103. white.g = 255;
  104. white.b = 255;
  105. c1.x = 200;
  106. c1.y = 400;
  107. c2.x = 600;
  108. c2.y = 400;
  109. sierpinski(c1, c2, 0);
  110. }
  111. /* -------------------------------------------------------------- */
  112. EFI_STATUS efi_main(EFI_HANDLE IH, EFI_SYSTEM_TABLE *ST)
  113. {
  114. /* EFI_GUID guid; */
  115. EFI_GRAPHICS_OUTPUT_PROTOCOL GOP;
  116. struct sysinfo sys;
  117. if(EFI_ERROR(ST->BootServices->LocateProtocol(
  118. EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, NULL, GOP)))
  119. {
  120. ST->ConOut->OutputString(ST->ConOut, L"No GOP.\n");
  121. return EFI_UNSUPPORTED;
  122. }
  123. askForMode(ST, &sys);
  124. GOP->SetMode(sys.gfxMode);
  125. /* Framebuffer demo: Sierpinski triangle */
  126. gfxDemo();
  127. /* Endless loop, left after 5 minutes (watchdog timer) */
  128. for(;;){}
  129. /* Never reached. Make the compiler happy */
  130. return EFI_SUCCESS;
  131. }