Esempio n. 1
0
/*!
 * Handle mousemotion events
 */
static void inputHandleMouseMotionEvent(SDL_MouseMotionEvent *motionEvent)
{
	switch (motionEvent->type)
	{
	case SDL_MOUSEMOTION:
		/* store the current mouse position */
		mouseXPos = motionEvent->x;
		mouseYPos = motionEvent->y;

		/* now see if a drag has started */
		if ((aMouseState[dragKey].state == KEY_PRESSED ||
		     aMouseState[dragKey].state == KEY_DOWN) &&
		    (ABSDIF(dragX, mouseXPos) > DRAG_THRESHOLD ||
		     ABSDIF(dragY, mouseYPos) > DRAG_THRESHOLD))
		{
			aMouseState[dragKey].state = KEY_DRAG;
		}
		break;
	default:
		break;
	}
}
Esempio n. 2
0
/***************************************************************************
 * sab_baud:      Function to compute the best register value to achieve
 *                a given baudrate.
 *                
 *
 *     Parameters   : 
 *                  port:    The port being used  (in only)
 *                  encbaud: 2* the baudrate. We use the
 *                           double value so as to support 134.5 (in only)
 *                  bgr      Value of reg BGR for baudrate(output)
 *                  ccr2     Value of reg CCR2 for baudrate (output)
 *                  ccr4     Value of reg CCR4 for baudrate (output)
 *                  truebaud The actual baudrate achieved (output).
 *
 *
 *     Return value : Return TRUE if the vaudrate can be set, FALSE otherwise 
 *
 *     Prerequisite : The various ports must have been initialized
 *
 *     Remark       : Stolen from the Aurora ase driver.
 *
 *     Author       : fw
 *
 *     Revision     : Oct 9 2000, creation
 ***************************************************************************/
unsigned int 
sab8253x_baud(sab_port_t *port, unsigned long encbaud,
	      unsigned char *bgr, unsigned char *ccr2,
	      unsigned char *ccr4, unsigned long *truebaudp)
{
	unsigned char	 bgr_std, bgr_enh, ccr2_std, ccr2_enh, ccr4_enh;
	unsigned int		 ok_std, ok_enh;
	unsigned long	 truebaud_std, truebaud_enh, truebaud,clkspeed;
	
	bgr_std = bgr_enh = 0;
	ccr2_std = ccr2_enh = 0;
	ccr4_enh = 0;
	
	/*
	 * the port/chip/board structure will tell us:
	 *  1) clock speed
	 *  2) chip revision (to figure out if the enhanced method is
	 *     available.
	 */
	
	clkspeed = port->chip->c_cim ? port->chip->c_cim->ci_clkspeed :  port->board->b_clkspeed;
	
#ifdef NODEBUGGING
	printk("With clk speed %ld, baud rate = %ld\n",clkspeed, encbaud);
#endif
	
	ok_std = sab8253x_baudstd(encbaud, clkspeed, &bgr_std,
				  &ccr2_std, &truebaud_std);
#ifdef NODEBUGGING
	printk("Std gives bgr = 0x%x, ccr2=0x%x for speed %ld\n",bgr_std,ccr2_std,truebaud_std);
#endif
	if(port->chip->c_revision >= SAB82532_VSTR_VN_3_2) 
	{
		ok_enh = sab8253x_baudenh(encbaud, clkspeed,
					  &bgr_enh, &ccr2_enh, &truebaud_enh);
#ifdef NODEBUGGING
		printk("Enh gives bgr = 0x%x, ccr2=0x%x for speed %ld\n",bgr_enh,ccr2_enh,truebaud_enh);
#endif
	} 
	else 
		ok_enh = FALSE;
	
	/*
	 * Did both methods return values?
	 */
	if (ok_std && ok_enh) 
	{
		/*
		 * Find the closest of the two.
		 */
		if (ABSDIF((truebaud_enh<<1), encbaud) <
		    ABSDIF((truebaud_std<<1), encbaud)) 
		{
			ok_std = FALSE;
		}
		else 
		{
			ok_enh = FALSE;
		}
	}
	
	/*
	 * Now return the values.
	 */
	
	if (ok_std || ok_enh) 
	{
		truebaud = ok_std ? truebaud_std : truebaud_enh;
		
		/*
		 * If the true baud rate is off by more than 5%, then
		 *  we don't support it.
		 */
		if (ROUND_DIV(ABSDIF((truebaud<<1), encbaud), encbaud) != 0) 
		{
			/*
			 * We're not even in the right ballpark.  This
			 *  test is here to deal with overflow conditions.
			 */
			return FALSE;
		}
		else if (ROUND_DIV(ABSDIF((truebaud<<1), encbaud) * 100,
				   encbaud) >= 5) 
		{
			return FALSE;
		}
		
		*truebaudp = truebaud;
		
		if (ok_enh) 
		{
			*ccr4 |= SAB82532_CCR4_EBRG;
			*ccr2 = ccr2_enh;
			*bgr = bgr_enh;
#ifdef DEBUGGING
			printk("Enhanced Baud at %ld, ccr4 = 0x%x, ccr2 = 9x%x, bgr = 0x%x\n",
			       truebaud,*ccr4,*ccr2,*bgr);
#endif
		} 
		else 
		{
			*ccr4 &= ~SAB82532_CCR4_EBRG;
			*ccr2 = ccr2_std;
			*bgr = bgr_std;
#ifdef DEBUGGING
			printk("Standard Baud at %ld, ccr4 = 0x%x, ccr2 = 9x%x, bgr = 0x%x\n",
			       truebaud,*ccr4,*ccr2,*bgr);
#endif
		}
		
		return TRUE;
	}
	else 
	{
		return FALSE;
	}
}