ReactOS  0.4.14-dev-57-g333b8f1
blue.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * FILE: services/dd/blue/blue.c
5  * PURPOSE: Console (blue screen) device driver
6  * PROGRAMMER: Eric Kohl
7  * UPDATE HISTORY:
8  * ??? Created
9  */
10 
11 /* INCLUDES ******************************************************************/
12 
13 #include "blue.h"
14 
15 #define NDEBUG
16 #include <debug.h>
17 
18 // ROS Internal. Please deprecate.
20 BOOLEAN
21 NTAPI
23  VOID
24 );
25 
26 /* NOTES ******************************************************************/
27 /*
28  * [[character][attribute]][[character][attribute]]....
29  */
30 
31 
32 /* TYPEDEFS ***************************************************************/
33 
34 typedef struct _DEVICE_EXTENSION
35 {
36  PUCHAR VideoMemory; /* Pointer to video memory */
41  UCHAR ScanLines; /* Height of a text line */
42  USHORT Rows; /* Number of rows */
43  USHORT Columns; /* Number of columns */
45 
46 typedef struct _VGA_REGISTERS
47 {
48  UCHAR CRT[24];
54 
56 {
57  /* CRT Controller Registers */
58  {0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81, 0xBF, 0x1F, 0x00, 0x47, 0x1E, 0x00,
59  0x00, 0x00, 0x05, 0xF0, 0x9C, 0x8E, 0x8F, 0x28, 0x1F, 0x96, 0xB9, 0xA3},
60  /* Attribute Controller Registers */
61  {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39, 0x3A, 0x3B,
62  0x3C, 0x3D, 0x3E, 0x3F, 0x0C, 0x00, 0x0F, 0x08, 0x00},
63  /* Graphics Controller Registers */
64  {0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0E, 0x00, 0xFF},
65  /* Sequencer Registers */
66  {0x03, 0x00, 0x03, 0x00, 0x02},
67  /* Misc Output Register */
68  0x67
69 };
70 
71 static const UCHAR DefaultPalette[] =
72 {
73  0, 0, 0,
74  0, 0, 0xC0,
75  0, 0xC0, 0,
76  0, 0xC0, 0xC0,
77  0xC0, 0, 0,
78  0xC0, 0, 0xC0,
79  0xC0, 0xC0, 0,
80  0xC0, 0xC0, 0xC0,
81  0x80, 0x80, 0x80,
82  0, 0, 0xFF,
83  0, 0xFF, 0,
84  0, 0xFF, 0xFF,
85  0xFF, 0, 0,
86  0xFF, 0, 0xFF,
87  0xFF, 0xFF, 0,
88  0xFF, 0xFF, 0xFF
89 };
90 
91 /* FUNCTIONS **************************************************************/
92 
93 static VOID FASTCALL
94 ScrSetRegisters(const VGA_REGISTERS *Registers)
95 {
96  UINT32 i;
97 
98  /* Update misc output register */
99  WRITE_PORT_UCHAR(MISC, Registers->Misc);
100 
101  /* Synchronous reset on */
102  WRITE_PORT_UCHAR(SEQ, 0x00);
103  WRITE_PORT_UCHAR(SEQDATA, 0x01);
104 
105  /* Write sequencer registers */
106  for (i = 1; i < sizeof(Registers->Sequencer); i++)
107 {
109  WRITE_PORT_UCHAR(SEQDATA, Registers->Sequencer[i]);
110  }
111 
112  /* Synchronous reset off */
113  WRITE_PORT_UCHAR(SEQ, 0x00);
114  WRITE_PORT_UCHAR(SEQDATA, 0x03);
115 
116  /* Deprotect CRT registers 0-7 */
117  WRITE_PORT_UCHAR(CRTC, 0x11);
118  WRITE_PORT_UCHAR(CRTCDATA, Registers->CRT[0x11] & 0x7f);
119 
120  /* Write CRT registers */
121  for (i = 0; i < sizeof(Registers->CRT); i++)
122  {
124  WRITE_PORT_UCHAR(CRTCDATA, Registers->CRT[i]);
125  }
126 
127  /* Write graphics controller registers */
128  for (i = 0; i < sizeof(Registers->Graphics); i++)
129  {
131  WRITE_PORT_UCHAR(GRAPHICSDATA, Registers->Graphics[i]);
132  }
133 
134  /* Write attribute controller registers */
135  for (i = 0; i < sizeof(Registers->Attribute); i++)
136  {
139  WRITE_PORT_UCHAR(ATTRIB, Registers->Attribute[i]);
140  }
141 
142  /* Set the PEL mask. */
143  WRITE_PORT_UCHAR(PELMASK, 0xff);
144 }
145 
146 static VOID FASTCALL
148 {
149  unsigned int offset;
150  UCHAR data, value;
151  ULONG Index;
152 
154 
155  /* Disable screen and enable palette access. */
157  WRITE_PORT_UCHAR(ATTRIB, 0x00);
158 
159  for (Index = 0; Index < sizeof(DefaultPalette) / 3; Index++)
160  {
165  }
166 
167  /* Enable screen and disable palette access. */
169  WRITE_PORT_UCHAR(ATTRIB, 0x20);
170 
171  /* get current output position */
175  offset += (READ_PORT_UCHAR (CRTC_DATA) << 8);
176 
177  /* switch blinking characters off */
182  data = data & ~0x08;
186 
187  /* read screen information from crt controller */
189  DeviceExtension->Columns = READ_PORT_UCHAR (CRTC_DATA) + 1;
191  DeviceExtension->Rows = READ_PORT_UCHAR (CRTC_DATA);
194  DeviceExtension->Rows |= (((data & 0x02) << 7) | ((data & 0x40) << 3));
195  DeviceExtension->Rows++;
197  DeviceExtension->ScanLines = (READ_PORT_UCHAR (CRTC_DATA) & 0x1F) + 1;
198 
199  /* show blinking cursor */
201  WRITE_PORT_UCHAR (CRTC_DATA, (DeviceExtension->ScanLines - 1) & 0x1F);
203  data = READ_PORT_UCHAR (CRTC_DATA) & 0xE0;
205  data | ((DeviceExtension->ScanLines - 1) & 0x1F));
206 
207  /* calculate number of text rows */
208  DeviceExtension->Rows =
209  DeviceExtension->Rows / DeviceExtension->ScanLines;
210 #ifdef BOCHS_30ROWS
211  DeviceExtension->Rows = 30;
212 #endif
213 
214  /* Upload a default font for the default codepage 437 */
215  ScrLoadFontTable(437);
216 
217  DPRINT ("%d Columns %d Rows %d Scanlines\n",
218  DeviceExtension->Columns,
219  DeviceExtension->Rows,
220  DeviceExtension->ScanLines);
221 }
222 
225 
227 static NTSTATUS NTAPI
229  PIRP Irp)
230 {
231  PDEVICE_EXTENSION DeviceExtension;
234 
235  DeviceExtension = DeviceObject->DeviceExtension;
236 
238  {
239  ScrAcquireOwnership(DeviceExtension);
240 
241  /* get pointer to video memory */
242  BaseAddress.QuadPart = VIDMEM_BASE;
243  DeviceExtension->VideoMemory =
244  (PUCHAR)MmMapIoSpace (BaseAddress, DeviceExtension->Rows * DeviceExtension->Columns * 2, MmNonCached);
245  }
246  else
247  {
248  /* store dummy values here */
249  DeviceExtension->Columns = 1;
250  DeviceExtension->Rows = 1;
251  DeviceExtension->ScanLines = 1;
252  }
253 
254  DeviceExtension->CursorSize = 5; /* FIXME: value correct?? */
255  DeviceExtension->CursorVisible = TRUE;
256 
257  /* more initialization */
258  DeviceExtension->CharAttribute = 0x17; /* light grey on blue */
259  DeviceExtension->Mode = ENABLE_PROCESSED_OUTPUT |
261 
263 
264  Irp->IoStatus.Status = Status;
266 
267  return (Status);
268 }
269 
271 static NTSTATUS NTAPI
273  PIRP Irp)
274 {
278  char *pch = Irp->UserBuffer;
279  PUCHAR vidmem;
280  unsigned int i;
281  int j, offset;
282  int cursorx, cursory;
283  int rows, columns;
284  int processed = DeviceExtension->Mode & ENABLE_PROCESSED_OUTPUT;
285 
287  {
288  /* Display is in graphics mode, we're not allowed to touch it */
290 
291  Irp->IoStatus.Status = Status;
293 
294  return Status;
295  }
296 
297  vidmem = DeviceExtension->VideoMemory;
298  rows = DeviceExtension->Rows;
299  columns = DeviceExtension->Columns;
300 
301  _disable();
306  _enable();
307 
308  cursory = offset / columns;
309  cursorx = offset % columns;
310  if( processed == 0 )
311  {
312  /* raw output mode */
313  // FIXME: Does the buffer only contains chars? or chars + attributes?
314  // FIXME2: Fix buffer overflow.
315  memcpy( &vidmem[(cursorx * 2) + (cursory * columns * 2)], pch, stk->Parameters.Write.Length );
316  offset += (stk->Parameters.Write.Length / 2);
317  }
318  else {
319  for (i = 0; i < stk->Parameters.Write.Length; i++, pch++)
320  {
321  switch (*pch)
322  {
323  case '\b':
324  if (cursorx > 0)
325  {
326  cursorx--;
327  }
328  else if (cursory > 0)
329  {
330  cursorx = columns - 1;
331  cursory--;
332  }
333  vidmem[(cursorx * 2) + (cursory * columns * 2)] = ' ';
334  vidmem[(cursorx * 2) + (cursory * columns * 2) + 1] = (char) DeviceExtension->CharAttribute;
335  break;
336 
337  case '\n':
338  cursory++;
339  cursorx = 0;
340  break;
341 
342  case '\r':
343  cursorx = 0;
344  break;
345 
346  case '\t':
347  offset = TAB_WIDTH - (cursorx % TAB_WIDTH);
348  for (j = 0; j < offset; j++)
349  {
350  vidmem[(cursorx * 2) + (cursory * columns * 2)] = ' ';
351  cursorx++;
352 
353  if (cursorx >= columns)
354  {
355  cursory++;
356  cursorx = 0;
357  }
358  }
359  break;
360 
361  default:
362  vidmem[(cursorx * 2) + (cursory * columns * 2)] = *pch;
363  vidmem[(cursorx * 2) + (cursory * columns * 2) + 1] = (char) DeviceExtension->CharAttribute;
364  cursorx++;
365  if (cursorx >= columns)
366  {
367  cursory++;
368  cursorx = 0;
369  }
370  break;
371  }
372 
373  /* Scroll up the contents of the screen if we are at the end */
374  if (cursory >= rows)
375  {
376  unsigned short *LinePtr;
377 
378  memcpy (vidmem,
379  &vidmem[columns * 2],
380  columns * (rows - 1) * 2);
381 
382  LinePtr = (unsigned short *) &vidmem[columns * (rows - 1) * 2];
383 
384  for (j = 0; j < columns; j++)
385  {
386  LinePtr[j] = DeviceExtension->CharAttribute << 8;
387  }
388  cursory = rows - 1;
389  for (j = 0; j < columns; j++)
390  {
391  vidmem[(j * 2) + (cursory * columns * 2)] = ' ';
392  vidmem[(j * 2) + (cursory * columns * 2) + 1] = (char)DeviceExtension->CharAttribute;
393  }
394  }
395  }
396 
397  /* Set the cursor position */
398  offset = (cursory * columns) + cursorx;
399  }
400  _disable();
404  offset >>= 8;
406  _enable();
407 
409 
410  Irp->IoStatus.Status = Status;
412 
413  return Status;
414 }
415 
417 static NTSTATUS NTAPI
419  PIRP Irp)
420 {
422  PDEVICE_EXTENSION DeviceExtension;
424 
425  DeviceExtension = DeviceObject->DeviceExtension;
426  switch (stk->Parameters.DeviceIoControl.IoControlCode)
427  {
429  {
430  PCONSOLE_SCREEN_BUFFER_INFO pcsbi = (PCONSOLE_SCREEN_BUFFER_INFO)Irp->AssociatedIrp.SystemBuffer;
431  int rows = DeviceExtension->Rows;
432  int columns = DeviceExtension->Columns;
433  unsigned int offset;
434 
436  {
437  /* read cursor position from crtc */
438  _disable();
442  offset += (READ_PORT_UCHAR (CRTC_DATA) << 8);
443  _enable();
444  }
445  else
446  {
447  offset = 0;
448  }
449 
450  pcsbi->dwSize.X = columns;
451  pcsbi->dwSize.Y = rows;
452 
453  pcsbi->dwCursorPosition.X = (SHORT)(offset % columns);
454  pcsbi->dwCursorPosition.Y = (SHORT)(offset / columns);
455 
456  pcsbi->wAttributes = DeviceExtension->CharAttribute;
457 
458  pcsbi->srWindow.Left = 0;
459  pcsbi->srWindow.Right = columns - 1;
460  pcsbi->srWindow.Top = 0;
461  pcsbi->srWindow.Bottom = rows - 1;
462 
463  pcsbi->dwMaximumWindowSize.X = columns;
464  pcsbi->dwMaximumWindowSize.Y = rows;
465 
466  Irp->IoStatus.Information = sizeof (CONSOLE_SCREEN_BUFFER_INFO);
468  }
469  break;
470 
472  {
473  PCONSOLE_SCREEN_BUFFER_INFO pcsbi = (PCONSOLE_SCREEN_BUFFER_INFO)Irp->AssociatedIrp.SystemBuffer;
474  unsigned int offset;
475 
476  if ( pcsbi->dwCursorPosition.X < 0 || pcsbi->dwCursorPosition.X >= DeviceExtension->Columns ||
477  pcsbi->dwCursorPosition.Y < 0 || pcsbi->dwCursorPosition.Y >= DeviceExtension->Rows )
478  {
479  Irp->IoStatus.Information = 0;
481  break;
482  }
483 
484  DeviceExtension->CharAttribute = pcsbi->wAttributes;
485  offset = (pcsbi->dwCursorPosition.Y * DeviceExtension->Columns) +
486  pcsbi->dwCursorPosition.X;
487 
489  {
490  _disable();
495  _enable();
496  }
497 
498  Irp->IoStatus.Information = 0;
500  }
501  break;
502 
504  {
505  PCONSOLE_CURSOR_INFO pcci = (PCONSOLE_CURSOR_INFO)Irp->AssociatedIrp.SystemBuffer;
506 
507  pcci->dwSize = DeviceExtension->CursorSize;
508  pcci->bVisible = DeviceExtension->CursorVisible;
509 
510  Irp->IoStatus.Information = sizeof (CONSOLE_CURSOR_INFO);
512  }
513  break;
514 
516  {
517  PCONSOLE_CURSOR_INFO pcci = (PCONSOLE_CURSOR_INFO)Irp->AssociatedIrp.SystemBuffer;
518  UCHAR data, value;
519  ULONG size, height;
520 
521  DeviceExtension->CursorSize = pcci->dwSize;
522  DeviceExtension->CursorVisible = pcci->bVisible;
523 
525  {
526  height = DeviceExtension->ScanLines;
527  data = (pcci->bVisible) ? 0x00 : 0x20;
528 
529  size = (pcci->dwSize * height) / 100;
530  if (size < 1)
531  {
532  size = 1;
533  }
534 
535  data |= (UCHAR)(height - size);
536 
537  _disable();
541  value = READ_PORT_UCHAR (CRTC_DATA) & 0xE0;
543 
544  _enable();
545  }
546 
547  Irp->IoStatus.Information = 0;
549  }
550  break;
551 
553  {
554  PCONSOLE_MODE pcm = (PCONSOLE_MODE)Irp->AssociatedIrp.SystemBuffer;
555 
556  pcm->dwMode = DeviceExtension->Mode;
557 
558  Irp->IoStatus.Information = sizeof(CONSOLE_MODE);
560  }
561  break;
562 
564  {
565  PCONSOLE_MODE pcm = (PCONSOLE_MODE)Irp->AssociatedIrp.SystemBuffer;
566 
567  DeviceExtension->Mode = pcm->dwMode;
568 
569  Irp->IoStatus.Information = 0;
571  }
572  break;
573 
575  {
576  POUTPUT_ATTRIBUTE Buf = (POUTPUT_ATTRIBUTE)Irp->AssociatedIrp.SystemBuffer;
577  PUCHAR vidmem;
578  int offset;
579  ULONG dwCount;
580  ULONG nMaxLength = Buf->nLength;
581 
582  if ( Buf->dwCoord.X < 0 || Buf->dwCoord.X >= DeviceExtension->Columns ||
583  Buf->dwCoord.Y < 0 || Buf->dwCoord.Y >= DeviceExtension->Rows )
584  {
585  Buf->dwTransfered = 0;
586  Irp->IoStatus.Information = 0;
588  break;
589  }
590 
592  {
593  vidmem = DeviceExtension->VideoMemory;
594  offset = (Buf->dwCoord.Y * DeviceExtension->Columns * 2) +
595  (Buf->dwCoord.X * 2) + 1;
596 
597  nMaxLength = min(nMaxLength,
598  (DeviceExtension->Rows - Buf->dwCoord.Y)
599  * DeviceExtension->Columns - Buf->dwCoord.X);
600 
601  for (dwCount = 0; dwCount < nMaxLength; dwCount++)
602  {
603  vidmem[offset + (dwCount * 2)] = (char) Buf->wAttribute;
604  }
605  }
606 
607  Buf->dwTransfered = nMaxLength;
608 
609  Irp->IoStatus.Information = 0;
611  }
612  break;
613 
615  {
616  POUTPUT_ATTRIBUTE Buf = (POUTPUT_ATTRIBUTE)Irp->AssociatedIrp.SystemBuffer;
617  PUSHORT pAttr = (PUSHORT)MmGetSystemAddressForMdl(Irp->MdlAddress);
618  PUCHAR vidmem;
619  int offset;
620  ULONG dwCount;
621  ULONG nMaxLength;
622 
623  if ( Buf->dwCoord.X < 0 || Buf->dwCoord.X >= DeviceExtension->Columns ||
624  Buf->dwCoord.Y < 0 || Buf->dwCoord.Y >= DeviceExtension->Rows )
625  {
626  Buf->dwTransfered = 0;
627  Irp->IoStatus.Information = 0;
629  break;
630  }
631 
633  {
634  vidmem = DeviceExtension->VideoMemory;
635  offset = (Buf->dwCoord.Y * DeviceExtension->Columns * 2) +
636  (Buf->dwCoord.X * 2) + 1;
637 
638  nMaxLength = min(stk->Parameters.DeviceIoControl.OutputBufferLength,
639  (DeviceExtension->Rows - Buf->dwCoord.Y)
640  * DeviceExtension->Columns - Buf->dwCoord.X);
641 
642  for (dwCount = 0; dwCount < nMaxLength; dwCount++, pAttr++)
643  {
644  *((char *)pAttr) = vidmem[offset + (dwCount * 2)];
645  }
646 
647  Buf->dwTransfered = dwCount;
648  }
649  else
650  {
651  Buf->dwTransfered = 0;
652  }
653 
654  Irp->IoStatus.Information = sizeof(OUTPUT_ATTRIBUTE);
656  }
657  break;
658 
660  {
661  COORD *pCoord = (COORD *)MmGetSystemAddressForMdl(Irp->MdlAddress);
662  CHAR *pAttr = (CHAR *)(pCoord + 1);
663  PUCHAR vidmem;
664  int offset;
665  ULONG dwCount;
666  ULONG nMaxLength;
667 
668  if ( pCoord->X < 0 || pCoord->X >= DeviceExtension->Columns ||
669  pCoord->Y < 0 || pCoord->Y >= DeviceExtension->Rows )
670  {
671  Irp->IoStatus.Information = 0;
673  break;
674  }
675 
677  {
678  vidmem = DeviceExtension->VideoMemory;
679  offset = (pCoord->Y * DeviceExtension->Columns * 2) +
680  (pCoord->X * 2) + 1;
681 
682  nMaxLength = min(stk->Parameters.DeviceIoControl.OutputBufferLength - sizeof(COORD),
683  (DeviceExtension->Rows - pCoord->Y)
684  * DeviceExtension->Columns - pCoord->X);
685 
686  for (dwCount = 0; dwCount < nMaxLength; dwCount++, pAttr++)
687  {
688  vidmem[offset + (dwCount * 2)] = *pAttr;
689  }
690  }
691 
692  Irp->IoStatus.Information = 0;
694  }
695  break;
696 
698  DeviceExtension->CharAttribute = (USHORT)*(PUSHORT)Irp->AssociatedIrp.SystemBuffer;
699  Irp->IoStatus.Information = 0;
701  break;
702 
704  {
705  POUTPUT_CHARACTER Buf = (POUTPUT_CHARACTER)Irp->AssociatedIrp.SystemBuffer;
706  PUCHAR vidmem;
707  int offset;
708  ULONG dwCount;
709  ULONG nMaxLength = Buf->nLength;
710 
711  if ( Buf->dwCoord.X < 0 || Buf->dwCoord.X >= DeviceExtension->Columns ||
712  Buf->dwCoord.Y < 0 || Buf->dwCoord.Y >= DeviceExtension->Rows )
713  {
714  Buf->dwTransfered = 0;
715  Irp->IoStatus.Information = 0;
717  break;
718  }
719 
721  {
722  vidmem = DeviceExtension->VideoMemory;
723  offset = (Buf->dwCoord.Y * DeviceExtension->Columns * 2) +
724  (Buf->dwCoord.X * 2);
725 
726  nMaxLength = min(nMaxLength,
727  (DeviceExtension->Rows - Buf->dwCoord.Y)
728  * DeviceExtension->Columns - Buf->dwCoord.X);
729 
730  for (dwCount = 0; dwCount < nMaxLength; dwCount++)
731  {
732  vidmem[offset + (dwCount * 2)] = (char) Buf->cCharacter;
733  }
734  }
735 
736  Buf->dwTransfered = nMaxLength;
737 
738  Irp->IoStatus.Information = 0;
740  }
741  break;
742 
744  {
745  POUTPUT_CHARACTER Buf = (POUTPUT_CHARACTER)Irp->AssociatedIrp.SystemBuffer;
746  LPSTR pChar = (LPSTR)MmGetSystemAddressForMdl(Irp->MdlAddress);
747  PUCHAR vidmem;
748  int offset;
749  ULONG dwCount;
750  ULONG nMaxLength;
751 
752  if ( Buf->dwCoord.X < 0 || Buf->dwCoord.X >= DeviceExtension->Columns ||
753  Buf->dwCoord.Y < 0 || Buf->dwCoord.Y >= DeviceExtension->Rows )
754  {
755  Buf->dwTransfered = 0;
756  Irp->IoStatus.Information = 0;
758  break;
759  }
760 
762  {
763  vidmem = DeviceExtension->VideoMemory;
764  offset = (Buf->dwCoord.Y * DeviceExtension->Columns * 2) +
765  (Buf->dwCoord.X * 2);
766 
767  nMaxLength = min(stk->Parameters.DeviceIoControl.OutputBufferLength,
768  (DeviceExtension->Rows - Buf->dwCoord.Y)
769  * DeviceExtension->Columns - Buf->dwCoord.X);
770 
771  for (dwCount = 0; dwCount < nMaxLength; dwCount++, pChar++)
772  {
773  *pChar = vidmem[offset + (dwCount * 2)];
774  }
775 
776  Buf->dwTransfered = dwCount;
777  }
778  else
779  {
780  Buf->dwTransfered = 0;
781  }
782 
783  Irp->IoStatus.Information = sizeof(OUTPUT_ATTRIBUTE);
785  }
786  break;
787 
789  {
790  COORD *pCoord = (COORD *)MmGetSystemAddressForMdl(Irp->MdlAddress);
791  LPSTR pChar = (CHAR *)(pCoord + 1);
792  PUCHAR vidmem;
793  int offset;
794  ULONG dwCount;
795  ULONG nMaxLength;
796 
797  if ( pCoord->X < 0 || pCoord->X >= DeviceExtension->Columns ||
798  pCoord->Y < 0 || pCoord->Y >= DeviceExtension->Rows )
799  {
800  Irp->IoStatus.Information = 0;
802  break;
803  }
804 
806  {
807  vidmem = DeviceExtension->VideoMemory;
808  offset = (pCoord->Y * DeviceExtension->Columns * 2) +
809  (pCoord->X * 2);
810 
811  nMaxLength = min(stk->Parameters.DeviceIoControl.OutputBufferLength - sizeof(COORD),
812  (DeviceExtension->Rows - pCoord->Y)
813  * DeviceExtension->Columns - pCoord->X);
814 
815  for (dwCount = 0; dwCount < nMaxLength; dwCount++, pChar++)
816  {
817  vidmem[offset + (dwCount * 2)] = *pChar;
818  }
819  }
820 
821  Irp->IoStatus.Information = 0;
823  }
824  break;
825 
826  case IOCTL_CONSOLE_DRAW:
827  {
828  PCONSOLE_DRAW ConsoleDraw;
829  PUCHAR Src, Dest;
830  UINT32 SrcDelta, DestDelta, i, Offset;
831 
833  {
834  ConsoleDraw = (PCONSOLE_DRAW) MmGetSystemAddressForMdl(Irp->MdlAddress);
835  Src = (PUCHAR) (ConsoleDraw + 1);
836  SrcDelta = ConsoleDraw->SizeX * 2;
837  Dest = DeviceExtension->VideoMemory +
838  (ConsoleDraw->Y * DeviceExtension->Columns + ConsoleDraw->X) * 2;
839  DestDelta = DeviceExtension->Columns * 2;
840 
841  for (i = 0; i < ConsoleDraw->SizeY; i++)
842  {
843  RtlCopyMemory(Dest, Src, SrcDelta);
844  Src += SrcDelta;
845  Dest += DestDelta;
846  }
847 
848  Offset = (ConsoleDraw->CursorY * DeviceExtension->Columns) +
849  ConsoleDraw->CursorX;
850 
851  _disable();
856  _enable();
857  }
858 
859  Irp->IoStatus.Information = 0;
861  }
862  break;
863 
865  {
866  UINT32 CodePage = (UINT32)*(PULONG)Irp->AssociatedIrp.SystemBuffer;
867 
869  {
870  /* Upload a font for the codepage if needed */
871  ScrLoadFontTable(CodePage);
872  }
873 
874  Irp->IoStatus.Information = 0;
876  }
877  break;
878 
879  default:
881  }
882 
883  Irp->IoStatus.Status = Status;
885 
886  return Status;
887 }
888 
890 static NTSTATUS NTAPI
892  PIRP Irp)
893 {
896 
897  switch (stk->MajorFunction)
898  {
899  case IRP_MJ_CLOSE:
901  break;
902 
903  default:
905  break;
906  }
907 
908 
909  Irp->IoStatus.Status = Status;
911 
912  return Status;
913 }
914 
915 
916 /*
917  * Module entry point
918  */
921 {
924  UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\BlueScreen");
925  UNICODE_STRING SymlinkName = RTL_CONSTANT_STRING(L"\\??\\BlueScreen");
926 
927  DPRINT ("Screen Driver 0.0.6\n");
928 
934 
936  sizeof(DEVICE_EXTENSION),
937  &DeviceName,
940  TRUE,
941  &DeviceObject);
942 
943  if (!NT_SUCCESS(Status))
944  {
945  return Status;
946  }
947 
948  Status = IoCreateSymbolicLink (&SymlinkName, &DeviceName);
949  if (NT_SUCCESS(Status))
951  else
953  return Status;
954 }
955 
956 /* EOF */
#define CRTC_SCANLINES
Definition: blue.h:90
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
struct tagCONSOLE_CURSOR_INFO * PCONSOLE_CURSOR_INFO
#define CRTCDATA
Definition: blue.h:124
#define GRAPHICSDATA
Definition: blue.h:126
PBYTE vidmem
Definition: vgavideo.c:18
#define IOCTL_CONSOLE_WRITE_OUTPUT_ATTRIBUTE
Definition: ntddblue.h:14
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define IOCTL_CONSOLE_SET_SCREEN_BUFFER_INFO
Definition: ntddblue.h:5
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define FILE_DEVICE_SCREEN
Definition: winioctl.h:133
#define IOCTL_CONSOLE_SET_TEXT_ATTRIBUTE
Definition: ntddblue.h:15
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define NTHALAPI
Definition: ntoskrnl.h:39
struct _DEVICE_EXTENSION DEVICE_EXTENSION
static const VGA_REGISTERS VidpMode3Regs
Definition: blue.c:55
UCHAR Sequencer[5]
Definition: blue.c:51
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTHALAPI BOOLEAN NTAPI HalQueryDisplayOwnership(VOID)
Definition: display.c:378
unsigned char * PUCHAR
Definition: retypes.h:3
char CHAR
Definition: xmlstorage.h:175
NTSTATUS NTAPI DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
Definition: blue.c:920
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:528
void __cdecl _enable(void)
Definition: intrin_arm.h:373
LONG NTSTATUS
Definition: precomp.h:26
struct tagCONSOLE_SCREEN_BUFFER_INFO CONSOLE_SCREEN_BUFFER_INFO
void ScrLoadFontTable(UINT32 CodePage)
Definition: font.c:27
GLintptr offset
Definition: glext.h:5920
static DRIVER_DISPATCH ScrDispatch
Definition: blue.c:889
ULONG CursorSize
Definition: blue.c:37
#define CRTC_CURSORPOSHI
Definition: blue.h:93
struct tagCONSOLE_MODE * PCONSOLE_MODE
#define ATTRIB
Definition: blue.h:127
struct Line * LinePtr
Definition: ncftp.h:78
#define IOCTL_CONSOLE_SET_CURSOR_INFO
Definition: ntddblue.h:7
PVOID NTAPI MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
Definition: iosup.c:47
#define MISC
Definition: blue.h:120
WCHAR DeviceName[]
Definition: adapter.cpp:21
char * LPSTR
Definition: xmlstorage.h:182
#define PELMASK
Definition: blue.h:129
#define FASTCALL
Definition: nt_native.h:50
int32_t INT
Definition: typedefs.h:56
#define pch(ap)
Definition: match.c:418
#define CRTC_ROWS
Definition: blue.h:89
#define IOCTL_CONSOLE_FILL_OUTPUT_CHARACTER
Definition: ntddblue.h:18
PUCHAR VideoMemory
Definition: blue.c:36
#define ENABLE_WRAP_AT_EOL_OUTPUT
Definition: blue.h:45
static const UCHAR DefaultPalette[]
Definition: blue.c:71
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
#define CRTC_COLUMNS
Definition: blue.h:87
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
unsigned int UINT32
static DRIVER_DISPATCH ScrWrite
Definition: blue.c:270
#define CRTC_DATA
Definition: blue.h:85
short SHORT
Definition: pedump.c:59
#define VIDMEM_BASE
Definition: blue.h:81
struct _VGA_REGISTERS * PVGA_REGISTERS
#define ATTRC_INPST1
Definition: blue.h:114
#define IOCTL_CONSOLE_FILL_OUTPUT_ATTRIBUTE
Definition: ntddblue.h:12
UCHAR Misc
Definition: blue.c:52
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
unsigned char
Definition: typeof.h:29
USHORT Rows
Definition: blue.c:42
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
#define IOCTL_CONSOLE_GET_CURSOR_INFO
Definition: ntddblue.h:6
void DPRINT(...)
Definition: polytest.cpp:61
UCHAR Graphics[9]
Definition: blue.c:50
#define IOCTL_CONSOLE_READ_OUTPUT_ATTRIBUTE
Definition: ntddblue.h:13
#define ATTRC_WRITEREG
Definition: blue.h:112
struct _VGA_REGISTERS VGA_REGISTERS
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
SHORT Left
Definition: blue.h:25
ULONG CursorY
Definition: ntddblue.h:61
ULONG X
Definition: bl.h:1340
#define SEQ
Definition: blue.h:121
#define PELINDEX
Definition: blue.h:130
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
BOOLEAN bVisible
Definition: blue.h:41
GLsizeiptr size
Definition: glext.h:5919
SHORT Bottom
Definition: blue.h:28
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct tagCONSOLE_DRAW * PCONSOLE_DRAW
#define IOCTL_CONSOLE_GET_MODE
Definition: ntddblue.h:8
static const UCHAR Index[8]
Definition: usbohci.c:18
#define STATUS
Definition: blue.h:128
#define CRTC_CURSOREND
Definition: blue.h:92
SHORT Top
Definition: blue.h:26
UCHAR CRT[24]
Definition: blue.c:48
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
Definition: ncftp.h:79
unsigned char UCHAR
Definition: xmlstorage.h:181
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
#define CRTC_CURSORPOSLO
Definition: blue.h:94
UCHAR Attribute[21]
Definition: blue.c:49
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static DRIVER_DISPATCH ScrIoControl
Definition: blue.c:416
#define CRTC
Definition: blue.h:123
DRIVER_DISPATCH(nfs41_FsdDispatch)
#define CRTC_OVERFLOW
Definition: blue.h:88
GLsizei const GLfloat * value
Definition: glext.h:6069
Definition: bl.h:1338
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
#define IOCTL_CONSOLE_DRAW
Definition: ntddblue.h:22
Status
Definition: gdiplustypes.h:24
#define ENABLE_PROCESSED_OUTPUT
Definition: blue.h:44
#define SEQDATA
Definition: blue.h:122
ULONG dwMode
Definition: ntddblue.h:32
USHORT CharAttribute
Definition: blue.c:39
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
struct tagOUTPUT_CHARACTER * POUTPUT_CHARACTER
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
unsigned short USHORT
Definition: pedump.c:61
#define TAB_WIDTH
Definition: blue.h:116
#define IOCTL_CONSOLE_SET_MODE
Definition: ntddblue.h:9
static VOID FASTCALL ScrAcquireOwnership(PDEVICE_EXTENSION DeviceExtension)
Definition: blue.c:147
#define IOCTL_CONSOLE_READ_OUTPUT_CHARACTER
Definition: ntddblue.h:19
unsigned int * PULONG
Definition: retypes.h:1
#define min(a, b)
Definition: monoChain.cc:55
#define CRTC_COMMAND
Definition: blue.h:84
struct tagOUTPUT_ATTRIBUTE * POUTPUT_ATTRIBUTE
#define IOCTL_CONSOLE_GET_SCREEN_BUFFER_INFO
Definition: ntddblue.h:4
#define IRP_MJ_READ
Definition: rdpdr.c:46
ULONG Mode
Definition: blue.c:40
#define IOCTL_CONSOLE_LOADFONT
Definition: ntddblue.h:24
#define GRAPHICS
Definition: blue.h:125
#define PELDATA
Definition: blue.h:131
struct _DEVICE_EXTENSION * PDEVICE_EXTENSION
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2181
static int processed(const type_t *type)
Definition: typegen.c:2236
void __cdecl _disable(void)
Definition: intrin_arm.h:365
ULONG CursorX
Definition: ntddblue.h:60
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define MmGetSystemAddressForMdl(Mdl)
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:532
USHORT Columns
Definition: blue.c:43
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER
Definition: ntddblue.h:20
SHORT Right
Definition: blue.h:27
BOOLEAN NTAPI InbvCheckDisplayOwnership(VOID)
Definition: inbv.c:557
struct tagCONSOLE_SCREEN_BUFFER_INFO * PCONSOLE_SCREEN_BUFFER_INFO
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
static VOID FASTCALL ScrSetRegisters(const VGA_REGISTERS *Registers)
Definition: blue.c:94
return STATUS_SUCCESS
Definition: btrfs.c:2966
ULONG Y
Definition: bl.h:1341
INT CursorVisible
Definition: blue.c:38
#define ATTRC_READREG
Definition: blue.h:113
static DRIVER_DISPATCH ScrCreate
Definition: blue.c:226
struct tagOUTPUT_ATTRIBUTE OUTPUT_ATTRIBUTE
unsigned short * PUSHORT
Definition: retypes.h:2
#define CRTC_CURSORSTART
Definition: blue.h:91
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
UCHAR ScanLines
Definition: blue.c:41