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 17static status_t joy_open(const char *name, uint32 flags, void **cookie); 18static status_t joy_close(void *cookie); 19static status_t joy_free(void *cookie); 20static status_t joy_control(void *cookie, uint32 op, void *data, size_t len); 21static status_t joy_read(void *cookie, off_t pos, void *data, size_t *len); 22static 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 27device_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 41static status_t 42joy_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 63static status_t 64joy_close(void * cookie) 65{ 66 return (*gameport->close_hook)(cookie); 67} 68 69 70static status_t 71joy_free(void * cookie) 72{ 73 return (*gameport->free_hook)(cookie); 74} 75 76 77static status_t 78joy_control(void * cookie, uint32 iop, void * data, size_t len) 79{ 80 return (*gameport->control_hook)(cookie, iop, data, len); 81} 82 83 84static status_t 85joy_read(void * cookie, off_t pos, void * data, size_t * nread) 86{ 87 return (*gameport->read_hook)(cookie, pos, data, nread); 88} 89 90 91static status_t 92joy_write(void * cookie, off_t pos, const void * data, size_t * nwritten) 93{ 94 return (*gameport->write_hook)(cookie, pos, data, nwritten); 95} 96