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