1 /*
2  * joystick.h - Common joystick emulation.
3  *
4  * Written by
5  *  Andreas Boose <viceteam@t-online.de>
6  *  Marco van den Heuvel <blackystardust68@yahoo.com>
7  *
8  * This file is part of VICE, the Versatile Commodore Emulator.
9  * See README for copyright notice.
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24  *  02111-1307  USA.
25  *
26  */
27 
28 #ifndef VICE_JOYSTICK_H
29 #define VICE_JOYSTICK_H
30 
31 #include "types.h"
32 
33 extern int joystick_init(void);
34 extern int joystick_resources_init(void);
35 extern int joystick_cmdline_options_init(void);
36 
37 /* These joy_arch_* functions need to be defined in every port. */
38 extern int joy_arch_init(void);
39 extern int joy_arch_resources_init(void);
40 extern int joy_arch_cmdline_options_init(void);
41 extern int joy_arch_set_device(int port_idx, int new_dev);
42 
43 extern int joystick_check_set(signed long key, int keysetnum, unsigned int joyport);
44 extern int joystick_check_clr(signed long key, int keysetnum, unsigned int joyport);
45 extern void joystick_joypad_clear(void);
46 
47 extern void joystick_set_value_absolute(unsigned int joyport, uint8_t value);
48 extern void joystick_set_value_or(unsigned int joyport, uint8_t value);
49 extern void joystick_set_value_and(unsigned int joyport, uint8_t value);
50 extern void joystick_clear(unsigned int joyport);
51 extern void joystick_clear_all(void);
52 
53 extern void joystick_event_playback(CLOCK offset, void *data);
54 extern void joystick_event_delayed_playback(void *data);
55 extern void joystick_register_delay(unsigned int delay);
56 
57 extern uint8_t get_joystick_value(int index);
58 
59 typedef void (*joystick_machine_func_t)(void);
60 extern void joystick_register_machine(joystick_machine_func_t func);
61 
62 /*! the number of joysticks that can be attached to the emu */
63 #define JOYSTICK_NUM 5
64 
65 /* the values used internally to represent joystick state
66 FIXME: this is only an extern because of
67 src/c64dtv/c64dtvcia1.c and
68 src/c64dtv/hummeradc.c */
69 extern uint8_t joystick_value[JOYSTICK_NUM + 1];
70 
71 /* the mapping of real devices to emulated joystick ports */
72 extern int joystick_port_map[JOYSTICK_NUM];
73 
74 #if (!defined(__OS2__) || defined(USE_SDLUI) || defined(USE_SDLUI2)) && !defined(__LIBRETRO__)
75 #define COMMON_JOYKEYS
76 
77 #define JOYSTICK_KEYSET_NUM 3
78 #define JOYSTICK_KEYSET_NUM_KEYS 9
79 #define JOYSTICK_KEYSET_IDX_NUMBLOCK 0
80 #define JOYSTICK_KEYSET_IDX_A 1
81 #define JOYSTICK_KEYSET_IDX_B 2
82 extern int joykeys[JOYSTICK_KEYSET_NUM][JOYSTICK_KEYSET_NUM_KEYS];
83 
84 /* several things depend on the order/exact values of the members in this enum,
85  * DO NOT CHANGE!
86  */
87 typedef enum {
88     JOYSTICK_KEYSET_FIRE,
89     JOYSTICK_KEYSET_SW,
90     JOYSTICK_KEYSET_S,
91     JOYSTICK_KEYSET_SE,
92     JOYSTICK_KEYSET_W,
93     JOYSTICK_KEYSET_E,
94     JOYSTICK_KEYSET_NW,
95     JOYSTICK_KEYSET_N,
96     JOYSTICK_KEYSET_NE
97 } joystick_direction_t;
98 #endif
99 
100 #endif
101