ReactOS 0.4.16-dev-106-g10b08aa
screen.c File Reference
#include "green.h"
#include <debug.h>
Include dependency graph for screen.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define ESC   ((UCHAR)0x1b)
 

Functions

static VOID AddToSendBuffer (IN PSCREEN_DEVICE_EXTENSION DeviceExtension, IN ULONG NumberOfChars,...)
 
NTSTATUS ScreenAddDevice (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT Pdo)
 
NTSTATUS ScreenWrite (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS ScreenDeviceControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 

Macro Definition Documentation

◆ ESC

#define ESC   ((UCHAR)0x1b)

Definition at line 16 of file screen.c.

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file screen.c.

Function Documentation

◆ AddToSendBuffer()

static VOID AddToSendBuffer ( IN PSCREEN_DEVICE_EXTENSION  DeviceExtension,
IN ULONG  NumberOfChars,
  ... 
)
static

Definition at line 27 of file screen.c.

31{
32 PIRP Irp;
33 IO_STATUS_BLOCK ioStatus;
36 ULONG SizeLeft;
37 int CurrentInt;
38 UCHAR CurrentChar;
40 LARGE_INTEGER ZeroOffset;
41
42 ZeroOffset.QuadPart = 0;
43
44 SizeLeft = sizeof(DeviceExtension->SendBuffer) - DeviceExtension->SendBufferPosition;
45 if (SizeLeft < NumberOfChars * 2 || NumberOfChars == 0)
46 {
47 SerialDevice = ((PGREEN_DEVICE_EXTENSION)DeviceExtension->Green->DeviceExtension)->Serial;
51 DeviceExtension->SendBuffer, DeviceExtension->SendBufferPosition,
52 &ZeroOffset,
53 NULL, /* Event */
54 &ioStatus);
55 if (!Irp)
56 {
57 DPRINT1("IoBuildSynchronousFsdRequest() failed. Unable to flush output buffer\n");
58 return;
59 }
60
62
64 {
65 DPRINT1("IoCallDriver() failed. Status = 0x%08lx\n", Status);
66 return;
67 }
68 DeviceExtension->SendBufferPosition = 0;
69 SizeLeft = sizeof(DeviceExtension->SendBuffer);
70 }
71
72 va_start(args, NumberOfChars);
73 while (NumberOfChars-- > 0)
74 {
75 CurrentInt = va_arg(args, int);
76
77 if (CurrentInt > 0)
78 {
79 CurrentChar = (UCHAR)CurrentInt;
80
81 /* Why 0xff chars are printed on a 'dir' ? */
82 if (CurrentChar == 0xff) CurrentChar = ' ';
83
84 DeviceExtension->SendBuffer[DeviceExtension->SendBufferPosition++] = CurrentChar;
85 SizeLeft--;
86 }
87 else if (CurrentInt == 0)
88 {
89 DeviceExtension->SendBuffer[DeviceExtension->SendBufferPosition++] = '0';
90 SizeLeft--;
91 }
92 else
93 {
94 CurrentInt = -CurrentInt;
95 ASSERT(CurrentInt < 100);
96 if (CurrentInt >= 10)
97 {
98 DeviceExtension->SendBuffer[DeviceExtension->SendBufferPosition++] =
99 (CurrentInt / 10) % 10 + '0';
100 SizeLeft--;
101 }
102 DeviceExtension->SendBuffer[DeviceExtension->SendBufferPosition++] =
103 CurrentInt % 10 + '0';
104 SizeLeft--;
105 }
106 }
107 va_end(args);
108}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define va_arg(ap, T)
Definition: acmsvcex.h:89
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
@ SerialDevice
Definition: bl.h:249
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
struct _GREEN_DEVICE_EXTENSION * PGREEN_DEVICE_EXTENSION
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
#define IoCallDriver
Definition: irp.c:1225
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define args
Definition: format.c:66
Definition: match.c:390
uint32_t ULONG
Definition: typedefs.h:59
LONGLONG QuadPart
Definition: typedefs.h:114
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by ScreenAddDevice(), ScreenDeviceControl(), and ScreenWrite().

◆ ScreenAddDevice()

NTSTATUS ScreenAddDevice ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  Pdo 
)

Definition at line 111 of file screen.c.

114{
115 /* We want to be an upper filter of Blue, if it is existing.
116 * We also *have to* create a Fdo on top of the given Pdo.
117 * Hence, we have 2 cases:
118 * - Blue doesn't exist -> Create a unique Fdo (named Blue) at
119 * the top of the given Pdo
120 * - Blue does exist -> Create a Fdo at the top of the existing
121 * DO, and create a "pass to Green" FDO at the top of the Pdo
122 */
124 PDEVICE_OBJECT PassThroughFdo = NULL;
125 PDEVICE_OBJECT LowerDevice = NULL;
126 PDEVICE_OBJECT PreviousBlue = NULL;
127 PSCREEN_DEVICE_EXTENSION DeviceExtension = NULL;
128 UNICODE_STRING BlueScreenName = RTL_CONSTANT_STRING(L"\\Device\\BlueScreen");
130
131 DPRINT("ScreenInitialize() called\n");
132
133 /* Try to create a unique Fdo */
137 &BlueScreenName,
140 TRUE,
141 &Fdo);
142
144 {
145 DPRINT("Attaching to old blue\n");
146
147 /* Suggested by hpoussin .. Hide previous blue device
148 * This makes us able to coexist with blue, and install
149 * when loaded */
153 NULL,
156 TRUE,
157 &Fdo);
158 if (!NT_SUCCESS(Status))
159 {
160 DPRINT("IoCreateDevice() failed with status 0x%08lx\n", Status);
161 goto cleanup;
162 }
163
164 /* Initialize some fields, as IoAttachDevice will trigger the
165 * sending of IRP_MJ_CLEANUP/IRP_MJ_CLOSE. We have to know where to
166 * dispatch these IRPs... */
167 ((PSCREEN_DEVICE_EXTENSION)Fdo->DeviceExtension)->Common.Type = ScreenPDO;
169 Fdo,
170 &BlueScreenName,
171 &LowerDevice);
172 if (!NT_SUCCESS(Status))
173 {
174 DPRINT("IoAttachDevice() failed with status 0x%08lx\n", Status);
175 goto cleanup;
176 }
177 PreviousBlue = LowerDevice;
178
179 /* Attach a faked FDO to PDO */
183 NULL,
186 TRUE,
187 &PassThroughFdo);
188 if (!NT_SUCCESS(Status))
189 {
190 DPRINT("IoCreateDevice() failed with status 0x%08lx\n", Status);
191 goto cleanup;
192 }
194 ((PCOMMON_FDO_DEVICE_EXTENSION)PassThroughFdo->DeviceExtension)->LowerDevice = Fdo;
195 PassThroughFdo->StackSize = Fdo->StackSize + 1;
196 }
197 else if (NT_SUCCESS(Status))
198 {
199 /* Attach the named Fdo on top of Pdo */
200 LowerDevice = IoAttachDeviceToDeviceStack(Fdo, Pdo);
201 }
202 else
203 {
204 DPRINT("IoCreateDevice() failed with status 0x%08lx\n", Status);
205 return Status;
206 }
207
208 /* We definately have a device object. PreviousBlue may or may
209 * not be null */
210 DeviceExtension = (PSCREEN_DEVICE_EXTENSION)Fdo->DeviceExtension;
211 RtlZeroMemory(DeviceExtension, sizeof(SCREEN_DEVICE_EXTENSION));
212 DeviceExtension->Common.Type = ScreenFDO;
213 DeviceExtension->Common.LowerDevice = LowerDevice;
215 ((PGREEN_DEVICE_EXTENSION)DeviceExtension->Green->DeviceExtension)->ScreenFdo = Fdo;
216 DeviceExtension->PreviousBlue = PreviousBlue;
217 IoAttachDeviceToDeviceStack(PassThroughFdo ? PassThroughFdo : Fdo, Pdo);
218
219 /* initialize screen */
220 DeviceExtension->Columns = 80;
221 DeviceExtension->Rows = 25;
222 DeviceExtension->ScanLines = 16;
223 DeviceExtension->VideoMemory = (PUCHAR)ExAllocatePool(
224 PagedPool,
225 2 * DeviceExtension->Columns * DeviceExtension->Rows * sizeof(UCHAR));
226 if (!DeviceExtension->VideoMemory)
227 {
228 DPRINT("ExAllocatePool() failed\n");
230 goto cleanup;
231 }
232 DeviceExtension->TabWidth = 8;
233
234 /* more initialization */
235 DeviceExtension->Mode = ENABLE_PROCESSED_OUTPUT |
237
238 /* initialize screen at next write */
239 AddToSendBuffer(DeviceExtension, 2, ESC, 'c'); /* reset device */
240 AddToSendBuffer(DeviceExtension, 4, ESC, '[', '7', 'l'); /* disable line wrap */
241 AddToSendBuffer(DeviceExtension, 4, ESC, '[', '3', 'g'); /* clear all tabs */
242
243 Fdo->Flags |= DO_POWER_PAGABLE;
244 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
245
247
248cleanup:
249 if (!NT_SUCCESS(Status))
250 {
251 if (DeviceExtension)
252 ExFreePool(DeviceExtension->VideoMemory);
253 if (LowerDevice)
254 IoDetachDevice(LowerDevice);
255 if (Fdo)
257 if (PassThroughFdo)
258 IoDeleteDevice(PassThroughFdo);
259 }
260
261 return Status;
262}
#define ENABLE_WRAP_AT_EOL_OUTPUT
Definition: blue.h:54
#define ENABLE_PROCESSED_OUTPUT
Definition: blue.h:53
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define TRUE
Definition: types.h:120
static void cleanup(void)
Definition: main.c:1335
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PagedPool
Definition: env_spec_w32.h:308
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
@ ScreenPDO
Definition: green.h:24
@ PassThroughFDO
Definition: green.h:29
@ ScreenFDO
Definition: green.h:27
struct _GREEN_DRIVER_EXTENSION * PGREEN_DRIVER_EXTENSION
struct _COMMON_FDO_DEVICE_EXTENSION * PCOMMON_FDO_DEVICE_EXTENSION
struct _SCREEN_DEVICE_EXTENSION * PSCREEN_DEVICE_EXTENSION
#define ESC
Definition: screen.c:16
static VOID AddToSendBuffer(IN PSCREEN_DEVICE_EXTENSION DeviceExtension, IN ULONG NumberOfChars,...)
Definition: screen.c:27
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
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
NTSTATUS NTAPI IoAttachDevice(PDEVICE_OBJECT SourceDevice, PUNICODE_STRING TargetDeviceName, PDEVICE_OBJECT *AttachedDevice)
Definition: device.c:913
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1904
#define L(x)
Definition: ntvdm.h:50
#define FILE_DEVICE_SCREEN
Definition: winioctl.h:73
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
GREEN_DEVICE_TYPE Type
Definition: green.h:40
PDEVICE_OBJECT LowerDevice
Definition: green.h:41
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PDEVICE_OBJECT Green
Definition: green.h:63
COMMON_FDO_DEVICE_EXTENSION Common
Definition: green.h:62
PDEVICE_OBJECT PreviousBlue
Definition: green.h:77
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
unsigned char * PUCHAR
Definition: typedefs.h:53
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_ WDFDRIVER _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT Pdo
Definition: wdfminiport.h:72
#define DO_POWER_PAGABLE

Referenced by GreenAddDevice().

◆ ScreenDeviceControl()

NTSTATUS ScreenDeviceControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 408 of file screen.c.

411{
413 PSCREEN_DEVICE_EXTENSION DeviceExtension;
416
418 DeviceExtension = (PSCREEN_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
419 SerialDevice = ((PGREEN_DEVICE_EXTENSION)DeviceExtension->Green->DeviceExtension)->Serial;
420 if (!SerialDevice)
421 {
422 DPRINT1("Calling blue\n");
424 return IoCallDriver(DeviceExtension->PreviousBlue, Irp);
425 }
426
427 switch (Stack->Parameters.DeviceIoControl.IoControlCode)
428 {
429#if 0
431 {
433 DPRINT("IRP_MJ_DEVICE_CONTROL / IOCTL_CONSOLE_GET_SCREEN_BUFFER_INFO\n");
434
435 pcsbi = (PCONSOLE_SCREEN_BUFFER_INFO)Irp->AssociatedIrp.SystemBuffer;
436
437 pcsbi->dwSize.X = DeviceExtension->Columns;
438 pcsbi->dwSize.Y = DeviceExtension->Rows;
439
440 pcsbi->dwCursorPosition.X = (SHORT)(DeviceExtension->LogicalOffset % DeviceExtension->Columns);
441 pcsbi->dwCursorPosition.Y = (SHORT)(DeviceExtension->LogicalOffset / DeviceExtension->Columns);
442
443 pcsbi->wAttributes = DeviceExtension->CharAttribute;
444
445 pcsbi->srWindow.Left = 1;
446 pcsbi->srWindow.Right = DeviceExtension->Columns;
447 pcsbi->srWindow.Top = 1;
448 pcsbi->srWindow.Bottom = DeviceExtension->Rows;
449
450 pcsbi->dwMaximumWindowSize.X = DeviceExtension->Columns;
451 pcsbi->dwMaximumWindowSize.Y = DeviceExtension->Rows;
452
453 Irp->IoStatus.Information = sizeof(CONSOLE_SCREEN_BUFFER_INFO);
455 break;
456 }
458 {
460 DPRINT("IRP_MJ_DEVICE_CONTROL / IOCTL_CONSOLE_SET_SCREEN_BUFFER_INFO\n");
461
462 pcsbi = (PCONSOLE_SCREEN_BUFFER_INFO)Irp->AssociatedIrp.SystemBuffer;
463 /* FIXME: remove */ { pcsbi->dwCursorPosition.X++; }
464 /* FIXME: remove */ { pcsbi->dwCursorPosition.Y++; }
465 ASSERT(pcsbi->dwCursorPosition.X >= 1);
466 ASSERT(pcsbi->dwCursorPosition.Y >= 1);
467 ASSERT(pcsbi->dwCursorPosition.X <= DeviceExtension->Columns);
468 ASSERT(pcsbi->dwCursorPosition.Y <= DeviceExtension->Rows);
469
470 DeviceExtension->LogicalOffset = (
471 (pcsbi->dwCursorPosition.Y-1) * DeviceExtension->Columns +
472 (pcsbi->dwCursorPosition.X-1)) * 2;
473 AddToSendBuffer(DeviceExtension, 6, ESC, '[',
474 -(int)pcsbi->dwCursorPosition.Y, ';',
475 -(int)pcsbi->dwCursorPosition.X, 'H');
476
477 /* flush buffer */
478 AddToSendBuffer(DeviceExtension, 0);
479
480 DeviceExtension->CharAttribute = pcsbi->wAttributes;
481
482 Irp->IoStatus.Information = 0;
484 break;
485 }
487 {
488 PCONSOLE_CURSOR_INFO pcci = (PCONSOLE_CURSOR_INFO)Irp->AssociatedIrp.SystemBuffer;
489 DPRINT("IRP_MJ_DEVICE_CONTROL / IOCTL_CONSOLE_GET_CURSOR_INFO\n");
490
491 pcci->dwSize = 1;
492 pcci->bVisible = TRUE;
493
494 Irp->IoStatus.Information = sizeof (CONSOLE_CURSOR_INFO);
496 break;
497 }
499 {
500 PCONSOLE_MODE pcm = (PCONSOLE_MODE)Irp->AssociatedIrp.SystemBuffer;
501 DPRINT("IRP_MJ_DEVICE_CONTROL / IOCTL_CONSOLE_GET_MODE\n");
502
503 pcm->dwMode = DeviceExtension->Mode;
504
505 Irp->IoStatus.Information = sizeof(CONSOLE_MODE);
507 break;
508 }
510 {
511 PCONSOLE_MODE pcm = (PCONSOLE_MODE)Irp->AssociatedIrp.SystemBuffer;
512 DPRINT("IRP_MJ_DEVICE_CONTROL / IOCTL_CONSOLE_SET_MODE\n");
513
514 DeviceExtension->Mode = pcm->dwMode;
515
516 Irp->IoStatus.Information = 0;
518 break;
519 }
521 {
522 DPRINT1("IRP_MJ_DEVICE_CONTROL / IOCTL_CONSOLE_FILL_OUTPUT_ATTRIBUTE\n");
523 Status = STATUS_NOT_IMPLEMENTED; /* FIXME: IOCTL_CONSOLE_FILL_OUTPUT_ATTRIBUTE */
524 break;
525 }
527 {
528 DPRINT1("IRP_MJ_DEVICE_CONTROL / IOCTL_CONSOLE_READ_OUTPUT_ATTRIBUTE\n");
529 Status = STATUS_NOT_IMPLEMENTED; /* FIXME: IOCTL_CONSOLE_READ_OUTPUT_ATTRIBUTE */
530 break;
531 }
533 {
534 DPRINT1("IRP_MJ_DEVICE_CONTROL / IOCTL_CONSOLE_WRITE_OUTPUT_ATTRIBUTE\n");
535 Status = STATUS_NOT_IMPLEMENTED; /* FIXME: IOCTL_CONSOLE_WRITE_OUTPUT_ATTRIBUTE */
536 break;
537 }
539 {
540 DPRINT("IRP_MJ_DEVICE_CONTROL / IOCTL_CONSOLE_SET_TEXT_ATTRIBUTE\n");
541
542 DeviceExtension->CharAttribute = (WORD)*(PWORD)Irp->AssociatedIrp.SystemBuffer;
543 Irp->IoStatus.Information = 0;
545 break;
546 }
548 {
549 DPRINT1("IRP_MJ_DEVICE_CONTROL / IOCTL_CONSOLE_FILL_OUTPUT_CHARACTER\n");
550 Status = STATUS_NOT_IMPLEMENTED; /* FIXME:IOCTL_CONSOLE_FILL_OUTPUT_CHARACTER */
551 break;
552 }
554 {
555 DPRINT1("IRP_MJ_DEVICE_CONTROL / IOCTL_CONSOLE_READ_OUTPUT_CHARACTER\n");
556 Status = STATUS_NOT_IMPLEMENTED; /* FIXME: IOCTL_CONSOLE_READ_OUTPUT_CHARACTER */
557 break;
558 }
560 {
561 DPRINT1("IRP_MJ_DEVICE_CONTROL / IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER\n");
562 Status = STATUS_NOT_IMPLEMENTED; /* FIXME: IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER */
563 break;
564 }
566 {
567 PCONSOLE_DRAW ConsoleDraw;
568 PUCHAR Video;
569 ULONG x, y;
570 BOOLEAN DoOptimization = FALSE;
571 DPRINT("IRP_MJ_DEVICE_CONTROL / IOCTL_CONSOLE_DRAW\n");
572
573 ConsoleDraw = (PCONSOLE_DRAW)MmGetSystemAddressForMdl(Irp->MdlAddress);
574 /* FIXME: remove */ { ConsoleDraw->X++; ConsoleDraw->CursorX++; }
575 /* FIXME: remove */ { ConsoleDraw->Y++; ConsoleDraw->CursorY++; }
576 DPRINT1("%lu %lu %lu %lu\n",
577 ConsoleDraw->X, ConsoleDraw->Y,
578 ConsoleDraw->SizeX, ConsoleDraw->SizeY);
579 ASSERT(ConsoleDraw->X >= 1);
580 ASSERT(ConsoleDraw->Y >= 1);
581 ASSERT(ConsoleDraw->X <= DeviceExtension->Columns);
582 ASSERT(ConsoleDraw->Y <= DeviceExtension->Rows);
583 ASSERT(ConsoleDraw->X + ConsoleDraw->SizeX >= 1);
584 ASSERT(ConsoleDraw->Y + ConsoleDraw->SizeY >= 1);
585 ASSERT(ConsoleDraw->X + ConsoleDraw->SizeX - 1 <= DeviceExtension->Columns);
586 ASSERT(ConsoleDraw->Y + ConsoleDraw->SizeY - 1 <= DeviceExtension->Rows);
587 ASSERT(ConsoleDraw->CursorX >= 1);
588 ASSERT(ConsoleDraw->CursorY >= 1);
589 ASSERT(ConsoleDraw->CursorX <= DeviceExtension->Columns);
590 ASSERT(ConsoleDraw->CursorY <= DeviceExtension->Rows);
591
592#if 0
593 if (ConsoleDraw->X == 1
594 && ConsoleDraw->Y == 1
595 && ConsoleDraw->SizeX == DeviceExtension->Columns
596 && ConsoleDraw->SizeY == DeviceExtension->Rows)
597 {
598 /* search if we need to clear all screen */
599 DoOptimization = TRUE;
600 Video = (PUCHAR)(ConsoleDraw + 1);
601 x = 0;
602 while (DoOptimization && x < DeviceExtension->Columns * DeviceExtension->Rows)
603 {
604 if (Video[x++] != ' ')
605 {
606 DoOptimization = FALSE;
607 }
608 /*if (Video[x++] != DeviceExtension->CharAttribute) DoOptimization = FALSE; */
609 }
610 if (DoOptimization)
611 {
612 AddToSendBuffer(DeviceExtension, 4, ESC, '[', '2', 'J');
613 }
614 }
615#endif
616 /* add here more optimizations if needed */
617
618 if (!DoOptimization)
619 {
620 for (y = 0; y < ConsoleDraw->SizeY; y++)
621 {
622 AddToSendBuffer(DeviceExtension, 6, ESC, '[',
623 -(int)(ConsoleDraw->Y + y), ';',
624 -(int)(ConsoleDraw->X), 'H');
625 Video = (PUCHAR)(ConsoleDraw + 1);
626 Video = &Video[((ConsoleDraw->Y + y) * /*DeviceExtension->Columns +*/ ConsoleDraw->X) * 2];
627 for (x = 0; x < ConsoleDraw->SizeX; x++)
628 {
629 AddToSendBuffer(DeviceExtension, 1, Video[x * 2]);
630 }
631 }
632 }
633
634 DeviceExtension->LogicalOffset = (
635 (ConsoleDraw->CursorY-1) * DeviceExtension->Columns +
636 (ConsoleDraw->CursorX-1)) * 2;
637 AddToSendBuffer(DeviceExtension, 6, ESC, '[',
638 -(int)(ConsoleDraw->CursorY), ';',
639 -(int)(ConsoleDraw->CursorX), 'H');
640
641 /* flush buffer */
642 AddToSendBuffer(DeviceExtension, 0);
643
644 Irp->IoStatus.Information = 0;
646 break;
647 }
648#endif
649 default:
650 {
651 DPRINT1("IRP_MJ_DEVICE_CONTROL / unknown ioctl code 0x%lx\n",
652 Stack->Parameters.DeviceIoControl.IoControlCode);
653 /* Call lower driver */
655 return IoCallDriver(DeviceExtension->Common.LowerDevice, Irp);
656 }
657 }
658
659 if (!NT_SUCCESS(Status))
660 {
661 /* Don't call blue (if any), as we encountered an error */
662 Irp->IoStatus.Status = Status;
664 return Status;
665 }
666 else
667 {
668 /* Call lower driver */
670 return IoCallDriver(DeviceExtension->Common.LowerDevice, Irp);
671 }
672}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
unsigned char BOOLEAN
static const COLUMN_LIST Columns[]
Definition: listview.c:19
struct tagCONSOLE_SCREEN_BUFFER_INFO CONSOLE_SCREEN_BUFFER_INFO
struct tagCONSOLE_CURSOR_INFO CONSOLE_CURSOR_INFO
struct tagCONSOLE_CURSOR_INFO * PCONSOLE_CURSOR_INFO
struct tagCONSOLE_SCREEN_BUFFER_INFO * PCONSOLE_SCREEN_BUFFER_INFO
#define FALSE
Definition: types.h:117
unsigned short WORD
Definition: ntddk_ex.h:93
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define IOCTL_CONSOLE_DRAW
Definition: ntddblue.h:22
#define IOCTL_CONSOLE_READ_OUTPUT_ATTRIBUTE
Definition: ntddblue.h:14
#define IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER
Definition: ntddblue.h:20
#define IOCTL_CONSOLE_GET_MODE
Definition: ntddblue.h:10
#define IOCTL_CONSOLE_FILL_OUTPUT_CHARACTER
Definition: ntddblue.h:18
#define IOCTL_CONSOLE_READ_OUTPUT_CHARACTER
Definition: ntddblue.h:19
#define IOCTL_CONSOLE_SET_MODE
Definition: ntddblue.h:11
#define IOCTL_CONSOLE_WRITE_OUTPUT_ATTRIBUTE
Definition: ntddblue.h:15
struct tagCONSOLE_MODE CONSOLE_MODE
struct tagCONSOLE_DRAW * PCONSOLE_DRAW
#define IOCTL_CONSOLE_SET_TEXT_ATTRIBUTE
Definition: ntddblue.h:16
struct tagCONSOLE_MODE * PCONSOLE_MODE
#define IOCTL_CONSOLE_GET_CURSOR_INFO
Definition: ntddblue.h:8
#define IOCTL_CONSOLE_SET_SCREEN_BUFFER_INFO
Definition: ntddblue.h:7
#define IOCTL_CONSOLE_GET_SCREEN_BUFFER_INFO
Definition: ntddblue.h:6
#define IOCTL_CONSOLE_FILL_OUTPUT_ATTRIBUTE
Definition: ntddblue.h:13
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
WORD * PWORD
Definition: pedump.c:67
short SHORT
Definition: pedump.c:59
USHORT CursorY
Definition: ntddblue.h:56
USHORT SizeX
Definition: ntddblue.h:53
USHORT SizeY
Definition: ntddblue.h:54
USHORT CursorX
Definition: ntddblue.h:55
ULONG dwMode
Definition: ntddblue.h:30
SHORT Y
Definition: blue.h:27
SHORT X
Definition: blue.h:26
SHORT Right
Definition: blue.h:34
SHORT Left
Definition: blue.h:32
SHORT Top
Definition: blue.h:33
SHORT Bottom
Definition: blue.h:35
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define MmGetSystemAddressForMdl(Mdl)

Referenced by GreenDispatch().

◆ ScreenWrite()

NTSTATUS ScreenWrite ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 265 of file screen.c.

268{
271 PSCREEN_DEVICE_EXTENSION DeviceExtension;
273 PUCHAR VideoMemory; /* FIXME: is it useful? */
274 ULONG VideoMemorySize; /* FIXME: is it useful? */
275
277 ULONG CursorX, CursorY;
278 ULONG i, j;
280 DBG_UNREFERENCED_LOCAL_VARIABLE(VideoMemorySize);
281
282 DPRINT("ScreenWrite() called\n");
283
285 Buffer = Irp->UserBuffer;
286 DeviceExtension = (PSCREEN_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
287 VideoMemory = DeviceExtension->VideoMemory;
288
289 SerialDevice = ((PGREEN_DEVICE_EXTENSION)DeviceExtension->Green->DeviceExtension)->Serial;
290 if (!SerialDevice)
291 {
292 DPRINT1("Calling blue\n");
294 return IoCallDriver(DeviceExtension->PreviousBlue, Irp);
295 }
296
297 Columns = DeviceExtension->Columns;
298 Rows = DeviceExtension->Rows;
299 CursorX = (DeviceExtension->LogicalOffset / 2) % Columns + 1;
300 CursorY = (DeviceExtension->LogicalOffset / 2) / Columns + 1;
301 VideoMemorySize = Columns * Rows * 2 * sizeof(UCHAR);
302
303 if (!(DeviceExtension->Mode & ENABLE_PROCESSED_OUTPUT))
304 {
305 /* raw output mode */
306 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
308
310 }
311 else
312 {
313 for (i = 0; i < Stack->Parameters.Write.Length; i++, Buffer++)
314 {
315 switch (*Buffer)
316 {
317 case '\b':
318 {
319 if (CursorX > 1)
320 {
321 CursorX--;
322 AddToSendBuffer(DeviceExtension, 6, ESC, '[', -(int)CursorY, ';', -(int)CursorX, 'H');
323 AddToSendBuffer(DeviceExtension, 1, ' ');
324 AddToSendBuffer(DeviceExtension, 6, ESC, '[', -(int)CursorY, ';', -(int)CursorX, 'H');
325 }
326 else if (CursorY > 1)
327 {
328 CursorX = Columns;
329 CursorY--;
330 AddToSendBuffer(DeviceExtension, 6, ESC, '[', -(int)CursorY, ';', -(int)CursorX, 'H');
331 }
332 break;
333 }
334 case '\n':
335 {
336 CursorY++;
337 CursorX = 1;
338 AddToSendBuffer(DeviceExtension, 1, '\n');
339 AddToSendBuffer(DeviceExtension, 6, ESC, '[', -(int)CursorY, ';', '1', 'H');
340 break;
341 }
342 case '\r':
343 {
344 if (CursorX > 1)
345 {
346 AddToSendBuffer(DeviceExtension, 4, ESC, '[', -(int)(CursorX-1), 'D');
347 CursorX = 1;
348 }
349 break;
350 }
351 case '\t':
352 {
353 ULONG Offset = DeviceExtension->TabWidth - (CursorX % DeviceExtension->TabWidth);
354 for (j = 0; j < Offset; j++)
355 {
356#ifdef FORCE_POSITION
357 AddToSendBuffer(DeviceExtension, 6, ESC, '[', -(int)CursorY, ';', -(int)CursorX, 'H');
358#endif
359 AddToSendBuffer(DeviceExtension, 1, ' ');
360 CursorX++;
361 if (CursorX > Columns)
362 {
363 CursorX = 1;
364 CursorY++;
365 }
366 }
367 break;
368 }
369 default:
370 {
371#ifdef FORCE_POSITION
372 AddToSendBuffer(DeviceExtension, 6, ESC, '[', -(int)CursorY, ';', -(int)CursorX, 'H');
373#endif
374 AddToSendBuffer(DeviceExtension, 1, *Buffer);
375 CursorX++;
376 if (CursorX > Columns)
377 {
378 CursorX = 1;
379 DPRINT("Y: %lu -> %lu\n", CursorY, CursorY + 1);
380 CursorY++;
381 AddToSendBuffer(DeviceExtension, 6, ESC, '[', -(int)CursorY, ';', '1', 'H');
382
383 }
384 }
385 }
386 if (CursorY >= Rows)
387 {
388 DPRINT("Y: %lu -> %lu\n", CursorY, CursorY - 1);
389 CursorY--;
390 AddToSendBuffer(DeviceExtension, 6, ESC, '[', -(int)1, ';', -(int)(Rows), 'r');
391 AddToSendBuffer(DeviceExtension, 2, ESC, 'D');
392 AddToSendBuffer(DeviceExtension, 6, ESC, '[', -(int)CursorY, ';', -(int)CursorX, 'H');
393 }
394 }
395 }
396
397 DeviceExtension->LogicalOffset = ((CursorX-1) + (CursorY-1) * Columns) * 2;
398
399 /* flush output buffer */
400 AddToSendBuffer(DeviceExtension, 0);
401
402 /* Call lower driver */
404 return IoCallDriver(DeviceExtension->Common.LowerDevice, Irp);
405}
Definition: bufpool.h:45
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
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 DBG_UNREFERENCED_LOCAL_VARIABLE(L)
Definition: ntbasedef.h:319
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
_In_ ULONG Rows
Definition: haltypes.h:7

Referenced by GreenDispatch().