1995-09-04 00:59:53 +04:00
|
|
|
/* $NetBSD: adb.c,v 1.4 1995/09/03 20:59:53 briggs Exp $ */
|
1994-12-04 02:33:55 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (C) 1994 Bradley A. Grantham
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
1995-04-21 06:47:35 +04:00
|
|
|
e* notice, this list of conditions and the following disclaimer in the
|
1994-12-04 02:33:55 +03:00
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Bradley A. Grantham.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/systm.h>
|
1995-04-21 06:47:35 +04:00
|
|
|
|
1994-12-04 02:33:55 +03:00
|
|
|
#include <machine/adbsys.h>
|
|
|
|
#include <machine/keyboard.h>
|
1995-04-21 06:47:35 +04:00
|
|
|
|
|
|
|
#include "adbvar.h"
|
1994-12-04 02:33:55 +03:00
|
|
|
#include "../mac68k/macrom.h"
|
|
|
|
|
|
|
|
/*
|
1995-04-21 06:47:35 +04:00
|
|
|
* Function declarations.
|
1994-12-04 02:33:55 +03:00
|
|
|
*/
|
1995-04-21 06:47:35 +04:00
|
|
|
static void adbattach __P((struct device *parent, struct device *dev, void *aux));
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
/*
|
|
|
|
* Global variables.
|
|
|
|
*/
|
|
|
|
int adb_polling = 0; /* Are we polling? (Debugger mode) */
|
1994-12-04 02:33:55 +03:00
|
|
|
|
|
|
|
/*
|
1995-04-21 06:47:35 +04:00
|
|
|
* Local variables.
|
1994-12-04 02:33:55 +03:00
|
|
|
*/
|
1995-04-21 06:47:35 +04:00
|
|
|
|
|
|
|
/* External keyboard translation matrix */
|
|
|
|
extern unsigned char keyboard[128][3];
|
|
|
|
|
|
|
|
/* Event queue definitions */
|
1994-12-04 02:33:55 +03:00
|
|
|
#if !defined(ADB_MAX_EVENTS)
|
|
|
|
#define ADB_MAX_EVENTS 200 /* Maximum events to be kept in queue */
|
1995-04-21 06:47:35 +04:00
|
|
|
/* maybe should be higher for slower macs? */
|
|
|
|
#endif /* !defined(ADB_MAX_EVENTS) */
|
1994-12-04 02:33:55 +03:00
|
|
|
static adb_event_t adb_evq[ADB_MAX_EVENTS]; /* ADB event queue */
|
1995-04-21 06:47:35 +04:00
|
|
|
static int adb_evq_tail = 0; /* event queue tail */
|
|
|
|
static int adb_evq_len = 0; /* event queue length */
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
/* ADB device state information */
|
1994-12-04 02:33:55 +03:00
|
|
|
static int adb_isopen = 0; /* Are we queuing events for adb_read? */
|
|
|
|
static struct selinfo adb_selinfo; /* select() info */
|
|
|
|
static struct proc *adb_ioproc = NULL; /* process to wakeup */
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
/* Key repeat parameters */
|
|
|
|
static int adb_rptdelay = 20; /* ticks before auto-repeat */
|
|
|
|
static int adb_rptinterval = 6; /* ticks between auto-repeat */
|
|
|
|
static int adb_repeating = -1; /* key that is auto-repeating */
|
|
|
|
static adb_event_t adb_rptevent;/* event to auto-repeat */
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
extern int matchbyname();
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
/* Driver definition. */
|
|
|
|
struct cfdriver adbcd = {
|
|
|
|
NULL, "adb", matchbyname, adbattach, DV_DULL, sizeof(struct device),
|
|
|
|
};
|
1994-12-04 02:33:55 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
adbattach(parent, dev, aux)
|
1995-04-21 06:47:35 +04:00
|
|
|
struct device *parent, *dev;
|
|
|
|
void *aux;
|
1994-12-04 02:33:55 +03:00
|
|
|
{
|
|
|
|
printf(" (ADB event device)\n");
|
|
|
|
}
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
void
|
|
|
|
adb_enqevent(event)
|
|
|
|
adb_event_t *event;
|
1994-12-04 02:33:55 +03:00
|
|
|
{
|
1995-04-21 06:47:35 +04:00
|
|
|
int s;
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
if (adb_evq_tail < 0 || adb_evq_tail >= ADB_MAX_EVENTS)
|
1994-12-04 02:33:55 +03:00
|
|
|
panic("adb: event queue tail is out of bounds");
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
if (adb_evq_len < 0 || adb_evq_len > ADB_MAX_EVENTS)
|
1994-12-04 02:33:55 +03:00
|
|
|
panic("adb: event queue len is out of bounds");
|
|
|
|
|
|
|
|
s = splhigh();
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
if (adb_evq_len == ADB_MAX_EVENTS) {
|
1994-12-04 02:33:55 +03:00
|
|
|
splx(s);
|
1995-04-21 06:47:35 +04:00
|
|
|
return; /* Oh, well... */
|
1994-12-04 02:33:55 +03:00
|
|
|
}
|
|
|
|
adb_evq[(adb_evq_len + adb_evq_tail) % ADB_MAX_EVENTS] =
|
1995-04-21 06:47:35 +04:00
|
|
|
*event;
|
1994-12-04 02:33:55 +03:00
|
|
|
adb_evq_len++;
|
|
|
|
|
|
|
|
selwakeup(&adb_selinfo);
|
1995-04-21 06:47:35 +04:00
|
|
|
if (adb_ioproc)
|
1994-12-04 02:33:55 +03:00
|
|
|
psignal(adb_ioproc, SIGIO);
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
void
|
|
|
|
adb_handoff(event)
|
|
|
|
adb_event_t *event;
|
1994-12-04 02:33:55 +03:00
|
|
|
{
|
1995-04-21 06:47:35 +04:00
|
|
|
if (adb_isopen && !adb_polling) {
|
1994-12-04 02:33:55 +03:00
|
|
|
adb_enqevent(event);
|
1995-04-21 06:47:35 +04:00
|
|
|
} else {
|
|
|
|
if (event->def_addr == 2)
|
1994-12-04 02:33:55 +03:00
|
|
|
ite_intr(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
void
|
|
|
|
adb_autorepeat(keyp)
|
|
|
|
void *keyp;
|
1994-12-04 02:33:55 +03:00
|
|
|
{
|
1995-04-21 06:47:35 +04:00
|
|
|
int key = (int) keyp;
|
1994-12-04 02:33:55 +03:00
|
|
|
|
|
|
|
adb_rptevent.bytes[0] |= 0x80;
|
|
|
|
microtime(&adb_rptevent.timestamp);
|
|
|
|
adb_handoff(&adb_rptevent); /* do key up */
|
|
|
|
|
|
|
|
adb_rptevent.bytes[0] &= 0x7f;
|
|
|
|
microtime(&adb_rptevent.timestamp);
|
|
|
|
adb_handoff(&adb_rptevent); /* do key down */
|
1995-04-21 06:47:35 +04:00
|
|
|
|
|
|
|
if (adb_repeating == key) {
|
1994-12-04 02:33:55 +03:00
|
|
|
timeout(adb_autorepeat, keyp, adb_rptinterval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
void
|
|
|
|
adb_dokeyupdown(event)
|
|
|
|
adb_event_t *event;
|
1994-12-04 02:33:55 +03:00
|
|
|
{
|
1995-04-21 06:47:35 +04:00
|
|
|
int adb_key;
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
if (event->def_addr == 2) {
|
1994-12-04 02:33:55 +03:00
|
|
|
adb_key = event->u.k.key & 0x7f;
|
1995-04-21 06:47:35 +04:00
|
|
|
if (!(event->u.k.key & 0x80) &&
|
|
|
|
keyboard[event->u.k.key & 0x7f][0] != 0) {
|
1994-12-04 02:33:55 +03:00
|
|
|
/* ignore shift & control */
|
1995-04-21 06:47:35 +04:00
|
|
|
if (adb_repeating != -1) {
|
1994-12-04 02:33:55 +03:00
|
|
|
untimeout(adb_autorepeat,
|
1995-04-21 06:47:35 +04:00
|
|
|
(void *) adb_rptevent.u.k.key);
|
1994-12-04 02:33:55 +03:00
|
|
|
}
|
|
|
|
adb_rptevent = *event;
|
|
|
|
adb_repeating = adb_key;
|
|
|
|
timeout(adb_autorepeat,
|
1995-04-21 06:47:35 +04:00
|
|
|
(void *) adb_key, adb_rptdelay);
|
|
|
|
} else {
|
|
|
|
if (adb_repeating != -1) {
|
1994-12-04 02:33:55 +03:00
|
|
|
adb_repeating = -1;
|
|
|
|
untimeout(adb_autorepeat,
|
1995-04-21 06:47:35 +04:00
|
|
|
(void *) adb_rptevent.u.k.key);
|
1994-12-04 02:33:55 +03:00
|
|
|
}
|
|
|
|
adb_rptevent = *event;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
adb_handoff(event);
|
|
|
|
}
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
static adb_ms_buttons = 0;
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
void
|
|
|
|
adb_keymaybemouse(event)
|
|
|
|
adb_event_t *event;
|
1994-12-04 02:33:55 +03:00
|
|
|
{
|
1995-04-21 06:47:35 +04:00
|
|
|
static int optionkey_down = 0;
|
1994-12-04 02:33:55 +03:00
|
|
|
adb_event_t new_event;
|
1995-04-21 06:47:35 +04:00
|
|
|
|
|
|
|
if (event->u.k.key == ADBK_KEYDOWN(ADBK_OPTION)) {
|
1994-12-04 02:33:55 +03:00
|
|
|
optionkey_down = 1;
|
1995-04-21 06:47:35 +04:00
|
|
|
} else if (event->u.k.key == ADBK_KEYUP(ADBK_OPTION)) {
|
|
|
|
/* key up */
|
1994-12-04 02:33:55 +03:00
|
|
|
optionkey_down = 0;
|
1995-04-21 06:47:35 +04:00
|
|
|
if (adb_ms_buttons & 0xfe) {
|
1994-12-04 02:33:55 +03:00
|
|
|
adb_ms_buttons &= 1;
|
|
|
|
new_event.def_addr = ADBADDR_MS;
|
|
|
|
new_event.u.m.buttons = adb_ms_buttons;
|
|
|
|
new_event.u.m.dx = new_event.u.m.dy = 0;
|
|
|
|
microtime(&new_event.timestamp);
|
|
|
|
adb_dokeyupdown(&new_event);
|
|
|
|
}
|
1995-04-21 06:47:35 +04:00
|
|
|
} else if (optionkey_down) {
|
|
|
|
if (event->u.k.key == ADBK_KEYDOWN(ADBK_LEFT)) {
|
1994-12-04 02:33:55 +03:00
|
|
|
adb_ms_buttons |= 2; /* middle down */
|
|
|
|
new_event.def_addr = ADBADDR_MS;
|
|
|
|
new_event.u.m.buttons = adb_ms_buttons;
|
|
|
|
new_event.u.m.dx = new_event.u.m.dy = 0;
|
|
|
|
microtime(&new_event.timestamp);
|
|
|
|
adb_dokeyupdown(&new_event);
|
1995-04-21 06:47:35 +04:00
|
|
|
} else if (event->u.k.key == ADBK_KEYUP(ADBK_LEFT)) {
|
1994-12-04 02:33:55 +03:00
|
|
|
adb_ms_buttons &= ~2; /* middle up */
|
|
|
|
new_event.def_addr = ADBADDR_MS;
|
|
|
|
new_event.u.m.buttons = adb_ms_buttons;
|
|
|
|
new_event.u.m.dx = new_event.u.m.dy = 0;
|
|
|
|
microtime(&new_event.timestamp);
|
|
|
|
adb_dokeyupdown(&new_event);
|
1995-04-21 06:47:35 +04:00
|
|
|
} else if (event->u.k.key == ADBK_KEYDOWN(ADBK_RIGHT)) {
|
1994-12-04 02:33:55 +03:00
|
|
|
adb_ms_buttons |= 4; /* right down */
|
|
|
|
new_event.def_addr = ADBADDR_MS;
|
|
|
|
new_event.u.m.buttons = adb_ms_buttons;
|
|
|
|
new_event.u.m.dx = new_event.u.m.dy = 0;
|
|
|
|
microtime(&new_event.timestamp);
|
|
|
|
adb_dokeyupdown(&new_event);
|
1995-04-21 06:47:35 +04:00
|
|
|
} else if (event->u.k.key == ADBK_KEYUP(ADBK_RIGHT)) {
|
1994-12-04 02:33:55 +03:00
|
|
|
adb_ms_buttons &= ~4; /* right up */
|
|
|
|
new_event.def_addr = ADBADDR_MS;
|
|
|
|
new_event.u.m.buttons = adb_ms_buttons;
|
|
|
|
new_event.u.m.dx = new_event.u.m.dy = 0;
|
|
|
|
microtime(&new_event.timestamp);
|
|
|
|
adb_dokeyupdown(&new_event);
|
1995-04-21 06:47:35 +04:00
|
|
|
} else if (ADBK_MODIFIER(event->u.k.key)) {
|
|
|
|
/* ctrl, shift, cmd */
|
1994-12-04 02:33:55 +03:00
|
|
|
adb_dokeyupdown(event);
|
1995-06-30 05:23:21 +04:00
|
|
|
} else if (!(event->u.k.key & 0x80)) {
|
1995-04-21 06:47:35 +04:00
|
|
|
/* key down */
|
1994-12-04 02:33:55 +03:00
|
|
|
new_event = *event;
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
/* send option-down */
|
|
|
|
new_event.u.k.key = ADBK_KEYDOWN(ADBK_OPTION);
|
1994-12-04 02:33:55 +03:00
|
|
|
new_event.bytes[0] = new_event.u.k.key;
|
|
|
|
microtime(&new_event.timestamp);
|
|
|
|
adb_dokeyupdown(&new_event);
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
/* send key-down */
|
|
|
|
new_event.u.k.key = event->bytes[0];
|
1994-12-04 02:33:55 +03:00
|
|
|
new_event.bytes[0] = new_event.u.k.key;
|
|
|
|
microtime(&new_event.timestamp);
|
|
|
|
adb_dokeyupdown(&new_event);
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
/* send key-up */
|
1995-06-30 05:23:21 +04:00
|
|
|
new_event.u.k.key =
|
|
|
|
ADBK_KEYUP(ADBK_KEYVAL(event->bytes[0]));
|
1994-12-04 02:33:55 +03:00
|
|
|
microtime(&new_event.timestamp);
|
|
|
|
new_event.bytes[0] = new_event.u.k.key;
|
1995-06-30 05:23:21 +04:00
|
|
|
adb_dokeyupdown(&new_event);
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
/* send option-up */
|
1995-06-30 05:23:21 +04:00
|
|
|
new_event.u.k.key = ADBK_KEYUP(ADBK_OPTION);
|
1994-12-04 02:33:55 +03:00
|
|
|
new_event.bytes[0] = new_event.u.k.key;
|
|
|
|
microtime(&new_event.timestamp);
|
|
|
|
adb_dokeyupdown(&new_event);
|
1995-04-21 06:47:35 +04:00
|
|
|
} else {
|
|
|
|
/* option-keyup -- do nothing. */
|
1994-12-04 02:33:55 +03:00
|
|
|
}
|
1995-04-21 06:47:35 +04:00
|
|
|
} else {
|
1994-12-04 02:33:55 +03:00
|
|
|
adb_dokeyupdown(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
void
|
|
|
|
adb_processevent(event)
|
|
|
|
adb_event_t *event;
|
1994-12-04 02:33:55 +03:00
|
|
|
{
|
|
|
|
adb_event_t new_event;
|
1995-09-04 00:59:53 +04:00
|
|
|
int i, button_bit, max_byte, mask;
|
1994-12-04 02:33:55 +03:00
|
|
|
|
|
|
|
new_event = *event;
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
switch (event->def_addr) {
|
|
|
|
case ADBADDR_KBD:
|
|
|
|
new_event.u.k.key = event->bytes[0];
|
|
|
|
new_event.bytes[1] = 0xff;
|
|
|
|
adb_keymaybemouse(&new_event);
|
|
|
|
if (event->bytes[1] != 0xff) {
|
|
|
|
new_event.u.k.key = event->bytes[1];
|
|
|
|
new_event.bytes[0] = event->bytes[1];
|
1994-12-04 02:33:55 +03:00
|
|
|
new_event.bytes[1] = 0xff;
|
|
|
|
adb_keymaybemouse(&new_event);
|
1995-04-21 06:47:35 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ADBADDR_MS:
|
1995-09-04 00:59:53 +04:00
|
|
|
/*
|
|
|
|
* This should handle both plain ol' Apple mice and mice
|
|
|
|
* that claim to support the Extended Apple Mouse Protocol.
|
|
|
|
*/
|
|
|
|
max_byte = event->byte_count;
|
|
|
|
button_bit = 1;
|
|
|
|
/* Classic Mouse Protocol (up to 2 buttons) */
|
|
|
|
for (i = 0; i < 2; i++, button_bit <<= 1)
|
|
|
|
/* 0 when button down */
|
|
|
|
if (!(event->bytes[i] & 0x80))
|
|
|
|
adb_ms_buttons |= button_bit;
|
|
|
|
else
|
|
|
|
adb_ms_buttons &= ~button_bit;
|
|
|
|
/* Extended Protocol (up to 6 more buttons) */
|
|
|
|
for (mask = 0x80; i < max_byte;
|
|
|
|
i += (mask == 0x80), button_bit <<= 1) {
|
|
|
|
/* 0 when button down */
|
|
|
|
if (!(event->bytes[i] & mask))
|
|
|
|
adb_ms_buttons |= button_bit;
|
|
|
|
else
|
|
|
|
adb_ms_buttons &= ~button_bit;
|
|
|
|
mask = ((mask >> 4) & 0xf) | ((mask & 0xf) << 4);
|
|
|
|
}
|
1995-04-21 06:47:35 +04:00
|
|
|
new_event.u.m.buttons = adb_ms_buttons;
|
|
|
|
new_event.u.m.dx = ((signed int) (event->bytes[1] & 0x3f)) -
|
|
|
|
((event->bytes[1] & 0x40) ? 64 : 0);
|
|
|
|
new_event.u.m.dy = ((signed int) (event->bytes[0] & 0x3f)) -
|
|
|
|
((event->bytes[0] & 0x40) ? 64 : 0);
|
|
|
|
adb_dokeyupdown(&new_event);
|
|
|
|
break;
|
|
|
|
default: /* God only knows. */
|
|
|
|
adb_dokeyupdown(event);
|
1994-12-04 02:33:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
int
|
|
|
|
adbopen(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag, mode;
|
|
|
|
struct proc *p;
|
1994-12-04 02:33:55 +03:00
|
|
|
{
|
|
|
|
register int unit;
|
|
|
|
int error = 0;
|
|
|
|
int s;
|
1995-04-21 06:47:35 +04:00
|
|
|
|
1994-12-04 02:33:55 +03:00
|
|
|
unit = minor(dev);
|
1995-04-21 06:47:35 +04:00
|
|
|
if (unit != 0)
|
|
|
|
return (ENXIO);
|
|
|
|
|
1994-12-04 02:33:55 +03:00
|
|
|
s = splhigh();
|
1995-04-21 06:47:35 +04:00
|
|
|
if (adb_isopen) {
|
1994-12-04 02:33:55 +03:00
|
|
|
splx(s);
|
1995-04-21 06:47:35 +04:00
|
|
|
return (EBUSY);
|
1994-12-04 02:33:55 +03:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
adb_evq_tail = 0;
|
|
|
|
adb_evq_len = 0;
|
|
|
|
adb_isopen = 1;
|
|
|
|
adb_ioproc = p;
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
int
|
|
|
|
adbclose(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag, mode;
|
|
|
|
struct proc *p;
|
1994-12-04 02:33:55 +03:00
|
|
|
{
|
|
|
|
adb_isopen = 0;
|
|
|
|
adb_ioproc = NULL;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
int
|
|
|
|
adbread(dev, uio, flag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flag;
|
1994-12-04 02:33:55 +03:00
|
|
|
{
|
|
|
|
int s, error;
|
|
|
|
int willfit;
|
|
|
|
int total;
|
|
|
|
int firstmove;
|
|
|
|
int moremove;
|
|
|
|
|
|
|
|
if (uio->uio_resid < sizeof(adb_event_t))
|
|
|
|
return (EMSGSIZE); /* close enough. */
|
|
|
|
|
|
|
|
s = splhigh();
|
1995-04-21 06:47:35 +04:00
|
|
|
if (adb_evq_len == 0) {
|
|
|
|
splx(s);
|
|
|
|
return (0);
|
1994-12-04 02:33:55 +03:00
|
|
|
}
|
|
|
|
willfit = howmany(uio->uio_resid, sizeof(adb_event_t));
|
|
|
|
total = (adb_evq_len < willfit) ? adb_evq_len : willfit;
|
|
|
|
|
|
|
|
firstmove = (adb_evq_tail + total > ADB_MAX_EVENTS)
|
1995-04-21 06:47:35 +04:00
|
|
|
? (ADB_MAX_EVENTS - adb_evq_tail) : total;
|
|
|
|
|
|
|
|
error = uiomove((caddr_t) & adb_evq[adb_evq_tail],
|
|
|
|
firstmove * sizeof(adb_event_t), uio);
|
|
|
|
if (error) {
|
1994-12-04 02:33:55 +03:00
|
|
|
splx(s);
|
1995-04-21 06:47:35 +04:00
|
|
|
return (error);
|
1994-12-04 02:33:55 +03:00
|
|
|
}
|
|
|
|
moremove = total - firstmove;
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
if (moremove > 0) {
|
|
|
|
error = uiomove((caddr_t) & adb_evq[0],
|
|
|
|
moremove * sizeof(adb_event_t), uio);
|
|
|
|
if (error) {
|
1994-12-04 02:33:55 +03:00
|
|
|
splx(s);
|
1995-04-21 06:47:35 +04:00
|
|
|
return (error);
|
1994-12-04 02:33:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
adb_evq_tail = (adb_evq_tail + total) % ADB_MAX_EVENTS;
|
|
|
|
adb_evq_len -= total;
|
|
|
|
splx(s);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
adbwrite(dev, uio, flag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int flag;
|
1994-12-04 02:33:55 +03:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
int
|
|
|
|
adbioctl(dev, cmd, data, flag, p)
|
|
|
|
dev_t dev;
|
|
|
|
int cmd;
|
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
|
|
|
struct proc *p;
|
1994-12-04 02:33:55 +03:00
|
|
|
{
|
1995-04-21 06:47:35 +04:00
|
|
|
switch (cmd) {
|
|
|
|
case ADBIOC_DEVSINFO: {
|
|
|
|
adb_devinfo_t *di;
|
|
|
|
ADBDataBlock adbdata;
|
|
|
|
int totaldevs;
|
|
|
|
int adbaddr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
di = (void *) data;
|
|
|
|
|
|
|
|
/* Initialize to no devices */
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
di->dev[i].addr = -1;
|
|
|
|
|
|
|
|
totaldevs = CountADBs();
|
|
|
|
for (i = 1; i <= totaldevs; i++) {
|
|
|
|
adbaddr = GetIndADB(&adbdata, i);
|
|
|
|
di->dev[adbaddr].addr = adbaddr;
|
|
|
|
di->dev[adbaddr].default_addr = adbdata.origADBAddr;
|
|
|
|
di->dev[adbaddr].handler_id = adbdata.devType;
|
1994-12-04 02:33:55 +03:00
|
|
|
}
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
/* Must call ADB Manager to get devices now */
|
|
|
|
break;
|
|
|
|
}
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
case ADBIOC_GETREPEAT:{
|
|
|
|
adb_rptinfo_t *ri;
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
ri = (void *) data;
|
|
|
|
ri->delay_ticks = adb_rptdelay;
|
|
|
|
ri->interval_ticks = adb_rptinterval;
|
|
|
|
break;
|
|
|
|
}
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
case ADBIOC_SETREPEAT:{
|
|
|
|
adb_rptinfo_t *ri;
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
ri = (void *) data;
|
|
|
|
adb_rptdelay = ri->delay_ticks;
|
|
|
|
adb_rptinterval = ri->interval_ticks;
|
|
|
|
break;
|
|
|
|
}
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
case ADBIOC_RESET:
|
|
|
|
adb_init();
|
|
|
|
break;
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
case ADBIOC_LISTENCMD:{
|
|
|
|
adb_listencmd_t *lc;
|
1994-12-04 02:33:55 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
lc = (void *) data;
|
1994-12-04 02:33:55 +03:00
|
|
|
}
|
1995-04-21 06:47:35 +04:00
|
|
|
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
return (0);
|
1994-12-04 02:33:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
int
|
|
|
|
adbselect(dev, rw, p)
|
|
|
|
dev_t dev;
|
|
|
|
int rw;
|
|
|
|
struct proc *p;
|
1994-12-04 02:33:55 +03:00
|
|
|
{
|
|
|
|
switch (rw) {
|
1995-04-21 06:47:35 +04:00
|
|
|
case FREAD:
|
|
|
|
/* succeed if there is something to read */
|
|
|
|
if (adb_evq_len > 0)
|
|
|
|
return (1);
|
|
|
|
selrecord(p, &adb_selinfo);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FWRITE:
|
|
|
|
return (1); /* always fails => never blocks */
|
|
|
|
break;
|
1994-12-04 02:33:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|