public Mouse(uint screenWidth, uint screenHeight) { //Create and initialise the underlying driver mouse = new Cosmos.Hardware.Mouse(); mouse.Initialize(screenWidth, screenHeight); }
/// <summary> /// Identifies a PS/2 device. /// </summary> /// <param name="aPort">The port of the PS/2 device to identify.</param> /// <param name="aDevice">An instance of the identified device.</param> private void IdentifyDevice(byte aPort, out Device aDevice) { aDevice = null; if (aPort == 1 || aPort == 2) { var xSecondPort = aPort == 2; WaitToWrite(); SendDeviceCommand(DeviceCommand.DisableScanning, xSecondPort); WaitToWrite(); SendDeviceCommand(DeviceCommand.IdentifyDevice, xSecondPort); byte xFirstByte = 0; byte xSecondByte = 0; if (ReadByteAfterAckWithTimeout(ref xFirstByte)) { /* * |--------|---------------------------| * | Byte | Device Type | * |--------|---------------------------| * | 0x00 | Standard PS/2 mouse | * |--------|---------------------------| * | 0x03 | Mouse with scroll wheel | * |--------|---------------------------| * | 0x04 | 5-button mouse | * |--------|---------------------------| * | 0x50 | Laptop Touchpad | * |--------|---------------------------| */ if (xFirstByte == 0x00 || xFirstByte == 0x03 || xFirstByte == 0x04 || xFirstByte == 0x50) { var xDevice = new PS2Mouse(aPort, xFirstByte); xDevice.Initialize(); aDevice = xDevice; } /* * |-----------------|----------------------------------------------------------------| * | Bytes | Device Type | * |-----------------|----------------------------------------------------------------| * | 0xAB, 0x41 | MF2 keyboard with translation enabled in the PS/2 Controller | * | or 0xAB, 0xC1 | (not possible for the second PS/2 port) | * |-----------------|----------------------------------------------------------------| * | 0xAB, 0x83 | MF2 keyboard | * |-----------------|----------------------------------------------------------------| */ else if (xFirstByte == 0xAB && ReadDataWithTimeout(ref xSecondByte)) { // TODO: replace xTest with (xSecondByte == 0x41 || xSecondByte == 0xC1) // when the stack corruption detection works better for complex conditions var xTest = (xSecondByte == 0x41 || xSecondByte == 0xC1); if (xTest && aPort == 1) { var xDevice = new PS2Keyboard(aPort); xDevice.Initialize(); aDevice = xDevice; } else if (xSecondByte == 0x83) { var xDevice = new PS2Keyboard(aPort); xDevice.Initialize(); aDevice = xDevice; } } } /* * |--------|---------------------------------------------------------------------| * | Byte | Device Type | * |--------|---------------------------------------------------------------------| * | None | Ancient AT keyboard with translation enabled in the PS/Controller | * | | (not possible for the second PS/2 port) | * |--------|---------------------------------------------------------------------| */ else if (aPort == 1) { var xDevice = new PS2Keyboard(aPort); xDevice.Initialize(); aDevice = xDevice; } if (aDevice == null) { mDebugger.SendInternal("(PS/2 Controller) Device detection failed:"); mDebugger.SendInternal("First Byte: " + xFirstByte); mDebugger.SendInternal("Second Byte: " + xSecondByte); Console.WriteLine("(PS/2 Controller) Device detection failed."); Console.WriteLine("This is usually Fine for USB to PS / 2 Emulation"); Console.WriteLine("Press any key to Resume (Good Luck)"); Console.ReadLine(); } } else { throw new Exception("(PS/2 Controller) Port " + aPort + " doesn't exist"); } }
/// <summary> /// Identifies a PS/2 device. /// </summary> /// <param name="aPort">The port of the PS/2 device to identify.</param> /// <param name="aDevice">An instance of the identified device.</param> private Device IdentifyDevice(byte aPort) { if (aPort == 1 || aPort == 2) { var xSecondPort = aPort == 2; if (!SendDeviceCommand(DeviceCommand.DisableScanning, xSecondPort)) { return(null); } if (!SendDeviceCommand(DeviceCommand.IdentifyDevice, xSecondPort)) { return(null); } byte xFirstByte = 0; byte xSecondByte = 0; if (ReadByteAfterAckWithTimeout(ref xFirstByte)) { /* * |--------|---------------------------| * | Byte | Device Type | * |--------|---------------------------| * | 0x00 | Standard PS/2 mouse | * |--------|---------------------------| * | 0x03 | Mouse with scroll wheel | * |--------|---------------------------| * | 0x04 | 5-button mouse | * |--------|---------------------------| */ if (xFirstByte == 0x00 || xFirstByte == 0x03 || xFirstByte == 0x04) { var xDevice = new PS2Mouse(this, aPort, xFirstByte); xDevice.Initialize(); return(xDevice); } /* * |-----------------|----------------------------------------------------------------| * | Bytes | Device Type | * |-----------------|----------------------------------------------------------------| * | 0xAB, 0x41 | MF2 keyboard with translation enabled in the PS/2 Controller | * | or 0xAB, 0xC1 | (not possible for the second PS/2 port) | * |-----------------|----------------------------------------------------------------| * | 0xAB, 0x83 | MF2 keyboard | * |-----------------|----------------------------------------------------------------| */ else if (xFirstByte == 0xAB && ReadDataWithTimeout(ref xSecondByte)) { // TODO: replace xTest with (xSecondByte == 0x41 || xSecondByte == 0xC1) // when the stack corruption detection works better for complex conditions. // // https://github.com/CosmosOS/IL2CPU/issues/8 // var xTest = (xSecondByte == 0x41 || xSecondByte == 0xC1); if (xTest && aPort == 1) { var xDevice = new PS2Keyboard(this, aPort); xDevice.Initialize(); return(xDevice); } else if (xSecondByte == 0x83) { var xDevice = new PS2Keyboard(this, aPort); xDevice.Initialize(); return(xDevice); } } } /* * |--------|---------------------------------------------------------------------| * | Byte | Device Type | * |--------|---------------------------------------------------------------------| * | None | Ancient AT keyboard with translation enabled in the PS/Controller | * | | (not possible for the second PS/2 port) | * |--------|---------------------------------------------------------------------| */ else if (aPort == 1) { var xDevice = new PS2Keyboard(this, aPort); xDevice.Initialize(); return(xDevice); } mDebugger.SendInternal("(PS/2 Controller) Device detection failed:"); mDebugger.SendInternal("First Byte: " + xFirstByte); mDebugger.SendInternal("Second Byte: " + xSecondByte); return(null); } else { throw new Exception("(PS/2 Controller) Port " + aPort + " doesn't exist"); } }