1 // license:BSD-3-Clause
2 // copyright-holders:Enik Land
3 /**********************************************************************
4 
5     Sega SK-1100 keyboard link cable emulation
6 
7 The cable is used only to link two Mark III's through keyboard, what
8 is supported by the game F-16 Fighting Falcon for its 2 players mode.
9 
10 **********************************************************************/
11 
12 #ifndef MAME_BUS_SG1000_EXP_SK1100_KBLINK_H
13 #define MAME_BUS_SG1000_EXP_SK1100_KBLINK_H
14 
15 #pragma once
16 
17 
18 #include "sk1100prn.h"
19 #include "imagedev/bitbngr.h"
20 
21 
22 
23 //**************************************************************************
24 //  TYPE DEFINITIONS
25 //**************************************************************************
26 
27 // ======================> sk1100_link_cable_device
28 
29 class sk1100_link_cable_device : public device_t,
30 	public device_sk1100_printer_port_interface
31 {
32 public:
33 	// construction/destruction
34 	sk1100_link_cable_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);
35 
36 protected:
37 	// device-level overrides
38 	virtual void device_start() override;
39 	virtual void device_reset() override;
40 	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
41 	virtual void device_add_mconfig(machine_config &config) override;
42 
43 	// device_sk1100_link_cable_interface overrides
44 
DECLARE_WRITE_LINE_MEMBER(input_data)45 	virtual DECLARE_WRITE_LINE_MEMBER( input_data ) override { m_data = state; set_data_transfer(); }
DECLARE_WRITE_LINE_MEMBER(input_reset)46 	virtual DECLARE_WRITE_LINE_MEMBER( input_reset ) override { m_reset = state; set_data_transfer(); }
DECLARE_WRITE_LINE_MEMBER(input_feed)47 	virtual DECLARE_WRITE_LINE_MEMBER( input_feed ) override { m_feed = state; set_data_transfer(); }
48 
DECLARE_READ_LINE_MEMBER(output_fault)49 	virtual DECLARE_READ_LINE_MEMBER( output_fault ) override { set_data_read(); return m_fault; }
DECLARE_READ_LINE_MEMBER(output_busy)50 	virtual DECLARE_READ_LINE_MEMBER( output_busy ) override { set_data_read(); return m_busy; }
51 
52 private:
53 	static constexpr int TIMER_POLL = 1;
54 	static constexpr int TIMER_SEND = 2;
55 	static constexpr int TIMER_READ = 3;
56 
57 	void queue();
58 	void set_data_transfer();
59 	void set_data_read();
60 
61 	required_device<bitbanger_device> m_stream;
62 
63 	u8 m_input_buffer[1000];
64 	u32 m_input_count;
65 	u32 m_input_index;
66 	emu_timer *m_timer_poll;
67 	emu_timer *m_timer_send;
68 	emu_timer *m_timer_read;
69 	bool m_update_received_data;
70 	int m_data;
71 	int m_reset;
72 	int m_feed;
73 	int m_busy;
74 	int m_fault;
75 };
76 
77 
78 // device type definition
79 DECLARE_DEVICE_TYPE(SK1100_LINK_CABLE, sk1100_link_cable_device)
80 
81 
82 #endif // MAME_BUS_SG1000_EXP_SK1100_KBLINK_H
83