14
15
#include <unistd.h>
18
#include <linux/adb.h>
19
#include <linux/cuda.h>
18
21
int fd; /* put this here where everybody can see it. Hey, it's not so */
19
22
/* much a global as it is an "object variable," where this */
20
23
/* program is the object. Yeah, that's it! Ahem. */
22
static void setmouse( int );
23
static int showmouse( void );
24
static void send( char *, int );
25
static void listen( char * );
27
int main(int argc, char **argv)
31
fd = open("/dev/adb", O_RDWR);
33
perror("opening /dev/adb");
39
if ((argc == 2 && (mode <= 0 || mode >= 0x0fd)) || argc >= 3) {
40
(void) printf("usage: mousemode [n]\n");
41
(void) printf(" Configures mouse at ADB address 3 to use handler ID n.\n");
42
(void) printf(" If n is omitted, prints value of current handler ID.\n");
51
(void) printf("%d\n", showmouse());
57
static void setmouse(int mode)
61
/* curious parties should read Inside Mac/Devices/ADB Manager, */
62
/* looking at page 5-11. Inside Mac is available as pdf files */
63
/* from Apple's site. */
65
/* CUDA device 0? (the clock seems to be at 1) */
67
/* mouse (0x30) listen (0x08) reg 3 (0x03) */
69
/* service request enable (0x20), device addr 3 (0x03) */
71
/* device handler ID == mode */
78
static int showmouse()
82
y[0]=(char) 0x000; /* Cuda device 0 */
83
y[1]=(char) 0x03f; /* mouse talk reg 3 */
88
/* make sure reply is from: */
89
if (y[0] == (char) 0 /* cuda device 0 */
90
&& y[1] == (char) 0 /* no status/error bits (I'm guessing) */
91
&& y[2] == (char) 0x03f) { /* mouse talk reg 3 */
92
/* skip 1st byte of reg 3, and return handler ID */
99
static void send(char *y, int len)
103
n = (int) write(fd, y, (size_t) len);
105
perror("writing /dev/adb");
111
static void listen(char *y)
116
n = (int) read(fd, y, (size_t) 80);
120
perror("reading /dev/adb");
27
send(unsigned char *y, int len)
33
for (n=0; n < len; n++)
34
printf("0x%02x ",y[n]);
38
n = write(fd, y, (size_t) len);
40
perror("writing /dev/adb");
47
listen(unsigned char *y)
57
printf("0x%02x ",y[i]);
62
perror("reading /dev/adb");
69
setmouse(int addr, int mode)
73
/* curious parties should read Inside Mac/Devices/ADB Manager, */
74
/* looking at page 5-11. Inside Mac is available as pdf files */
75
/* from Apple's site. */
77
/* CUDA device 0? (the clock seems to be at 1) */
79
/* mouse (0x30) listen (0x08) reg 3 (0x03) */
80
y[1] = ADB_WRITEREG(addr, 3);
81
/* service request enable (0x20), device addr 3 (0x03) */
84
/* device handler ID == mode */
97
y[1] = ADB_READREG(addr, 3);
102
/* make sure reply is from: */
103
if (y[0] == ADB_READREG(addr, 3)) {
111
main(int argc, char **argv)
115
// argc==2: 'mousemode <addr>'
116
// argc==3: 'mousemode <addr> <handler>'
117
if (argc < 2 || argc > 3) {
118
printf("usage: mousemode <addr> [<handler>]\n");
119
printf(" Configures mouse at ADB address <addr> to use <handler>\n");
120
printf(" without <handler>, print value of current handler\n");
124
fd = open("/dev/adb", O_RDWR);
126
perror("opening /dev/adb");
130
addr = atoi(argv[1]);
132
mode = atoi(argv[2]);
133
printf("handler for addr %d was %d\n", addr, showmouse(addr));
134
printf("trying to set handler to %d...\n", mode);
135
setmouse(addr, mode);
136
printf("handler is now %d\n", showmouse(addr));
138
printf("handler for addr %d is %d\n", addr, showmouse(addr));