Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

271 lines
8.2 KiB

  1. #include "bldrx86.h"
  2. #include "vmode.h"
  3. #include "vga.h"
  4. #define SCREEN_WIDTH (640) /* gfx mode resolution: width */
  5. #define SCREEN_HEIGHT (480) /* gfx mode resolution: height */
  6. #define SCREEN_PIXELS (SCREEN_WIDTH * SCREEN_HEIGHT)
  7. #define VGA_ADR ((UCHAR*)0xA0000) /* beginning of VGA memory */
  8. #define LINE_MEM_LENGTH (SCREEN_WIDTH / 8) /* 1 bit per pixel in every map */
  9. #define MAP_PAGE_SZ (64*1024) /* size of single map */
  10. #define PROGRESS_BAR_MEM_OFS (LINE_MEM_LENGTH * (SCREEN_HEIGHT - 40)) /* starts at 20th line from the bottom */
  11. #define BOOTBMP_FNAME "boot.bmp"
  12. #define DOTSBMP_FNAME "dots.bmp"
  13. BOOLEAN DisplayLogoOnBoot = FALSE;
  14. BOOLEAN GraphicsMode = FALSE;
  15. VOID
  16. GrDisplayMBCSChar(
  17. IN PUCHAR image,
  18. IN unsigned width,
  19. IN UCHAR top,
  20. IN UCHAR bottom
  21. );
  22. extern unsigned CharacterImageHeight;
  23. extern BOOLEAN BlShowProgressBar;
  24. extern int BlMaxFilesToLoad;
  25. extern int BlNumFilesLoaded;
  26. NTLDRGRAPHICSCONTEXT LoaderGfxContext = {0,0L,0L,0L,NULL /*,EINVAL,EINVAL*/};
  27. #define DIAMETER (6)
  28. VOID BlRedrawGfxProgressBar(VOID) // Redraws the progress bar (with the last percentage)
  29. {
  30. if (BlShowProgressBar && BlMaxFilesToLoad) {
  31. BlUpdateProgressBar((BlNumFilesLoaded * 100) / BlMaxFilesToLoad);
  32. }
  33. }
  34. #define BMP_FILE_SIZE (1024*1024)
  35. #define SMALL_BMP_SIZE (1024)
  36. UCHAR empty_circle [SMALL_BMP_SIZE];
  37. UCHAR simple_circle [SMALL_BMP_SIZE];
  38. UCHAR left_2_circles [SMALL_BMP_SIZE];
  39. UCHAR left_3_circles [SMALL_BMP_SIZE];
  40. UCHAR left_4_circles [SMALL_BMP_SIZE];
  41. UCHAR right_2_circles [SMALL_BMP_SIZE];
  42. UCHAR right_3_circles [SMALL_BMP_SIZE];
  43. UCHAR right_4_circles [SMALL_BMP_SIZE];
  44. #define DOT_WIDTH (13)
  45. #define DOT_HEIGHT (13)
  46. #define DOT_BLANK (7)
  47. #define PROGRESS_BAR_Y_OFS (340)
  48. #define PROGRESS_BAR_X_OFS (130)
  49. #define DOTS_IN_PBAR (20)
  50. #define BITS(w) ((w)*4)
  51. #define BYTES(b) (((b)/8)+(((b)%8)?1:0))
  52. #define DOTS(n) (((n)*DOT_WIDTH)+(((n)-1)*DOT_BLANK))
  53. #define DOTS2BYTES(n) (BYTES(BITS(DOTS(n))))
  54. #define SCANLINE (7)
  55. // #define INC_MOD(x) x = (x + 1) % (DOTS_IN_PBAR+5)
  56. #define INC_MOD(x) x = (x + 1)
  57. VOID PrepareGfxProgressBar (VOID)
  58. {
  59. ULONG i=0;
  60. if (DisplayLogoOnBoot) {
  61. PaletteOff ();
  62. /*
  63. VidBitBlt (LoaderGfxContext.DotBuffer + sizeof(BITMAPFILEHEADER), 0, 0);
  64. VidScreenToBufferBlt (simple_circle, 0, 0, DOTS(1), DOT_HEIGHT, DOTS2BYTES(1));
  65. VidScreenToBufferBlt (left_2_circles, 0, 0, DOTS(2), DOT_HEIGHT, DOTS2BYTES(2));
  66. VidScreenToBufferBlt (left_3_circles, 0, 0, DOTS(3), DOT_HEIGHT, DOTS2BYTES(3));
  67. VidScreenToBufferBlt (left_4_circles, 0, 0, DOTS(4), DOT_HEIGHT, DOTS2BYTES(4));
  68. VidScreenToBufferBlt (right_2_circles, 3*(DOT_WIDTH+DOT_BLANK), 0, DOTS(2), DOT_HEIGHT, DOTS2BYTES(2));
  69. VidScreenToBufferBlt (right_3_circles, 2*(DOT_WIDTH+DOT_BLANK), 0, DOTS(3), DOT_HEIGHT, DOTS2BYTES(3));
  70. VidScreenToBufferBlt (right_4_circles, DOT_WIDTH+DOT_BLANK, 0, DOTS(4), DOT_HEIGHT, DOTS2BYTES(4));
  71. */
  72. DrawBitmap ();
  73. // VidScreenToBufferBlt (empty_circle, PROGRESS_BAR_X_OFS, PROGRESS_BAR_Y_OFS, DOTS(1), DOT_HEIGHT, DOTS2BYTES(1));
  74. PaletteOn();
  75. }
  76. }
  77. VOID BlUpdateGfxProgressBar(ULONG fPercentage)
  78. {
  79. static ULONG current = 0;
  80. static ULONG delay = 5;
  81. ULONG i = 0;
  82. ULONG x, xl;
  83. ULONG dots = fPercentage; // (fPercentage * (DOTS_IN_PBAR+5)) / 100;
  84. /*
  85. if (delay && delay--)
  86. return;
  87. if (DisplayLogoOnBoot && (current<(DOTS_IN_PBAR+5))) {
  88. x = PROGRESS_BAR_X_OFS + ((current-5) * (DOT_WIDTH+DOT_BLANK));
  89. switch (current) {
  90. case 0:
  91. VidBufferToScreenBlt (simple_circle, PROGRESS_BAR_X_OFS, PROGRESS_BAR_Y_OFS, DOTS(1), DOT_HEIGHT, DOTS2BYTES(1));
  92. break;
  93. case 1:
  94. VidBufferToScreenBlt (right_2_circles, PROGRESS_BAR_X_OFS, PROGRESS_BAR_Y_OFS, DOTS(2), DOT_HEIGHT, DOTS2BYTES(2));
  95. break;
  96. case 2:
  97. VidBufferToScreenBlt (right_3_circles, PROGRESS_BAR_X_OFS, PROGRESS_BAR_Y_OFS, DOTS(3), DOT_HEIGHT, DOTS2BYTES(3));
  98. break;
  99. case 3:
  100. VidBufferToScreenBlt (right_4_circles, PROGRESS_BAR_X_OFS, PROGRESS_BAR_Y_OFS, DOTS(4), DOT_HEIGHT, DOTS2BYTES(4));
  101. break;
  102. case DOTS_IN_PBAR:
  103. xl = PROGRESS_BAR_X_OFS + ((DOTS_IN_PBAR-4) * (DOT_WIDTH+DOT_BLANK));
  104. VidBufferToScreenBlt (left_4_circles, xl, PROGRESS_BAR_Y_OFS, DOTS(4), DOT_HEIGHT, DOTS2BYTES(4));
  105. VidBufferToScreenBlt (empty_circle, x, PROGRESS_BAR_Y_OFS, DOTS(1), DOT_HEIGHT, DOTS2BYTES(1));
  106. break;
  107. case DOTS_IN_PBAR+1:
  108. xl = PROGRESS_BAR_X_OFS + ((DOTS_IN_PBAR-3) * (DOT_WIDTH+DOT_BLANK));
  109. VidBufferToScreenBlt (left_3_circles, xl, PROGRESS_BAR_Y_OFS, DOTS(3), DOT_HEIGHT, DOTS2BYTES(3));
  110. VidBufferToScreenBlt (empty_circle, x, PROGRESS_BAR_Y_OFS, DOTS(1), DOT_HEIGHT, DOTS2BYTES(1));
  111. break;
  112. case DOTS_IN_PBAR+2:
  113. xl = PROGRESS_BAR_X_OFS + ((DOTS_IN_PBAR-2) * (DOT_WIDTH+DOT_BLANK));
  114. VidBufferToScreenBlt (left_2_circles, xl, PROGRESS_BAR_Y_OFS, DOTS(2), DOT_HEIGHT, DOTS2BYTES(2));
  115. VidBufferToScreenBlt (empty_circle, x, PROGRESS_BAR_Y_OFS, DOTS(1), DOT_HEIGHT, DOTS2BYTES(1));
  116. break;
  117. case DOTS_IN_PBAR+3:
  118. xl = PROGRESS_BAR_X_OFS + ((DOTS_IN_PBAR-1) * (DOT_WIDTH+DOT_BLANK));
  119. VidBufferToScreenBlt (simple_circle, xl, PROGRESS_BAR_Y_OFS, DOTS(1), DOT_HEIGHT, DOTS2BYTES(1));
  120. VidBufferToScreenBlt (empty_circle, x, PROGRESS_BAR_Y_OFS, DOTS(1), DOT_HEIGHT, DOTS2BYTES(1));
  121. break;
  122. case DOTS_IN_PBAR+4:
  123. VidBufferToScreenBlt (empty_circle, x, PROGRESS_BAR_Y_OFS, DOTS(1), DOT_HEIGHT, DOTS2BYTES(1));
  124. break;
  125. default:
  126. xl = PROGRESS_BAR_X_OFS + ((current-4) * (DOT_WIDTH+DOT_BLANK));
  127. VidBitBlt (LoaderGfxContext.DotBuffer + sizeof(BITMAPFILEHEADER), xl, PROGRESS_BAR_Y_OFS);
  128. VidBufferToScreenBlt (empty_circle, x, PROGRESS_BAR_Y_OFS, DOTS(1), DOT_HEIGHT, DOTS2BYTES(1));
  129. break;
  130. }
  131. INC_MOD(current);
  132. }
  133. */
  134. }
  135. PUCHAR LoadBitmapFile (IN ULONG DriveId, PCHAR path)
  136. {
  137. ULONG bmp_file = -1;
  138. ULONG file_size, size_read, page_count, actual_base;
  139. FILE_INFORMATION FileInfo;
  140. ARC_STATUS status = EINVAL;
  141. PUCHAR buffer = NULL;
  142. status = BlOpen (DriveId, path, ArcOpenReadOnly, &bmp_file);
  143. if (status==ESUCCESS) { // file opened Ok
  144. status = BlGetFileInformation(bmp_file, &FileInfo);
  145. if (status == ESUCCESS) {
  146. file_size = FileInfo.EndingAddress.LowPart;
  147. page_count = (ULONG)(ROUND_TO_PAGES(file_size) >> PAGE_SHIFT);
  148. status = BlAllocateDescriptor ( MemoryFirmwareTemporary,
  149. 0,
  150. page_count,
  151. &actual_base);
  152. if (status == ESUCCESS) {
  153. buffer = (PCHAR)((ULONG_PTR)actual_base << PAGE_SHIFT);
  154. status = BlRead(bmp_file, buffer, file_size, &size_read);
  155. }
  156. } // getting file information
  157. BlClose(bmp_file);
  158. } // file opening
  159. return buffer;
  160. }
  161. VOID PaletteOff (VOID)
  162. {
  163. if (DisplayLogoOnBoot) {
  164. InitPaletteConversionTable();
  165. InitPaletteWithBlack ();
  166. }
  167. }
  168. VOID PaletteOn (VOID)
  169. {
  170. if (DisplayLogoOnBoot) {
  171. InitPaletteConversionTable();
  172. InitPaletteWithTable(LoaderGfxContext.Palette, LoaderGfxContext.ColorsUsed);
  173. }
  174. }
  175. VOID LoadBootLogoBitmap (IN ULONG DriveId, PCHAR path) // Loads ntldr bitmap and initializes
  176. { // loader graphics context.
  177. PBITMAPINFOHEADER bih;
  178. CHAR path_fname [256];
  179. while (*path !='\\')
  180. path++;
  181. strcpy (path_fname, path);
  182. strcat (path_fname, "\\" BOOTBMP_FNAME);
  183. LoaderGfxContext.BmpBuffer = LoadBitmapFile (DriveId, path_fname);
  184. // read bitmap palette
  185. if (LoaderGfxContext.BmpBuffer != NULL) { // bitmap data read Ok
  186. bih = (PBITMAPINFOHEADER) (LoaderGfxContext.BmpBuffer + sizeof(BITMAPFILEHEADER));
  187. LoaderGfxContext.Palette = (PRGBQUAD)(((PUCHAR)bih) + bih->biSize);
  188. LoaderGfxContext.ColorsUsed = bih->biClrUsed ? bih->biClrUsed : 16;
  189. /*
  190. strcpy (path_fname, path);
  191. strcat (path_fname, "\\" DOTSBMP_FNAME);
  192. LoaderGfxContext.DotBuffer = LoadBitmapFile (DriveId, path_fname);
  193. */
  194. }
  195. DisplayLogoOnBoot = (LoaderGfxContext.BmpBuffer!=NULL) &&
  196. // (LoaderGfxContext.DotBuffer!=NULL) &&
  197. (LoaderGfxContext.Palette!=NULL);
  198. }
  199. VOID DrawBitmap (VOID)
  200. {
  201. if (DisplayLogoOnBoot)
  202. VidBitBlt (LoaderGfxContext.BmpBuffer + sizeof(BITMAPFILEHEADER), 0, 0);
  203. }