2018-09-28 20:35:51 +02:00
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
/* COS2000 - Compatible Operating System - LGPL v3 - Hord<72> Nicolas */
|
|
|
|
|
/* */
|
2007-04-02 16:06:06 +02:00
|
|
|
|
#include "types.h"
|
|
|
|
|
#include "asm.h"
|
|
|
|
|
#include "mouse.h"
|
|
|
|
|
#include "keyboard.h"
|
|
|
|
|
#include "vga.h"
|
|
|
|
|
#include "video.h"
|
|
|
|
|
|
2018-08-17 16:46:56 +02:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
/* initialise la souris */
|
|
|
|
|
|
2018-09-28 20:35:51 +02:00
|
|
|
|
bool initmouse(void)
|
2007-04-02 16:06:06 +02:00
|
|
|
|
{
|
2018-08-17 16:46:56 +02:00
|
|
|
|
u16 i = 1024;
|
2007-04-02 16:06:06 +02:00
|
|
|
|
|
2018-08-17 16:46:56 +02:00
|
|
|
|
outkbd(0x64, 0xA8); /* autoris<69> Aux */
|
2007-04-02 16:06:06 +02:00
|
|
|
|
|
2018-08-17 16:46:56 +02:00
|
|
|
|
outmseack(0xf3); /*sample */
|
|
|
|
|
outmseack(100); /*sample donn<6E>e */
|
2007-04-02 16:06:06 +02:00
|
|
|
|
|
2018-08-17 16:46:56 +02:00
|
|
|
|
outmseack(0xe8); /*resolution */
|
|
|
|
|
outmseack(3); /*resolution donn<6E>e */
|
2007-04-02 16:06:06 +02:00
|
|
|
|
|
2018-08-17 16:46:56 +02:00
|
|
|
|
outmseack(0xe7); /* echelle 2:1 */
|
2007-04-02 16:06:06 +02:00
|
|
|
|
|
2018-08-17 16:46:56 +02:00
|
|
|
|
outmseack(0xf4); /* Autorise peripherique */
|
2007-04-02 16:06:06 +02:00
|
|
|
|
|
2018-08-17 16:46:56 +02:00
|
|
|
|
outmsecmd(0x47); /* Autorise interruption */
|
2007-04-02 16:06:06 +02:00
|
|
|
|
|
2018-08-17 16:46:56 +02:00
|
|
|
|
while (i-- > 0)
|
|
|
|
|
if (inb(0x60) == 250)
|
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
2007-04-02 16:06:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-17 16:46:56 +02:00
|
|
|
|
static u8 bytepos = 0, mousereplies = 0;
|
|
|
|
|
static u8 mpacket[3];
|
|
|
|
|
static s32 mousex = 40, mousey = 12;
|
|
|
|
|
static u16 oldx = 0, oldy = 0;
|
|
|
|
|
static u8 oldchar = 0x00, oldattr = 0x07;
|
|
|
|
|
static bool mousebut1 = 0, mousebut2 = 0, mousebut3 = 0;
|
|
|
|
|
static u8 speed = 6;
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
/* ecriture vers souris */
|
2007-04-02 16:06:06 +02:00
|
|
|
|
|
|
|
|
|
void outmseack(u8 value)
|
|
|
|
|
{
|
2018-08-17 16:46:56 +02:00
|
|
|
|
outkbd(0x64, 0xD4);
|
|
|
|
|
outb(0x60, value);
|
|
|
|
|
mousereplies++;
|
2007-04-02 16:06:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-17 16:46:56 +02:00
|
|
|
|
/* ecriture vers mode */
|
|
|
|
|
|
2007-04-02 16:06:06 +02:00
|
|
|
|
void outmsecmd(u8 command)
|
|
|
|
|
{
|
2018-08-17 16:46:56 +02:00
|
|
|
|
outkbd(0x64, 0x60);
|
|
|
|
|
outb(0x60, command);
|
2007-04-02 16:06:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-17 16:46:56 +02:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
/* Handler d'interruption de la souris IRQ 12 */
|
|
|
|
|
|
2018-09-28 20:35:51 +02:00
|
|
|
|
void mouse(void)
|
2007-04-02 16:06:06 +02:00
|
|
|
|
{
|
2018-08-17 16:46:56 +02:00
|
|
|
|
cli();
|
|
|
|
|
pushf();
|
|
|
|
|
pushad();
|
|
|
|
|
u8 mbyte = inb(0x60);
|
|
|
|
|
s8 changex, changey;
|
|
|
|
|
|
|
|
|
|
if (mousereplies > 0) {
|
|
|
|
|
if (mbyte == 0xFA) {
|
|
|
|
|
mousereplies--;
|
|
|
|
|
goto endofint;
|
|
|
|
|
}
|
|
|
|
|
mousereplies = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mpacket[bytepos] = mbyte;
|
|
|
|
|
bytepos++;
|
|
|
|
|
|
|
|
|
|
if (bytepos == 3) {
|
|
|
|
|
bytepos = 0;
|
|
|
|
|
if (mpacket[1] == 0) {
|
|
|
|
|
changex = 0;
|
|
|
|
|
} else {
|
|
|
|
|
changex = (mpacket[0] & 0x10) ?
|
|
|
|
|
mpacket[1] - 256 : mpacket[1];
|
|
|
|
|
}
|
|
|
|
|
if (mpacket[2] == 0) {
|
|
|
|
|
changey = 0;
|
|
|
|
|
} else {
|
|
|
|
|
changey = -((mpacket[0] & 0x20) ?
|
|
|
|
|
mpacket[2] - 256 : mpacket[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mousex += (changex << speed);
|
|
|
|
|
mousey += (changey << speed);
|
|
|
|
|
|
|
|
|
|
if (mousex < 0) {
|
|
|
|
|
mousex = 0;
|
|
|
|
|
}
|
|
|
|
|
if (mousex >= 65535) {
|
|
|
|
|
mousex = 65535;
|
|
|
|
|
}
|
|
|
|
|
if (mousey < 0) {
|
|
|
|
|
mousey = 0;
|
|
|
|
|
}
|
|
|
|
|
if (mousey >= 65535) {
|
|
|
|
|
mousey = 65535;
|
|
|
|
|
}
|
2018-10-13 13:23:00 +02:00
|
|
|
|
u16 newx = (u32) mousex * getwidth() / 65536;
|
|
|
|
|
u16 newy = (u32) mousey * getheight() / 65536;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
|
|
|
|
|
// Retrieve mouse button status from packet
|
|
|
|
|
mousebut1 = mpacket[0] & 1;
|
|
|
|
|
mousebut2 = mpacket[0] & 2;
|
|
|
|
|
mousebut3 = mpacket[0] & 4;
|
|
|
|
|
|
2007-04-02 16:06:06 +02:00
|
|
|
|
// printf("RX:%d\tRY:%d\tX:%d\tY:%d\tB1:%d\tB2:%d\tB3:%d\t\r\n",changex,changey,mousex,mousey,mousebut1,mousebut2,mousebut3);
|
|
|
|
|
|
2018-08-17 16:46:56 +02:00
|
|
|
|
if ((newx != oldx) || (newy != oldy)) {
|
|
|
|
|
showchar(oldx, oldy, oldchar, oldattr);
|
|
|
|
|
oldx = newx;
|
|
|
|
|
oldy = newy;
|
|
|
|
|
oldchar = getchar(oldx, oldy);
|
|
|
|
|
oldattr = getattrib(oldx, oldy);
|
|
|
|
|
showchar(newx, newy, 0xDB, 0x0F);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
endofint:
|
|
|
|
|
irqendmaster();
|
|
|
|
|
irqendslave();
|
|
|
|
|
popad();
|
|
|
|
|
popf();
|
|
|
|
|
sti();
|
|
|
|
|
asm("addl $0x18,%esp;\
|
2018-07-24 04:04:07 +02:00
|
|
|
|
popl %bx;\
|
|
|
|
|
iret;");
|
2018-08-17 16:46:56 +02:00
|
|
|
|
iret();
|
2007-04-02 16:06:06 +02:00
|
|
|
|
}
|
2018-09-28 20:35:51 +02:00
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|