ReactOS  0.4.13-dev-235-g7373cb3
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  DPRINT ("%d Columns %d Rows %d Scanlines\n",
215  DeviceExtension->Columns,
216  DeviceExtension->Rows,
217  DeviceExtension->ScanLines);
218 }
219 
222 
224 static NTSTATUS NTAPI
226  PIRP Irp)
227 {
228  PDEVICE_EXTENSION DeviceExtension;
231 
232  DeviceExtension = DeviceObject->DeviceExtension;
233 
235  {
236  ScrAcquireOwnership(DeviceExtension);
237 
238  /* get pointer to video memory */
239  BaseAddress.QuadPart = VIDMEM_BASE;
240  DeviceExtension->VideoMemory =
241  (PUCHAR)MmMapIoSpace (BaseAddress, DeviceExtension->Rows * DeviceExtension->Columns * 2, MmNonCached);
242  }
243  else
244  {
245  /* store dummy values here */
246  DeviceExtension->Columns = 1;
247  DeviceExtension->Rows = 1;
248  DeviceExtension->ScanLines = 1;
249  }
250 
251  DeviceExtension->CursorSize = 5; /* FIXME: value correct?? */
252  DeviceExtension->CursorVisible = TRUE;
253 
254  /* more initialization */
255  DeviceExtension->CharAttribute = 0x17; /* light grey on blue */
256  DeviceExtension->Mode = ENABLE_PROCESSED_OUTPUT |
258 
260 
261  Irp->IoStatus.Status = Status;
263 
264  return (Status);
265 }
266 
268 static NTSTATUS NTAPI
270  PIRP Irp)
271 {
275  char *pch = Irp->UserBuffer;
276  PUCHAR vidmem;
277  unsigned int i;
278  int j, offset;
279  int cursorx, cursory;
280  int rows, columns;
281  int processed = DeviceExtension->Mode & ENABLE_PROCESSED_OUTPUT;
282 
284  {
285  /* Display is in graphics mode, we're not allowed to touch it */
287 
288  Irp->IoStatus.Status = Status;
290 
291  return Status;
292  }
293 
294  vidmem = DeviceExtension->VideoMemory;
295  rows = DeviceExtension->Rows;
296  columns = DeviceExtension->Columns;
297 
298  _disable();
303  _enable();
304 
305  cursory = offset / columns;
306  cursorx = offset % columns;
307  if( processed == 0 )
308  {
309  /* raw output mode */
310  // FIXME: Does the buffer only contains chars? or chars + attributes?
311  // FIXME2: Fix buffer overflow.
312  memcpy( &vidmem[(cursorx * 2) + (cursory * columns * 2)], pch, stk->Parameters.Write.Length );
313  offset += (stk->Parameters.Write.Length / 2);
314  }
315  else {
316  for (i = 0; i < stk->Parameters.Write.Length; i++, pch++)
317  {
318  switch (*pch)
319  {
320  case '\b':
321  if (cursorx > 0)
322  {
323  cursorx--;
324  }
325  else if (cursory > 0)
326  {
327  cursorx = columns - 1;
328  cursory--;
329  }
330  vidmem[(cursorx * 2) + (cursory * columns * 2)] = ' ';
331  vidmem[(cursorx * 2) + (cursory * columns * 2) + 1] = (char) DeviceExtension->CharAttribute;
332  break;
333 
334  case '\n':
335  cursory++;
336  cursorx = 0;
337  break;
338 
339  case '\r':
340  cursorx = 0;
341  break;
342 
343  case '\t':
344  offset = TAB_WIDTH - (cursorx % TAB_WIDTH);
345  for (j = 0; j < offset; j++)
346  {
347  vidmem[(cursorx * 2) + (cursory * columns * 2)] = ' ';
348  cursorx++;
349 
350  if (cursorx >= columns)
351  {
352  cursory++;
353  cursorx = 0;
354  }
355  }
356  break;
357 
358  default:
359  vidmem[(cursorx * 2) + (cursory * columns * 2)] = *pch;
360  vidmem[(cursorx * 2) + (cursory * columns * 2) + 1] = (char) DeviceExtension->CharAttribute;
361  cursorx++;
362  if (cursorx >= columns)
363  {
364  cursory++;
365  cursorx = 0;
366  }
367  break;
368  }
369 
370  /* Scroll up the contents of the screen if we are at the end */
371  if (cursory >= rows)
372  {
373  unsigned short *LinePtr;
374 
375  memcpy (vidmem,
376  &vidmem[columns * 2],
377  columns * (rows - 1) * 2);
378 
379  LinePtr = (unsigned short *) &vidmem[columns * (rows - 1) * 2];
380 
381  for (j = 0; j < columns; j++)
382  {
383  LinePtr[j] = DeviceExtension->CharAttribute << 8;
384  }
385  cursory = rows - 1;
386  for (j = 0; j < columns; j++)
387  {
388  vidmem[(j * 2) + (cursory * columns * 2)] = ' ';
389  vidmem[(j * 2) + (cursory * columns * 2) + 1] = (char)DeviceExtension->CharAttribute;
390  }
391  }
392  }
393 
394  /* Set the cursor position */
395  offset = (cursory * columns) + cursorx;
396  }
397  _disable();
401  offset >>= 8;
403  _enable();
404 
406 
407  Irp->IoStatus.Status = Status;
409 
410  return Status;
411 }
412 
414 static NTSTATUS NTAPI
416  PIRP Irp)
417 {
419  PDEVICE_EXTENSION DeviceExtension;
421 
422  DeviceExtension = DeviceObject->DeviceExtension;
423  switch (stk->Parameters.DeviceIoControl.IoControlCode)
424  {
426  {
427  PCONSOLE_SCREEN_BUFFER_INFO pcsbi = (PCONSOLE_SCREEN_BUFFER_INFO)Irp->AssociatedIrp.SystemBuffer;
428  int rows = DeviceExtension->Rows;
429  int columns = DeviceExtension->Columns;
430  unsigned int offset;
431 
433  {
434  /* read cursor position from crtc */
435  _disable();
439  offset += (READ_PORT_UCHAR (CRTC_DATA) << 8);
440  _enable();
441  }
442  else
443  {
444  offset = 0;
445  }
446 
447  pcsbi->dwSize.X = columns;
448  pcsbi->dwSize.Y = rows;
449 
450  pcsbi->dwCursorPosition.X = (SHORT)(offset % columns);
451  pcsbi->dwCursorPosition.Y = (SHORT)(offset / columns);
452 
453  pcsbi->wAttributes = DeviceExtension->CharAttribute;
454 
455  pcsbi->srWindow.Left = 0;
456  pcsbi->srWindow.Right = columns - 1;
457  pcsbi->srWindow.Top = 0;
458  pcsbi->srWindow.Bottom = rows - 1;
459 
460  pcsbi->dwMaximumWindowSize.X = columns;
461  pcsbi->dwMaximumWindowSize.Y = rows;
462 
463  Irp->IoStatus.Information = sizeof (CONSOLE_SCREEN_BUFFER_INFO);
465  }
466  break;
467 
469  {
470  PCONSOLE_SCREEN_BUFFER_INFO pcsbi = (PCONSOLE_SCREEN_BUFFER_INFO)Irp->AssociatedIrp.SystemBuffer;
471  unsigned int offset;
472 
473  if ( pcsbi->dwCursorPosition.X < 0 || pcsbi->dwCursorPosition.X >= DeviceExtension->Columns ||
474  pcsbi->dwCursorPosition.Y < 0 || pcsbi->dwCursorPosition.Y >= DeviceExtension->Rows )
475  {
476  Irp->IoStatus.Information = 0;
478  break;
479  }
480 
481  DeviceExtension->CharAttribute = pcsbi->wAttributes;
482  offset = (pcsbi->dwCursorPosition.Y * DeviceExtension->Columns) +
483  pcsbi->dwCursorPosition.X;
484 
486  {
487  _disable();
492  _enable();
493  }
494 
495  Irp->IoStatus.Information = 0;
497  }
498  break;
499 
501  {
502  PCONSOLE_CURSOR_INFO pcci = (PCONSOLE_CURSOR_INFO)Irp->AssociatedIrp.SystemBuffer;
503 
504  pcci->dwSize = DeviceExtension->CursorSize;
505  pcci->bVisible = DeviceExtension->CursorVisible;
506 
507  Irp->IoStatus.Information = sizeof (CONSOLE_CURSOR_INFO);
509  }
510  break;
511 
513  {
514  PCONSOLE_CURSOR_INFO pcci = (PCONSOLE_CURSOR_INFO)Irp->AssociatedIrp.SystemBuffer;
515  UCHAR data, value;
516  ULONG size, height;
517 
518  DeviceExtension->CursorSize = pcci->dwSize;
519  DeviceExtension->CursorVisible = pcci->bVisible;
520 
522  {
523  height = DeviceExtension->ScanLines;
524  data = (pcci->bVisible) ? 0x00 : 0x20;
525 
526  size = (pcci->dwSize * height) / 100;
527  if (size < 1)
528  {
529  size = 1;
530  }
531 
532  data |= (UCHAR)(height - size);
533 
534  _disable();
538  value = READ_PORT_UCHAR (CRTC_DATA) & 0xE0;
540 
541  _enable();
542  }
543 
544  Irp->IoStatus.Information = 0;
546  }
547  break;
548 
550  {
551  PCONSOLE_MODE pcm = (PCONSOLE_MODE)Irp->AssociatedIrp.SystemBuffer;
552 
553  pcm->dwMode = DeviceExtension->Mode;
554 
555  Irp->IoStatus.Information = sizeof(CONSOLE_MODE);
557  }
558  break;
559 
561  {
562  PCONSOLE_MODE pcm = (PCONSOLE_MODE)Irp->AssociatedIrp.SystemBuffer;
563 
564  DeviceExtension->Mode = pcm->dwMode;
565 
566  Irp->IoStatus.Information = 0;
568  }
569  break;
570 
572  {
573  POUTPUT_ATTRIBUTE Buf = (POUTPUT_ATTRIBUTE)Irp->AssociatedIrp.SystemBuffer;
574  PUCHAR vidmem;
575  int offset;
576  ULONG dwCount;
577  ULONG nMaxLength = Buf->nLength;
578 
579  if ( Buf->dwCoord.X < 0 || Buf->dwCoord.X >= DeviceExtension->Columns ||
580  Buf->dwCoord.Y < 0 || Buf->dwCoord.Y >= DeviceExtension->Rows )
581  {
582  Buf->dwTransfered = 0;
583  Irp->IoStatus.Information = 0;
585  break;
586  }
587 
589  {
590  vidmem = DeviceExtension->VideoMemory;
591  offset = (Buf->dwCoord.Y * DeviceExtension->Columns * 2) +
592  (Buf->dwCoord.X * 2) + 1;
593 
594  nMaxLength = min(nMaxLength,
595  (DeviceExtension->Rows - Buf->dwCoord.Y)
596  * DeviceExtension->Columns - Buf->dwCoord.X);
597 
598  for (dwCount = 0; dwCount < nMaxLength; dwCount++)
599  {
600  vidmem[offset + (dwCount * 2)] = (char) Buf->wAttribute;
601  }
602  }
603 
604  Buf->dwTransfered = nMaxLength;
605 
606  Irp->IoStatus.Information = 0;
608  }
609  break;
610 
612  {
613  POUTPUT_ATTRIBUTE Buf = (POUTPUT_ATTRIBUTE)Irp->AssociatedIrp.SystemBuffer;
614  PUSHORT pAttr = (PUSHORT)MmGetSystemAddressForMdl(Irp->MdlAddress);
615  PUCHAR vidmem;
616  int offset;
617  ULONG dwCount;
618  ULONG nMaxLength;
619 
620  if ( Buf->dwCoord.X < 0 || Buf->dwCoord.X >= DeviceExtension->Columns ||
621  Buf->dwCoord.Y < 0 || Buf->dwCoord.Y >= DeviceExtension->Rows )
622  {
623  Buf->dwTransfered = 0;
624  Irp->IoStatus.Information = 0;
626  break;
627  }
628 
630  {
631  vidmem = DeviceExtension->VideoMemory;
632  offset = (Buf->dwCoord.Y * DeviceExtension->Columns * 2) +
633  (Buf->dwCoord.X * 2) + 1;
634 
635  nMaxLength = min(stk->Parameters.DeviceIoControl.OutputBufferLength,
636  (DeviceExtension->Rows - Buf->dwCoord.Y)
637  * DeviceExtension->Columns - Buf->dwCoord.X);
638 
639  for (dwCount = 0; dwCount < nMaxLength; dwCount++, pAttr++)
640  {
641  *((char *)pAttr) = vidmem[offset + (dwCount * 2)];
642  }
643 
644  Buf->dwTransfered = dwCount;
645  }
646  else
647  {
648  Buf->dwTransfered = 0;
649  }
650 
651  Irp->IoStatus.Information = sizeof(OUTPUT_ATTRIBUTE);
653  }
654  break;
655 
657  {
658  COORD *pCoord = (COORD *)MmGetSystemAddressForMdl(Irp->MdlAddress);
659  CHAR *pAttr = (CHAR *)(pCoord + 1);
660  PUCHAR vidmem;
661  int offset;
662  ULONG dwCount;
663  ULONG nMaxLength;
664 
665  if ( pCoord->X < 0 || pCoord->X >= DeviceExtension->Columns ||
666  pCoord->Y < 0 || pCoord->Y >= DeviceExtension->Rows )
667  {
668  Irp->IoStatus.Information = 0;
670  break;
671  }
672 
674  {
675  vidmem = DeviceExtension->VideoMemory;
676  offset = (pCoord->Y * DeviceExtension->Columns * 2) +
677  (pCoord->X * 2) + 1;
678 
679  nMaxLength = min(stk->Parameters.DeviceIoControl.OutputBufferLength - sizeof(COORD),
680  (DeviceExtension->Rows - pCoord->Y)
681  * DeviceExtension->Columns - pCoord->X);
682 
683  for (dwCount = 0; dwCount < nMaxLength; dwCount++, pAttr++)
684  {
685  vidmem[offset + (dwCount * 2)] = *pAttr;
686  }
687  }
688 
689  Irp->IoStatus.Information = 0;
691  }
692  break;
693 
695  DeviceExtension->CharAttribute = (USHORT)*(PUSHORT)Irp->AssociatedIrp.SystemBuffer;
696  Irp->IoStatus.Information = 0;
698  break;
699 
701  {
702  POUTPUT_CHARACTER Buf = (POUTPUT_CHARACTER)Irp->AssociatedIrp.SystemBuffer;
703  PUCHAR vidmem;
704  int offset;
705  ULONG dwCount;
706  ULONG nMaxLength = Buf->nLength;
707 
708  if ( Buf->dwCoord.X < 0 || Buf->dwCoord.X >= DeviceExtension->Columns ||
709  Buf->dwCoord.Y < 0 || Buf->dwCoord.Y >= DeviceExtension->Rows )
710  {
711  Buf->dwTransfered = 0;
712  Irp->IoStatus.Information = 0;
714  break;
715  }
716 
718  {
719  vidmem = DeviceExtension->VideoMemory;
720  offset = (Buf->dwCoord.Y * DeviceExtension->Columns * 2) +
721  (Buf->dwCoord.X * 2);
722 
723  nMaxLength = min(nMaxLength,
724  (DeviceExtension->Rows - Buf->dwCoord.Y)
725  * DeviceExtension->Columns - Buf->dwCoord.X);
726 
727  for (dwCount = 0; dwCount < nMaxLength; dwCount++)
728  {
729  vidmem[offset + (dwCount * 2)] = (char) Buf->cCharacter;
730  }
731  }
732 
733  Buf->dwTransfered = nMaxLength;
734 
735  Irp->IoStatus.Information = 0;
737  }
738  break;
739 
741  {
742  POUTPUT_CHARACTER Buf = (POUTPUT_CHARACTER)Irp->AssociatedIrp.SystemBuffer;
743  LPSTR pChar = (LPSTR)MmGetSystemAddressForMdl(Irp->MdlAddress);
744  PUCHAR vidmem;
745  int offset;
746  ULONG dwCount;
747  ULONG nMaxLength;
748 
749  if ( Buf->dwCoord.X < 0 || Buf->dwCoord.X >= DeviceExtension->Columns ||
750  Buf->dwCoord.Y < 0 || Buf->dwCoord.Y >= DeviceExtension->Rows )
751  {
752  Buf->dwTransfered = 0;
753  Irp->IoStatus.Information = 0;
755  break;
756  }
757 
759  {
760  vidmem = DeviceExtension->VideoMemory;
761  offset = (Buf->dwCoord.Y * DeviceExtension->Columns * 2) +
762  (Buf->dwCoord.X * 2);
763 
764  nMaxLength = min(stk->Parameters.DeviceIoControl.OutputBufferLength,
765  (DeviceExtension->Rows - Buf->dwCoord.Y)
766  * DeviceExtension->Columns - Buf->dwCoord.X);
767 
768  for (dwCount = 0; dwCount < nMaxLength; dwCount++, pChar++)
769  {
770  *pChar = vidmem[offset + (dwCount * 2)];
771  }
772 
773  Buf->dwTransfered = dwCount;
774  }
775  else
776  {
777  Buf->dwTransfered = 0;
778  }
779 
780  Irp->IoStatus.Information = sizeof(OUTPUT_ATTRIBUTE);
782  }
783  break;
784 
786  {
787  COORD *pCoord = (COORD *)MmGetSystemAddressForMdl(Irp->MdlAddress);
788  LPSTR pChar = (CHAR *)(pCoord + 1);
789  PUCHAR vidmem;
790  int offset;
791  ULONG dwCount;
792  ULONG nMaxLength;
793 
794  if ( pCoord->X < 0 || pCoord->X >= DeviceExtension->Columns ||
795  pCoord->Y < 0 || pCoord->Y >= DeviceExtension->Rows )
796  {
797  Irp->IoStatus.Information = 0;
799  break;
800  }
801 
803  {
804  vidmem = DeviceExtension->VideoMemory;
805  offset = (pCoord->Y * DeviceExtension->Columns * 2) +
806  (pCoord->X * 2);
807 
808  nMaxLength = min(stk->Parameters.DeviceIoControl.OutputBufferLength - sizeof(COORD),
809  (DeviceExtension->Rows - pCoord->Y)
810  * DeviceExtension->Columns - pCoord->X);
811 
812  for (dwCount = 0; dwCount < nMaxLength; dwCount++, pChar++)
813  {
814  vidmem[offset + (dwCount * 2)] = *pChar;
815  }
816  }
817 
818  Irp->IoStatus.Information = 0;
820  }
821  break;
822 
823  case IOCTL_CONSOLE_DRAW:
824  {
825  PCONSOLE_DRAW ConsoleDraw;
826  PUCHAR Src, Dest;
827  UINT32 SrcDelta, DestDelta, i, Offset;
828 
830  {
831  ConsoleDraw = (PCONSOLE_DRAW) MmGetSystemAddressForMdl(Irp->MdlAddress);
832  Src = (PUCHAR) (ConsoleDraw + 1);
833  SrcDelta = ConsoleDraw->SizeX * 2;
834  Dest = DeviceExtension->VideoMemory +
835  (ConsoleDraw->Y * DeviceExtension->Columns + ConsoleDraw->X) * 2;
836  DestDelta = DeviceExtension->Columns * 2;
837 
838  for (i = 0; i < ConsoleDraw->SizeY; i++)
839  {
840  RtlCopyMemory(Dest, Src, SrcDelta);
841  Src += SrcDelta;
842  Dest += DestDelta;
843  }
844 
845  Offset = (ConsoleDraw->CursorY * DeviceExtension->Columns) +
846  ConsoleDraw->CursorX;
847 
848  _disable();
853  _enable();
854  }
855 
856  Irp->IoStatus.Information = 0;
858  }
859  break;
860 
862  {
863  UINT32 CodePage = (UINT32)*(PULONG)Irp->AssociatedIrp.SystemBuffer;
864 
866  {
867  // Upload a font for the codepage if needed
868  ScrLoadFontTable(CodePage);
869  }
870 
871  Irp->IoStatus.Information = 0;
873  }
874  break;
875 
876  default:
878  }
879 
880  Irp->IoStatus.Status = Status;
882 
883  return Status;
884 }
885 
887 static NTSTATUS NTAPI
889  PIRP Irp)
890 {
893 
894  switch (stk->MajorFunction)
895  {
896  case IRP_MJ_CLOSE:
898  break;
899 
900  default:
902  break;
903  }
904 
905 
906  Irp->IoStatus.Status = Status;
908 
909  return Status;
910 }
911 
912 
913 /*
914  * Module entry point
915  */
918 {
921  UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\BlueScreen");
922  UNICODE_STRING SymlinkName = RTL_CONSTANT_STRING(L"\\??\\BlueScreen");
923 
924  DPRINT ("Screen Driver 0.0.6\n");
925 
931 
933  sizeof(DEVICE_EXTENSION),
934  &DeviceName,
937  TRUE,
938  &DeviceObject);
939 
940  if (!NT_SUCCESS(Status))
941  {
942  return Status;
943  }
944 
945  Status = IoCreateSymbolicLink (&SymlinkName, &DeviceName);
946  if (NT_SUCCESS(Status))
948  else
950  return Status;
951 }
952 
953 /* 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:917
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:535
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:886
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:267
#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:413
#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:1250
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:2180
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:565
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:539
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:419
struct tagCONSOLE_SCREEN_BUFFER_INFO * PCONSOLE_SCREEN_BUFFER_INFO
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
static VOID FASTCALL ScrSetRegisters(const VGA_REGISTERS *Registers)
Definition: blue.c:94
return STATUS_SUCCESS
Definition: btrfs.c:2745
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:223
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