From 24aa6ec2a5453a84fe04bca39e964663b386240c Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 3 Oct 1993 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1993-10-03 --- carrera/clock.c | 1 + carrera/kbd.c | 67 +++++++++++++++++++++++++++++++++++++++++++++--- carrera/screen.c | 45 ++++++++++++++++---------------- port/devbit.c | 6 +++-- 4 files changed, 91 insertions(+), 28 deletions(-) diff --git a/carrera/clock.c b/carrera/clock.c index 40393236aea0c974a79520e7b6252ac988f89949..426e49c6a376c605a1a91f0e7d63ee15ef078403 100644 --- a/carrera/clock.c +++ b/carrera/clock.c @@ -87,6 +87,7 @@ clock(Ureg *ur) } checkalarms(); + mouseclock(); if(up == 0 || (ur->status&IE) == 0 || up->state != Running) return; diff --git a/carrera/kbd.c b/carrera/kbd.c index e60664d346963e6030ab8ca8ebbe7f4bdba54fc0..b06b13abc9909a9329c60fd66c2d77ef431bec1f 100644 --- a/carrera/kbd.c +++ b/carrera/kbd.c @@ -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; } diff --git a/carrera/screen.c b/carrera/screen.c index 30d4d3e624a25073decc057d127c32e9bc5e3ebe..a289c6ae2f5ce8afd937dc269670b700a94f264d 100644 --- a/carrera/screen.c +++ b/carrera/screen.c @@ -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 */ diff --git a/port/devbit.c b/port/devbit.c index f6301364e80bf5f0a9ef9c469c2d3ea874857bfe..3d4b6bb53144a87cd2d0e98b27da75c708cce1dd 100644 --- a/port/devbit.c +++ b/port/devbit.c @@ -105,7 +105,8 @@ extern GBitmap gscreen; typedef struct Mouseinfo Mouseinfo; typedef struct Cursorinfo Cursorinfo; -struct Mouseinfo{ +struct Mouseinfo +{ /* * First three fields are known in some l.s's */ @@ -119,7 +120,8 @@ struct Mouseinfo{ Rendez r; }; -struct Cursorinfo{ +struct Cursorinfo +{ Cursor; Lock; int visible; /* on screen */