1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4 
5     CMD SwiftLink RS-232 cartridge emulation
6 
7 **********************************************************************/
8 
9 /*
10 
11     http://mclauchlan.site.net.au/scott/C=Hacking/C-Hacking10/C-Hacking10-swiftlink.html
12 
13 */
14 
15 #include "emu.h"
16 #include "swiftlink.h"
17 #include "bus/rs232/rs232.h"
18 
19 
20 
21 //**************************************************************************
22 //  MACROS/CONSTANTS
23 //**************************************************************************
24 
25 #define MOS6551_TAG     "mos6551"
26 #define RS232_TAG       "rs232"
27 
28 
29 
30 //**************************************************************************
31 //  DEVICE DEFINITIONS
32 //**************************************************************************
33 
34 DEFINE_DEVICE_TYPE(C64_SWIFTLINK, c64_swiftlink_cartridge_device, "c64_swiftlink", "C64 SwiftLink cartridge")
35 
36 
37 //-------------------------------------------------
38 //  device_add_mconfig - add device configuration
39 //-------------------------------------------------
40 
device_add_mconfig(machine_config & config)41 void c64_swiftlink_cartridge_device::device_add_mconfig(machine_config &config)
42 {
43 	MOS6551(config, m_acia, 0);
44 	m_acia->set_xtal(3.6864_MHz_XTAL);
45 	m_acia->irq_handler().set(FUNC(c64_swiftlink_cartridge_device::acia_irq_w));
46 	m_acia->txd_handler().set(RS232_TAG, FUNC(rs232_port_device::write_txd));
47 
48 	rs232_port_device &rs232(RS232_PORT(config, RS232_TAG, default_rs232_devices, nullptr));
49 	rs232.rxd_handler().set(m_acia, FUNC(mos6551_device::write_rxd));
50 	rs232.dcd_handler().set(m_acia, FUNC(mos6551_device::write_dcd));
51 	rs232.dsr_handler().set(m_acia, FUNC(mos6551_device::write_dsr));
52 	rs232.cts_handler().set(m_acia, FUNC(mos6551_device::write_cts));
53 }
54 
55 
56 //-------------------------------------------------
57 //  INPUT_PORTS( c64_swiftlink )
58 //-------------------------------------------------
59 
60 static INPUT_PORTS_START( c64_swiftlink )
61 	PORT_START("CS")
62 	PORT_DIPNAME( 0x03, 0x01, "Base Address" )
63 	PORT_DIPSETTING(    0x00, "$D700 (C128)" )
64 	PORT_DIPSETTING(    0x01, "$DE00" )
65 	PORT_DIPSETTING(    0x02, "$DF00" )
66 
67 	PORT_START("IRQ")
68 	PORT_DIPNAME( 0x01, 0x01, "Interrupt" )
69 	PORT_DIPSETTING(    0x00, "IRQ" )
70 	PORT_DIPSETTING(    0x01, "NMI" )
71 INPUT_PORTS_END
72 
73 
74 //-------------------------------------------------
75 //  input_ports - device-specific input ports
76 //-------------------------------------------------
77 
device_input_ports() const78 ioport_constructor c64_swiftlink_cartridge_device::device_input_ports() const
79 {
80 	return INPUT_PORTS_NAME( c64_swiftlink );
81 }
82 
83 
84 
85 //**************************************************************************
86 //  LIVE DEVICE
87 //**************************************************************************
88 
89 //-------------------------------------------------
90 //  c64_swiftlink_cartridge_device - constructor
91 //-------------------------------------------------
92 
c64_swiftlink_cartridge_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)93 c64_swiftlink_cartridge_device::c64_swiftlink_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
94 	device_t(mconfig, C64_SWIFTLINK, tag, owner, clock),
95 	device_c64_expansion_card_interface(mconfig, *this),
96 	m_acia(*this, MOS6551_TAG),
97 	m_io_cs(*this, "CS"),
98 	m_io_irq(*this, "IRQ"), m_cs(0), m_irq(0)
99 {
100 }
101 
102 
103 //-------------------------------------------------
104 //  device_start - device-specific startup
105 //-------------------------------------------------
106 
device_start()107 void c64_swiftlink_cartridge_device::device_start()
108 {
109 }
110 
111 
112 //-------------------------------------------------
113 //  device_reset - device-specific reset
114 //-------------------------------------------------
115 
device_reset()116 void c64_swiftlink_cartridge_device::device_reset()
117 {
118 	m_acia->reset();
119 
120 	m_cs = m_io_cs->read();
121 	m_irq = m_io_irq->read();
122 }
123 
124 
125 //-------------------------------------------------
126 //  c64_cd_r - cartridge data read
127 //-------------------------------------------------
128 
c64_cd_r(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)129 uint8_t c64_swiftlink_cartridge_device::c64_cd_r(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
130 {
131 	if (((m_cs == DE00) && !io1) || ((m_cs == DF00) && !io2) ||
132 		((m_cs == D700) && ((offset & 0xff00) == 0xd700)))
133 	{
134 		data = m_acia->read(offset & 0x03);
135 	}
136 
137 	return data;
138 }
139 
140 
141 //-------------------------------------------------
142 //  c64_cd_w - cartridge data write
143 //-------------------------------------------------
144 
c64_cd_w(offs_t offset,uint8_t data,int sphi2,int ba,int roml,int romh,int io1,int io2)145 void c64_swiftlink_cartridge_device::c64_cd_w(offs_t offset, uint8_t data, int sphi2, int ba, int roml, int romh, int io1, int io2)
146 {
147 	if (((m_cs == DE00) && !io1) || ((m_cs == DF00) && !io2) ||
148 		((m_cs == D700) && ((offset & 0xff00) == 0xd700)))
149 	{
150 		m_acia->write(offset & 0x03, data);
151 	}
152 }
153 
154 
155 //-------------------------------------------------
156 //  acia_irq_w -
157 //-------------------------------------------------
158 
WRITE_LINE_MEMBER(c64_swiftlink_cartridge_device::acia_irq_w)159 WRITE_LINE_MEMBER( c64_swiftlink_cartridge_device::acia_irq_w )
160 {
161 	switch (m_irq)
162 	{
163 	case IRQ: m_slot->irq_w(state); break;
164 	case NMI: m_slot->nmi_w(state); break;
165 	}
166 }
167