DataMuseum.dk

Presents historical artifacts from the history of:

Regnecentalen RC-900

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Regnecentalen RC-900

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download

⟦34552c88a⟧ TextFile

    Length: 4086 (0xff6)
    Types: TextFile
    Notes: UNIX file
    Names: »mouse.c«

Derivation

└─⟦0cfe73749⟧ Bits:30004154/config.imd SW95707I VP/ix MS-DOS emulator Rel. 1.1
└─⟦0cfe73749⟧ UNIX Filesystem
    └─⟦this⟧ »vc/new/usr/vpix/src/bmouse/mouse.c« 

TextFile

/*
 * Copyrighted as an unpublished work.
 * (c) Copyright 1987 INTERACTIVE Systems Corporation
 * All rights reserved.
 *
 * RESTRICTED RIGHTS
 *
 * These programs are supplied under a license.  They may be used,
 * disclosed, and/or copied only as permitted under such license
 * agreement.  Any copy must contain the above copyright notice and
 * this restricted rights notice.  Use, copying, and/or disclosure
 * of the programs is strictly prohibited unless otherwise provided
 * in the license agreement.
 *
 */

#ident "@(#)mouse.c	1.3 - 88/05/05"

#include "sys/param.h"
#include "sys/types.h"
#include "sys/sysmacros.h"
#include "sys/dir.h"
#include "sys/signal.h"
#include "sys/user.h"
#include "sys/errno.h"
#include "sys/mouse.h"
#ifdef VPIX
#include "sys/immu.h"
#include "sys/region.h"
#include "sys/proc.h"
#include "sys/tss.h"
#include "sys/v86.h"
#endif /* VPIX */

static char mousepresent;
static char mouseinuse;
static char mousemode;
static char mousestatus;
static int xmotion, ymotion;
#ifdef VPIX
static struct proc *ectproc;
static char rupted;
#endif /* VPIX */

#define UPPERLIM        127
#define LOWERLIM        -128
#define ONEBYTE(x)      ((x)>UPPERLIM?UPPERLIM:(x)<LOWERLIM?LOWERLIM:(x))

mouseinit()
{       unsigned char id1, id2;

	/* Try reading the InPort identification register.  It should
	 * alternate between a signature and a version number */
	id1 = inb (MOUSE1 + IDENTREG);
	id2 = inb (MOUSE1 + IDENTREG);
	if (id1 != id2 && (id1 == SIGN || id2 == SIGN))
		mousepresent = 1;
	else return;

	/* Reset the mouse to make sure it does not interrupt */
	outb (MOUSE1 + ADDRREG, RESET | MODE);
}

mouseopen(dev, flag)
	int dev;
{
        register int i;
	register struct lp *lp;

	/* insist on minor device 0 */
	if (minor(dev))
	{       u.u_error = ENXIO;
		return;
	}

	/* make sure there is a mouse */
	if (mousepresent == 0)
	{       u.u_error = ENXIO;
		return;
	}

	/* enforce exclusive use */
	if (mouseinuse)
	{       u.u_error = EBUSY;
		return;
	}

	mouseinuse = 1;
	xmotion = ymotion = 0;
	mousestatus = 0;

#ifdef VPIX
	ectproc = u.u_procp;
	rupted = 0;
#endif /* VPIX */

	/* Set appropriate modes for mouse and enable interrupts */
	mousemode = HZ30 | DATAINT | QUADMODE;
	outb (MOUSE1 + ADDRREG, MODE);
	outb (MOUSE1 + DATAREG, mousemode);
}


mouseclose(dev)
	int dev;
{
	/* Reset the mouse to make sure it does not interrupt */
	mousemode = 0;
	outb (MOUSE1 + ADDRREG, RESET | MODE);

	mouseinuse = 0;
}


mouseioctl(dev, cmd, arg, flag)
	caddr_t arg;
{       struct mouseinfo info;
	register int intmask;

	switch (cmd)
	{ case MOUSEIOCREAD:
		/* prevent mouse interrupts during update */
		intmask = splhi ();

		/* read and reset the accumulated interrupt info */
		info.status = mousestatus;
		info.xmotion = ONEBYTE (xmotion);
		info.ymotion = ONEBYTE (ymotion);
		xmotion = ymotion = 0;
		mousestatus &= ~BUTCHNGMASK;
#ifdef VPIX
		rupted = 0;
#endif /* VPIX */

		/* resume mouse interrupts */
		splx (intmask);

		if (copyout (&info, arg, sizeof info))
			u.u_error = EFAULT;
		break;
	}
}

mouseintr(ivect)
	int	ivect;
{       char    status, c;

	/* Select mode register and turn on the HOLD data bit */
	outb (MOUSE1 + ADDRREG, MODE);
	outb (MOUSE1 + DATAREG, mousemode + HOLD);

	/* Select and read the status register */
	outb (MOUSE1 + ADDRREG, MSTATUS);
	status = inb (MOUSE1 + DATAREG);

	/* if mouse moved, save the motion */
	if (status & MOVEMENT)
	{       outb (MOUSE1 + ADDRREG, DATA1);
		c = inb (MOUSE1 + DATAREG);
		xmotion += c;
		outb (MOUSE1 + ADDRREG, DATA2);
		c = inb (MOUSE1 + DATAREG);
		ymotion += c;
	}
	mousestatus = status | (mousestatus & ~BUTSTATMASK);

	/* Select mode register and turn off the HOLD data bit */
	outb (MOUSE1 + ADDRREG, MODE);
	outb (MOUSE1 + DATAREG, mousemode);

#ifdef VPIX
	/* Send a pseudorupt if this is an ECT and the mouse has
	 * been read since the last pseudorupt and the status changed.
	 */
	if (ectproc && ectproc->p_v86 && !rupted && (status & (MOVEMENT | BUTCHNGMASK)))
	{       v86setint (ectproc->p_v86, V86VI_MOUSE);
		rupted = 1;
	}
#endif /* VPIX */
}