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