diff --git a/reactos/drivers/input/sermouse/mouse.c b/reactos/drivers/input/sermouse/mouse.c deleted file mode 100644 index d4020623b99..00000000000 --- a/reactos/drivers/input/sermouse/mouse.c +++ /dev/null @@ -1,272 +0,0 @@ -/* - - ** Mouse driver 0.0.3 - ** Written by Jason Filby (jasonfilby@yahoo.com) - ** For ReactOS (www.sid-dis.com/reactos) - - ** Note: The serial.o driver must be loaded before loading this driver - - ** Known Limitations: - ** Only supports mice on COM port 1 - - ** Old Driver, We done build it. Just keep for History. (S.E.) - -*/ - -#include -#include -#include -/* #include */ -#include - -#define MOUSE_IRQ_COM1 4 -#define MOUSE_IRQ_COM2 3 - -#define COM1_PORT 0x3f8 -#define COM2_PORT 0x2f8 - -#define max_screen_x 79 -#define max_screen_y 24 - -static unsigned int MOUSE_IRQ=MOUSE_IRQ_COM1; -static unsigned int MOUSE_COM=COM1_PORT; - -static unsigned int bytepos=0, coordinate; -static unsigned char mpacket[3]; -static signed int mouse_x=40, mouse_y=12; -static unsigned char mouse_button1, mouse_button2; -static signed int horiz_sensitivity, vert_sensitivity; - -BOOLEAN microsoft_mouse_handler(PKINTERRUPT Interrupt, PVOID ServiceContext) -{ - unsigned int mbyte=inb(MOUSE_COM); - - // Synchronize - if((mbyte&64)==64) { bytepos=0; }; - - mpacket[bytepos]=mbyte; - bytepos++; - - // Process packet - if(bytepos==3) { - // Retrieve change in x and y from packet - int change_x=((mpacket[0] & 3) << 6) + mpacket[1]; - int change_y=((mpacket[0] & 12) << 4) + mpacket[2]; - - // Some mice need this - if(coordinate==1) { - change_x-=128; - change_y-=128; - }; - - // Change to signed - if(change_x>=128) { change_x=change_x-256; }; - if(change_y>=128) { change_y=change_y-256; }; - - // Adjust mouse position according to sensitivity - mouse_x+=change_x/horiz_sensitivity; - mouse_y+=change_y/vert_sensitivity; - - // Check that mouse is still in screen - if(mouse_x<0) { mouse_x=0; }; - if(mouse_x>max_screen_x) { mouse_x=max_screen_x; }; - if(mouse_y<0) { mouse_y=0; }; - if(mouse_y>max_screen_y) { mouse_y=max_screen_y; }; - - // Retrieve mouse button status from packet - mouse_button1=mpacket[0] & 32; - mouse_button2=mpacket[0] & 16; - - bytepos=0; - }; - -}; - -void InitializeMouseHardware(unsigned int mtype) -{ - char clear_error_bits; - - outb_p(MOUSE_COM+3, 0x80); // set DLAB on - outb_p(MOUSE_COM, 0x60); // speed LO byte - outb_p(MOUSE_COM+1, 0); // speed HI byte - outb_p(MOUSE_COM+3, mtype); // 2=MS Mouse; 3=Mouse systems mouse - outb_p(MOUSE_COM+1, 0); // set comm and DLAB to 0 - outb_p(MOUSE_COM+4, 1); // DR int enable - - clear_error_bits=inb_p(MOUSE_COM+5); // clear error bits -}; - -int DetMicrosoft(void) -{ - char tmp, ind; - int buttons=0, i; - - outb_p(MOUSE_COM+4, 0x0b); - tmp=inb_p(MOUSE_COM); - - // Check the first for bytes for signs that this is an MS mouse - for(i=0; i<4; i++) { - while((inb_p(MOUSE_COM+5) & 1)==0) ; - ind=inb_p(MOUSE_COM); - if(ind==0x33) buttons=3; - if(ind==0x4d) buttons=2; - }; - - return buttons; -}; - -int CheckMouseType(unsigned int mtype) -{ - unsigned int retval=0; - - InitializeMouseHardware(mtype); - if(mtype==2) retval=DetMicrosoft(); - if(mtype==3) { - outb_p(MOUSE_COM+4, 11); - retval=3; - }; - outb_p(MOUSE_COM+1, 1); - - return retval; -}; - -void ClearMouse(void) -{ - // Waits until the mouse calms down but also quits out after a while - // in case some destructive user wants to keep moving the mouse - // before we're done - - unsigned int restarts=0, i; - for (i=0; i<60000; i++) - { - unsigned temp=inb(MOUSE_COM); - if(temp!=0) { - restarts++; - if(restarts<300000) { - i=0; - } else - { - i=60000; - }; - }; - }; -}; - -void InitializeMouse(void) -{ - int mbuttons=0, gotmouse=0; - ULONG MappedIrq; - KIRQL Dirql; - KAFFINITY Affinity; - PKINTERRUPT IrqObject; - - horiz_sensitivity=2; - vert_sensitivity=3; - - // Check for Microsoft mouse (2 buttons) - if(CheckMouseType(2)!=0) - { - gotmouse=1; - DbgPrint("Microsoft Mouse Detected\n"); - ClearMouse(); - coordinate=0; - }; - - // Check for Microsoft Systems mouse (3 buttons) - if(gotmouse==0) { - if(CheckMouseType(3)!=0) - { - gotmouse=1; - DbgPrint("Microsoft Mouse Detected\n"); - ClearMouse(); - coordinate=1; - }; - }; - - if(gotmouse==0) { - DbgPrint("No Mouse Detected!\n"); - } else { - MappedIrq = HalGetInterruptVector(Internal, 0, 0, MOUSE_IRQ, - &Dirql, &Affinity); - - IoConnectInterrupt(&IrqObject, microsoft_mouse_handler, NULL, - NULL, MappedIrq, Dirql, Dirql, 0, FALSE, - Affinity, FALSE); - }; -}; - -// For test purposes only -unsigned char get_text_char(int x, int y) -{ - unsigned char getchar; - char *vidmem=(char*)physical_to_linear((0xb8000+(y*160)+(x*2))); - getchar=*vidmem; - return getchar; -}; - -// For test purposes only -unsigned char get_text_color(int x, int y) -{ - unsigned char getcolor; - char *vidmem=(char*)physical_to_linear((0xb8000+(y*160)+(x*2))); - vidmem++; - getcolor=*vidmem; - return getcolor; -}; - -// For test purposes only -void put_text_char(int x, int y, unsigned char putchar[2]) -{ - char *vidmem=(char*)physical_to_linear((0xb8000+(y*160)+(x*2))); - *vidmem=putchar[0]; - vidmem++; - *vidmem=putchar[1]; -}; - -// For test purposes only -void test_mouse(void) -{ - static int i=0, forcechange=0; - static int old_x=40, old_y=12; - static unsigned char old_cursor[2], new_cursor[2]; - - DbgPrint("Testing mouse..."); - - old_cursor[0]=' '; - old_cursor[1]=7; - new_cursor[0]='Û'; - new_cursor[1]=15; - - old_cursor[0]=get_text_char(mouse_x, mouse_y); - old_cursor[1]=get_text_color(mouse_x, mouse_y); - put_text_char(mouse_x, mouse_y, new_cursor); - - while(i!=1) - { - if(mouse_button1!=0) { new_cursor[1]=10; mouse_button1=0; forcechange=1; }; - if(mouse_button2!=0) { new_cursor[1]=12; mouse_button2=0; forcechange=1; }; - - if((mouse_x!=old_x) || (mouse_y!=old_y) || (forcechange==1)) { - forcechange=0; - - put_text_char(old_x, old_y, old_cursor); - old_cursor[0]=get_text_char(mouse_x, mouse_y); - old_cursor[1]=get_text_color(mouse_x, mouse_y); - put_text_char(mouse_x, mouse_y, new_cursor); - - old_x=mouse_x; - old_y=mouse_y; - }; - }; -}; - -NTSTATUS STDCALL -DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) -{ - DbgPrint("Mouse Driver 0.0.3\n"); - InitializeMouse(); - test_mouse(); - - return(STATUS_SUCCESS); -}; - diff --git a/reactos/drivers/input/sermouse/mouse.h b/reactos/drivers/input/sermouse/mouse.h index 0532f483c01..29dff25d9d5 100644 --- a/reactos/drivers/input/sermouse/mouse.h +++ b/reactos/drivers/input/sermouse/mouse.h @@ -1,12 +1,13 @@ typedef struct _DEVICE_EXTENSION { PDEVICE_OBJECT DeviceObject; - ULONG InputDataCount; - PMOUSE_INPUT_DATA MouseInputData; + ULONG ActiveQueue; + ULONG InputDataCount[2]; + MOUSE_INPUT_DATA MouseInputData[2][MOUSE_BUFFER_SIZE]; CLASS_INFORMATION ClassInformation; PKINTERRUPT MouseInterrupt; KDPC IsrDpc; - KDPC IsrDpcRetry; -} DEVICE_EXTENSION, *PDEVICE_EXTENSION; \ No newline at end of file +} DEVICE_EXTENSION, *PDEVICE_EXTENSION; + diff --git a/reactos/drivers/input/sermouse/sermouse.c b/reactos/drivers/input/sermouse/sermouse.c index d625924bb86..be6773dd5cb 100644 --- a/reactos/drivers/input/sermouse/sermouse.c +++ b/reactos/drivers/input/sermouse/sermouse.c @@ -1,18 +1,16 @@ /* - - ** Mouse driver 0.0.4 + ** Mouse driver 0.0.5 ** Written by Jason Filby (jasonfilby@yahoo.com) - ** For ReactOS (www.sid-dis.com/reactos) + ** For ReactOS (www.reactos.com) ** Note: The serial.o driver must be loaded before loading this driver ** Known Limitations: ** Only supports mice on COM port 1 - */ #include -#include "../include/mouse.h" +#include #include "sermouse.h" #include "mouse.h" @@ -34,18 +32,40 @@ static signed int mouse_x=40, mouse_y=12; static unsigned char mouse_button1, mouse_button2; static signed int horiz_sensitivity, vert_sensitivity; +// Previous button state +static ULONG PreviousButtons = 0; + BOOLEAN microsoft_mouse_handler(PKINTERRUPT Interrupt, PVOID ServiceContext) { + PDEVICE_OBJECT DeviceObject = (PDEVICE_OBJECT)ServiceContext; + PDEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension; + PMOUSE_INPUT_DATA Input; + ULONG Queue, ButtonsDiff; unsigned int mbyte=READ_PORT_UCHAR((PUCHAR)MOUSE_COM); // Synchronize - if((mbyte&64)==64) { bytepos=0; } + if((mbyte&64)==64) + bytepos=0; mpacket[bytepos]=mbyte; bytepos++; // Process packet if(bytepos==3) { + // Set local variables for DeviceObject and DeviceExtension + DeviceObject = (PDEVICE_OBJECT)ServiceContext; + DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension; + Queue = DeviceExtension->ActiveQueue % 2; + + // Prevent buffer overflow + if (DeviceExtension->InputDataCount[Queue] == MOUSE_BUFFER_SIZE) + { + return TRUE; + } + + Input = &DeviceExtension->MouseInputData[Queue] + [DeviceExtension->InputDataCount[Queue]]; + // Retrieve change in x and y from packet int change_x=((mpacket[0] & 3) << 6) + mpacket[1]; int change_y=((mpacket[0] & 12) << 4) + mpacket[2]; @@ -70,11 +90,50 @@ BOOLEAN microsoft_mouse_handler(PKINTERRUPT Interrupt, PVOID ServiceContext) if(mouse_y<0) { mouse_y=0; } if(mouse_y>max_screen_y) { mouse_y=max_screen_y; } + Input->LastX = mouse_x; + Input->LastY = mouse_y; + // Retrieve mouse button status from packet mouse_button1=mpacket[0] & 32; mouse_button2=mpacket[0] & 16; + + // Determine the current state of the buttons + Input->RawButtons = mouse_button1 + mouse_button2; + + /* Determine ButtonFlags */ + Input->ButtonFlags = 0; + ButtonsDiff = PreviousButtons ^ Input->RawButtons; + + if (ButtonsDiff & 32) + { + if (Input->RawButtons & 32) + { + Input->ButtonFlags |= MOUSE_BUTTON_1_DOWN; + } else { + Input->ButtonFlags |= MOUSE_BUTTON_1_UP; + } + } + + if (ButtonsDiff & 16) + { + if (Input->RawButtons & 16) + { + Input->ButtonFlags |= MOUSE_BUTTON_2_DOWN; + } else { + Input->ButtonFlags |= MOUSE_BUTTON_2_UP; + } + } bytepos=0; + + /* Send the Input data to the Mouse Class driver */ + DeviceExtension->InputDataCount[Queue]++; + KeInsertQueueDpc(&DeviceExtension->IsrDpc, DeviceObject->CurrentIrp, NULL); + + /* Copy RawButtons to Previous Buttons for Input */ + PreviousButtons = Input->RawButtons; + + return TRUE; } } @@ -89,7 +148,7 @@ void InitializeMouseHardware(unsigned int mtype) WRITE_PORT_UCHAR((PUCHAR)MOUSE_COM+3, mtype); // 2=MS Mouse; 3=Mouse systems mouse WRITE_PORT_UCHAR((PUCHAR)MOUSE_COM+1, 0); // set comm and DLAB to 0 WRITE_PORT_UCHAR((PUCHAR)MOUSE_COM+4, 1); // DR int enable - + clear_error_bits=READ_PORT_UCHAR((PUCHAR)MOUSE_COM+5); // clear error bits } @@ -186,26 +245,18 @@ BOOLEAN InitializeMouse(PDEVICE_OBJECT DeviceObject) if(gotmouse==0) return FALSE; - DeviceExtension->InputDataCount = 0; - DeviceExtension->MouseInputData = ExAllocatePool(NonPagedPool, sizeof(MOUSE_INPUT_DATA) * MOUSE_BUFFER_SIZE); + DeviceExtension->ActiveQueue = 0; + MappedIrq = HalGetInterruptVector(Internal, 0, 0, MOUSE_IRQ, &Dirql, &Affinity); - MappedIrq = HalGetInterruptVector(Internal, 0, 0, MOUSE_IRQ, - &Dirql, &Affinity); - - IoConnectInterrupt(&DeviceExtension->MouseInterrupt, microsoft_mouse_handler, NULL, - NULL, MappedIrq, Dirql, Dirql, 0, FALSE, - Affinity, FALSE); + IoConnectInterrupt(&DeviceExtension->MouseInterrupt, microsoft_mouse_handler, + DeviceObject, NULL, MappedIrq, Dirql, Dirql, 0, FALSE, + Affinity, FALSE); return TRUE; } VOID SerialMouseInitializeDataQueue(PVOID Context) { - ; -/* PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION)DeviceExtension; - - DeviceExtension->InputDataCount = 0; - DeviceExtension->MouseInputData = ExAllocatePool(NonPagedPool, sizeof(MOUSE_INPUT_DATA) * MOUSE_BUFFER_SIZE); */ } BOOLEAN MouseSynchronizeRoutine(PVOID Context) @@ -329,7 +380,7 @@ VOID SerialMouseIsrDpc(PKDPC Dpc, PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID C NULL, &DeviceExtension->InputDataCount); - DeviceExtension->InputDataCount = 0; + DeviceExtension->ActiveQueue = 0; } NTSTATUS STDCALL @@ -340,10 +391,13 @@ DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) UNICODE_STRING SymlinkName; PDEVICE_EXTENSION DeviceExtension; - DbgPrint("Serial Mouse Driver 0.0.4\n"); - - if(InitializeMouse(DeviceObject) == FALSE) + if(InitializeMouse(DeviceObject) == TRUE) + { + DbgPrint("Serial Mouse Driver 0.0.5\n"); + } else { + DbgPrint("Serial mouse not found.\n"); return STATUS_UNSUCCESSFUL; + } DriverObject->MajorFunction[IRP_MJ_CREATE] = SerialMouseDispatch; DriverObject->MajorFunction[IRP_MJ_CLOSE] = SerialMouseDispatch; @@ -367,7 +421,7 @@ DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) DeviceExtension = DeviceObject->DeviceExtension; KeInitializeDpc(&DeviceExtension->IsrDpc, (PKDEFERRED_ROUTINE)SerialMouseIsrDpc, DeviceObject); - KeInitializeDpc(&DeviceExtension->IsrDpcRetry, (PKDEFERRED_ROUTINE)SerialMouseIsrDpc, DeviceObject); return(STATUS_SUCCESS); } + diff --git a/reactos/drivers/input/sermouse/sermouse.h b/reactos/drivers/input/sermouse/sermouse.h index 5ab0f5f2b58..c5c89fcd2ae 100644 --- a/reactos/drivers/input/sermouse/sermouse.h +++ b/reactos/drivers/input/sermouse/sermouse.h @@ -2,46 +2,21 @@ // CHAOS is also under the GNU General Public License. /* Mouse commands. */ -/* Set resolution. */ -#define MOUSE_SET_RESOLUTION 0xE8 - -/* Set 1:1 scaling. */ - -#define MOUSE_SET_SCALE11 0xE6 - -/* Set 2:1 scaling. */ - -#define MOUSE_SET_SCALE21 0xE7 - -/* Get scaling factor. */ - -#define MOUSE_GET_SCALE 0xE9 - -/* Set stream mode. */ - -#define MOUSE_SET_STREAM 0xEA +#define MOUSE_SET_RESOLUTION 0xE8 // Set resolution +#define MOUSE_SET_SCALE11 0xE6 // Set 1:1 scaling +#define MOUSE_SET_SCALE21 0xE7 // Set 2:1 scaling +#define MOUSE_GET_SCALE 0xE9 // Get scaling factor +#define MOUSE_SET_STREAM 0xEA // Set stream mode /* Set sample rate (number of times the controller will poll the port per second). */ - #define MOUSE_SET_SAMPLE_RATE 0xF3 -/* Enable mouse device. */ - -#define MOUSE_ENABLE_DEVICE 0xF4 - -/* Disable mouse device. */ - -#define MOUSE_DISABLE_DEVICE 0xF5 - -/* Reset aux device. */ - -#define MOUSE_RESET 0xFF - -/* Command byte ACK. */ - -#define MOUSE_ACK 0xFA +#define MOUSE_ENABLE_DEVICE 0xF4 // Enable mouse device +#define MOUSE_DISABLE_DEVICE 0xF5 // Disable mouse device +#define MOUSE_RESET 0xFF // Reset aux device +#define MOUSE_ACK 0xFA // Command byte ACK #define MOUSE_INTERRUPTS_OFF (CONTROLLER_MODE_KCC | \ CONTROLLER_MODE_DISABLE_MOUSE | \ @@ -78,3 +53,4 @@ static VOID MouseDpcRoutine(PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2); +