x68kIo.c revision 1406604b
1/* $NetBSD: x68kIo.c,v 1.4 2025/06/17 15:53:57 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; 88 89 input_lock(); 90 olderrno = errno; 91 x68kEnqueueEvents(); 92 errno = olderrno; 93 input_unlock(); 94} 95 96/*-------------------------------------------------------------------- 97 * ProcessInputEvents -- 98 * Retrieve all waiting input events and pass them to DIX in their 99 * correct chronological order. Only reads from the system pointer 100 * and keyboard. 101 * 102 * Results: 103 * None. 104 * 105 * Side Effects: 106 * Events are passed to the DIX layer. 107 * 108 *-----------------------------------------------------------------*/ 109void 110ProcessInputEvents(void) 111{ 112 (void) mieqProcessInputEvents (); 113} 114 115/*-------------------------------------------------------------------- 116 * x68kEnqueueEvents 117 * When a SIGIO is received, read device hard events and 118 * enqueue them using the mi event queue 119 */ 120 121static void 122x68kEnqueueEvents(void) 123{ 124 Firm_event *ptrEvents, /* Current pointer event */ 125 *kbdEvents; /* Current keyboard event */ 126 int numPtrEvents, /* Number of remaining pointer events */ 127 numKbdEvents; /* Number of remaining keyboard events */ 128 int nPE, /* Original number of pointer events */ 129 nKE; /* Original number of keyboard events */ 130 Bool PtrAgain, /* need to (re)read */ 131 KbdAgain; /* need to (re)read */ 132 DeviceIntPtr pPointer; 133 DeviceIntPtr pKeyboard; 134 X68kKbdPrivPtr kbdPriv; 135 X68kMousePrivPtr ptrPriv; 136 137 pPointer = x68kPointerDevice; 138 pKeyboard = x68kKeyboardDevice; 139 ptrPriv = (X68kMousePrivPtr) pPointer->public.devicePrivate; 140 kbdPriv = (X68kKbdPrivPtr) pKeyboard->public.devicePrivate; 141 if (!pPointer->public.on || !pKeyboard->public.on) 142 return; 143 144 numPtrEvents = 0; 145 PtrAgain = TRUE; 146 numKbdEvents = 0; 147 KbdAgain = TRUE; 148 ptrEvents = NULL; /* XXX gcc */ 149 kbdEvents = NULL; /* XXX gcc */ 150 151 /* 152 * So long as one event from either device remains unprocess, we loop: 153 * Take the oldest remaining event and pass it to the proper module 154 * for processing. The DDXEvent will be sent to ProcessInput by the 155 * function called. 156 */ 157 while (1) { 158 /* 159 * Get events from both the pointer and the keyboard, storing the number 160 * of events gotten in nPE and nKE and keeping the start of both arrays 161 * in pE and kE 162 */ 163 if ((numPtrEvents == 0) && PtrAgain) { 164 ptrEvents = x68kMouseGetEvents (ptrPriv->fd, &nPE, &PtrAgain); 165 numPtrEvents = nPE; 166 } 167 if ((numKbdEvents == 0) && KbdAgain) { 168 kbdEvents = x68kKbdGetEvents (kbdPriv->fd, &nKE, &KbdAgain); 169 numKbdEvents = nKE; 170 } 171 if ((numPtrEvents == 0) && (numKbdEvents == 0)) 172 break; 173 if (numPtrEvents && numKbdEvents) { 174 if (timercmp (&kbdEvents->time, &ptrEvents->time, <)) { 175 x68kKbdEnqueueEvent (pKeyboard, kbdEvents); 176 numKbdEvents--; 177 kbdEvents++; 178 } else { 179 x68kMouseEnqueueEvent (pPointer, ptrEvents); 180 numPtrEvents--; 181 ptrEvents++; 182 } 183 } else if (numKbdEvents) { 184 x68kKbdEnqueueEvent (pKeyboard, kbdEvents); 185 numKbdEvents--; 186 kbdEvents++; 187 } else { 188 x68kMouseEnqueueEvent (pPointer, ptrEvents); 189 numPtrEvents--; 190 ptrEvents++; 191 } 192 } 193} 194 195/* EOF x68kIo.c */ 196