x68kIo.c revision ba64b02e
1/* $NetBSD: x68kIo.c,v 1.1 2014/03/01 19:34:47 tsutsui Exp $ */ 2/*------------------------------------------------------------------------- 3 * Copyright (c) 1996 Yasushi Yamasaki 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Yasushi Yamasaki 17 * 4. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 *-----------------------------------------------------------------------*/ 31 32/*- 33 * 34 * Copyright (c) 1987 by the Regents of the University of California 35 * 36 * Permission to use, copy, modify, and distribute this 37 * software and its documentation for any purpose and without 38 * fee is hereby granted, provided that the above copyright 39 * notice appear in all copies. The University of California 40 * makes no representations about the suitability of this 41 * software for any purpose. It is provided "as is" without 42 * express or implied warranty. 43 * 44 * 45 */ 46 47/************************************************************ 48Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA. 49 50 All Rights Reserved 51 52Permission to use, copy, modify, and distribute this 53software and its documentation for any purpose and without 54fee is hereby granted, provided that the above copyright no- 55tice appear in all copies and that both that copyright no- 56tice and this permission notice appear in supporting docu- 57mentation, and that the names of Sun or X Consortium 58not be used in advertising or publicity pertaining to 59distribution of the software without specific prior 60written permission. Sun and X Consortium make no 61representations about the suitability of this software for 62any purpose. It is provided "as is" without any express or 63implied warranty. 64 65SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 66INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- 67NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI- 68ABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 69ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 70PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 71OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH 72THE USE OR PERFORMANCE OF THIS SOFTWARE. 73 74********************************************************/ 75 76#include "x68k.h" 77#include "mi.h" 78 79static void x68kEnqueueEvents(void); 80 81/*-------------------------------------------------------------------- 82 * function "x68kSigIOHandler" 83 * 84 * purpose: handles signals from input devices. 85 * enqueue inputs into mi event queue 86 * argument: (int)sig 87 * returns: nothing 88 *------------------------------------------------------------------*/ 89void 90x68kSigIOHandler(int sig) 91{ 92 int olderrno = errno; 93 94 x68kEnqueueEvents(); 95 errno = olderrno; 96} 97 98/*-------------------------------------------------------------------- 99 * ProcessInputEvents -- 100 * Retrieve all waiting input events and pass them to DIX in their 101 * correct chronological order. Only reads from the system pointer 102 * and keyboard. 103 * 104 * Results: 105 * None. 106 * 107 * Side Effects: 108 * Events are passed to the DIX layer. 109 * 110 *-----------------------------------------------------------------*/ 111void 112ProcessInputEvents(void) 113{ 114 (void) mieqProcessInputEvents (); 115} 116 117/*-------------------------------------------------------------------- 118 * x68kEnqueueEvents 119 * When a SIGIO is received, read device hard events and 120 * enqueue them using the mi event queue 121 */ 122 123static void 124x68kEnqueueEvents(void) 125{ 126 Firm_event *ptrEvents, /* Current pointer event */ 127 *kbdEvents; /* Current keyboard event */ 128 int numPtrEvents, /* Number of remaining pointer events */ 129 numKbdEvents; /* Number of remaining keyboard events */ 130 int nPE, /* Original number of pointer events */ 131 nKE; /* Original number of keyboard events */ 132 Bool PtrAgain, /* need to (re)read */ 133 KbdAgain; /* need to (re)read */ 134 DeviceIntPtr pPointer; 135 DeviceIntPtr pKeyboard; 136 X68kKbdPrivPtr kbdPriv; 137 X68kMousePrivPtr ptrPriv; 138 139 pPointer = x68kPointerDevice; 140 pKeyboard = x68kKeyboardDevice; 141 ptrPriv = (X68kMousePrivPtr) pPointer->public.devicePrivate; 142 kbdPriv = (X68kKbdPrivPtr) pKeyboard->public.devicePrivate; 143 if (!pPointer->public.on || !pKeyboard->public.on) 144 return; 145 146 numPtrEvents = 0; 147 PtrAgain = TRUE; 148 numKbdEvents = 0; 149 KbdAgain = TRUE; 150 ptrEvents = NULL; /* XXX gcc */ 151 kbdEvents = NULL; /* XXX gcc */ 152 153 /* 154 * So long as one event from either device remains unprocess, we loop: 155 * Take the oldest remaining event and pass it to the proper module 156 * for processing. The DDXEvent will be sent to ProcessInput by the 157 * function called. 158 */ 159 while (1) { 160 /* 161 * Get events from both the pointer and the keyboard, storing the number 162 * of events gotten in nPE and nKE and keeping the start of both arrays 163 * in pE and kE 164 */ 165 if ((numPtrEvents == 0) && PtrAgain) { 166 ptrEvents = x68kMouseGetEvents (ptrPriv->fd, &nPE, &PtrAgain); 167 numPtrEvents = nPE; 168 } 169 if ((numKbdEvents == 0) && KbdAgain) { 170 kbdEvents = x68kKbdGetEvents (kbdPriv->fd, &nKE, &KbdAgain); 171 numKbdEvents = nKE; 172 } 173 if ((numPtrEvents == 0) && (numKbdEvents == 0)) 174 break; 175 if (numPtrEvents && numKbdEvents) { 176 if (timercmp (&kbdEvents->time, &ptrEvents->time, <)) { 177 x68kKbdEnqueueEvent (pKeyboard, kbdEvents); 178 numKbdEvents--; 179 kbdEvents++; 180 } else { 181 x68kMouseEnqueueEvent (pPointer, ptrEvents); 182 numPtrEvents--; 183 ptrEvents++; 184 } 185 } else if (numKbdEvents) { 186 x68kKbdEnqueueEvent (pKeyboard, kbdEvents); 187 numKbdEvents--; 188 kbdEvents++; 189 } else { 190 x68kMouseEnqueueEvent (pPointer, ptrEvents); 191 numPtrEvents--; 192 ptrEvents++; 193 } 194 } 195} 196 197/* EOF x68kIo.c */ 198