summaryrefslogtreecommitdiff
path: root/i386/i386at/kd_mouse.c
diff options
context:
space:
mode:
authorThomas Schwinge <tschwinge@gnu.org>2006-06-30 20:46:09 +0000
committerThomas Schwinge <tschwinge@gnu.org>2009-06-18 00:26:37 +0200
commitaea8ac0d99eef1e71127b6b397ce67f394feb649 (patch)
tree59ce5293d6276078cc6f14ac6b51561294bea482 /i386/i386at/kd_mouse.c
parent57c412aeb0f2e475adc33e5c86b2ddfec0453dec (diff)
2006-06-30 Samuel Thibault <samuel.thibault@ens-lyon.org>
* i386/i386at/kd_mouse.c (mouse_char_in, mouse_char) Remove variables. (mouse_char_index) New variable. (mouse_handle_byte, kd_mouse_read): Use MOUSEBUF instead of MOUSE_CHAR for storing incoming command characters. (kd_mouse_read_reset): New function. (ibm_ps2_mouse_open, ibm_ps2_mouse_close): Call new kd_mouse_read_reset function.
Diffstat (limited to 'i386/i386at/kd_mouse.c')
-rw-r--r--i386/i386at/kd_mouse.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/i386/i386at/kd_mouse.c b/i386/i386at/kd_mouse.c
index 0c104d3..ecd28a4 100644
--- a/i386/i386at/kd_mouse.c
+++ b/i386/i386at/kd_mouse.c
@@ -122,8 +122,7 @@ int mouse_baud = BCNT1200;
boolean_t mouse_char_cmd = FALSE; /* mouse response is to cmd */
boolean_t mouse_char_wanted = FALSE; /* want mouse response */
-boolean_t mouse_char_in = FALSE; /* have mouse response */
-unsigned char mouse_char; /* mouse response */
+int mouse_char_index; /* mouse response */
/*
@@ -573,11 +572,11 @@ mouse_handle_byte(ch)
/*
* Mouse character is response to command
*/
- mouse_char = ch;
- mouse_char_in = TRUE;
+ if (mousebufindex < mousebufsize)
+ mousebuf[mousebufindex++] = ch;
if (mouse_char_wanted) {
mouse_char_wanted = FALSE;
- wakeup(&mouse_char);
+ wakeup(&mousebuf);
}
return;
}
@@ -747,22 +746,33 @@ int kd_mouse_read(void)
{
int ch;
- while (!mouse_char_in) {
+ if (mouse_char_index >= mousebufsize)
+ return -1;
+
+ while (mousebufindex <= mouse_char_index) {
mouse_char_wanted = TRUE;
#ifdef MACH_KERNEL
- assert_wait((event_t) &mouse_char, FALSE);
+ assert_wait((event_t) &mousebuf, FALSE);
thread_block((void (*)()) 0);
#else /* MACH_KERNEL */
- sleep(&mouse_char, PZERO);
+ sleep(&mousebuf, PZERO);
#endif /* MACH_KERNEL */
}
- ch = mouse_char;
- mouse_char_in = FALSE;
+ ch = mousebuf[mouse_char_index++];
return ch;
}
+/*
+ * Prepare buffer for receiving next packet from mouse.
+ */
+void kd_mouse_read_reset(void)
+{
+ mousebufindex = 0;
+ mouse_char_index = 0;
+}
+
ibm_ps2_mouse_open(dev)
{
spl_t s = spltty();
@@ -775,6 +785,7 @@ ibm_ps2_mouse_open(dev)
kd_cmdreg_write(0x47); /* allow mouse interrupts */
/* magic number for ibm? */
+ kd_mouse_read_reset();
kd_mouse_write(0xff); /* reset mouse */
if (kd_mouse_read() != 0xfa) {
splx(s);
@@ -784,18 +795,21 @@ ibm_ps2_mouse_open(dev)
(void) kd_mouse_read(); /* discard 2-character mouse ID */
(void) kd_mouse_read();
+ kd_mouse_read_reset();
kd_mouse_write(0xea); /* set stream mode */
if (kd_mouse_read() != 0xfa) {
splx(s);
return; /* need ACK */
}
+ kd_mouse_read_reset();
kd_mouse_write(0xf4); /* enable */
if (kd_mouse_read() != 0xfa) {
splx(s);
return; /* need ACK */
}
+ kd_mouse_read_reset();
mouse_char_cmd = FALSE; /* now we get mouse packets */
splx(s);
@@ -807,6 +821,7 @@ ibm_ps2_mouse_close(dev)
mouse_char_cmd = TRUE; /* responses are to commands */
+ kd_mouse_read_reset();
kd_mouse_write(0xff); /* reset mouse */
if (kd_mouse_read() == 0xfa) {
/* got ACK: discard 2-char mouse ID */