ReactOS  0.4.15-dev-1049-g1062a29
common.c
Go to the documentation of this file.
1 #include "precomp.h"
2 
3 /* GLOBALS ********************************************************************/
4 
6 
9 
11 {
12  0,
13  0,
14  SCREEN_WIDTH - 1,
15  SCREEN_HEIGHT - 1
16 };
17 
18 /*
19  * Boot video driver default palette is similar to the standard 16-color
20  * CGA palette, but it has Red and Blue channels swapped, and also dark
21  * and light gray colors swapped.
22  */
24 {
25  RGB( 0, 0, 0), /* Black */
26  RGB(128, 0, 0), /* Red */
27  RGB( 0, 128, 0), /* Green */
28  RGB(128, 128, 0), /* Brown */
29  RGB( 0, 0, 128), /* Blue */
30  RGB(128, 0, 128), /* Magenta */
31  RGB( 0, 128, 128), /* Cyan */
32  RGB(128, 128, 128), /* Dark Gray */
33  RGB(192, 192, 192), /* Light Gray */
34  RGB(255, 0, 0), /* Light Red */
35  RGB( 0, 255, 0), /* Light Green */
36  RGB(255, 255, 0), /* Yellow */
37  RGB( 0, 0, 255), /* Light Blue */
38  RGB(255, 0, 255), /* Light Magenta */
39  RGB( 0, 255, 255), /* Light Cyan */
40  RGB(255, 255, 255), /* White */
41 };
42 
44 
45 /* PRIVATE FUNCTIONS **********************************************************/
46 
47 static VOID
48 NTAPI
50  _In_ ULONG Left,
51  _In_ ULONG Top,
52  _In_ ULONG Width,
53  _In_ ULONG Height,
55  _In_ ULONG BitsPerPixel,
57 {
58  ULONG X, Y, Pixel;
59  UCHAR Colors;
61  const ULONG Bottom = Top + Height;
62  const ULONG Right = Left + Width;
63 
64  /* Check if the buffer isn't 4bpp */
65  if (BitsPerPixel != 4)
66  {
67  /* FIXME: TODO */
68  DbgPrint("Unhandled BitBlt\n"
69  "%lux%lu @ (%lu|%lu)\n"
70  "Bits Per Pixel %lu\n"
71  "Buffer: %p. Delta: %lu\n",
72  Width,
73  Height,
74  Left,
75  Top,
76  BitsPerPixel,
77  Buffer,
78  Delta);
79  return;
80  }
81 
83 
84  /* 4bpp blitting */
85  for (Y = Top; Y < Bottom; ++Y)
86  {
88 
89  for (X = Left, Pixel = 0;
90  X < Right;
91  ++X, ++Pixel)
92  {
93  if (Pixel % 2 == 0)
94  {
95  /* Extract colors at every two pixels */
96  Colors = *InputBuffer++;
97 
98  SetPixel(X, Y, Colors >> 4);
99  }
100  else
101  {
102  SetPixel(X, Y, Colors & 0x0F);
103  }
104  }
105 
106  Buffer += Delta;
107  }
108 }
109 
110 static VOID
111 NTAPI
113  _In_ ULONG Left,
114  _In_ ULONG Top,
115  _In_ ULONG Width,
116  _In_ ULONG Height,
118 {
119  ULONG YDelta;
120  ULONG x;
121  ULONG RleValue, NewRleValue;
122  ULONG Color, Color2;
123  ULONG i, j;
124  ULONG Code;
125 
127 
128  /* Set Y height and current X value and start loop */
129  YDelta = Top + Height - 1;
130  x = Left;
131  for (;;)
132  {
133  /* Get the current value and advance in the buffer */
134  RleValue = *Buffer;
135  Buffer++;
136  if (RleValue)
137  {
138  /* Check if we've gone past the edge */
139  if ((x + RleValue) > (Width + Left))
140  {
141  /* Fixup the pixel value */
142  RleValue = Left - x + Width;
143  }
144 
145  /* Get the new value */
146  NewRleValue = *Buffer;
147 
148  /* Get the two colors */
149  Color = NewRleValue >> 4;
150  Color2 = NewRleValue & 0xF;
151 
152  /* Increase buffer position */
153  Buffer++;
154 
155  /* Check if we need to do a fill */
156  if (Color == Color2)
157  {
158  /* Do a fill and continue the loop */
159  RleValue += x;
160  VidSolidColorFill(x, YDelta, RleValue - 1, YDelta, (UCHAR)Color);
161  x = RleValue;
162  continue;
163  }
164 
165  /* Check if the pixel value is 1 or below */
166  if (RleValue > 1)
167  {
168  /* Set loop variables */
169  for (i = (RleValue - 2) / 2 + 1; i > 0; --i)
170  {
171  /* Set the pixels */
172  SetPixel(x, YDelta, (UCHAR)Color);
173  x++;
174  SetPixel(x, YDelta, (UCHAR)Color2);
175  x++;
176 
177  /* Decrease pixel value */
178  RleValue -= 2;
179  }
180  }
181 
182  /* Check if there is any value at all */
183  if (RleValue)
184  {
185  /* Set the pixel and increase position */
186  SetPixel(x, YDelta, (UCHAR)Color);
187  x++;
188  }
189 
190  /* Start over */
191  continue;
192  }
193 
194  /* Get the current pixel value */
195  RleValue = *Buffer;
196  Code = RleValue;
197  switch (Code)
198  {
199  /* Case 0 */
200  case 0:
201  {
202  /* Set new x value, decrease distance and restart */
203  x = Left;
204  YDelta--;
205  Buffer++;
206  continue;
207  }
208 
209  /* Case 1 */
210  case 1:
211  {
212  /* Done */
213  return;
214  }
215 
216  /* Case 2 */
217  case 2:
218  {
219  /* Set new x value, decrease distance and restart */
220  Buffer++;
221  x += *Buffer;
222  Buffer++;
223  YDelta -= *Buffer;
224  Buffer++;
225  continue;
226  }
227 
228  /* Other values */
229  default:
230  {
231  Buffer++;
232  break;
233  }
234  }
235 
236  /* Check if we've gone past the edge */
237  if ((x + RleValue) > (Width + Left))
238  {
239  /* Set fixed up loop count */
240  i = RleValue - Left - Width + x;
241 
242  /* Fixup pixel value */
243  RleValue -= i;
244  }
245  else
246  {
247  /* Clear loop count */
248  i = 0;
249  }
250 
251  /* Check the value now */
252  if (RleValue > 1)
253  {
254  /* Set loop variables */
255  for (j = (RleValue - 2) / 2 + 1; j > 0; --j)
256  {
257  /* Get the new value */
258  NewRleValue = *Buffer;
259 
260  /* Get the two colors */
261  Color = NewRleValue >> 4;
262  Color2 = NewRleValue & 0xF;
263 
264  /* Increase buffer position */
265  Buffer++;
266 
267  /* Set the pixels */
268  SetPixel(x, YDelta, (UCHAR)Color);
269  x++;
270  SetPixel(x, YDelta, (UCHAR)Color2);
271  x++;
272 
273  /* Decrease pixel value */
274  RleValue -= 2;
275  }
276  }
277 
278  /* Check if there is any value at all */
279  if (RleValue)
280  {
281  /* Set the pixel and increase position */
282  Color = *Buffer >> 4;
283  Buffer++;
284  SetPixel(x, YDelta, (UCHAR)Color);
285  x++;
286  i--;
287  }
288 
289  /* Check loop count now */
290  if ((LONG)i > 0)
291  {
292  /* Decrease it */
293  i--;
294 
295  /* Set new position */
296  Buffer = Buffer + (i / 2) + 1;
297  }
298 
299  /* Check if we need to increase the buffer */
300  if ((ULONG_PTR)Buffer & 1) Buffer++;
301  }
302 }
303 
304 /* PUBLIC FUNCTIONS ***********************************************************/
305 
306 /*
307  * @implemented
308  */
309 ULONG
310 NTAPI
312  _In_ ULONG Color)
313 {
314  ULONG OldColor;
315 
316  /* Save the old color and set the new one */
317  OldColor = VidpTextColor;
319  return OldColor;
320 }
321 
322 VOID
323 NTAPI
326  _In_ ULONG Left,
327  _In_ ULONG Top,
328  _In_ BOOLEAN Transparent)
329 {
330  ULONG BackColor;
331 
332  /*
333  * If the caller wanted transparent, then send the special value (16),
334  * else use our default and call the helper routine.
335  */
336  BackColor = Transparent ? BV_COLOR_NONE : BV_COLOR_LIGHT_CYAN;
337 
338  /* Loop every character and adjust the position */
339  for (; *String; ++String, Left += BOOTCHAR_WIDTH)
340  {
341  /* Display a character */
342  DisplayCharacter(*String, Left, Top, BV_COLOR_LIGHT_BLUE, BackColor);
343  }
344 }
345 
346 VOID
347 NTAPI
349  _In_ ULONG Left,
350  _In_ ULONG Top,
351  _In_ ULONG Right,
352  _In_ ULONG Bottom)
353 {
354  /* Assert alignment */
355  ASSERT((Left % BOOTCHAR_WIDTH) == 0);
356  ASSERT((Right % BOOTCHAR_WIDTH) == BOOTCHAR_WIDTH - 1);
357 
358  /* Set Scroll Region */
359  VidpScrollRegion[0] = Left;
360  VidpScrollRegion[1] = Top;
361  VidpScrollRegion[2] = Right;
363 
364  /* Set current X and Y */
365  VidpCurrentX = Left;
366  VidpCurrentY = Top;
367 }
368 
369 /*
370  * @implemented
371  */
372 VOID
373 NTAPI
376 {
377  /* Start looping the string */
378  for (; *String; ++String)
379  {
380  /* Treat new-line separately */
381  if (*String == '\n')
382  {
383  /* Modify Y position */
386  {
387  /* Scroll the view and clear the current row */
391  }
392  else
393  {
394  /* Preserve the current row */
396  }
397 
398  /* Update current X */
400 
401  /* No need to clear this row */
402  ClearRow = FALSE;
403  }
404  else if (*String == '\r')
405  {
406  /* Update current X */
408 
409  /* If a new-line does not follow we will clear the current row */
410  if (String[1] != '\n') ClearRow = TRUE;
411  }
412  else
413  {
414  /* Clear the current row if we had a return-carriage without a new-line */
415  if (ClearRow)
416  {
418  ClearRow = FALSE;
419  }
420 
421  /* Display this character */
424 
425  /* Check if we should scroll */
427  {
428  /* Update Y position and check if we should scroll it */
431  {
432  /* Scroll the view and clear the current row */
436  }
437  else
438  {
439  /* Preserve the current row */
441  }
442 
443  /* Update current X */
445  }
446  }
447  }
448 }
449 
450 VOID
451 NTAPI
454  _In_ ULONG Left,
455  _In_ ULONG Top,
456  _In_ ULONG Width,
457  _In_ ULONG Height,
458  _In_ ULONG Delta)
459 {
460  /* Make sure we have a width and height */
461  if (!Width || !Height)
462  return;
463 
464  /* Call the helper function */
465  BitBlt(Left, Top, Width, Height, Buffer, 4, Delta);
466 }
467 
468 VOID
469 NTAPI
472  _In_ ULONG Left,
473  _In_ ULONG Top)
474 {
475  PBITMAPINFOHEADER BitmapInfoHeader;
476  LONG Delta;
477  PUCHAR BitmapOffset;
478  ULONG PaletteCount;
479 
480  /* Get the Bitmap Header */
481  BitmapInfoHeader = (PBITMAPINFOHEADER)Buffer;
482 
483  /* Initialize the palette */
484  PaletteCount = BitmapInfoHeader->biClrUsed ?
485  BitmapInfoHeader->biClrUsed : BV_MAX_COLORS;
486  InitPaletteWithTable((PULONG)(Buffer + BitmapInfoHeader->biSize),
487  PaletteCount);
488 
489  /* Make sure we can support this bitmap */
490  ASSERT((BitmapInfoHeader->biBitCount * BitmapInfoHeader->biPlanes) <= 4);
491 
492  /*
493  * Calculate the delta and align it on 32-bytes, then calculate
494  * the actual start of the bitmap data.
495  */
496  Delta = (BitmapInfoHeader->biBitCount * BitmapInfoHeader->biWidth) + 31;
497  Delta >>= 3;
498  Delta &= ~3;
499  BitmapOffset = Buffer + sizeof(BITMAPINFOHEADER) + PaletteCount * sizeof(ULONG);
500 
501  /* Check the compression of the bitmap */
502  if (BitmapInfoHeader->biCompression == BI_RLE4)
503  {
504  /* Make sure we have a width and a height */
505  if ((BitmapInfoHeader->biWidth) && (BitmapInfoHeader->biHeight))
506  {
507  /* We can use RLE Bit Blt */
508  RleBitBlt(Left,
509  Top,
510  BitmapInfoHeader->biWidth,
511  BitmapInfoHeader->biHeight,
512  BitmapOffset);
513  }
514  }
515  else
516  {
517  /* Check if the height is negative */
518  if (BitmapInfoHeader->biHeight < 0)
519  {
520  /* Make it positive in the header */
521  BitmapInfoHeader->biHeight *= -1;
522  }
523  else
524  {
525  /* Update buffer offset */
526  BitmapOffset += ((BitmapInfoHeader->biHeight - 1) * Delta);
527  Delta *= -1;
528  }
529 
530  /* Make sure we have a width and a height */
531  if ((BitmapInfoHeader->biWidth) && (BitmapInfoHeader->biHeight))
532  {
533  /* Do the BitBlt */
534  BitBlt(Left,
535  Top,
536  BitmapInfoHeader->biWidth,
537  BitmapInfoHeader->biHeight,
538  BitmapOffset,
539  BitmapInfoHeader->biBitCount,
540  Delta);
541  }
542  }
543 }
UCHAR VidpTextColor
Definition: common.c:5
VOID PrepareForSetPixel(VOID)
Definition: vga.c:81
FORCEINLINE VOID SetPixel(_In_ ULONG Left, _In_ ULONG Top, _In_ UCHAR Color)
Definition: arm.h:50
#define Y(I)
USHORT biBitCount
Definition: precomp.h:37
#define DbgPrint
Definition: loader.c:25
#define RGB(r, g, b)
Definition: precomp.h:62
#define TRUE
Definition: types.h:120
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
unsigned char * PUCHAR
Definition: retypes.h:3
VOID NTAPI VidDisplayString(_In_z_ PUCHAR String)
Definition: common.c:374
#define SCREEN_WIDTH
Definition: pc98video.c:27
VOID NTAPI DisplayCharacter(_In_ CHAR Character, _In_ ULONG Left, _In_ ULONG Top, _In_ ULONG TextColor, _In_ ULONG BackColor)
Definition: bootvid.c:13
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
ULONG biCompression
Definition: precomp.h:38
#define BV_COLOR_WHITE
Definition: display.h:30
static WCHAR String[]
Definition: stringtable.c:55
VOID NTAPI InitPaletteWithTable(_In_ PULONG Table, _In_ ULONG Count)
Definition: bootvid.c:170
CHAR InputBuffer[80]
Definition: conmgr.c:33
static VOID NTAPI RleBitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_ PUCHAR Buffer)
Definition: common.c:112
struct Color Color
uint32_t ULONG_PTR
Definition: typedefs.h:65
ULONG VidpScrollRegion[4]
Definition: common.c:10
#define BOOTCHAR_HEIGHT
Definition: precomp.h:27
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
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
const RGBQUAD VidpDefaultPalette[BV_MAX_COLORS]
Definition: common.c:23
struct tagBITMAPINFOHEADER * PBITMAPINFOHEADER
long LONG
Definition: pedump.c:60
unsigned char BOOLEAN
Definition: bufpool.h:45
#define BV_COLOR_NONE
Definition: display.h:31
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 Code
Definition: deflate.h:80
#define SCREEN_HEIGHT
Definition: pc98video.c:28
static BOOLEAN ClearRow
Definition: common.c:43
VOID NTAPI DoScroll(_In_ ULONG Scroll)
Definition: bootvid.c:59
ULONG RGBQUAD
Definition: precomp.h:50
ULONG VidpCurrentY
Definition: common.c:8
VOID NTAPI VidBitBlt(_In_ PUCHAR Buffer, _In_ ULONG Left, _In_ ULONG Top)
Definition: common.c:470
Colors
Definition: ansiprsr.h:4
ULONG NTAPI VidSetTextColor(_In_ ULONG Color)
Definition: common.c:311
VOID NTAPI VidSolidColorFill(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Right, _In_ ULONG Bottom, _In_ UCHAR Color)
Definition: bootvid.c:274
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
#define BV_COLOR_LIGHT_CYAN
Definition: display.h:29
#define _In_reads_bytes_(size)
Definition: no_sal2.h:229
#define _In_
Definition: no_sal2.h:204
static LPHIST_ENTRY Bottom
Definition: history.c:54
VOID NTAPI VidSetScrollRegion(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Right, _In_ ULONG Bottom)
Definition: common.c:348
#define _In_z_
Definition: no_sal2.h:239
static ULONG Delta
Definition: xboxvideo.c:33
unsigned int * PULONG
Definition: retypes.h:1
#define BV_COLOR_LIGHT_BLUE
Definition: display.h:27
#define BI_RLE4
Definition: precomp.h:48
VOID NTAPI VidDisplayStringXY(_In_z_ PUCHAR String, _In_ ULONG Left, _In_ ULONG Top, _In_ BOOLEAN Transparent)
Definition: common.c:324
VOID NTAPI VidBufferToScreenBlt(_In_reads_bytes_(Delta *Height) PUCHAR Buffer, _In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_ ULONG Delta)
Definition: common.c:452
unsigned int ULONG
Definition: retypes.h:1
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
static LPHIST_ENTRY Top
Definition: history.c:53
#define BOOTCHAR_WIDTH
Definition: precomp.h:28
VOID NTAPI PreserveRow(_In_ ULONG CurrentTop, _In_ ULONG TopDelta, _In_ BOOLEAN Restore)
Definition: bootvid.c:107
ULONG VidpCurrentX
Definition: common.c:7
static VOID NTAPI BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Delta *Height) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Delta)
Definition: common.c:49
#define X(b, s)
#define BV_MAX_COLORS
Definition: display.h:32