xref: /haiku/src/add-ons/kernel/drivers/audio/emuxki/joy.c (revision c9060eb991e10e477ece52478d6743fc7691c143)
1 /*
2  * Copyright 2008 Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Alexander Coers		Alexander.Coers@gmx.de
7  *		Fredrik Modéen 		fredrik@modeen.se
8  */
9 
10 #include "emuxki.h"
11 #include "debug.h"
12 
13 #if !defined(_KERNEL_EXPORT_H)
14 #include <KernelExport.h>
15 #endif /* _KERNEL_EXPORT_H */
16 
17 static status_t joy_open(const char *name, uint32 flags, void **cookie);
18 static status_t joy_close(void *cookie);
19 static status_t joy_free(void *cookie);
20 static status_t joy_control(void *cookie, uint32 op, void *data, size_t len);
21 static status_t joy_read(void *cookie, off_t pos, void *data, size_t *len);
22 static status_t joy_write(void *cookie, off_t pos, const void *data, size_t *len);
23 
24 #define MIN_COMP -7
25 #define MAX_COMP 8
26 
27 device_hooks joy_hooks = {
28     &joy_open,
29     &joy_close,
30     &joy_free,
31     &joy_control,
32     &joy_read,
33     &joy_write,
34     NULL,		/* select */
35     NULL,		/* deselect */
36     NULL,		/* readv */
37     NULL		/* writev */
38 };
39 
40 
41 static status_t
42 joy_open(const char * name, uint32 flags, void ** cookie)
43 {
44 	int ix;
45 	int offset = -1;
46 
47 	LOG(("GamePort: joy_open()\n"));
48 
49 	*cookie = NULL;
50 	for (ix = 0; ix < num_cards; ix++) {
51 		if (!strcmp(name, cards[ix].joy.name1)) {
52 			offset = 0;
53 			break;
54 		}
55 	}
56 	if (offset < 0) {
57 		return ENODEV;
58 	}
59 	return (*gameport->open_hook)(cards[ix].joy.driver, flags, cookie);
60 }
61 
62 
63 static status_t
64 joy_close(void * cookie)
65 {
66 	return (*gameport->close_hook)(cookie);
67 }
68 
69 
70 static status_t
71 joy_free(void * cookie)
72 {
73 	return (*gameport->free_hook)(cookie);
74 }
75 
76 
77 static status_t
78 joy_control(void * cookie, uint32 iop, void * data, size_t len)
79 {
80 	return (*gameport->control_hook)(cookie, iop, data, len);
81 }
82 
83 
84 static status_t
85 joy_read(void * cookie, off_t pos, void * data, size_t * nread)
86 {
87 	return (*gameport->read_hook)(cookie, pos, data, nread);
88 }
89 
90 
91 static status_t
92 joy_write(void * cookie, off_t pos, const void * data, size_t * nwritten)
93 {
94 	return (*gameport->write_hook)(cookie, pos, data, nwritten);
95 }
96