1 // license:BSD-3-Clause
2 // copyright-holders:68bit
3
4 #include "emu.h"
5 #include "swtpc8212.h"
6
swtpc8212_terminal_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)7 swtpc8212_terminal_device::swtpc8212_terminal_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
8 : device_t(mconfig, SERIAL_TERMINAL_SWTPC8212, tag, owner, clock)
9 , device_rs232_port_interface(mconfig, *this)
10 , m_swtpc8212(*this, "swtpc8212")
11 , m_flow_control(*this, "FLOW_CONTROL")
12 {
13 }
14
device_add_mconfig(machine_config & config)15 void swtpc8212_terminal_device::device_add_mconfig(machine_config &config)
16 {
17 SWTPC8212(config, m_swtpc8212, 0);
18 m_swtpc8212->rs232_conn_txd_handler().set(FUNC(swtpc8212_terminal_device::output_rxd));
19 m_swtpc8212->rs232_conn_rts_handler().set(FUNC(swtpc8212_terminal_device::route_term_rts));
20 m_swtpc8212->rs232_conn_dtr_handler().set(FUNC(swtpc8212_terminal_device::route_term_dtr));
21 }
22
23 INPUT_PORTS_START(swtpc8212_terminal)
24
25 PORT_START("FLOW_CONTROL")
26 PORT_CONFNAME(0x1, 1, "Flow control") PORT_CHANGED_MEMBER(DEVICE_SELF, swtpc8212_terminal_device, flow_control, 0)
27 PORT_CONFSETTING(0x00, "None")
28 PORT_CONFSETTING(0x01, "Terminal DTR to remote CTS")
29
30 INPUT_PORTS_END
31
device_input_ports() const32 ioport_constructor swtpc8212_terminal_device::device_input_ports() const
33 {
34 return INPUT_PORTS_NAME(swtpc8212_terminal);
35 }
36
WRITE_LINE_MEMBER(swtpc8212_terminal_device::input_txd)37 WRITE_LINE_MEMBER(swtpc8212_terminal_device::input_txd)
38 {
39 m_swtpc8212->rs232_conn_rxd_w(state);
40 }
41
WRITE_LINE_MEMBER(swtpc8212_terminal_device::route_term_rts)42 WRITE_LINE_MEMBER(swtpc8212_terminal_device::route_term_rts)
43 {
44 // Loop the terminal RTS output to the terminal CTS input.
45 m_swtpc8212->rs232_conn_cts_w(state);
46 }
47
48 // This terminal uses DTR for hardware flow control.
WRITE_LINE_MEMBER(swtpc8212_terminal_device::route_term_dtr)49 WRITE_LINE_MEMBER(swtpc8212_terminal_device::route_term_dtr)
50 {
51 if (m_flow_control->read())
52 {
53 // Connect the terminal DTR output to CTS at the other end.
54 output_cts(state);
55 }
56
57 // Cache the state, in case the ioport setting changes.
58 m_dtr = state;
59 }
60
INPUT_CHANGED_MEMBER(swtpc8212_terminal_device::flow_control)61 INPUT_CHANGED_MEMBER(swtpc8212_terminal_device::flow_control)
62 {
63 if (newval)
64 output_cts(m_dtr);
65 else
66 output_cts(0);
67 }
68
device_start()69 void swtpc8212_terminal_device::device_start()
70 {
71 save_item(NAME(m_dtr));
72 }
73
device_reset()74 void swtpc8212_terminal_device::device_reset()
75 {
76 // To the terminal
77 m_swtpc8212->rs232_conn_cts_w(0);
78
79 // To the computer
80 output_rxd(1);
81 output_dcd(0);
82 output_dsr(0);
83 if (!m_flow_control->read())
84 output_cts(0);
85 }
86
87 DEFINE_DEVICE_TYPE(SERIAL_TERMINAL_SWTPC8212, swtpc8212_terminal_device, "swtpc8212_terminal", "SWTPC8212 Terminal")
88