Mouse type now configurable
This commit is contained in:
parent
d9fe1a30d7
commit
09dbd1dd65
21 changed files with 494 additions and 238 deletions
129
src/mouse_ps2.c
129
src/mouse_ps2.c
|
|
@ -16,7 +16,7 @@ enum
|
|||
#define MOUSE_ENABLE 0x20
|
||||
#define MOUSE_SCALE 0x10
|
||||
|
||||
static struct
|
||||
typedef struct mouse_ps2_t
|
||||
{
|
||||
int mode;
|
||||
|
||||
|
|
@ -27,54 +27,58 @@ static struct
|
|||
uint8_t command;
|
||||
|
||||
int cd;
|
||||
} mouse_ps2;
|
||||
|
||||
int x, y, b;
|
||||
} mouse_ps2_t;
|
||||
|
||||
void mouse_ps2_write(uint8_t val)
|
||||
void mouse_ps2_write(uint8_t val, void *p)
|
||||
{
|
||||
if (mouse_ps2.cd)
|
||||
mouse_ps2_t *mouse = (mouse_ps2_t *)p;
|
||||
|
||||
if (mouse->cd)
|
||||
{
|
||||
mouse_ps2.cd = 0;
|
||||
switch (mouse_ps2.command)
|
||||
mouse->cd = 0;
|
||||
switch (mouse->command)
|
||||
{
|
||||
case 0xe8: /*Set mouse resolution*/
|
||||
mouse_ps2.resolution = val;
|
||||
mouse->resolution = val;
|
||||
keyboard_at_adddata_mouse(0xfa);
|
||||
break;
|
||||
|
||||
case 0xf3: /*Set sample rate*/
|
||||
mouse_ps2.sample_rate = val;
|
||||
mouse->sample_rate = val;
|
||||
keyboard_at_adddata_mouse(0xfa);
|
||||
break;
|
||||
|
||||
// default:
|
||||
// fatal("mouse_ps2 : Bad data write %02X for command %02X\n", val, mouse_ps2.command);
|
||||
// fatal("mouse_ps2 : Bad data write %02X for command %02X\n", val, mouse->command);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t temp;
|
||||
|
||||
mouse_ps2.command = val;
|
||||
switch (mouse_ps2.command)
|
||||
mouse->command = val;
|
||||
switch (mouse->command)
|
||||
{
|
||||
case 0xe6: /*Set scaling to 1:1*/
|
||||
mouse_ps2.flags &= ~MOUSE_SCALE;
|
||||
mouse->flags &= ~MOUSE_SCALE;
|
||||
keyboard_at_adddata_mouse(0xfa);
|
||||
break;
|
||||
|
||||
case 0xe7: /*Set scaling to 2:1*/
|
||||
mouse_ps2.flags |= MOUSE_SCALE;
|
||||
mouse->flags |= MOUSE_SCALE;
|
||||
keyboard_at_adddata_mouse(0xfa);
|
||||
break;
|
||||
|
||||
case 0xe8: /*Set mouse resolution*/
|
||||
mouse_ps2.cd = 1;
|
||||
mouse->cd = 1;
|
||||
keyboard_at_adddata_mouse(0xfa);
|
||||
break;
|
||||
|
||||
case 0xe9: /*Status request*/
|
||||
keyboard_at_adddata_mouse(0xfa);
|
||||
temp = mouse_ps2.flags;
|
||||
temp = mouse->flags;
|
||||
if (mouse_buttons & 1)
|
||||
temp |= 1;
|
||||
if (mouse_buttons & 2)
|
||||
|
|
@ -82,8 +86,8 @@ void mouse_ps2_write(uint8_t val)
|
|||
if (mouse_buttons & 4)
|
||||
temp |= 3;
|
||||
keyboard_at_adddata_mouse(temp);
|
||||
keyboard_at_adddata_mouse(mouse_ps2.resolution);
|
||||
keyboard_at_adddata_mouse(mouse_ps2.sample_rate);
|
||||
keyboard_at_adddata_mouse(mouse->resolution);
|
||||
keyboard_at_adddata_mouse(mouse->sample_rate);
|
||||
break;
|
||||
|
||||
case 0xf2: /*Read ID*/
|
||||
|
|
@ -92,60 +96,63 @@ void mouse_ps2_write(uint8_t val)
|
|||
break;
|
||||
|
||||
case 0xf3: /*Set sample rate*/
|
||||
mouse_ps2.cd = 1;
|
||||
mouse->cd = 1;
|
||||
keyboard_at_adddata_mouse(0xfa);
|
||||
break;
|
||||
|
||||
case 0xf4: /*Enable*/
|
||||
mouse_ps2.flags |= MOUSE_ENABLE;
|
||||
mouse->flags |= MOUSE_ENABLE;
|
||||
keyboard_at_adddata_mouse(0xfa);
|
||||
break;
|
||||
|
||||
case 0xf5: /*Disable*/
|
||||
mouse_ps2.flags &= ~MOUSE_ENABLE;
|
||||
mouse->flags &= ~MOUSE_ENABLE;
|
||||
keyboard_at_adddata_mouse(0xfa);
|
||||
break;
|
||||
|
||||
case 0xff: /*Reset*/
|
||||
mouse_ps2.mode = MOUSE_STREAM;
|
||||
mouse_ps2.flags = 0;
|
||||
mouse->mode = MOUSE_STREAM;
|
||||
mouse->flags = 0;
|
||||
keyboard_at_adddata_mouse(0xfa);
|
||||
keyboard_at_adddata_mouse(0xaa);
|
||||
keyboard_at_adddata_mouse(0x00);
|
||||
break;
|
||||
|
||||
// default:
|
||||
// fatal("mouse_ps2 : Bad command %02X\n", val, mouse_ps2.command);
|
||||
// fatal("mouse_ps2 : Bad command %02X\n", val, mouse->command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int ps2_x = 0, ps2_y = 0, ps2_b = 0;
|
||||
void mouse_ps2_poll(int x, int y, int b)
|
||||
void mouse_ps2_poll(int x, int y, int b, void *p)
|
||||
{
|
||||
mouse_ps2_t *mouse = (mouse_ps2_t *)p;
|
||||
uint8_t packet[3] = {0x08, 0, 0};
|
||||
if (!x && !y && b == ps2_b) return;
|
||||
|
||||
if (!x && !y && b == mouse->b)
|
||||
return;
|
||||
|
||||
if (!mouse_scan)
|
||||
return;
|
||||
ps2_x += x;
|
||||
ps2_y -= y;
|
||||
if (mouse_ps2.mode == MOUSE_STREAM && (mouse_ps2.flags & MOUSE_ENABLE) &&
|
||||
|
||||
mouse->x += x;
|
||||
mouse->y -= y;
|
||||
if (mouse->mode == MOUSE_STREAM && (mouse->flags & MOUSE_ENABLE) &&
|
||||
((mouse_queue_end - mouse_queue_start) & 0xf) < 13)
|
||||
{
|
||||
ps2_b = b;
|
||||
mouse->b = b;
|
||||
// pclog("Send packet : %i %i\n", ps2_x, ps2_y);
|
||||
if (ps2_x > 255)
|
||||
ps2_x = 255;
|
||||
if (ps2_x < -256)
|
||||
ps2_x = -256;
|
||||
if (ps2_y > 255)
|
||||
ps2_y = 255;
|
||||
if (ps2_y < -256)
|
||||
ps2_y = -256;
|
||||
if (ps2_x < 0)
|
||||
if (mouse->x > 255)
|
||||
mouse->x = 255;
|
||||
if (mouse->x < -256)
|
||||
mouse->x = -256;
|
||||
if (mouse->y > 255)
|
||||
mouse->y = 255;
|
||||
if (mouse->y < -256)
|
||||
mouse->y = -256;
|
||||
if (mouse->x < 0)
|
||||
packet[0] |= 0x10;
|
||||
if (ps2_y < 0)
|
||||
if (mouse->y < 0)
|
||||
packet[0] |= 0x20;
|
||||
if (mouse_buttons & 1)
|
||||
packet[0] |= 1;
|
||||
|
|
@ -153,10 +160,10 @@ void mouse_ps2_poll(int x, int y, int b)
|
|||
packet[0] |= 2;
|
||||
if (mouse_buttons & 4)
|
||||
packet[0] |= 4;
|
||||
packet[1] = ps2_x & 0xff;
|
||||
packet[2] = ps2_y & 0xff;
|
||||
packet[1] = mouse->x & 0xff;
|
||||
packet[2] = mouse->y & 0xff;
|
||||
|
||||
ps2_x = ps2_y = 0;
|
||||
mouse->x = mouse->y = 0;
|
||||
|
||||
keyboard_at_adddata_mouse(packet[0]);
|
||||
keyboard_at_adddata_mouse(packet[1]);
|
||||
|
|
@ -164,12 +171,34 @@ void mouse_ps2_poll(int x, int y, int b)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void mouse_ps2_init()
|
||||
void *mouse_ps2_init()
|
||||
{
|
||||
mouse_poll = mouse_ps2_poll;
|
||||
mouse_write = mouse_ps2_write;
|
||||
mouse_ps2.cd = 0;
|
||||
mouse_ps2.flags = 0;
|
||||
mouse_ps2.mode = MOUSE_STREAM;
|
||||
mouse_ps2_t *mouse = (mouse_ps2_t *)malloc(sizeof(mouse_ps2_t));
|
||||
memset(mouse, 0, sizeof(mouse_ps2_t));
|
||||
|
||||
// mouse_poll = mouse_ps2_poll;
|
||||
// mouse_write = mouse_ps2_write;
|
||||
mouse->cd = 0;
|
||||
mouse->flags = 0;
|
||||
mouse->mode = MOUSE_STREAM;
|
||||
|
||||
keyboard_at_set_mouse(mouse_ps2_write, mouse);
|
||||
|
||||
return mouse;
|
||||
}
|
||||
|
||||
void mouse_ps2_close(void *p)
|
||||
{
|
||||
mouse_ps2_t *mouse = (mouse_ps2_t *)p;
|
||||
|
||||
free(mouse);
|
||||
}
|
||||
|
||||
mouse_t mouse_ps2_2_button =
|
||||
{
|
||||
"2-button mouse (PS/2)",
|
||||
mouse_ps2_init,
|
||||
mouse_ps2_close,
|
||||
mouse_ps2_poll,
|
||||
MOUSE_TYPE_PS2
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue