1 // license:BSD-3-Clause
2 // copyright-holders:Fabio Priuli
3 /**********************************************************************
4 
5     Nintendo Family Computer & Entertainment System Joypads
6 
7 **********************************************************************/
8 
9 #ifndef MAME_BUS_NES_CTRL_JOYPAD_H
10 #define MAME_BUS_NES_CTRL_JOYPAD_H
11 
12 #pragma once
13 
14 #include "ctrl.h"
15 
16 
17 //**************************************************************************
18 //  TYPE DEFINITIONS
19 //**************************************************************************
20 
21 // ======================> nes_joypad_device
22 
23 class nes_joypad_device : public device_t,
24 							public device_nes_control_port_interface
25 {
26 public:
27 	// construction/destruction
28 	nes_joypad_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
29 
30 	virtual ioport_constructor device_input_ports() const override;
31 
32 protected:
33 	nes_joypad_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);
34 
35 	// device-level overrides
36 	virtual void device_start() override;
37 	virtual void device_reset() override;
38 
39 	virtual uint8_t read_bit0() override;
40 	virtual void write(uint8_t data) override;
41 
42 	required_ioport m_joypad;
43 	uint32_t m_latch;
44 };
45 
46 // ======================> nes_fcpad2_device
47 
48 class nes_fcpad2_device : public nes_joypad_device
49 {
50 public:
51 	// construction/destruction
52 	nes_fcpad2_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
53 
54 	virtual ioport_constructor device_input_ports() const override;
55 
56 protected:
57 	virtual uint8_t read_exp(offs_t offset) override;
58 	virtual void write(uint8_t data) override;
59 };
60 
61 // ======================> nes_ccpadl_device
62 
63 class nes_ccpadl_device : public nes_joypad_device
64 {
65 public:
66 	// construction/destruction
67 	nes_ccpadl_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
68 
69 	virtual ioport_constructor device_input_ports() const override;
70 };
71 
72 // ======================> nes_ccpadr_device
73 
74 class nes_ccpadr_device : public nes_joypad_device
75 {
76 public:
77 	// construction/destruction
78 	nes_ccpadr_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
79 
80 	virtual ioport_constructor device_input_ports() const override;
81 };
82 
83 // ======================> nes_arcstick_device
84 
85 class nes_arcstick_device : public nes_joypad_device
86 {
87 public:
88 	// construction/destruction
89 	nes_arcstick_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
90 
91 protected:
92 	virtual ioport_constructor device_input_ports() const override;
93 	virtual void device_add_mconfig(machine_config &config) override;
94 
read_bit0()95 	virtual uint8_t read_bit0() override { return 0; }
96 	virtual uint8_t read_exp(offs_t offset) override;
97 	virtual void write(uint8_t data) override;
98 
99 	required_device<nes_control_port_device> m_daisychain;
100 	required_ioport m_cfg;
101 };
102 
103 
104 // device type definition
105 DECLARE_DEVICE_TYPE(NES_JOYPAD,         nes_joypad_device)
106 DECLARE_DEVICE_TYPE(NES_FCPAD_P2,       nes_fcpad2_device)
107 DECLARE_DEVICE_TYPE(NES_CCPAD_LEFT,     nes_ccpadl_device)
108 DECLARE_DEVICE_TYPE(NES_CCPAD_RIGHT,    nes_ccpadr_device)
109 DECLARE_DEVICE_TYPE(NES_ARCSTICK,       nes_arcstick_device)
110 
111 #endif // MAME_BUS_NES_CTRL_JOYPAD_H
112