@@ 19,6 19,7 @@ enum
Ktest= 0xAB, /* keyboard test */
Kdisable= 0xAD, /* disable keyboard */
Kenable= 0xAE, /* enable keyboard */
+ Kmseena= 0xA8, /* enable mouse */
Krdin= 0xC0, /* read input port */
Krdout= 0xD0, /* read output port */
Kwrout= 0xD1, /* write output port */
@@ 46,6 47,7 @@ enum
* command register bits
*/
Cintena= 1<<0, /* enable output interrupt */
+ Cmseint= 1<<1, /* enable mouse interrupt */
Csystem= 1<<2, /* set system */
Cinhibit= 1<<3, /* inhibit override */
Cdisable= 1<<4, /* disable keyboard */
@@ 187,11 189,34 @@ kbdackwait(void)
void
mouseintr(void)
{
- uchar code;
+ uchar c;
+ static int nb;
+ int buttons, dx, dy;
+ static short msg[3];
+ static uchar b[] = {0, 1, 4, 5, 2, 3, 6, 7, 0, 1, 2, 5, 2, 3, 6, 7 };
kbdwait();
- code = KBDDAT;
- print("mouse intr %d\n", code);
+ c = KBDDAT;
+
+ /*
+ * check byte 0 for consistency
+ */
+ if(nb==0 && (c&0xc8)!=0x08)
+ return;
+
+ msg[nb] = c;
+ if(++nb == 3){
+ nb = 0;
+ if(msg[0] & 0x10)
+ msg[1] |= 0xFF00;
+ if(msg[0] & 0x20)
+ msg[2] |= 0xFF00;
+
+ buttons = b[msg[0]&7];
+ dx = msg[1];
+ dy = -msg[2];
+ mousetrack(buttons, dx, dy);
+ }
}
int
@@ 342,6 367,35 @@ empty(void)
}
}
+/*
+ * send a command to the mouse
+ */
+static int
+mousecmd(int cmd)
+{
+ int tries;
+ unsigned int c;
+
+ c = 0;
+ tries = 0;
+ do{
+ if(tries++ > 2)
+ break;
+ OUTWAIT;
+ KBDCTL = 0xD4;
+ OUTWAIT;
+ KBDDAT = cmd;
+ OUTWAIT;
+ kbdwait();
+ c = KBDDAT;
+ } while(c == 0xFE || c == 0);
+ if(c != 0xFA){
+ print("mouse returns %2.2ux to the %2.2ux command\n", c, cmd);
+ return -1;
+ }
+ return 0;
+}
+
int
kbdinit(void)
{
@@ 387,10 441,15 @@ kbdinit(void)
OUTWAIT;
KBDCTL = Kwrcmd;
OUTWAIT;
- KBDDAT = Csystem | Cinhibit | Cintena;
+ KBDDAT = Csystem | Cinhibit | Cintena | Cmseint;
OUTWAIT;
KBDCTL = Kenable;
+ OUTWAIT;
+ KBDCTL = Kmseena;
empty();
+ mousecmd(0xEA);
+ mousecmd(0xF4);
+
return 1;
}
@@ 128,22 128,6 @@ GBitmap bgrnd =
0
};
-Cursor fatarrow = {
- { -1, -1 },
- {
- 0xff, 0xff, 0x80, 0x01, 0x80, 0x02, 0x80, 0x0c,
- 0x80, 0x10, 0x80, 0x10, 0x80, 0x08, 0x80, 0x04,
- 0x80, 0x02, 0x80, 0x01, 0x80, 0x02, 0x8c, 0x04,
- 0x92, 0x08, 0x91, 0x10, 0xa0, 0xa0, 0xc0, 0x40,
- },
- {
- 0x00, 0x00, 0x7f, 0xfe, 0x7f, 0xfc, 0x7f, 0xf0,
- 0x7f, 0xe0, 0x7f, 0xe0, 0x7f, 0xf0, 0x7f, 0xf8,
- 0x7f, 0xfc, 0x7f, 0xfe, 0x7f, 0xfc, 0x73, 0xf8,
- 0x61, 0xf0, 0x60, 0xe0, 0x40, 0x40, 0x00, 0x00,
- },
-};
-
static Rectangle window;
static Point cursor;
static int h, w;
@@ 202,8 186,6 @@ screeninit(void)
gbitblt(&gscreen, Pt(0, 0), &gscreen, gscreen.r, 0);
- memmove(&arrow, &fatarrow, sizeof(fatarrow));
-
screenwin();
}
@@ 502,9 484,10 @@ twizzle(uchar *f, uchar *t)
void
screenupdate(void)
{
+ Rectangle r;
+ ulong *s, *h, in1, in2;
uchar *sp, *hp, *edisp;
int i, y, len, off, page, inc;
- Rectangle r;
r = mbb;
mbb = NULLMBB;
@@ 529,11 512,13 @@ screenupdate(void)
inc = gscreen.width*4;
off = r.min.y * inc + r.min.x;
+
sp = ((uchar*)gscreen.base) + off;
page = off>>16;
off &= (1<<16)-1;
- hp = edisp = 0;
+ hp = 0;
+ edisp = 0;
for(y = r.min.y; y < r.max.y; y++){
if(hp >= edisp){
hp = ((uchar*)vgascreen.base) + off;
@@ 542,13 527,29 @@ screenupdate(void)
off = r.min.x;
page++;
}
- for(i = 0; i < len; i += 8)
- twizzle(sp+i, hp+i);
+ for(i = 0; i < len; i += 8) {
+ s = (ulong*)(sp+i);
+ h = (ulong*)(hp+i);
+ in1 = s[0];
+ in2 = s[1];
+ h[0] = swiz(in2);
+ h[1] = swiz(in1);
+ }
hp += inc;
sp += inc;
}
}
+void
+mousescreenupdate(void)
+{
+ if(canlock(&screenlock) == 0)
+ return;
+
+ screenupdate();
+ unlock(&screenlock);
+}
+
/*
* graphics
*/