console update

svn path=/trunk/; revision=374
This commit is contained in:
Eric Kohl 1999-04-11 20:59:24 +00:00
parent 98d0da7e1c
commit eee72fe55d
4 changed files with 396 additions and 118 deletions

View file

@ -1,7 +1,5 @@
#include <internal/mmhal.h>
#include <internal/halio.h> #include <internal/halio.h>
#include <internal/hal/page.h>
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#include <string.h> #include <string.h>
#include <internal/string.h> #include <internal/string.h>
@ -11,23 +9,11 @@
//#define NDEBUG //#define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
#define IDMAP_BASE (0xd0000000)
#define IDMAP_BASE 0xd0000000
#define VIDMEM_BASE 0xb8000 #define VIDMEM_BASE 0xb8000
/*
* Return a linear address which can be used to access the physical memory
* starting at x
*/
extern inline unsigned int physical_to_linear(unsigned int x)
{
return(x+IDMAP_BASE);
}
extern inline unsigned int linear_to_physical(unsigned int x)
{
return(x-IDMAP_BASE);
}
#define NR_ROWS 50 #define NR_ROWS 50
#define NR_COLUMNS 80 #define NR_COLUMNS 80
@ -39,6 +25,8 @@ extern inline unsigned int linear_to_physical(unsigned int x)
#define CRTC_CURSORPOSLO 0x0f #define CRTC_CURSORPOSLO 0x0f
#define CRTC_CURSORPOSHI 0x0e #define CRTC_CURSORPOSHI 0x0e
#define ATTRC_WRITEREG 0x3c0
#define ATTRC_READREG 0x3c1
@ -79,19 +67,33 @@ NTSTATUS ScrCreate (PDEVICE_OBJECT DeviceObject, PIRP Irp)
PDEVICE_EXTENSION DeviceExtension; PDEVICE_EXTENSION DeviceExtension;
NTSTATUS Status; NTSTATUS Status;
unsigned int offset; unsigned int offset;
BYTE data, value;
DeviceExtension = DeviceObject->DeviceExtension; DeviceExtension = DeviceObject->DeviceExtension;
/* initialize device extension */ /* initialize device extension */
/* get pointer to video memory */ /* get pointer to video memory */
DeviceExtension->VideoMemory = (PBYTE)physical_to_linear (VIDMEM_BASE); /* FIXME : use MmMapIoSpace() */
DeviceExtension->VideoMemory = (PBYTE)(IDMAP_BASE + VIDMEM_BASE);
__asm__("cli\n\t");
/* get current output position */ /* get current output position */
__asm__("cli\n\t");
outb_p (CRTC_COMMAND, CRTC_CURSORPOSLO); outb_p (CRTC_COMMAND, CRTC_CURSORPOSLO);
offset = inb_p (CRTC_DATA); offset = inb_p (CRTC_DATA);
outb_p (CRTC_COMMAND, CRTC_CURSORPOSHI); outb_p (CRTC_COMMAND, CRTC_CURSORPOSHI);
offset += (inb_p (CRTC_DATA) << 8); offset += (inb_p (CRTC_DATA) << 8);
/* switch blinking characters off */
inb_p (0x3da);
value = inb_p (0x3c0);
outb_p (0x3c0, 0x10);
data = inb_p (0x3c1);
data = data & ~0x08;
outb_p (0x3c0, data);
outb_p (0x3c0, value);
inb_p (0x3da);
__asm__("sti\n\t"); __asm__("sti\n\t");
DeviceExtension->CursorX = (SHORT)(offset % NR_COLUMNS); DeviceExtension->CursorX = (SHORT)(offset % NR_COLUMNS);
@ -175,13 +177,12 @@ NTSTATUS ScrWrite (PDEVICE_OBJECT DeviceObject, PIRP Irp)
{ {
vidmem[(cursorx * 2) + (cursory * NR_COLUMNS * 2)] = ' '; vidmem[(cursorx * 2) + (cursory * NR_COLUMNS * 2)] = ' ';
cursorx++; cursorx++;
/*
if (cursorx >= NR_COLUMNS) if (cursorx >= NR_COLUMNS)
{ {
cursory++; cursory++;
cursorx = 0; cursorx = 0;
} }
*/
} }
break; break;
@ -194,6 +195,7 @@ NTSTATUS ScrWrite (PDEVICE_OBJECT DeviceObject, PIRP Irp)
cursory++; cursory++;
cursorx = 0; cursorx = 0;
} }
break;
} }
@ -247,7 +249,6 @@ NTSTATUS ScrIoControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
PDEVICE_EXTENSION DeviceExtension; PDEVICE_EXTENSION DeviceExtension;
NTSTATUS Status; NTSTATUS Status;
DeviceExtension = DeviceObject->DeviceExtension; DeviceExtension = DeviceObject->DeviceExtension;
switch (stk->Parameters.DeviceIoControl.IoControlCode) switch (stk->Parameters.DeviceIoControl.IoControlCode)
@ -264,11 +265,21 @@ NTSTATUS ScrIoControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
offset += (inb_p (CRTC_DATA) << 8); offset += (inb_p (CRTC_DATA) << 8);
__asm__("sti\n\t"); __asm__("sti\n\t");
pcsbi->dwSize.X = NR_ROWS;
pcsbi->dwSize.Y = NR_COLUMNS;
pcsbi->dwCursorPosition.X = (SHORT)(offset % NR_COLUMNS); pcsbi->dwCursorPosition.X = (SHORT)(offset % NR_COLUMNS);
pcsbi->dwCursorPosition.Y = (SHORT)(offset / NR_COLUMNS); pcsbi->dwCursorPosition.Y = (SHORT)(offset / NR_COLUMNS);
pcsbi->dwSize.X = NR_ROWS; pcsbi->wAttributes = DeviceExtension->CharAttribute;
pcsbi->dwSize.Y = NR_COLUMNS;
pcsbi->srWindow.Left = 0;
pcsbi->srWindow.Right = NR_COLUMNS - 1;
pcsbi->srWindow.Top = 0;
pcsbi->srWindow.Bottom = NR_ROWS - 1;
pcsbi->dwMaximumWindowSize.X = NR_COLUMNS;
pcsbi->dwMaximumWindowSize.Y = NR_ROWS;
Irp->IoStatus.Information = sizeof (CONSOLE_SCREEN_BUFFER_INFO); Irp->IoStatus.Information = sizeof (CONSOLE_SCREEN_BUFFER_INFO);
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
@ -283,6 +294,8 @@ NTSTATUS ScrIoControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
DeviceExtension->CursorX = pcsbi->dwCursorPosition.X; DeviceExtension->CursorX = pcsbi->dwCursorPosition.X;
DeviceExtension->CursorY = pcsbi->dwCursorPosition.Y; DeviceExtension->CursorY = pcsbi->dwCursorPosition.Y;
DeviceExtension->CharAttribute = pcsbi->wAttributes;
offset = (pcsbi->dwCursorPosition.Y * NR_COLUMNS) + offset = (pcsbi->dwCursorPosition.Y * NR_COLUMNS) +
pcsbi->dwCursorPosition.X; pcsbi->dwCursorPosition.X;
@ -300,14 +313,12 @@ NTSTATUS ScrIoControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
case IOCTL_CONSOLE_GET_CURSOR_INFO: case IOCTL_CONSOLE_GET_CURSOR_INFO:
{ {
// PCONSOLE_CURSOR_INFO pcci = (PCONSOLE_CURSOR_INFO)Irp->AssociatedIrp.SystemBuffer; PCONSOLE_CURSOR_INFO pcci = (PCONSOLE_CURSOR_INFO)Irp->AssociatedIrp.SystemBuffer;
// DPRINT("GetConsoleCursorInfo: pcci=%p\n", pcci); pcci->dwSize = DeviceExtension->CursorSize;
// DPRINT("GetConsoleCursorInfo\n"); pcci->bVisible = DeviceExtension->CursorVisible;
// pcci->dwSize = 10;
// pcci->bVisible = FALSE;
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = sizeof (CONSOLE_CURSOR_INFO);
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
} }
break; break;
@ -341,18 +352,38 @@ NTSTATUS ScrIoControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
} }
break; break;
case IOCTL_CONSOLE_GET_MODE:
{
PCONSOLE_MODE pcm = (PCONSOLE_MODE)Irp->AssociatedIrp.SystemBuffer;
pcm->dwMode = DeviceExtension->Mode;
Irp->IoStatus.Information = sizeof(CONSOLE_MODE);
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_SET_MODE:
{
PCONSOLE_MODE pcm = (PCONSOLE_MODE)Irp->AssociatedIrp.SystemBuffer;
DeviceExtension->Mode = pcm->dwMode;
Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_FILL_OUTPUT_ATTRIBUTE: case IOCTL_CONSOLE_FILL_OUTPUT_ATTRIBUTE:
{ {
PFILL_OUTPUT_ATTRIBUTE Buf = (PFILL_OUTPUT_ATTRIBUTE)Irp->AssociatedIrp.SystemBuffer; POUTPUT_ATTRIBUTE Buf = (POUTPUT_ATTRIBUTE)Irp->AssociatedIrp.SystemBuffer;
char *vidmem; char *vidmem;
int offset; int offset;
DWORD dwCount; DWORD dwCount;
vidmem = DeviceExtension->VideoMemory; vidmem = DeviceExtension->VideoMemory;
offset = (DeviceExtension->CursorY * NR_COLUMNS * 2) + offset = (Buf->dwCoord.Y * NR_COLUMNS * 2) +
(DeviceExtension->CursorX * 2) + 1; (Buf->dwCoord.X * 2) + 1;
CHECKPOINT CHECKPOINT
@ -361,19 +392,63 @@ NTSTATUS ScrIoControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
vidmem[offset + (dwCount * 2)] = (char) Buf->wAttribute; vidmem[offset + (dwCount * 2)] = (char) Buf->wAttribute;
} }
Buf->dwTransfered = Buf->nLength;
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
} }
break; break;
#if 0
case IOCTL_CONSOLE_READ_OUTPUT_ATTRIBUTE: case IOCTL_CONSOLE_READ_OUTPUT_ATTRIBUTE:
case IOCTL_CONSOLE_WRITE_OUTPUT_ATTRIBUTE: {
POUTPUT_ATTRIBUTE Buf = (POUTPUT_ATTRIBUTE)Irp->AssociatedIrp.SystemBuffer;
LPWORD pAttr = (LPWORD)MmGetSystemAddressForMdl(Irp->MdlAddress);
char *vidmem;
int offset;
DWORD dwCount;
vidmem = DeviceExtension->VideoMemory;
offset = (Buf->dwCoord.Y * NR_COLUMNS * 2) +
(Buf->dwCoord.X * 2) + 1;
for (dwCount = 0; dwCount < stk->Parameters.Write.Length; dwCount++, pAttr++)
{
(char) *pAttr = vidmem[offset + (dwCount * 2)];
}
Buf->dwTransfered = dwCount;
Irp->IoStatus.Information = sizeof(OUTPUT_ATTRIBUTE);
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_WRITE_OUTPUT_ATTRIBUTE:
{
POUTPUT_ATTRIBUTE Buf = (POUTPUT_ATTRIBUTE)Irp->AssociatedIrp.SystemBuffer;
LPWORD pAttr = (LPWORD)MmGetSystemAddressForMdl(Irp->MdlAddress);
char *vidmem;
int offset;
DWORD dwCount;
vidmem = DeviceExtension->VideoMemory;
offset = (Buf->dwCoord.Y * NR_COLUMNS * 2) +
(Buf->dwCoord.X * 2) + 1;
for (dwCount = 0; dwCount < stk->Parameters.Write.Length; dwCount++, pAttr++)
{
vidmem[offset + (dwCount * 2)] = (char) *pAttr;
}
Buf->dwTransfered = dwCount;
Irp->IoStatus.Information = sizeof(OUTPUT_ATTRIBUTE);
Status = STATUS_SUCCESS;
}
break; break;
#endif
case IOCTL_CONSOLE_SET_TEXT_ATTRIBUTE: case IOCTL_CONSOLE_SET_TEXT_ATTRIBUTE:
DeviceExtension->CharAttribute = (WORD)Irp->AssociatedIrp.SystemBuffer; DeviceExtension->CharAttribute = (WORD)*(LPWORD)Irp->AssociatedIrp.SystemBuffer;
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
break; break;
@ -381,27 +456,74 @@ NTSTATUS ScrIoControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
case IOCTL_CONSOLE_FILL_OUTPUT_CHARACTER: case IOCTL_CONSOLE_FILL_OUTPUT_CHARACTER:
{ {
PFILL_OUTPUT_CHARACTER Buf = (PFILL_OUTPUT_CHARACTER)Irp->AssociatedIrp.SystemBuffer; POUTPUT_CHARACTER Buf = (POUTPUT_CHARACTER)Irp->AssociatedIrp.SystemBuffer;
char *vidmem; char *vidmem;
int offset; int offset;
DWORD dwCount; DWORD dwCount;
vidmem = DeviceExtension->VideoMemory; vidmem = DeviceExtension->VideoMemory;
offset = (DeviceExtension->CursorY * NR_COLUMNS * 2) + offset = (Buf->dwCoord.Y * NR_COLUMNS * 2) +
(DeviceExtension->CursorX * 2); (Buf->dwCoord.X * 2);
CHECKPOINT
for (dwCount = 0; dwCount < Buf->nLength; dwCount++) for (dwCount = 0; dwCount < Buf->nLength; dwCount++)
{ {
vidmem[offset + (dwCount * 2)] = (char) Buf->cCharacter; vidmem[offset + (dwCount * 2)] = (char) Buf->cCharacter;
} }
Buf->dwTransfered = Buf->nLength;
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
} }
break; break;
case IOCTL_CONSOLE_READ_OUTPUT_CHARACTER:
{
POUTPUT_CHARACTER Buf = (POUTPUT_CHARACTER)Irp->AssociatedIrp.SystemBuffer;
LPSTR pChar = (LPSTR)MmGetSystemAddressForMdl(Irp->MdlAddress);
char *vidmem;
int offset;
DWORD dwCount;
vidmem = DeviceExtension->VideoMemory;
offset = (Buf->dwCoord.Y * NR_COLUMNS * 2) +
(Buf->dwCoord.X * 2);
for (dwCount = 0; dwCount < stk->Parameters.Write.Length; dwCount++, pChar++)
{
*pChar = vidmem[offset + (dwCount * 2)];
}
Buf->dwTransfered = dwCount;
Irp->IoStatus.Information = sizeof(OUTPUT_ATTRIBUTE);
Status = STATUS_SUCCESS;
}
break;
case IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER:
{
POUTPUT_CHARACTER Buf = (POUTPUT_CHARACTER)Irp->AssociatedIrp.SystemBuffer;
LPSTR pChar = (LPSTR)MmGetSystemAddressForMdl(Irp->MdlAddress);
char *vidmem;
int offset;
DWORD dwCount;
vidmem = DeviceExtension->VideoMemory;
offset = (Buf->dwCoord.Y * NR_COLUMNS * 2) +
(Buf->dwCoord.X * 2) + 1;
for (dwCount = 0; dwCount < stk->Parameters.Write.Length; dwCount++, pChar++)
{
vidmem[offset + (dwCount * 2)] = (char) *pChar;
}
Buf->dwTransfered = dwCount;
Irp->IoStatus.Information = sizeof(OUTPUT_ATTRIBUTE);
Status = STATUS_SUCCESS;
}
break;
default: default:
@ -462,7 +584,7 @@ DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
ANSI_STRING asymlink_name; ANSI_STRING asymlink_name;
UNICODE_STRING symlink_name; UNICODE_STRING symlink_name;
DbgPrint ("Screen Driver 0.0.5\n"); DbgPrint ("Screen Driver 0.0.6\n");
DriverObject->MajorFunction[IRP_MJ_CREATE] = ScrCreate; DriverObject->MajorFunction[IRP_MJ_CREATE] = ScrCreate;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = ScrDispatch; DriverObject->MajorFunction[IRP_MJ_CLOSE] = ScrDispatch;

View file

@ -1,6 +1,7 @@
# #
# #
# #
OBJECTS = blue.o ../../../ntoskrnl/ntoskrnl.a OBJECTS = blue.o ../../../ntoskrnl/ntoskrnl.a
all: blue.sys all: blue.sys
@ -22,7 +23,7 @@ blue.sys: $(OBJECTS)
-Wl,--base-file,base.tmp $(OBJECTS) -Wl,--base-file,base.tmp $(OBJECTS)
- $(RM) junk.tmp - $(RM) junk.tmp
$(DLLTOOL) --dllname blue.sys --base-file base.tmp \ $(DLLTOOL) --dllname blue.sys --base-file base.tmp \
--output-exp temp.exp --output-exp temp.exp
- $(RM) base.tmp - $(RM) base.tmp
$(CC) --verbose -Wl,--image-base,0x10000 -Wl,-e,_DriverEntry@8 \ $(CC) --verbose -Wl,--image-base,0x10000 -Wl,-e,_DriverEntry@8 \
-specs=../../svc_specs -mdll -o blue.sys $(OBJECTS) -Wl,temp.exp -specs=../../svc_specs -mdll -o blue.sys $(OBJECTS) -Wl,temp.exp

View file

@ -6,43 +6,47 @@
#define IOCTL_CONSOLE_SET_SCREEN_BUFFER_INFO CTL_CODE(FILE_DEVICE_SCREEN, 0x802, METHOD_BUFFERED, FILE_WRITE_ACCESS) #define IOCTL_CONSOLE_SET_SCREEN_BUFFER_INFO CTL_CODE(FILE_DEVICE_SCREEN, 0x802, METHOD_BUFFERED, FILE_WRITE_ACCESS)
#define IOCTL_CONSOLE_GET_CURSOR_INFO CTL_CODE(FILE_DEVICE_SCREEN, 0x803, METHOD_BUFFERED, FILE_READ_ACCESS) #define IOCTL_CONSOLE_GET_CURSOR_INFO CTL_CODE(FILE_DEVICE_SCREEN, 0x803, METHOD_BUFFERED, FILE_READ_ACCESS)
#define IOCTL_CONSOLE_SET_CURSOR_INFO CTL_CODE(FILE_DEVICE_SCREEN, 0x804, METHOD_BUFFERED, FILE_WRITE_ACCESS) #define IOCTL_CONSOLE_SET_CURSOR_INFO CTL_CODE(FILE_DEVICE_SCREEN, 0x804, METHOD_BUFFERED, FILE_WRITE_ACCESS)
#define IOCTL_CONSOLE_GET_MODE CTL_CODE(FILE_DEVICE_SCREEN, 0x805, METHOD_BUFFERED, FILE_READ_ACCESS)
#define IOCTL_CONSOLE_SET_MODE CTL_CODE(FILE_DEVICE_SCREEN, 0x806, METHOD_BUFFERED, FILE_WRITE_ACCESS)
#define IOCTL_CONSOLE_FILL_OUTPUT_ATTRIBUTE CTL_CODE(FILE_DEVICE_SCREEN, 0x810, METHOD_BUFFERED, FILE_WRITE_ACCESS) #define IOCTL_CONSOLE_FILL_OUTPUT_ATTRIBUTE CTL_CODE(FILE_DEVICE_SCREEN, 0x810, METHOD_BUFFERED, FILE_WRITE_ACCESS)
#define IOCTL_CONSOLE_READ_OUTPUT_ATTRIBUTE CTL_CODE(FILE_DEVICE_SCREEN, 0x811, METHOD_BUFFERED, FILE_READ_ACCESS) #define IOCTL_CONSOLE_READ_OUTPUT_ATTRIBUTE CTL_CODE(FILE_DEVICE_SCREEN, 0x811, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
#define IOCTL_CONSOLE_WRITE_OUTPUT_ATTRIBUTE CTL_CODE(FILE_DEVICE_SCREEN, 0x812, METHOD_BUFFERED, FILE_WRITE_ACCESS) #define IOCTL_CONSOLE_WRITE_OUTPUT_ATTRIBUTE CTL_CODE(FILE_DEVICE_SCREEN, 0x812, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
#define IOCTL_CONSOLE_SET_TEXT_ATTRIBUTE CTL_CODE(FILE_DEVICE_SCREEN, 0x813, METHOD_BUFFERED, FILE_WRITE_ACCESS) #define IOCTL_CONSOLE_SET_TEXT_ATTRIBUTE CTL_CODE(FILE_DEVICE_SCREEN, 0x813, METHOD_BUFFERED, FILE_WRITE_ACCESS)
#define IOCTL_CONSOLE_FILL_OUTPUT_CHARACTER CTL_CODE(FILE_DEVICE_SCREEN, 0x820, METHOD_BUFFERED, FILE_WRITE_ACCESS) #define IOCTL_CONSOLE_FILL_OUTPUT_CHARACTER CTL_CODE(FILE_DEVICE_SCREEN, 0x820, METHOD_BUFFERED, FILE_WRITE_ACCESS)
#define IOCTL_CONSOLE_READ_OUTPUT_CHARACTER CTL_CODE(FILE_DEVICE_SCREEN, 0x821, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
#define IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER CTL_CODE(FILE_DEVICE_SCREEN, 0x822, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
/* TYPEDEFS **************************************************************/ /* TYPEDEFS **************************************************************/
typedef struct _FILL_OUTPUT_CHARACTER
typedef struct _CONSOLE_MODE
{ {
WCHAR cCharacter; DWORD dwMode;
DWORD nLength; } CONSOLE_MODE, *PCONSOLE_MODE;
COORD dwWriteCoord;
} FILL_OUTPUT_CHARACTER, *PFILL_OUTPUT_CHARACTER;
typedef struct _FILL_OUTPUT_ATTRIBUTE typedef struct _OUTPUT_ATTRIBUTE
{ {
WORD wAttribute; WORD wAttribute;
DWORD nLength; DWORD nLength;
COORD dwWriteCoord; COORD dwCoord;
} FILL_OUTPUT_ATTRIBUTE, *PFILL_OUTPUT_ATTRIBUTE; DWORD dwTransfered;
} OUTPUT_ATTRIBUTE, *POUTPUT_ATTRIBUTE;
typedef struct _WRITE_OUTPUT_ATTRIBUTE typedef struct _OUTPUT_CHARACTER
{ {
CONST WORD *lpAttribute; CHAR cCharacter;
DWORD nLength; DWORD nLength;
COORD dwWriteCoord; COORD dwCoord;
} WRITE_OUTPUT_ATTRIBUTE, *PWRITE_OUTPUT_ATTRIBUTE; DWORD dwTransfered;
} OUTPUT_CHARACTER, *POUTPUT_CHARACTER;

View file

@ -131,16 +131,16 @@ ReadConsoleA(HANDLE hConsoleInput,
LPVOID lpReserved) LPVOID lpReserved)
{ {
KEY_EVENT_RECORD KeyEventRecord; KEY_EVENT_RECORD KeyEventRecord;
int i,j; BOOL stat = TRUE;
BOOL stat;
PCHAR Buffer = (PCHAR)lpBuffer; PCHAR Buffer = (PCHAR)lpBuffer;
DWORD Result; DWORD Result;
int i;
for (i=0; (stat && i<nNumberOfCharsToRead);) for (i=0; (stat && i<nNumberOfCharsToRead);)
{ {
stat = ReadFile(hConsoleInput, stat = ReadFile(hConsoleInput,
&KeyEventRecord, &KeyEventRecord,
sizeof(KeyEventRecord), sizeof(KEY_EVENT_RECORD),
&Result, &Result,
NULL); NULL);
if (stat && KeyEventRecord.bKeyDown && KeyEventRecord.AsciiChar != 0) if (stat && KeyEventRecord.bKeyDown && KeyEventRecord.AsciiChar != 0)
@ -225,7 +225,7 @@ GetConsoleScreenBufferInfo(
if ( !DeviceIoControl( if ( !DeviceIoControl(
hConsoleOutput, hConsoleOutput,
IOCTL_CONSOLE_GET_SCREEN_BUFFER_INFO, IOCTL_CONSOLE_GET_SCREEN_BUFFER_INFO,
NULL, NULL,
0, 0,
lpConsoleScreenBufferInfo, lpConsoleScreenBufferInfo,
@ -292,13 +292,28 @@ FillConsoleOutputCharacterA(
LPDWORD lpNumberOfCharsWritten LPDWORD lpNumberOfCharsWritten
) )
{ {
return FillConsoleOutputCharacterW( DWORD dwBytesReturned;
hConsoleOutput, OUTPUT_CHARACTER Buffer;
(WCHAR) cCharacter,
nLength, Buffer.cCharacter = cCharacter;
dwWriteCoord, Buffer.nLength = nLength;
lpNumberOfCharsWritten Buffer.dwCoord = dwWriteCoord;
);
if (DeviceIoControl (hConsoleOutput,
IOCTL_CONSOLE_FILL_OUTPUT_CHARACTER,
&Buffer,
sizeof(OUTPUT_CHARACTER),
&Buffer,
sizeof(OUTPUT_CHARACTER),
&dwBytesReturned,
NULL))
{
*lpNumberOfCharsWritten = Buffer.dwTransfered;
return TRUE;
}
*lpNumberOfCharsWritten = 0;
return FALSE;
} }
@ -369,8 +384,28 @@ ReadConsoleInputA(
LPDWORD lpNumberOfEventsRead LPDWORD lpNumberOfEventsRead
) )
{ {
/* TO DO */ BOOL stat = TRUE;
return FALSE; DWORD Result;
int i;
for (i=0; (stat && i < nLength);)
{
stat = ReadFile(hConsoleInput,
&lpBuffer[i].Event.KeyEvent,
sizeof(KEY_EVENT_RECORD),
&Result,
NULL);
if (stat)
{
lpBuffer[i].EventType = KEY_EVENT;
i++;
}
}
if (lpNumberOfEventsRead != NULL)
{
*lpNumberOfEventsRead = i;
}
return(stat);
} }
@ -517,8 +552,26 @@ ReadConsoleOutputCharacterA(
LPDWORD lpNumberOfCharsRead LPDWORD lpNumberOfCharsRead
) )
{ {
/* TO DO */ DWORD dwBytesReturned;
return FALSE; OUTPUT_CHARACTER Buffer;
Buffer.dwCoord = dwReadCoord;
if (DeviceIoControl (hConsoleOutput,
IOCTL_CONSOLE_READ_OUTPUT_CHARACTER,
&Buffer,
sizeof(OUTPUT_CHARACTER),
lpCharacter,
nLength,
&dwBytesReturned,
NULL))
{
*lpNumberOfCharsRead = Buffer.dwTransfered;
return TRUE;
}
*lpNumberOfCharsRead = 0;
return FALSE;
} }
@ -555,8 +608,27 @@ ReadConsoleOutputAttribute(
LPDWORD lpNumberOfAttrsRead LPDWORD lpNumberOfAttrsRead
) )
{ {
/* TO DO */ DWORD dwBytesReturned;
return FALSE; OUTPUT_ATTRIBUTE Buffer;
Buffer.dwCoord = dwReadCoord;
if (DeviceIoControl (hConsoleOutput,
IOCTL_CONSOLE_READ_OUTPUT_ATTRIBUTE,
&Buffer,
sizeof(OUTPUT_ATTRIBUTE),
(PVOID)lpAttribute,
nLength,
&dwBytesReturned,
NULL))
{
*lpNumberOfAttrsRead = Buffer.dwTransfered;
return TRUE;
}
*lpNumberOfAttrsRead = 0;
return FALSE;
} }
@ -574,8 +646,26 @@ WriteConsoleOutputCharacterA(
LPDWORD lpNumberOfCharsWritten LPDWORD lpNumberOfCharsWritten
) )
{ {
/* TO DO */ DWORD dwBytesReturned;
return FALSE; OUTPUT_CHARACTER Buffer;
Buffer.dwCoord = dwWriteCoord;
if (DeviceIoControl (hConsoleOutput,
IOCTL_CONSOLE_WRITE_OUTPUT_CHARACTER,
&Buffer,
sizeof(OUTPUT_CHARACTER),
(LPSTR)lpCharacter,
nLength,
&dwBytesReturned,
NULL))
{
*lpNumberOfCharsWritten = Buffer.dwTransfered;
return TRUE;
}
*lpNumberOfCharsWritten = 0;
return FALSE;
} }
@ -614,25 +704,26 @@ WriteConsoleOutputAttribute(
) )
{ {
DWORD dwBytesReturned; DWORD dwBytesReturned;
WRITE_OUTPUT_ATTRIBUTE Buffer; OUTPUT_ATTRIBUTE Buffer;
Buffer.lpAttribute = lpAttribute; Buffer.dwCoord = dwWriteCoord;
Buffer.nLength = nLength;
Buffer.dwWriteCoord = dwWriteCoord;
if (!DeviceIoControl (hConsoleOutput, if (DeviceIoControl (hConsoleOutput,
IOCTL_CONSOLE_WRITE_OUTPUT_ATTRIBUTE, IOCTL_CONSOLE_WRITE_OUTPUT_ATTRIBUTE,
&Buffer, &Buffer,
sizeof(WRITE_OUTPUT_ATTRIBUTE), sizeof(OUTPUT_ATTRIBUTE),
lpNumberOfAttrsWritten, (PVOID)lpAttribute,
sizeof(DWORD), nLength,
// NULL, &dwBytesReturned,
// 0, NULL))
&dwBytesReturned, {
NULL)) *lpNumberOfAttrsWritten = Buffer.dwTransfered;
return FALSE; return TRUE;
}
return TRUE; *lpNumberOfAttrsWritten = 0;
return FALSE;
} }
@ -651,25 +742,28 @@ FillConsoleOutputAttribute(
) )
{ {
DWORD dwBytesReturned; DWORD dwBytesReturned;
FILL_OUTPUT_ATTRIBUTE Buffer; OUTPUT_ATTRIBUTE Buffer;
Buffer.wAttribute = wAttribute; Buffer.wAttribute = wAttribute;
Buffer.nLength = nLength; Buffer.nLength = nLength;
Buffer.dwWriteCoord = dwWriteCoord; Buffer.dwCoord = dwWriteCoord;
if (!DeviceIoControl (hConsoleOutput, if (DeviceIoControl (hConsoleOutput,
IOCTL_CONSOLE_FILL_OUTPUT_ATTRIBUTE, IOCTL_CONSOLE_FILL_OUTPUT_ATTRIBUTE,
&Buffer, &Buffer,
sizeof(FILL_OUTPUT_ATTRIBUTE), sizeof(OUTPUT_ATTRIBUTE),
// lpNumberOfAttrsWritten, &Buffer,
// sizeof(DWORD), sizeof(OUTPUT_ATTRIBUTE),
NULL, &dwBytesReturned,
0, NULL))
&dwBytesReturned, {
NULL)) *lpNumberOfAttrsWritten = Buffer.dwTransfered;
return FALSE; return TRUE;
}
return TRUE; *lpNumberOfAttrsWritten = 0;
return FALSE;
} }
@ -684,8 +778,25 @@ GetConsoleMode(
LPDWORD lpMode LPDWORD lpMode
) )
{ {
/* TO DO */ CONSOLE_MODE Buffer;
return FALSE; DWORD dwBytesReturned;
if (DeviceIoControl (hConsoleHandle,
IOCTL_CONSOLE_GET_MODE,
NULL,
0,
&Buffer,
sizeof(CONSOLE_MODE),
&dwBytesReturned,
NULL))
{
*lpMode = Buffer.dwMode;
SetLastError (ERROR_SUCCESS);
return TRUE;
}
SetLastError(0); /* FIXME: What error code? */
return FALSE;
} }
@ -735,8 +846,19 @@ GetConsoleCursorInfo(
PCONSOLE_CURSOR_INFO lpConsoleCursorInfo PCONSOLE_CURSOR_INFO lpConsoleCursorInfo
) )
{ {
/* TO DO */ DWORD dwBytesReturned;
return FALSE;
if (DeviceIoControl (hConsoleOutput,
IOCTL_CONSOLE_GET_CURSOR_INFO,
NULL,
0,
lpConsoleCursorInfo,
sizeof(CONSOLE_CURSOR_INFO),
&dwBytesReturned,
NULL))
return TRUE;
return FALSE;
} }
@ -766,8 +888,26 @@ SetConsoleMode(
DWORD dwMode DWORD dwMode
) )
{ {
/* TO DO */ CONSOLE_MODE Buffer;
return FALSE; DWORD dwBytesReturned;
Buffer.dwMode = dwMode;
if (DeviceIoControl (hConsoleHandle,
IOCTL_CONSOLE_SET_MODE,
&Buffer,
sizeof(CONSOLE_MODE),
NULL,
0,
&dwBytesReturned,
NULL))
{
SetLastError (ERROR_SUCCESS);
return TRUE;
}
SetLastError(0); /* FIXME: What error code? */
return FALSE;
} }
@ -827,8 +967,19 @@ SetConsoleCursorInfo(
CONST CONSOLE_CURSOR_INFO *lpConsoleCursorInfo CONST CONSOLE_CURSOR_INFO *lpConsoleCursorInfo
) )
{ {
/* TO DO */ DWORD dwBytesReturned;
return FALSE;
if (DeviceIoControl (hConsoleOutput,
IOCTL_CONSOLE_SET_CURSOR_INFO,
(PCONSOLE_CURSOR_INFO)lpConsoleCursorInfo,
sizeof(CONSOLE_CURSOR_INFO),
NULL,
0,
&dwBytesReturned,
NULL))
return TRUE;
return FALSE;
} }