Mouse Problem When Live Booted(Read) This will effect everybody with this code?

Jun 18, 2011 at 11:59 PM
Edited Jun 19, 2011 at 12:01 AM

Hey guys, I am worryed for you guys with this Mouse Code: 

 

namespace Cosmos.Hardware2
{
    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
        }

        public static byte mouse_cycle =0;
        private static int[] mouse_byte = new int[4];

        public static void HandleMouse()
        {
            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;
            }
        }
    }
}

This code deos not work when I real booted, I used a Virtual Boot for a while and it works fine but when I boot on a real computer it deos not work, the mouse deos not move, however it deos in a virutal machine, I tried this on three different computers. Is there a  problem with the code? And how do I fix this. Thanks Yours Truly - Matt

P.S. I wonder, can this be a problem with memory or is it the driver. Thanks

Coordinator
Jun 19, 2011 at 12:01 AM
> work, the mouse deos not move, however it deos in a virutal machine, I
> tried this on three different computers. Is there a problem with the
> code? And how do I fix this. Thanks Yours Truly - Matt

Do the have USB mice?
Jun 19, 2011 at 12:28 AM
Edited Jun 19, 2011 at 12:47 AM

No its a mouse that goes directly into the mouse port, thats what makes wonder. Thanks - Matt 

P.S. I also tried it on a laptop with a built in mouse. 

Jun 19, 2011 at 8:02 AM

Please help me fix this! I am using a Mouse pluged into the mouse port on my desktop computer, I tried this on my laptop and it did not work either, it has a built in mouse, I think I am calling the wrong IoPort. Please help! Thanks - Matt

Developer
Jun 19, 2011 at 5:41 PM
Edited Jun 19, 2011 at 5:45 PM

A laptop with built-in mouse should work, as the keyboard & mouse are connected internally via PS/2 in a laptop. That's as long as it's not a Mac, as Mac's have their keyboard & mouse connected via an internal Serial Port.  In other-words, it should work.

 

Also, Why is this mouse code different from the mouse code in Harware2 in the trunk version?

Jun 19, 2011 at 5:47 PM

Yeah I know it should work but it does not.When I boot my OS it asks me a question "Would You Like To Enter Admin Console Or GUI" I hit GUI and it goes into VGASCREEN mode. The mouse code works in VmWare. But when I boot from a cd, it does nothing. I am using MS4. I just dont know why. Now my desktop has a mouse that connects to the built in mouse port. But will that effect anything. Anyway let me know if its a IOPort or is it a memory problem. Thanks - Matt