1 /*
2  * (C) Gražvydas "notaz" Ignotas, 2011
3  *
4  * This work is licensed under the terms of any of these licenses
5  * (at your option):
6  *  - GNU GPL, version 2 or later.
7  *  - GNU LGPL, version 2.1 or later.
8  * See the COPYING file in the top-level directory.
9  */
10 
11 #ifndef _WIN32
12 #define CALLBACK
13 #else
14 #define WIN32_LEAN_AND_MEAN
15 #include <windows.h>
16 #endif
17 
18 #include "main.h"
19 
20 unsigned char CurPad, CurByte, CurCmd, CmdLen;
21 
22 /* since this is not a proper plugin, so we'll hook emu internals in a hackish way like this */
23 extern void *PAD1_startPoll, *PAD1_poll;
24 extern void *PAD2_startPoll, *PAD2_poll;
25 extern unsigned char CALLBACK PAD1__startPoll(int pad);
26 extern unsigned char CALLBACK PAD2__startPoll(int pad);
27 extern unsigned char CALLBACK PAD1__poll(unsigned char value);
28 extern unsigned char CALLBACK PAD2__poll(unsigned char value);
29 
30 #ifndef HAVE_LIBRETRO
31 
32 static int old_controller_type1 = -1, old_controller_type2 = -1;
33 
34 #define select_pad(n) \
35 	if (pad.controllerType != old_controller_type##n) \
36 	{ \
37 		switch (pad.controllerType) \
38 		{ \
39 		case PSE_PAD_TYPE_ANALOGPAD: \
40 			PAD##n##_startPoll = PADstartPoll_pad; \
41 			PAD##n##_poll = PADpoll_pad; \
42 			pad_init(); \
43 			break; \
44 		case PSE_PAD_TYPE_GUNCON: \
45 			/* Removed for new Guncon functionality, may have been required for very old touchscreen support */ \
46 			/* PAD##n##_startPoll = PADstartPoll_guncon; */ \
47 			/* PAD##n##_poll = PADpoll_guncon; */ \
48 			/* guncon_init(); */ \
49 			/* break; */ \
50 		case PSE_PAD_TYPE_NEGCON: \
51 		case PSE_PAD_TYPE_GUN: \
52 		default: \
53 			PAD##n##_startPoll = PAD##n##__startPoll; \
54 			PAD##n##_poll = PAD##n##__poll; \
55 			break; \
56 		} \
57 	}
58 #endif /* HAVE_LIBRETRO */
59 
60 
dfinput_activate(void)61 void dfinput_activate(void)
62 {
63 	#ifndef HAVE_LIBRETRO
64 	PadDataS pad;
65 
66 	pad.portMultitap = -1;
67 	pad.requestPadIndex = 0;
68 	PAD1_readPort1(&pad);
69 	select_pad(1);
70 
71 	pad.requestPadIndex = 1;
72 	PAD2_readPort2(&pad);
73 	select_pad(2);
74 	#endif
75 }
76