1 // license:BSD-3-Clause
2 // copyright-holders:Fabio Priuli
3 /**********************************************************************
4 
5     Nintendo Family Computer & Entertainment System controller port
6     emulation
7 
8 **********************************************************************
9 
10     Known Issues:
11     - Currently the FC expansion port is emulated as a control port
12 
13 **********************************************************************/
14 
15 #ifndef MAME_BUS_NES_CTRL_CTRL_H
16 #define MAME_BUS_NES_CTRL_CTRL_H
17 
18 #pragma once
19 
20 #include "screen.h"
21 
22 
23 //**************************************************************************
24 //  TYPE DEFINITIONS
25 //**************************************************************************
26 
27 class nes_control_port_device;
28 
29 // ======================> device_nes_control_port_interface
30 
31 class device_nes_control_port_interface : public device_interface
32 {
33 public:
34 	// construction/destruction
35 	virtual ~device_nes_control_port_interface();
36 
read_bit0()37 	virtual uint8_t read_bit0() { return 0; }
read_bit34()38 	virtual uint8_t read_bit34() { return 0; }
read_exp(offs_t offset)39 	virtual uint8_t read_exp(offs_t offset) { return 0; }
write(uint8_t data)40 	virtual void write(uint8_t data) { }
41 
42 protected:
43 	device_nes_control_port_interface(const machine_config &mconfig, device_t &device);
44 
45 	nes_control_port_device *m_port;
46 };
47 
48 
49 // ======================> nes_control_port_device
50 
51 class nes_control_port_device : public device_t,
52 								public device_single_card_slot_interface<device_nes_control_port_interface>
53 {
54 public:
55 	// construction/destruction
56 	template <typename T>
nes_control_port_device(machine_config const & mconfig,char const * tag,device_t * owner,T && opts,char const * dflt)57 	nes_control_port_device(machine_config const &mconfig, char const *tag, device_t *owner, T &&opts, char const *dflt)
58 		: nes_control_port_device(mconfig, tag, owner, (uint32_t)0)
59 	{
60 		option_reset();
61 		opts(*this);
62 		set_default_option(dflt);
63 		set_fixed(false);
64 	}
65 	nes_control_port_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
66 	virtual ~nes_control_port_device();
67 
68 	uint8_t read_bit0();
69 	uint8_t read_bit34();
70 	uint8_t read_exp(offs_t offset);
71 	void write(uint8_t data);
set_screen_tag(T && tag)72 	template <typename T> void set_screen_tag(T &&tag) { m_screen.set_tag(std::forward<T>(tag)); }
73 
74 	// for peripherals that interact with the machine's screen
75 	required_device<screen_device> m_screen;
76 
77 protected:
78 	// device-level overrides
79 	virtual void device_start() override;
80 
81 	// devices
82 	device_nes_control_port_interface *m_device;
83 };
84 
85 
86 // device type definition
87 DECLARE_DEVICE_TYPE(NES_CONTROL_PORT, nes_control_port_device)
88 
89 void nes_control_port1_devices(device_slot_interface &device);
90 void nes_control_port2_devices(device_slot_interface &device);
91 void fc_control_port1_devices(device_slot_interface &device);
92 void fc_control_port2_devices(device_slot_interface &device);
93 void fc_expansion_devices(device_slot_interface &device);
94 
95 
96 #endif // MAME_BUS_NES_CTRL_CTRL_H
97