ReactOS  0.4.14-dev-843-g15bc263
vga.c
Go to the documentation of this file.
1 #include "precomp.h"
2 
3 /* GLOBALS *******************************************************************/
4 
5 static ULONG ScrollRegion[4] =
6 {
7  0,
8  0,
9  SCREEN_WIDTH - 1,
10  SCREEN_HEIGHT - 1
11 };
12 static UCHAR lMaskTable[8] =
13 {
14  (1 << 8) - (1 << 0),
15  (1 << 7) - (1 << 0),
16  (1 << 6) - (1 << 0),
17  (1 << 5) - (1 << 0),
18  (1 << 4) - (1 << 0),
19  (1 << 3) - (1 << 0),
20  (1 << 2) - (1 << 0),
21  (1 << 1) - (1 << 0)
22 };
23 static UCHAR rMaskTable[8] =
24 {
25  (1 << 7),
26  (1 << 7) + (1 << 6),
27  (1 << 7) + (1 << 6) + (1 << 5),
28  (1 << 7) + (1 << 6) + (1 << 5) + (1 << 4),
29  (1 << 7) + (1 << 6) + (1 << 5) + (1 << 4) + (1 << 3),
30  (1 << 7) + (1 << 6) + (1 << 5) + (1 << 4) + (1 << 3) + (1 << 2),
31  (1 << 7) + (1 << 6) + (1 << 5) + (1 << 4) + (1 << 3) + (1 << 2) + (1 << 1),
32  (1 << 7) + (1 << 6) + (1 << 5) + (1 << 4) + (1 << 3) + (1 << 2) + (1 << 1) + (1 << 0),
33 };
35 {
36  (1 << 7),
37  (1 << 6),
38  (1 << 5),
39  (1 << 4),
40  (1 << 3),
41  (1 << 2),
42  (1 << 1),
43  (1 << 0),
44 };
45 static ULONG lookup[16] =
46 {
47  0x0000,
48  0x0100,
49  0x1000,
50  0x1100,
51  0x0001,
52  0x0101,
53  0x1001,
54  0x1101,
55  0x0010,
56  0x0110,
57  0x1010,
58  0x1110,
59  0x0011,
60  0x0111,
61  0x1011,
62  0x1111,
63 };
64 
69 static ULONG VidTextColor = 0xF;
71 
72 /* PRIVATE FUNCTIONS *********************************************************/
73 
74 static VOID
75 NTAPI
77 {
78  UCHAR Value;
79 
80  /* Switch to graphics mode register */
82 
83  /* Get the current register value, minus the current mode */
85 
86  /* Set the new mode */
88 }
89 
90 static VOID
92 {
93  /* Switch to mode 10 */
94  ReadWriteMode(10);
95 
96  /* Clear the 4 planes (we're already in unchained mode here) */
98 
99  /* Select the color don't care register */
101 }
102 
104 VOID
106  IN ULONG Top,
107  IN UCHAR Color)
108 {
109  PUCHAR PixelPosition;
110 
111  /* Calculate the pixel position */
112  PixelPosition = (PUCHAR)(VgaBase + (Left >> 3) + (Top * (SCREEN_WIDTH / 8)));
113 
114  /* Select the bitmask register and write the mask */
116 
117  /* Read the current pixel value and add our color */
118  WRITE_REGISTER_UCHAR(PixelPosition, READ_REGISTER_UCHAR(PixelPosition) & Color);
119 }
120 
121 #define SET_PIXELS(_PixelPtr, _PixelMask, _TextColor) \
122 do { \
123  /* Select the bitmask register and write the mask */ \
124  __outpw(VGA_BASE_IO_PORT + GRAPH_ADDRESS_PORT, ((_PixelMask) << 8) | IND_BIT_MASK); \
125  /* Set the new color */ \
126  WRITE_REGISTER_UCHAR((_PixelPtr), (UCHAR)(_TextColor)); \
127 } while (0);
128 
129 #ifdef CHAR_GEN_UPSIDE_DOWN
130 # define GetFontPtr(_Char) &FontData[_Char * BOOTCHAR_HEIGHT] + BOOTCHAR_HEIGHT - 1;
131 # define FONT_PTR_DELTA (-1)
132 #else
133 # define GetFontPtr(_Char) &FontData[_Char * BOOTCHAR_HEIGHT];
134 # define FONT_PTR_DELTA (1)
135 #endif
136 
137 static VOID
138 NTAPI
140  IN ULONG Left,
141  IN ULONG Top,
142  IN ULONG TextColor,
143  IN ULONG BackColor)
144 {
145  PUCHAR FontChar, PixelPtr;
146  ULONG Height;
147  UCHAR Shift;
148 
150 
151  /* Calculate shift */
152  Shift = Left & 7;
153 
154  /* Get the font and pixel pointer */
155  FontChar = GetFontPtr(Character);
156  PixelPtr = (PUCHAR)(VgaBase + (Left >> 3) + (Top * (SCREEN_WIDTH / 8)));
157 
158  /* Loop all pixel rows */
159  for (Height = BOOTCHAR_HEIGHT; Height > 0; --Height)
160  {
161  SET_PIXELS(PixelPtr, *FontChar >> Shift, TextColor);
162  PixelPtr += (SCREEN_WIDTH / 8);
163  FontChar += FONT_PTR_DELTA;
164  }
165 
166  /* Check if we need to update neighbor bytes */
167  if (Shift)
168  {
169  /* Calculate shift for 2nd byte */
170  Shift = 8 - Shift;
171 
172  /* Get the font and pixel pointer (2nd byte) */
173  FontChar = GetFontPtr(Character);
174  PixelPtr = (PUCHAR)(VgaBase + (Left >> 3) + (Top * (SCREEN_WIDTH / 8)) + 1);
175 
176  /* Loop all pixel rows */
177  for (Height = BOOTCHAR_HEIGHT; Height > 0; --Height)
178  {
179  SET_PIXELS(PixelPtr, *FontChar << Shift, TextColor);
180  PixelPtr += (SCREEN_WIDTH / 8);
181  FontChar += FONT_PTR_DELTA;
182  }
183  }
184 
185  /* Check if the background color is transparent */
186  if (BackColor >= 16)
187  {
188  /* We are done */
189  return;
190  }
191 
192  /* Calculate shift */
193  Shift = Left & 7;
194 
195  /* Get the font and pixel pointer */
196  FontChar = GetFontPtr(Character);
197  PixelPtr = (PUCHAR)(VgaBase + (Left >> 3) + (Top * (SCREEN_WIDTH / 8)));
198 
199  /* Loop all pixel rows */
200  for (Height = BOOTCHAR_HEIGHT; Height > 0; --Height)
201  {
202  SET_PIXELS(PixelPtr, ~*FontChar >> Shift, BackColor);
203  PixelPtr += (SCREEN_WIDTH / 8);
204  FontChar += FONT_PTR_DELTA;
205  }
206 
207  /* Check if we need to update neighbor bytes */
208  if (Shift)
209  {
210  /* Calculate shift for 2nd byte */
211  Shift = 8 - Shift;
212 
213  /* Get the font and pixel pointer (2nd byte) */
214  FontChar = GetFontPtr(Character);
215  PixelPtr = (PUCHAR)(VgaBase + (Left >> 3) + (Top * (SCREEN_WIDTH / 8)) + 1);
216 
217  /* Loop all pixel rows */
218  for (Height = BOOTCHAR_HEIGHT; Height > 0; --Height)
219  {
220  SET_PIXELS(PixelPtr, ~*FontChar << Shift, BackColor);
221  PixelPtr += (SCREEN_WIDTH / 8);
222  FontChar += FONT_PTR_DELTA;
223  }
224  }
225 }
226 
227 static VOID
228 NTAPI
230  IN ULONG Left,
231  IN ULONG Top,
232  IN ULONG TextColor,
233  IN ULONG BackColor)
234 {
235  /* Loop every character and adjust the position */
236  for (; *String; ++String, Left += 8)
237  {
238  /* Display a character */
239  DisplayCharacter(*String, Left, Top, TextColor, BackColor);
240  }
241 }
242 
243 static VOID
244 NTAPI
246  IN ULONG Rgb)
247 {
248  PCHAR Colors = (PCHAR)&Rgb;
249 
250  /* Set the palette index */
252 
253  /* Set RGB colors */
257 }
258 
259 static VOID
260 NTAPI
262  IN ULONG Count)
263 {
264  ULONG i;
265  PULONG Entry = Table;
266 
267  /* Loop every entry */
268  for (i = 0; i < Count; i++, Entry++)
269  {
270  /* Set the entry */
272  }
273 }
274 
275 static VOID
276 NTAPI
278  IN ULONG PaletteEntry)
279 {
280  /* Set the palette index */
282 
283  /* Set RGB colors */
284  __outpb(VGA_BASE_IO_PORT + DAC_DATA_REG_PORT, PaletteEntry & 0xFF);
285  __outpb(VGA_BASE_IO_PORT + DAC_DATA_REG_PORT, (PaletteEntry >>= 8) & 0xFF);
286  __outpb(VGA_BASE_IO_PORT + DAC_DATA_REG_PORT, (PaletteEntry >> 8) & 0xFF);
287 }
288 
289 VOID
290 NTAPI
292 {
293  ULONG PaletteEntry[16] = {0x000000,
294  0x000020,
295  0x002000,
296  0x002020,
297  0x200000,
298  0x200020,
299  0x202000,
300  0x202020,
301  0x303030,
302  0x00003F,
303  0x003F00,
304  0x003F3F,
305  0x3F0000,
306  0x3F003F,
307  0x3F3F00,
308  0x3F3F3F};
309  ULONG i;
310 
311  /* Loop all the entries and set their palettes */
312  for (i = 0; i < 16; i++) SetPaletteEntry(i, PaletteEntry[i]);
313 }
314 
315 static VOID
316 NTAPI
318 {
319  ULONG Top, RowSize;
320  PUCHAR OldPosition, NewPosition;
321 
322  /* Clear the 4 planes */
324 
325  /* Set the bitmask to 0xFF for all 4 planes */
327 
328  /* Set Mode 1 */
329  ReadWriteMode(1);
330 
331  RowSize = (ScrollRegion[2] - ScrollRegion[0] + 1) / 8;
332 
333  /* Calculate the position in memory for the row */
334  OldPosition = (PUCHAR)(VgaBase + (ScrollRegion[1] + Scroll) * (SCREEN_WIDTH / 8) + ScrollRegion[0] / 8);
335  NewPosition = (PUCHAR)(VgaBase + ScrollRegion[1] * (SCREEN_WIDTH / 8) + ScrollRegion[0] / 8);
336 
337  /* Start loop */
338  for (Top = ScrollRegion[1]; Top <= ScrollRegion[3]; ++Top)
339  {
340 #if defined(_M_IX86) || defined(_M_AMD64)
341  __movsb(NewPosition, OldPosition, RowSize);
342 #else
343  ULONG i;
344 
345  /* Scroll the row */
346  for (i = 0; i < RowSize; ++i)
347  WRITE_REGISTER_UCHAR(NewPosition + i, READ_REGISTER_UCHAR(OldPosition + i));
348 #endif
349  OldPosition += (SCREEN_WIDTH / 8);
350  NewPosition += (SCREEN_WIDTH / 8);
351  }
352 }
353 
354 static VOID
355 NTAPI
356 PreserveRow(IN ULONG CurrentTop,
357  IN ULONG TopDelta,
358  IN BOOLEAN Restore)
359 {
360  PUCHAR Position1, Position2;
361  ULONG Count;
362 
363  /* Clear the 4 planes */
365 
366  /* Set the bitmask to 0xFF for all 4 planes */
368 
369  /* Set Mode 1 */
370  ReadWriteMode(1);
371 
372  /* Calculate the position in memory for the row */
373  if (Restore)
374  {
375  /* Restore the row by copying back the contents saved off-screen */
376  Position1 = (PUCHAR)(VgaBase + CurrentTop * (SCREEN_WIDTH / 8));
377  Position2 = (PUCHAR)(VgaBase + SCREEN_HEIGHT * (SCREEN_WIDTH / 8));
378  }
379  else
380  {
381  /* Preserve the row by saving its contents off-screen */
382  Position1 = (PUCHAR)(VgaBase + SCREEN_HEIGHT * (SCREEN_WIDTH / 8));
383  Position2 = (PUCHAR)(VgaBase + CurrentTop * (SCREEN_WIDTH / 8));
384  }
385 
386  /* Set the count and loop every pixel */
387  Count = TopDelta * (SCREEN_WIDTH / 8);
388 #if defined(_M_IX86) || defined(_M_AMD64)
389  __movsb(Position1, Position2, Count);
390 #else
391  while (Count--)
392  {
393  /* Write the data back on the other position */
394  WRITE_REGISTER_UCHAR(Position1, READ_REGISTER_UCHAR(Position2));
395 
396  /* Increase both positions */
397  Position1++;
398  Position2++;
399  }
400 #endif
401 }
402 
403 static VOID
404 NTAPI
406  IN ULONG Top,
407  IN ULONG Width,
408  IN ULONG Height,
409  IN PUCHAR Buffer,
410  IN ULONG BitsPerPixel,
411  IN ULONG Delta)
412 {
413  ULONG sx, dx, dy;
414  UCHAR color;
415  ULONG offset = 0;
416  const ULONG Bottom = Top + Height;
417  const ULONG Right = Left + Width;
418 
419  /* Check if the buffer isn't 4bpp */
420  if (BitsPerPixel != 4)
421  {
422  /* FIXME: TODO */
423  DbgPrint("Unhandled BitBlt\n"
424  "%lux%lu @ (%lu|%lu)\n"
425  "Bits Per Pixel %lu\n"
426  "Buffer: %p. Delta: %lu\n",
427  Width,
428  Height,
429  Left,
430  Top,
431  BitsPerPixel,
432  Buffer,
433  Delta);
434  return;
435  }
436 
438 
439  /* 4bpp blitting */
440  for (dy = Top; dy < Bottom; ++dy)
441  {
442  sx = 0;
443  do
444  {
445  /* Extract color */
446  color = Buffer[offset + sx];
447 
448  /* Calc destination x */
449  dx = Left + (sx << 1);
450 
451  /* Set two pixels */
452  SetPixel(dx, dy, color >> 4);
453  SetPixel(dx + 1, dy, color & 0x0F);
454 
455  sx++;
456  } while (dx < Right);
457  offset += Delta;
458  }
459 }
460 
461 static VOID
462 NTAPI
464  IN ULONG Top,
465  IN ULONG Width,
466  IN ULONG Height,
467  IN PUCHAR Buffer)
468 {
469  ULONG YDelta;
470  ULONG x;
471  ULONG RleValue, NewRleValue;
472  ULONG Color, Color2;
473  ULONG i, j;
474  ULONG Code;
475 
477 
478  /* Set Y height and current X value and start loop */
479  YDelta = Top + Height - 1;
480  x = Left;
481  for (;;)
482  {
483  /* Get the current value and advance in the buffer */
484  RleValue = *Buffer;
485  Buffer++;
486  if (RleValue)
487  {
488  /* Check if we've gone past the edge */
489  if ((x + RleValue) > (Width + Left))
490  {
491  /* Fixup the pixel value */
492  RleValue = Left - x + Width;
493  }
494 
495  /* Get the new value */
496  NewRleValue = *Buffer;
497 
498  /* Get the two colors */
499  Color = NewRleValue >> 4;
500  Color2 = NewRleValue & 0xF;
501 
502  /* Increase buffer position */
503  Buffer++;
504 
505  /* Check if we need to do a fill */
506  if (Color == Color2)
507  {
508  /* Do a fill and continue the loop */
509  RleValue += x;
510  VidSolidColorFill(x, YDelta, RleValue - 1, YDelta, (UCHAR)Color);
511  x = RleValue;
512  continue;
513  }
514 
515  /* Check if the pixel value is 1 or below */
516  if (RleValue > 1)
517  {
518  /* Set loop variables */
519  for (i = (RleValue - 2) / 2 + 1; i > 0; --i)
520  {
521  /* Set the pixels */
522  SetPixel(x, YDelta, (UCHAR)Color);
523  x++;
524  SetPixel(x, YDelta, (UCHAR)Color2);
525  x++;
526 
527  /* Decrease pixel value */
528  RleValue -= 2;
529  }
530  }
531 
532  /* Check if there is any value at all */
533  if (RleValue)
534  {
535  /* Set the pixel and increase position */
536  SetPixel(x, YDelta, (UCHAR)Color);
537  x++;
538  }
539 
540  /* Start over */
541  continue;
542  }
543 
544  /* Get the current pixel value */
545  RleValue = *Buffer;
546  Code = RleValue;
547  switch (Code)
548  {
549  /* Case 0 */
550  case 0:
551  {
552  /* Set new x value, decrease distance and restart */
553  x = Left;
554  YDelta--;
555  Buffer++;
556  continue;
557  }
558 
559  /* Case 1 */
560  case 1:
561  {
562  /* Done */
563  return;
564  }
565 
566  /* Case 2 */
567  case 2:
568  {
569  /* Set new x value, decrease distance and restart */
570  Buffer++;
571  x += *Buffer;
572  Buffer++;
573  YDelta -= *Buffer;
574  Buffer++;
575  continue;
576  }
577 
578  /* Other values */
579  default:
580  {
581  Buffer++;
582  break;
583  }
584  }
585 
586  /* Check if we've gone past the edge */
587  if ((x + RleValue) > (Width + Left))
588  {
589  /* Set fixed up loop count */
590  i = RleValue - Left - Width + x;
591 
592  /* Fixup pixel value */
593  RleValue -= i;
594  }
595  else
596  {
597  /* Clear loop count */
598  i = 0;
599  }
600 
601  /* Check the value now */
602  if (RleValue > 1)
603  {
604  /* Set loop variables */
605  for (j = (RleValue - 2) / 2 + 1; j > 0; --j)
606  {
607  /* Get the new value */
608  NewRleValue = *Buffer;
609 
610  /* Get the two colors */
611  Color = NewRleValue >> 4;
612  Color2 = NewRleValue & 0xF;
613 
614  /* Increase buffer position */
615  Buffer++;
616 
617  /* Set the pixels */
618  SetPixel(x, YDelta, (UCHAR)Color);
619  x++;
620  SetPixel(x, YDelta, (UCHAR)Color2);
621  x++;
622 
623  /* Decrease pixel value */
624  RleValue -= 2;
625  }
626  }
627 
628  /* Check if there is any value at all */
629  if (RleValue)
630  {
631  /* Set the pixel and increase position */
632  Color = *Buffer >> 4;
633  Buffer++;
634  SetPixel(x, YDelta, (UCHAR)Color);
635  x++;
636  i--;
637  }
638 
639  /* Check loop count now */
640  if ((LONG)i > 0)
641  {
642  /* Decrease it */
643  i--;
644 
645  /* Set new position */
646  Buffer = Buffer + (i / 2) + 1;
647  }
648 
649  /* Check if we need to increase the buffer */
650  if ((ULONG_PTR)Buffer & 1) Buffer++;
651  }
652 }
653 
654 /* PUBLIC FUNCTIONS **********************************************************/
655 
656 /*
657  * @implemented
658  */
659 ULONG
660 NTAPI
662 {
663  ULONG OldColor;
664 
665  /* Save the old color and set the new one */
666  OldColor = VidTextColor;
668  return OldColor;
669 }
670 
671 /*
672  * @implemented
673  */
674 VOID
675 NTAPI
677  IN ULONG Left,
678  IN ULONG Top,
679  IN BOOLEAN Transparent)
680 {
681  ULONG BackColor;
682 
683  /*
684  * If the caller wanted transparent, then send the special value (16),
685  * else use our default and call the helper routine.
686  */
687  BackColor = Transparent ? 16 : 14;
688  DisplayStringXY(String, Left, Top, 12, BackColor);
689 }
690 
691 /*
692  * @implemented
693  */
694 VOID
695 NTAPI
697  IN ULONG Top,
698  IN ULONG Right,
699  IN ULONG Bottom)
700 {
701  /* Assert alignment */
702  ASSERT((Left & 0x7) == 0);
703  ASSERT((Right & 0x7) == 7);
704 
705  /* Set Scroll Region */
706  ScrollRegion[0] = Left;
707  ScrollRegion[1] = Top;
708  ScrollRegion[2] = Right;
709  ScrollRegion[3] = Bottom;
710 
711  /* Set current X and Y */
712  curr_x = Left;
713  curr_y = Top;
714 }
715 
716 /*
717  * @implemented
718  */
719 VOID
720 NTAPI
722 {
723  /* Select bit mask register and clear it */
726 }
727 
728 /*
729  * @implemented
730  */
731 VOID
732 NTAPI
734  IN ULONG Left,
735  IN ULONG Top,
736  IN ULONG Width,
737  IN ULONG Height,
738  IN ULONG Delta)
739 {
740  /* Make sure we have a width and height */
741  if (!Width || !Height) return;
742 
743  /* Call the helper function */
744  BitBlt(Left, Top, Width, Height, Buffer, 4, Delta);
745 }
746 
747 /*
748  * @implemented
749  */
750 VOID
751 NTAPI
753 {
754  ULONG TopDelta = BOOTCHAR_HEIGHT + 1;
755 
756  /* Start looping the string */
757  for (; *String; ++String)
758  {
759  /* Treat new-line separately */
760  if (*String == '\n')
761  {
762  /* Modify Y position */
763  curr_y += TopDelta;
764  if (curr_y + TopDelta - 1 > ScrollRegion[3])
765  {
766  /* Scroll the view and clear the current row */
767  VgaScroll(TopDelta);
768  curr_y -= TopDelta;
769  PreserveRow(curr_y, TopDelta, TRUE);
770  }
771  else
772  {
773  /* Preserve the current row */
774  PreserveRow(curr_y, TopDelta, FALSE);
775  }
776 
777  /* Update current X */
778  curr_x = ScrollRegion[0];
779 
780  /* No need to clear this row */
781  ClearRow = FALSE;
782  }
783  else if (*String == '\r')
784  {
785  /* Update current X */
786  curr_x = ScrollRegion[0];
787 
788  /* If a new-line does not follow we will clear the current row */
789  if (String[1] != '\n') ClearRow = TRUE;
790  }
791  else
792  {
793  /* Clear the current row if we had a return-carriage without a new-line */
794  if (ClearRow)
795  {
796  PreserveRow(curr_y, TopDelta, TRUE);
797  ClearRow = FALSE;
798  }
799 
800  /* Display this character */
802  curr_x += 8;
803 
804  /* Check if we should scroll */
805  if (curr_x + 7 > ScrollRegion[2])
806  {
807  /* Update Y position and check if we should scroll it */
808  curr_y += TopDelta;
809  if (curr_y + TopDelta - 1 > ScrollRegion[3])
810  {
811  /* Scroll the view and clear the current row */
812  VgaScroll(TopDelta);
813  curr_y -= TopDelta;
814  PreserveRow(curr_y, TopDelta, TRUE);
815  }
816  else
817  {
818  /* Preserve the current row */
819  PreserveRow(curr_y, TopDelta, FALSE);
820  }
821 
822  /* Update current X */
823  curr_x = ScrollRegion[0];
824  }
825  }
826  }
827 }
828 
829 /*
830  * @implemented
831  */
832 VOID
833 NTAPI
835  IN ULONG Left,
836  IN ULONG Top)
837 {
838  PBITMAPINFOHEADER BitmapInfoHeader;
839  LONG Delta;
840  PUCHAR BitmapOffset;
841 
842  /* Get the Bitmap Header */
843  BitmapInfoHeader = (PBITMAPINFOHEADER)Buffer;
844 
845  /* Initialize the palette */
846  InitPaletteWithTable((PULONG)(Buffer + BitmapInfoHeader->biSize),
847  (BitmapInfoHeader->biClrUsed) ?
848  BitmapInfoHeader->biClrUsed : 16);
849 
850  /* Make sure we can support this bitmap */
851  ASSERT((BitmapInfoHeader->biBitCount * BitmapInfoHeader->biPlanes) <= 4);
852 
853  /*
854  * Calculate the delta and align it on 32-bytes, then calculate
855  * the actual start of the bitmap data.
856  */
857  Delta = (BitmapInfoHeader->biBitCount * BitmapInfoHeader->biWidth) + 31;
858  Delta >>= 3;
859  Delta &= ~3;
860  BitmapOffset = Buffer + sizeof(BITMAPINFOHEADER) + 16 * sizeof(ULONG);
861 
862  /* Check the compression of the bitmap */
863  if (BitmapInfoHeader->biCompression == BI_RLE4)
864  {
865  /* Make sure we have a width and a height */
866  if ((BitmapInfoHeader->biWidth) && (BitmapInfoHeader->biHeight))
867  {
868  /* We can use RLE Bit Blt */
869  RleBitBlt(Left,
870  Top,
871  BitmapInfoHeader->biWidth,
872  BitmapInfoHeader->biHeight,
873  BitmapOffset);
874  }
875  }
876  else
877  {
878  /* Check if the height is negative */
879  if (BitmapInfoHeader->biHeight < 0)
880  {
881  /* Make it positive in the header */
882  BitmapInfoHeader->biHeight *= -1;
883  }
884  else
885  {
886  /* Update buffer offset */
887  BitmapOffset += ((BitmapInfoHeader->biHeight - 1) * Delta);
888  Delta *= -1;
889  }
890 
891  /* Make sure we have a width and a height */
892  if ((BitmapInfoHeader->biWidth) && (BitmapInfoHeader->biHeight))
893  {
894  /* Do the BitBlt */
895  BitBlt(Left,
896  Top,
897  BitmapInfoHeader->biWidth,
898  BitmapInfoHeader->biHeight,
899  BitmapOffset,
900  BitmapInfoHeader->biBitCount,
901  Delta);
902  }
903  }
904 }
905 
906 /*
907  * @implemented
908  */
909 VOID
910 NTAPI
912  IN ULONG Left,
913  IN ULONG Top,
914  IN ULONG Width,
915  IN ULONG Height,
916  IN ULONG Delta)
917 {
918  ULONG Plane;
919  ULONG XDistance;
920  ULONG LeftDelta, RightDelta;
921  ULONG PixelOffset;
922  PUCHAR PixelPosition;
923  PUCHAR k, i;
924  PULONG m;
925  UCHAR Value, Value2;
926  UCHAR a;
927  ULONG b;
928  ULONG x, y;
929 
930  /* Calculate total distance to copy on X */
931  XDistance = Left + Width - 1;
932 
933  /* Calculate the 8-byte left and right deltas */
934  LeftDelta = Left & 7;
935  RightDelta = 8 - LeftDelta;
936 
937  /* Clear the destination buffer */
938  RtlZeroMemory(Buffer, Delta * Height);
939 
940  /* Calculate the pixel offset and convert the X distance into byte form */
941  PixelOffset = Top * (SCREEN_WIDTH / 8) + (Left >> 3);
942  XDistance >>= 3;
943 
944  /* Loop the 4 planes */
945  for (Plane = 0; Plane < 4; ++Plane)
946  {
947  /* Set the current pixel position and reset buffer loop variable */
948  PixelPosition = (PUCHAR)(VgaBase + PixelOffset);
949  i = Buffer;
950 
951  /* Set Mode 0 */
952  ReadWriteMode(0);
953 
954  /* Set the current plane */
956 
957  /* Start the outer Y height loop */
958  for (y = Height; y > 0; --y)
959  {
960  /* Read the current value */
961  m = (PULONG)i;
962  Value = READ_REGISTER_UCHAR(PixelPosition);
963 
964  /* Set Pixel Position loop variable */
965  k = PixelPosition + 1;
966 
967  /* Check if we're still within bounds */
968  if (Left <= XDistance)
969  {
970  /* Start the X inner loop */
971  for (x = (XDistance - Left) + 1; x > 0; --x)
972  {
973  /* Read the current value */
974  Value2 = READ_REGISTER_UCHAR(k);
975 
976  /* Increase pixel position */
977  k++;
978 
979  /* Do the blt */
980  a = Value2 >> (UCHAR)RightDelta;
981  a |= Value << (UCHAR)LeftDelta;
982  b = lookup[a & 0xF];
983  a >>= 4;
984  b <<= 16;
985  b |= lookup[a];
986 
987  /* Save new value to buffer */
988  *m |= (b << Plane);
989 
990  /* Move to next destination location */
991  m++;
992 
993  /* Write new value */
994  Value = Value2;
995  }
996  }
997 
998  /* Update pixel position */
999  PixelPosition += (SCREEN_WIDTH / 8);
1000  i += Delta;
1001  }
1002  }
1003 }
1004 
1005 /*
1006  * @implemented
1007  */
1008 VOID
1009 NTAPI
1011  IN ULONG Top,
1012  IN ULONG Right,
1013  IN ULONG Bottom,
1014  IN UCHAR Color)
1015 {
1016  ULONG rMask, lMask;
1017  ULONG LeftOffset, RightOffset, Distance;
1018  PUCHAR Offset;
1019  ULONG i, j;
1020 
1021  /* Get the left and right masks, shifts, and delta */
1022  LeftOffset = Left >> 3;
1023  lMask = (lMaskTable[Left & 0x7] << 8) | IND_BIT_MASK;
1024  RightOffset = Right >> 3;
1025  rMask = (rMaskTable[Right & 0x7] << 8) | IND_BIT_MASK;
1026  Distance = RightOffset - LeftOffset;
1027 
1028  /* If there is no distance, then combine the right and left masks */
1029  if (!Distance) lMask &= rMask;
1030 
1032 
1033  /* Calculate pixel position for the read */
1034  Offset = (PUCHAR)(VgaBase + (Top * (SCREEN_WIDTH / 8)) + LeftOffset);
1035 
1036  /* Select the bitmask register and write the mask */
1038 
1039  /* Check if the top coord is below the bottom one */
1040  if (Top <= Bottom)
1041  {
1042  /* Start looping each line */
1043  for (i = (Bottom - Top) + 1; i > 0; --i)
1044  {
1045  /* Read the previous value and add our color */
1047 
1048  /* Move to the next line */
1049  Offset += (SCREEN_WIDTH / 8);
1050  }
1051  }
1052 
1053  /* Check if we have a delta */
1054  if (Distance > 0)
1055  {
1056  /* Calculate new pixel position */
1057  Offset = (PUCHAR)(VgaBase + (Top * (SCREEN_WIDTH / 8)) + RightOffset);
1058  Distance--;
1059 
1060  /* Select the bitmask register and write the mask */
1062 
1063  /* Check if the top coord is below the bottom one */
1064  if (Top <= Bottom)
1065  {
1066  /* Start looping each line */
1067  for (i = (Bottom - Top) + 1; i > 0; --i)
1068  {
1069  /* Read the previous value and add our color */
1071 
1072  /* Move to the next line */
1073  Offset += (SCREEN_WIDTH / 8);
1074  }
1075  }
1076 
1077  /* Check if we still have a delta */
1078  if (Distance > 0)
1079  {
1080  /* Calculate new pixel position */
1081  Offset = (PUCHAR)(VgaBase + (Top * (SCREEN_WIDTH / 8)) + LeftOffset + 1);
1082 
1083  /* Set the bitmask to 0xFF for all 4 planes */
1085 
1086  /* Check if the top coord is below the bottom one */
1087  if (Top <= Bottom)
1088  {
1089  /* Start looping each line */
1090  for (i = (Bottom - Top) + 1; i > 0; --i)
1091  {
1092  /* Loop the shift delta */
1093  for (j = Distance; j > 0; Offset++, --j)
1094  {
1095  /* Write the color */
1097  }
1098 
1099  /* Update position in memory */
1100  Offset += ((SCREEN_WIDTH / 8) - Distance);
1101  }
1102  }
1103  }
1104  }
1105 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2374
signed char * PCHAR
Definition: retypes.h:7
static VOID NTAPI SetPaletteEntryRGB(IN ULONG Id, IN ULONG Rgb)
Definition: vga.c:245
#define IN
Definition: typedefs.h:38
ASMGENDATA Table[]
Definition: genincdata.c:61
#define TRUE
Definition: types.h:120
#define DAC_DATA_REG_PORT
Definition: vga.h:77
static VOID NTAPI VgaScroll(IN ULONG Scroll)
Definition: vga.c:317
static UCHAR rMaskTable[8]
Definition: vga.c:23
USHORT biBitCount
Definition: precomp.h:31
_In_ ULONG Mode
Definition: hubbusif.h:303
VOID NTAPI VidBitBlt(IN PUCHAR Buffer, IN ULONG Left, IN ULONG Top)
Definition: vga.c:834
#define DbgPrint
Definition: loader.c:25
static ULONG VidTextColor
Definition: vga.c:69
VOID NTAPI VidDisplayStringXY(IN PUCHAR String, IN ULONG Left, IN ULONG Top, IN BOOLEAN Transparent)
Definition: vga.c:676
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
#define GetFontPtr(_Char)
Definition: vga.c:133
GLint dy
Definition: linetemp.h:97
unsigned char * PUCHAR
Definition: retypes.h:3
char CHAR
Definition: xmlstorage.h:175
VOID NTAPI VidDisplayString(IN PUCHAR String)
Definition: vga.c:752
GLintptr offset
Definition: glext.h:5920
#define BIT_MASK_DEFAULT
Definition: vga.h:167
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
static ULONG lookup[16]
Definition: vga.c:45
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define DAC_ADDRESS_WRITE_PORT
Definition: vga.h:76
ULONG biCompression
Definition: precomp.h:32
static WCHAR String[]
Definition: stringtable.c:55
static VOID NTAPI BitBlt(IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN PUCHAR Buffer, IN ULONG BitsPerPixel, IN ULONG Delta)
Definition: vga.c:405
#define IND_READ_MAP
Definition: vga.h:111
static VOID NTAPI RleBitBlt(IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN PUCHAR Buffer)
Definition: vga.c:463
const GLfloat * m
Definition: glext.h:10848
struct Color Color
DWORD Id
uint32_t ULONG_PTR
Definition: typedefs.h:63
ULONG_PTR VgaRegisterBase
Definition: vga.c:65
#define SCREEN_HEIGHT
Definition: precomp.h:18
#define BOOTCHAR_HEIGHT
Definition: precomp.h:11
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static VOID NTAPI DisplayStringXY(IN PUCHAR String, IN ULONG Left, IN ULONG Top, IN ULONG TextColor, IN ULONG BackColor)
Definition: vga.c:229
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
struct tagBITMAPINFOHEADER * PBITMAPINFOHEADER
long LONG
Definition: pedump.c:60
GLuint color
Definition: glext.h:6243
#define VGA_BASE_IO_PORT
Definition: vga.h:38
#define a
Definition: ke_i.h:78
#define FONT_PTR_DELTA
Definition: vga.c:134
static VOID PrepareForSetPixel(VOID)
Definition: vga.c:91
unsigned char BOOLEAN
static VOID NTAPI InitPaletteWithTable(IN PULONG Table, IN ULONG Count)
Definition: vga.c:261
#define SET_PIXELS(_PixelPtr, _PixelMask, _TextColor)
Definition: vga.c:121
#define FORCEINLINE
Definition: ntbasedef.h:221
Definition: bufpool.h:45
#define b
Definition: ke_i.h:79
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define PCHAR
Definition: match.c:90
ULONG NTAPI VidSetTextColor(IN ULONG Color)
Definition: vga.c:661
#define Code
Definition: deflate.h:80
FORCEINLINE VOID SetPixel(IN ULONG Left, IN ULONG Top, IN UCHAR Color)
Definition: vga.c:105
PPC_QUAL void __movsb(unsigned char *Destination, const unsigned char *Source, unsigned long Count)
Definition: intrin_ppc.h:323
VOID NTAPI VidCleanUp(VOID)
Definition: vga.c:721
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define IND_BIT_MASK
Definition: vga.h:114
static VOID NTAPI ReadWriteMode(IN UCHAR Mode)
Definition: vga.c:76
VOID NTAPI InitializePalette(VOID)
Definition: vga.c:291
#define GRAPH_ADDRESS_PORT
Definition: vga.h:81
Colors
Definition: ansiprsr.h:4
#define SCREEN_WIDTH
Definition: precomp.h:17
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID NTAPI VidScreenToBufferBlt(IN PUCHAR Buffer, IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN ULONG Delta)
Definition: vga.c:911
#define __inpb(Port)
Definition: precomp.h:59
static VOID NTAPI SetPaletteEntry(IN ULONG Id, IN ULONG PaletteEntry)
Definition: vga.c:277
NTKERNELAPI UCHAR NTAPI READ_REGISTER_UCHAR(IN PUCHAR Register)
#define __outpw(Port, Value)
Definition: precomp.h:68
#define SEQ_ADDRESS_PORT
Definition: vga.h:69
#define IND_GRAPH_MODE
Definition: vga.h:112
VOID NTAPI VidSetScrollRegion(IN ULONG Left, IN ULONG Top, IN ULONG Right, IN ULONG Bottom)
Definition: vga.c:696
ULONG curr_y
Definition: vga.c:68
static LPHIST_ENTRY Bottom
Definition: history.c:54
static ULONG ScrollRegion[4]
Definition: vga.c:5
static VOID NTAPI PreserveRow(IN ULONG CurrentTop, IN ULONG TopDelta, IN BOOLEAN Restore)
Definition: vga.c:356
ULONG_PTR VgaBase
Definition: vga.c:66
UCHAR PixelMask[8]
Definition: vga.c:34
unsigned short USHORT
Definition: pedump.c:61
static ULONG Delta
Definition: xboxvideo.c:32
_In_ ULONG Shift
Definition: rtlfuncs.h:2683
unsigned int * PULONG
Definition: retypes.h:1
static BOOLEAN ClearRow
Definition: vga.c:70
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLint dx
Definition: linetemp.h:97
#define BI_RLE4
Definition: precomp.h:42
VOID NTAPI VidSolidColorFill(IN ULONG Left, IN ULONG Top, IN ULONG Right, IN ULONG Bottom, IN UCHAR Color)
Definition: vga.c:1010
static UCHAR lMaskTable[8]
Definition: vga.c:12
static VOID NTAPI DisplayCharacter(IN CHAR Character, IN ULONG Left, IN ULONG Top, IN ULONG TextColor, IN ULONG BackColor)
Definition: vga.c:139
VOID NTAPI VidBufferToScreenBlt(IN PUCHAR Buffer, IN ULONG Left, IN ULONG Top, IN ULONG Width, IN ULONG Height, IN ULONG Delta)
Definition: vga.c:733
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define __outpb(Port, Value)
Definition: precomp.h:65
ULONG curr_x
Definition: vga.c:67
#define GRAPH_DATA_PORT
Definition: vga.h:82
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
static LPHIST_ENTRY Top
Definition: history.c:53
int k
Definition: mpi.c:3369
NTKERNELAPI VOID NTAPI WRITE_REGISTER_UCHAR(IN PUCHAR Register, IN UCHAR Value)
base of all file and directory entries
Definition: entries.h:82