This source file includes following definitions.
- atari_joystick_interrupt
- release_joystick
- open_joystick
- write_joystick
- read_joystick
- joystick_select
- atari_joystick_init
1
2
3
4
5
6
7
8
9
10 #include <linux/sched.h>
11 #include <linux/errno.h>
12 #include <linux/major.h>
13
14 #include <asm/atarikb.h>
15 #include <asm/atari_joystick.h>
16 #include <asm/atari_mouse.h>
17 #include <asm/segment.h>
18
19 #define MAJOR_NR JOYSTICK_MAJOR
20
21 #define ANALOG_JOY(n) (!(n & 0x80))
22 #define DIGITAL_JOY(n) (n & 0x80)
23 #define DEVICE_NR(n) (MINOR(n) & 0x7f)
24
25
26 static struct joystick_status joystick[2];
27 int atari_mouse_buttons;
28
29 void atari_joystick_interrupt(char *buf)
30 {
31 int j;
32
33
34 j = buf[0] & 0x1;
35 joystick[j].dir = buf[1] & 0xF;
36 joystick[j].fire = (buf[1] & 0x80) >> 7;
37 joystick[j].ready = 1;
38 wake_up_interruptible(&joystick[j].wait);
39
40
41 if (atari_mouse_interrupt_hook &&
42 j == 1 && (buf[1] & 1) != ((atari_mouse_buttons & 2) >> 1))
43 {
44 char faked_packet[3];
45
46 atari_mouse_buttons = (atari_mouse_buttons & 5) | ((buf[1] & 1) << 1);
47 faked_packet[0] = (atari_mouse_buttons & 1) |
48 (atari_mouse_buttons & 4 ? 2 : 0);
49 faked_packet[1] = 0;
50 faked_packet[2] = 0;
51 atari_mouse_interrupt_hook (faked_packet);
52 }
53
54
55 }
56
57 static void release_joystick(struct inode *inode, struct file *file)
58 {
59 int minor = DEVICE_NR(inode->i_rdev);
60
61 joystick[minor].active = 0;
62 joystick[minor].ready = 0;
63
64 if ((joystick[0].active == 0) && (joystick[1].active == 0))
65 ikbd_joystick_disable();
66 }
67
68 static int open_joystick(struct inode *inode, struct file *file)
69 {
70 int minor = DEVICE_NR(inode->i_rdev);
71
72 if (!DIGITAL_JOY(inode->i_rdev) || minor > 1)
73 return -ENODEV;
74 if (joystick[minor].active)
75 return -EBUSY;
76 joystick[minor].active = 1;
77 joystick[minor].ready = 0;
78 ikbd_joystick_event_on();
79 return 0;
80 }
81
82 static int write_joystick(struct inode *inode, struct file *file,
83 const char *buffer, int count)
84 {
85 return -EINVAL;
86 }
87
88 static int read_joystick(struct inode *inode, struct file *file,
89 char *buffer, int count)
90 {
91 int minor = DEVICE_NR(inode->i_rdev);
92 int i;
93
94 if (count < 2)
95 return -EINVAL;
96 if (!joystick[minor].ready)
97 return -EAGAIN;
98 put_user(joystick[minor].fire, buffer++);
99 put_user(joystick[minor].dir, buffer++);
100 for (i = 0; i < count; i++)
101 put_user(0, buffer++);
102 joystick[minor].ready = 0;
103
104 return i;
105 }
106
107 static int joystick_select(struct inode *inode, struct file *file, int sel_type, select_table *wait)
108 {
109 int minor = DEVICE_NR(inode->i_rdev);
110
111 if (sel_type != SEL_IN)
112 return 0;
113 if (joystick[minor].ready)
114 return 1;
115 select_wait(&joystick[minor].wait, wait);
116 return 0;
117 }
118
119 struct file_operations atari_joystick_fops = {
120 NULL,
121 read_joystick,
122 write_joystick,
123 NULL,
124 joystick_select,
125 NULL,
126 NULL,
127 open_joystick,
128 release_joystick
129 };
130
131 int atari_joystick_init(void)
132 {
133 joystick[0].active = joystick[1].active = 0;
134 joystick[0].ready = joystick[1].ready = 0;
135 joystick[0].wait = joystick[1].wait = NULL;
136
137 if (register_chrdev(MAJOR_NR, "joystick", &atari_joystick_fops))
138 printk("unable to get major %d for joystick devices\n", MAJOR_NR);
139
140 return 0;
141 }