Page 1 of 1

real pc & mouse

Posted: Tue Dec 16, 2008 6:03 am
by ahmedhalawa
Hello every body,
I had written Mouse Driver it run on virtual pc,but the problem is when i want to try it on realpc the pc reset #-o so what is the problem with this code :?:


mouse.cpp

Code: Select all

#include "../inc/mouse.h"
#include "../inc/system.h"
#include "../inc/video.h"          
#include "../inc/iop.h"             //in and out
/*******************/
mouse::mouse(){}
uchar       mouse_cycle=0;
signed char mouse_byte[3];
signed char mouse_x=0;
signed char mouse_y=0;
int mx=160,my=100
    ,ox=160,oy=160;
int mbits[3]={0,0,0};
void pmouse()
{
    if(mouse_byte[0] == 0x08 &&
       mouse_byte[1] == 0x00 &&
       mouse_byte[2] == 0x01){my--;}

    if(mouse_byte[0] == 0x28 &&
       mouse_byte[1] == 0x00 &&
       mouse_byte[2] == 0xFF){my++;}

    if(mouse_byte[0] == 0x08 &&
       mouse_byte[1] == 0x01 &&
       mouse_byte[2] == 0x00){mx++;}

    if(mouse_byte[0] == 0x18 &&
       mouse_byte[1] == 0xFF &&
       mouse_byte[2] == 0x00){mx--;}
    putpxl(ox,oy,0x10);
    putpxl(ox+1,oy+1,0x10);
    putpxl(ox+2,oy+2,0x10);
    putpxl(ox+3,oy+3,0x10);
    mbits[0] = getpxl(mx,my);
    mbits[1] = getpxl(mx+1,my+1);
    mbits[2] = getpxl(mx+2,my+2);
    mbits[3] = getpxl(mx+3,my+3);
    putpxl(mx,my,0x10);
    putpxl(mx+1,my+1,0x10);
    putpxl(mx+2,my+2,0x10);
    putpxl(mx+3,my+3,0x10);
    ox=mx;oy=my;
}
void mouse::handle(regs r)
{
  switch(mouse_cycle)
  {
    case 0:
      mouse_byte[0]=inb(0x60);
      mouse_cycle++;
      break;
    case 1:
      mouse_byte[1]=inb(0x60);
      mouse_cycle++;
      break;
    case 2:
      mouse_byte[2]=inb(0x60);
      mouse_x=mouse_byte[1];
      mouse_y=mouse_byte[2];
      mouse_cycle=0;
      pmouse();
      break;
  }
    outb(0x20,0x20);
    outb(0xA0,0x20);
}
/******************/
inline void mouse::waite(uchar a_type)
{
    uint tout = 1000;
    if(a_type == 1)
    {
        while(tout--)
        {
            if((inb(0x64) & 1)==1)
            {
                return;
            }
        }
    }else{
        while(tout--)
        {
            if((inb(0x64) & 2)==0)
            {
                return;
            }
        }
    }
}
inline void mouse::write(uchar c_byte)
{
    waite(1);
    outb(0x64,0xD4);
    waite(1);
    outb(0x60,c_byte);
}
void mouse::install()
{
    uchar status;
    outb(0x64,0xA8);
    waite(1);
    outb(0x64,0x20);
    waite(0);
    status=(inb(0x60)|2);
    waite(1);
    outb(0x64,0x60);
    waite(1);
    outb(0x60,status);
    write(0xF6);
    write(0xF4);
    /********************/
    mbits[0] = getpxl(ox,oy);
    mbits[1] = getpxl(ox+1,oy+1);
    mbits[2] = getpxl(ox+2,oy+2);
    mbits[3] = getpxl(ox+3,oy+3);
    putpxl(mx,my,0x10);
    putpxl(mx+1,my+1,0x10);
    putpxl(mx+2,my+2,0x10);
    putpxl(mx+3,my+3,0x10);

}

Code: Select all

#ifndef _H_mouse_
#define _H_mouse_
#include "interrupt.h"
class mouse: public interrupt
{
public:
	mouse();
	void install();
	void waite(uchar a_type);
	void write(uchar c_byte);
             void handle(regs r);
};
#endif


Re: real pc & mouse

Posted: Tue Dec 16, 2008 6:35 am
by AJ
I can't see the specific problem, but this is often due to an uninitialised variable or timing issue. Given that this is in an interrupt handler, it could be down to stack corruption.

Could you please locate the line of code where the reset happens?

Cheers,
Adam

Re: real pc & mouse

Posted: Tue Dec 16, 2008 6:42 am
by LoseThos
PS/2 is emulated in legacy mode by the ICH, when really it's USB, I'm pretty sure. Having keyboard and mouse together with PS/2 makes for all kinds of evils. I don't think you get an interrupt for each byte of mouse packet or keystroke. That's what I remember from when I wrote mine long ago. I tried everything and finally just put a spin-loop in my IRQ handlers to wait for the whole packet. The mouse now sucks-up lots of CPU when used. Someday, I'll do USB, perhaps, and it'll be fine. There's also that mouse interrupt enable trick that's listed in the Wiki.

Re: real pc & mouse

Posted: Thu Dec 18, 2008 10:07 am
by jal
LoseThos wrote:PS/2 is emulated in legacy mode by the ICH, when really it's USB, I'm pretty sure. Having keyboard and mouse together with PS/2 makes for all kinds of evils. I don't think you get an interrupt for each byte of mouse packet or keystroke. That's what I remember from when I wrote mine long ago. I tried everything and finally just put a spin-loop in my IRQ handlers to wait for the whole packet. The mouse now sucks-up lots of CPU when used. Someday, I'll do USB, perhaps, and it'll be fine. There's also that mouse interrupt enable trick that's listed in the Wiki.
Iirc, you are wrong, and one does get an interrupt for each byte. It was in a topic recently.


JAL