@Topic:
Es gab mal das OS StormOS (Wird im nächsten Lowlevel vorgestellt), wo es auch einen Maustreiber gab. Da die Website inzwischen verschwunden ist, poste ich einfach mal den kompletten Code (inkl. russischer Kommentare). Interssant sind hier erstmal die Funktionen CheckPS2 und InitMouse.
typedef struct {
unsigned char LButton;
unsigned char RButton;
short X;
short Y;
unsigned char Moved;
unsigned char Pressed;
} TMouse;
TMouse Mouse;
#define KEYB_CTRL 0x64
#define KEYB_BUF 0x60
// naudojami ekrano dydio nustatymai, kad nereik� kviesti ekrano objekto
unsigned short sWidth, sHeight;
/**
* �ungiama PS2 pel�
* @param Width ekrano ilgis
* @param Height ekrano auk�is
*/
void InitMouse(unsigned short Width, unsigned short Height) {
CheckPS2();
outportb(KEYB_CTRL, 0xA8); //�ungiame PS2 pel� bendravim�
CheckPS2();
outportb(KEYB_CTRL, 0xD4);
CheckPS2();
outportb(KEYB_BUF, 0xF4); // �ungiame duomen siuntim�
CheckPS2();
sWidth = Width;
sHeight = Height;
// nustatome koordinates ties ekrano viduriu
Mouse.X = sWidth / 2;
Mouse.Y = sHeight / 2;
Mouse.Moved = 0;
Mouse.Pressed = 0;
}
/**
* I�augomas ekrano buferis pelei ir nupie�ama pati pel�
*/
void InitMouseGFX() {
GetMouseBuffer(Mouse.X, Mouse.Y);
DrawMouse(Mouse.X, Mouse.Y);
}
/**
* Patikriname Input Buffer Flag, Output Buffer Flag ir MOBF
*/
void CheckPS2() {
unsigned long i = 0xFFFF;
while((inportb(KEYB_CTRL) & 0x3) && i) {
inportb(KEYB_BUF);
i--;
}
}
/**
* Klaviatros jungties skaitymas
* @return pel� "Scan" kodas
*/
char ReadMouse() {
unsigned long i;
char Status, Byte = 0;
for(i = 0; i < 0xFFFF; i++) {
Status = inportb(KEYB_CTRL);
if(Status & 0x01) {
Byte = inportb(KEYB_BUF);
if(!(Status & 0xC0))
return Byte;
}
}
return Byte;
}
void IRQ12() {
Mouse.Pressed = 0;
Mouse.Moved = 0;
char Buf[3];
// skaitome tris pel� siun�amus baitus
Buf[0] = ReadMouse();
Buf[1] = ReadMouse();
Buf[2] = ReadMouse();
// ar buvo paspaustas pel�, kuris nors vienas mygtukas
// �a�me tada status�
if(Buf[0] & 1) {
Mouse.LButton = 1;
Mouse.Pressed = 1;
}
if((Buf[0] & 2) >> 1) {
Mouse.RButton = 1;
Mouse.Pressed = 1;
}
if(Buf[1] + Buf[2]) {
PutMouseBuffer(Mouse.X, Mouse.Y);
Mouse.X += Buf[1];
Mouse.Y -= Buf[2];
Mouse.Moved = 1;
// tikriname ar po naujo pel� pajudinimo nebuvo perengtos ekrano ribos
// X a�je
if(Mouse.X >= sWidth)
Mouse.X = sWidth - 1;
if(Mouse.X < 0)
Mouse.X = 0;
// Y a�je
if(Mouse.Y >= sHeight) Mouse.Y = sHeight - 1;
if(Mouse.Y < 0) Mouse.Y = 0;
GetMouseBuffer(Mouse.X, Mouse.Y);
DrawMouse(Mouse.X, Mouse.Y);
}
}