aboutsummaryrefslogtreecommitdiff
path: root/plugins/dfinput/main.c
blob: 4204b86ff19c77f0f5e40f6dd2cebc70b0260ac1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * (C) Gražvydas "notaz" Ignotas, 2011
 *
 * This work is licensed under the terms of any of these licenses
 * (at your option):
 *  - GNU GPL, version 2 or later.
 *  - GNU LGPL, version 2.1 or later.
 * See the COPYING file in the top-level directory.
 */

#ifndef _WIN32
#define CALLBACK
#else
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif

#include "main.h"

unsigned char CurPad, CurByte, CurCmd, CmdLen;

/* since this is not a proper plugin, so we'll hook emu internals in a hackish way like this */
extern void *PAD1_startPoll, *PAD1_poll;
extern void *PAD2_startPoll, *PAD2_poll;
extern unsigned char CALLBACK PAD1__startPoll(int pad);
extern unsigned char CALLBACK PAD2__startPoll(int pad);
extern unsigned char CALLBACK PAD1__poll(unsigned char value);
extern unsigned char CALLBACK PAD2__poll(unsigned char value);

static int old_controller_type1 = -1, old_controller_type2 = -1;

#define select_pad(n) \
	if (pad.controllerType != old_controller_type##n) \
	{ \
		switch (pad.controllerType) \
		{ \
		case PSE_PAD_TYPE_ANALOGPAD: \
			PAD##n##_startPoll = PADstartPoll_pad; \
			PAD##n##_poll = PADpoll_pad; \
			pad_init(); \
			break; \
		case PSE_PAD_TYPE_GUNCON: \
			PAD##n##_startPoll = PADstartPoll_guncon; \
			PAD##n##_poll = PADpoll_guncon; \
			guncon_init(); \
			break; \
                case PSE_PAD_TYPE_NEGCON: \
		case PSE_PAD_TYPE_GUN: \
		default: \
			PAD##n##_startPoll = PAD##n##__startPoll; \
			PAD##n##_poll = PAD##n##__poll; \
			break; \
		} \
	}


void dfinput_activate(void)
{
	#ifndef HAVE_LIBRETRO
	PadDataS pad;

	pad.portMultitap = -1;
	pad.requestPadIndex = 0;
	PAD1_readPort1(&pad);
	select_pad(1);

	pad.requestPadIndex = 1;
	PAD2_readPort2(&pad);
	select_pad(2);
	#endif
}