summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/machine/pc_joy.h
blob: 8247bdfd87a11b0f5d6eebab350cf0fd9a8d334d (plain) (blame)
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
72
73
74
75
76
/*************************************************************************
 *
 *      pc_joy.h
 *
 *      joystick port
 *
 *************************************************************************/

#ifndef PC_JOY_H
#define PC_JOY_H

#include "emu.h"

#define MCFG_PC_JOY_ADD(_tag) \
	MCFG_DEVICE_ADD(_tag, PC_JOY, 0) \
	MCFG_DEVICE_SLOT_INTERFACE(pc_joysticks, "basic_joy", false)

SLOT_INTERFACE_EXTERN(pc_joysticks);

class device_pc_joy_interface: public device_slot_card_interface
{
public:
	device_pc_joy_interface(const machine_config &mconfig, device_t &device);
	virtual ~device_pc_joy_interface();

	virtual UINT8 x1(int delta) { return 0; }
	virtual UINT8 x2(int delta) { return 0; }
	virtual UINT8 y1(int delta) { return 0; }
	virtual UINT8 y2(int delta) { return 0; }
	virtual UINT8 btn() { return 0xf; }
	virtual void port_write() { }
};

class pc_joy_device :  public device_t,
							public device_slot_interface
{
public:
	pc_joy_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);

	DECLARE_READ8_MEMBER(joy_port_r);
	DECLARE_WRITE8_MEMBER(joy_port_w);
protected:
	virtual void device_start() { m_stime = machine().time(); }
	virtual void device_config_complete();
private:
	attotime m_stime;
	device_pc_joy_interface *m_dev;
};

extern const device_type PC_JOY;

class pc_basic_joy_device : public device_t,
							public device_pc_joy_interface
{
public:
	pc_basic_joy_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
	virtual ioport_constructor device_input_ports() const;

	virtual UINT8 x1(int delta) { return (m_x1->read() > delta); }
	virtual UINT8 x2(int delta) { return (m_x2->read() > delta); }
	virtual UINT8 y1(int delta) { return (m_y1->read() > delta); }
	virtual UINT8 y2(int delta) { return (m_y2->read() > delta); }
	virtual UINT8 btn() { return m_btn->read(); }

protected:
	virtual void device_start() {}

private:
	required_ioport m_btn;
	required_ioport m_x1;
	required_ioport m_y1;
	required_ioport m_x2;
	required_ioport m_y2;
};

#endif /* PC_JOY_H */