plan 9 kernel history: overview | file list | diff list

1994/0414/port/devmouse.c (diff list | history)

1994/0413/sys/src/9/port/devmouse.c:9,341994/0414/sys/src/9/port/devmouse.c:9,15 (short | long | prev | next)
1993/1006    
#include	"devtab.h" 
1994/0210    
#include	"screen.h" 
1993/1006    
 
/* 
 * Some monochrome screens are reversed from what we like: 
 * We want 0's bright and 1's dark. 
 * Indexed by an Fcode, these compensate for the source bitmap being wrong 
 * (exchange S rows) and destination (exchange D columns and invert result) 
 */ 
int flipS[] = { 
	0x0, 0x4, 0x8, 0xC, 0x1, 0x5, 0x9, 0xD, 
	0x2, 0x6, 0xA, 0xE, 0x3, 0x7, 0xB, 0xF 
}; 
                 
int flipD[] = { 
	0xF, 0xD, 0xE, 0xC, 0x7, 0x5, 0x6, 0x4, 
	0xB, 0x9, 0xA, 0x8, 0x3, 0x1, 0x2, 0x0,  
}; 
                 
int flipping;	/* are flip tables being used to transform Fcodes? */ 
                 
typedef struct Mouseinfo	Mouseinfo; 
typedef struct Cursorinfo	Cursorinfo; 
 
struct Mouseinfo 
{ 
1994/0413/sys/src/9/port/devmouse.c:48,761994/0414/sys/src/9/port/devmouse.c:29,40
1993/1006    
	int	open; 
}; 
 
struct Cursorinfo 
{ 
	Cursor; 
	Lock; 
	int	visible;	/* on screen */ 
	int	disable;	/* from being used */ 
1993/1026    
	int	frozen;	/* from being used */ 
1993/1006    
	Rectangle r;		/* location */ 
1994/0413    
                 
	int	l; 
	int	tl; 
	int	setop; 
	int	clrop; 
	Rectangle clipr; 
1993/1006    
}; 
                 
Mouseinfo	mouse; 
Cursorinfo	cursor; 
int		mouseshifted; 
int		mousetype; 
1994/0216    
int		mouseswap; 
1993/1006    
int		hwcurs; 
1993/1009    
Cursor	curs; 
1994/0414    
Cursor		curs; 
1993/1006    
 
Cursor	arrow = 
{ 
1994/0413/sys/src/9/port/devmouse.c:88,1321994/0414/sys/src/9/port/devmouse.c:52,62
1993/1006    
}; 
 
ulong setbits[16]; 
1994/0413    
Bitmap	set = 
1993/1006    
{ 
1994/0413    
	{0, 0, 16, 16}, 
	{0, 0, 16, 16}, 
1993/1006    
	0, 
1994/0413    
	setbits, 
1993/1006    
	1, 
	0, 
}; 
                 
ulong clrbits[16]; 
1994/0413    
Bitmap	clr = 
1993/1006    
{ 
	{0, 0, 16, 16}, 
1994/0413    
	{0, 0, 16, 16}, 
1993/1006    
	0, 
1994/0413    
	clrbits, 
1993/1006    
	1, 
	0, 
}; 
 
1994/0413    
ulong backbits[16*5]; 
ulong workbits[16*5]; 
Bitmap cursorwork = 
1994/0412    
{ 
1994/0413    
	{0, 0, 16+8, 16}, 
	{0, 0, 16+8, 16}, 
1994/0412    
	0, 
1994/0413    
	workbits, 
1994/0412    
	1, 
	0, 
}; 
                 
1993/1006    
void	Cursortocursor(Cursor*); 
int	mousechanged(void*); 
 
1994/0412    
extern	void	screenload(Rectangle, uchar*, int, int, int); 
extern	void	screenunload(Rectangle, uchar*, int, int, int); 
                 
1993/1006    
enum{ 
	Qdir, 
1993/1009    
	Qcursor, 
1994/0413/sys/src/9/port/devmouse.c:147,1951994/0414/sys/src/9/port/devmouse.c:77,95
1993/1006    
void 
mousereset(void) 
{ 
	ulong r; 
                 
	if(!conf.monitor) 
		return; 
 
	getcolor(0, &r, &r, &r); 
	if(r == 0) 
		flipping = 1; 
	flipping = 0;	/* howard, why is this necessary to get a black arrow on carrera? */ 
1993/1009    
	curs = arrow; 
1993/1006    
	Cursortocursor(&arrow); 
} 
 
void 
1994/0413    
cursorinit(void) 
{ 
	cursorwork.ldepth = gscreen.ldepth; 
	cursorwork.width = ((cursorwork.r.max.x << gscreen.ldepth) + 31) >> 5; 
                 
	cursor.l = cursorwork.width*BY2WD; 
                 
	if(flipping){ 
		cursor.setop = flipD[S|D]; 
		cursor.clrop = flipD[D&~S]; 
	} else { 
		cursor.setop = S|D; 
		cursor.clrop = D&~S; 
	} 
} 
                 
void 
1993/1006    
mouseinit(void) 
{ 
	if(!conf.monitor) 
		return; 
1994/0413    
 
1994/0412    
	if(gscreen.ldepth > 3){ 
1994/0413    
		print("mouse can't work ldepth > 3"); 
		cursor.disable = 1; 
1993/1006    
	} 
1994/0413    
                 
	cursorinit(); 
                 
1993/1006    
	cursoron(1); 
} 
 
1994/0413/sys/src/9/port/devmouse.c:198,2041994/0414/sys/src/9/port/devmouse.c:98,103
1993/1006    
{ 
	if(!conf.monitor) 
		error(Egreg); 
1994/0413    
	cursorinit(); 
1993/1006    
	return devattach('m', spec); 
} 
 
1994/0413/sys/src/9/port/devmouse.c:408,4141994/0414/sys/src/9/port/devmouse.c:307,313
1993/1006    
	uchar *p; 
 
	lock(&cursor); 
	memmove(&cursor, c, sizeof(Cursor)); 
1994/0414    
	memmove(&cursor.Cursor, c, sizeof(Cursor)); 
1993/1006    
	for(i=0; i<16; i++){ 
		p = (uchar*)&setbits[i]; 
		*p = c->set[2*i]; 
1994/0413/sys/src/9/port/devmouse.c:417,5321994/0414/sys/src/9/port/devmouse.c:316,326
1993/1006    
		*p = c->clr[2*i]; 
		*(p+1) = c->clr[2*i+1]; 
	} 
	if(hwcurs) 
		hwcursset(set.base, clr.base, cursor.offset.x, cursor.offset.y); 
1994/0414    
	setcursor(setbits, clrbits, cursor.offset.x, cursor.offset.y); 
1993/1026    
	unlock(&cursor); 
} 
 
void 
cursorlock(Rectangle r) 
{ 
	if(hwcurs) 
		return; 
	lock(&cursor); 
	if(rectXrect(cursor.r, r)){ 
		cursoroff(0); 
		cursor.frozen = 1; 
	} 
	cursor.disable++; 
	unlock(&cursor); 
} 
 
void 
cursorunlock(void) 
{ 
	if(hwcurs) 
		return; 
	lock(&cursor); 
	cursor.disable--; 
	if(cursor.frozen) 
		cursoron(0); 
	cursor.frozen = 0; 
1993/1006    
	unlock(&cursor); 
} 
                 
1994/0413    
typedef struct 
{ 
	Bitmap *dm; 
	Point p; 
	Bitmap *sm; 
	Rectangle r; 
	Fcode f; 
} XXX; 
                 
1993/1006    
void 
cursoron(int dolock) 
{ 
1994/0413    
	int off; 
	Rectangle r; 
	uchar *a; 
	XXX x; 
	extern int graphicssubtile(uchar*, int, int, Rectangle, Rectangle, uchar**); 
                 
1993/1006    
	if(cursor.disable) 
		return; 
	if(dolock) 
		lock(&cursor); 
	if(cursor.visible++ == 0){ 
		if(hwcurs) 
			hwcursmove(mouse.xy.x, mouse.xy.y); 
		else { 
			cursor.r.min = mouse.xy; 
			cursor.r.max = add(mouse.xy, Pt(16, 16)); 
			cursor.r = raddp(cursor.r, cursor.offset); 
1994/0413    
                 
			/* bit offset into backup area */ 
			off = ((1<<gscreen.ldepth)*cursor.r.min.x) & 7; 
                 
			/* clip the cursor rectangle */ 
			x.dm = &cursorwork; 
			x.p = Pt(off, 0); 
			x.sm = &gscreen; 
			x.r = cursor.r; 
			bitbltclip(&x); 
                 
			/* tile width */ 
			cursor.tl = graphicssubtile(0, cursor.l, gscreen.ldepth, 
					gscreen.r, x.r, &a); 
			if(cursor.tl > 0){ 
				/* get tile */ 
				screenunload(x.r, (uchar*)workbits, cursor.tl, cursor.l, 0); 
                 
				/* save for cursoroff */ 
				memmove(backbits, workbits, cursor.l*16); 
                 
				/* add mouse into work area */ 
				r = Rect(0, 0, Dx(x.r), Dy(x.r)); 
				bitblt(&cursorwork, x.p, &clr, r, cursor.clrop); 
				bitblt(&cursorwork, x.p, &set, r, cursor.setop); 
                 
				/* put back tile */ 
				cursor.clipr = x.r; 
				screenload(x.r, (uchar*)workbits, cursor.tl, cursor.l, 0); 
			} 
1993/1006    
		} 
	} 
	if(dolock) 
		unlock(&cursor); 
} 
                 
void 
cursoroff(int dolock) 
{ 
	if(cursor.disable) 
		return; 
	if(dolock) 
		lock(&cursor); 
1994/0413    
	if(--cursor.visible == 0 && !hwcurs && cursor.tl > 0) 
		screenload(cursor.clipr, (uchar*)backbits, cursor.tl, cursor.l, 0); 
1993/1006    
	if(dolock) 
		unlock(&cursor); 
} 
                 
/* 
 *  called by the clock routine to redraw the cursor 
 */ 
1994/0413/sys/src/9/port/devmouse.c:651,6541994/0414/sys/src/9/port/devmouse.c:445,454
1993/1006    
{ 
	USED(m); 
	return mouse.lastcounter - mouse.counter; 
1994/0414    
} 
 
Point 
mousexy(void) 
{ 
	return mouse.xy; 
1993/1006    
} 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)