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-12-12 15:25:04 +01: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-12-15 19:13:26 +01:00
|
|
|
|
__attribute__((interrupt)) void mouse_handler(exception_stack_noerror *caller)
|
2007-04-02 16:06:06 +02:00
|
|
|
|
{
|
2018-12-20 17:16:51 +01:00
|
|
|
|
cli();
|
2018-12-12 15:25:04 +01:00
|
|
|
|
u8 mbyte = inb(0x60);
|
|
|
|
|
s8 changex, changey;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
if (mousereplies > 0)
|
|
|
|
|
{
|
|
|
|
|
if (mbyte == 0xFA)
|
|
|
|
|
{
|
2018-08-17 16:46:56 +02:00
|
|
|
|
mousereplies--;
|
|
|
|
|
goto endofint;
|
|
|
|
|
}
|
|
|
|
|
mousereplies = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mpacket[bytepos] = mbyte;
|
|
|
|
|
bytepos++;
|
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
if (bytepos == 3)
|
|
|
|
|
{
|
2018-08-17 16:46:56 +02:00
|
|
|
|
bytepos = 0;
|
2018-12-12 15:25:04 +01:00
|
|
|
|
if (mpacket[1] == 0)
|
|
|
|
|
{
|
2018-08-17 16:46:56 +02:00
|
|
|
|
changex = 0;
|
|
|
|
|
}
|
2018-12-12 15:25:04 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
changex =
|
|
|
|
|
(mpacket[0] & 0x10) ? mpacket[1] -
|
|
|
|
|
256 : mpacket[1];
|
|
|
|
|
}
|
|
|
|
|
if (mpacket[2] == 0)
|
|
|
|
|
{
|
2018-08-17 16:46:56 +02:00
|
|
|
|
changey = 0;
|
2018-12-12 15:25:04 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
changey =
|
|
|
|
|
-((mpacket[0] & 0x20) ? mpacket[2] -
|
|
|
|
|
256 : mpacket[2]);
|
2018-08-17 16:46:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mousex += (changex << speed);
|
|
|
|
|
mousey += (changey << speed);
|
|
|
|
|
|
2018-12-12 15:25:04 +01:00
|
|
|
|
if (mousex < 0)
|
|
|
|
|
{
|
2018-08-17 16:46:56 +02:00
|
|
|
|
mousex = 0;
|
|
|
|
|
}
|
2018-12-12 15:25:04 +01:00
|
|
|
|
if (mousex >= 65535)
|
|
|
|
|
{
|
2018-08-17 16:46:56 +02:00
|
|
|
|
mousex = 65535;
|
|
|
|
|
}
|
2018-12-12 15:25:04 +01:00
|
|
|
|
if (mousey < 0)
|
|
|
|
|
{
|
2018-08-17 16:46:56 +02:00
|
|
|
|
mousey = 0;
|
|
|
|
|
}
|
2018-12-12 15:25:04 +01:00
|
|
|
|
if (mousey >= 65535)
|
|
|
|
|
{
|
2018-08-17 16:46:56 +02:00
|
|
|
|
mousey = 65535;
|
|
|
|
|
}
|
2018-12-12 15:25:04 +01:00
|
|
|
|
videoinfos *info = getvideo_info();
|
|
|
|
|
u16 newx = (u32) mousex * info->currentwidth / 65536;
|
|
|
|
|
u16 newy = (u32) mousey * info->currentheight / 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-12-12 15:25:04 +01:00
|
|
|
|
if (!info->isgraphic)
|
2018-08-17 16:46:56 +02:00
|
|
|
|
showchar(newx, newy, 0xDB, 0x0F);
|
|
|
|
|
}
|
2018-12-12 15:25:04 +01:00
|
|
|
|
endofint:
|
2018-08-17 16:46:56 +02:00
|
|
|
|
irqendmaster();
|
|
|
|
|
irqendslave();
|
2018-12-20 17:16:51 +01:00
|
|
|
|
sti();
|
2007-04-02 16:06:06 +02:00
|
|
|
|
}
|
2018-09-28 20:35:51 +02:00
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|