Syndicate the Cosmos Blog Feed.

Mouse Support

Cosmos now has mouse support...

... and a sample simple drawing app :)

I'm no artist. Daniel Story will draw better soon ;)

Comments:

mansi on 9/13/2009 wrote: can u please let me know where the source code of this mouse support application available?
Geis-OS on 10/5/2009 wrote: yeah this is so cool. Mouse support. Can you do this with Milestone 3? Or did you used a beta from Milestone 4?
Stephen Remde on 10/6/2009 wrote: private static void MouseDemo() { VGAScreen.SetMode320x200x8(); VGAScreen.SetPaletteEntry(0, 0, 0, 0); VGAScreen.SetPaletteEntry(1, 63, 0, 0); VGAScreen.SetPaletteEntry(2, 63, 63, 63); VGAScreen.Clear(0); uint x = (uint)Mouse.X; uint y = (uint)Mouse.Y; uint oc = 0; while (true) { uint mx = (uint)Mouse.X; uint my = (uint)Mouse.Y; if (mx != x || my != y) { if (Mouse.Buttons == Mouse.MouseState.Left) VGAScreen.SetPixel320x200x8(x, y, 1); else if (Mouse.Buttons == Mouse.MouseState.Right) VGAScreen.SetPixel320x200x8(x, y, 0); else VGAScreen.SetPixel320x200x8(x, y, oc); x = mx; y = my; oc = VGAScreen.GetPixel320x200x8(x, y); VGAScreen.SetPixel320x200x8(x, y, 2); } } }
Stephen Remde on 10/6/2009 wrote: Errr, didnt seem to format right. but thats the code i used to draw the picture above.
Geis-OS on 10/6/2009 wrote: using System; using Cosmos.Compiler.Builder; namespace CosmosBoot { class Program { #region Cosmos Builder logic // Most users wont touch this. This will call the Cosmos Build tool [STAThread] static void Main(string[] args) { BuildUI.Run(); } #endregion private static void MouseDemo() { VGAScreen.SetMode320x200x8(); VGAScreen.SetPaletteEntry(0, 0, 0, 0); VGAScreen.SetPaletteEntry(1, 63, 0, 0); VGAScreen.SetPaletteEntry(2, 63, 63, 63); VGAScreen.Clear(0); uint x = (uint)Mouse.X; uint y = (uint)Mouse.Y; uint oc = 0; while (true) { uint mx = (uint)Mouse.X; uint my = (uint)Mouse.Y; if (mx != x || my != y) { if (Mouse.Buttons == Mouse.MouseState.Left) VGAScreen.SetPixel320x200x8(x, y, 1); else if (Mouse.Buttons == Mouse.MouseState.Right) VGAScreen.SetPixel320x200x8(x, y, 0); else VGAScreen.SetPixel320x200x8(x, y, oc); x = mx; y = my; oc = VGAScreen.GetPixel320x200x8(x, y); VGAScreen.SetPixel320x200x8(x, y, 2); } } } } }
Geis-OS on 10/6/2009 wrote: I dont know why, but it says VGAScreen is wrong. I'm new with cosmos. What i have to do? I use Visual C# Express edition with milestone 3.
Stephen Remde on 10/6/2009 wrote: Try using Cosmos.Hardware if not, get the dev kit
Stephen Remde on 10/6/2009 wrote: Try "using Cosmos.Hardware;". If that doesn't work, use the devkit. Urg can we sort the formatting here Chad? xD
Tomi on 11/11/2009 wrote: Hi guys! You should make a package what keeps anykind of tutorials and demos inside of it. Not just a devkit. Greetings from Finland!
Tomi on 11/11/2009 wrote: By the way, is possible to run .com or .bat -console programs inside of this?
Jammy on 12/4/2009 wrote: I can't seem to get the mouse working...The VGA is fine, but the mouse just doesn't work. It's always reported as 0,0. :( Was there any Mouse.Initialize or something that I needed to do?
Jammy on 12/5/2009 wrote: And even though I said the VGA is fine, i meant that the mode you used is fine. All the other modes don't work.
Bill9603 on 6/16/2010 wrote: @Everyone who can't get the mouse to work and also @the coders who commented some code in the userkit The problem is in the "Cosmos.hardware" DLL In the source code, the developers commented out the Mouse.Initialize for some reason. To fix this you are going to need to add the "Cosmos.Hardware.Mouse" class into your program, and uncomment the code. here is the class, though i doubt it will format correctly :( public static class Mouse { public static int X, Y; public static MouseState Buttons; public static void Initialize() { //enable mouse WaitSignal(); CPUBus.Write8(0x64, 0xA8); // enable interrupt WaitSignal(); CPUBus.Write8(0x64, 0x20); WaitData(); byte status = (byte)(CPUBus.Read8(0x60) | 2); WaitSignal(); CPUBus.Write8(0x64, 0x60); WaitSignal(); CPUBus.Write8(0x60, status); //default Write(0xF6); Read(); //Acknowledge //Enable the mouse Write(0xF4); Read(); //Acknowledge Interrupts.AddIRQHandler(12, new Interrupts.InterruptDelegate(HandleMouse)); } private static byte Read() { WaitData(); return CPUBus.Read8(0x60); } private static void Write(byte b) { //Wait to be able to send a command WaitSignal(); //Tell the mouse we are sending a command CPUBus.Write8(0x64, 0xD4); //Wait for the final part WaitSignal(); //Finally write CPUBus.Write8(0x60, b); } private static void WaitData() { for (int i = 0; i < 1000 & ((CPUBus.Read8(0x64) & 1) == 1); i++) ; } private static void WaitSignal() { for (int i = 0; i < 1000 & ((CPUBus.Read8(0x64) & 2) != 0); i++) ; } public enum MouseState { None = 0, Left = 1, Right = 2, Middle = 4 } private static byte mouse_cycle = 0; private static int[] mouse_byte = new int[4]; public static void HandleMouse(ref Interrupts.InterruptContext context) { switch (mouse_cycle) { case 0: mouse_byte[0] = CPUBus.Read8(0x60); if ((mouse_byte[0] & 0x8) == 0x8) mouse_cycle++; break; case 1: mouse_byte[1] = CPUBus.Read8(0x60); mouse_cycle++; break; case 2: mouse_byte[2] = CPUBus.Read8(0x60); mouse_cycle = 0; if ((mouse_byte[0] & 0x10) == 0x10) X -= mouse_byte[1] ^ 0xff; else X += mouse_byte[1]; if ((mouse_byte[0] & 0x20) == 0x20) Y += mouse_byte[2] ^ 0xff; else Y -= mouse_byte[2]; if (X < 0) X = 0; else if (X > 319) X = 319; if (Y < 0) Y = 0; else if (Y > 199) Y = 199; Buttons = (MouseState)(mouse_byte[0] & 0x7); break; } } } Make sure that you "using Cosmos.Kernel" and "using Cosmos.Hardware" -I hope this helped, it frustrated me for months until I had to find the problem myself. --------- Bill9603
Bill9603 on 6/16/2010 wrote: See... bad formatting. Hey, COSMOS guys, do you need somebody to put formatting in here???

Post a comment