summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/rc2014/fdc.cpp
blob: 41cd7846744e9aa14402bf55104a7212efdfaf3b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// license:BSD-3-Clause
// copyright-holders:Miodrag Milanovic
/***************************************************************************

    RC2014 FDC

****************************************************************************/

#include "emu.h"
#include "fdc.h"

#include "machine/upd765.h"
#include "imagedev/floppy.h"
#include "formats/imd_dsk.h"
#include "formats/pc_dsk.h"

namespace {

//**************************************************************************
//  RC2014 Floppy Disk Controller FDC9266
//  Module author: Dr. Scott M. Baker
//**************************************************************************

class rc2014_fdc9266_device : public device_t, public device_rc2014_card_interface
{
public:
	// construction/destruction
	rc2014_fdc9266_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock);

protected:
	// device-level overrides
	virtual void device_start() override;
	virtual void device_reset() override;
	virtual void device_add_mconfig(machine_config &config) override;
	virtual ioport_constructor device_input_ports() const override;
private:
	void control_w(offs_t offset, uint8_t data);

	required_ioport m_addr;
	required_ioport_array<4> m_jp;
	required_device<upd765a_device> m_fdc;
	required_device_array<floppy_connector, 2> m_floppy;
};

rc2014_fdc9266_device::rc2014_fdc9266_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
	: device_t(mconfig, RC2014_FDC9266, tag, owner, clock)
	, device_rc2014_card_interface(mconfig, *this)
	, m_addr(*this, "SV1")
	, m_jp(*this, "JP%u", 1U)
	, m_fdc(*this, "fdc")
	, m_floppy(*this, "fdc:%u", 0U)
{
}

void rc2014_fdc9266_device::device_start()
{
}

void rc2014_fdc9266_device::device_reset()
{
	uint8_t base = m_addr->read() << 5; // SV1
	// A15-A8 and A1 not connected
	m_bus->installer(AS_IO)->install_read_handler(base+0x10, base+0x10, 0, 0xff02, 0, read8smo_delegate(m_fdc, FUNC(upd765a_device::msr_r)));
	m_bus->installer(AS_IO)->install_readwrite_handler(base+0x11, base+0x11, 0, 0xff02, 0, read8smo_delegate(m_fdc, FUNC(upd765a_device::fifo_r)), write8smo_delegate(m_fdc, FUNC(upd765a_device::fifo_w)));
	m_bus->installer(AS_IO)->install_write_handler(base+0x18, base+0x18, 0, 0xff02, 0, write8sm_delegate(*this, FUNC(rc2014_fdc9266_device::control_w)));
	// TODO: Use jumpers
}

void rc2014_fdc9266_device::control_w(offs_t, uint8_t data)
{
	// D0 - TC
	// D1 - MOTEA
	// D2 - MOTEB
	// D3 - P2
	// D4 - P1
	// D5 - P0
	// D6 - DENSEL
	// D7 - FDC_RST (trough inverter)
	m_fdc->tc_w(BIT(data,0)? true : false);
	if (m_floppy[0]->get_device())
		m_floppy[0]->get_device()->mon_w(!BIT(data,1));
	if (m_floppy[1]->get_device())
		m_floppy[1]->get_device()->mon_w(!BIT(data,2));

	m_fdc->set_rate(BIT(data,6) ? 500000 : 250000);
	m_fdc->reset_w(!BIT(data,7) ? ASSERT_LINE : CLEAR_LINE);
}

static void rc2014_floppies(device_slot_interface &device)
{
	device.option_add("35hd", FLOPPY_35_HD);
}

static void rc2014_floppy_formats(format_registration &fr)
{
	fr.add_mfm_containers();
	fr.add(FLOPPY_IMD_FORMAT);
	fr.add(FLOPPY_PC_FORMAT);
}

void rc2014_fdc9266_device::device_add_mconfig(machine_config &config)
{
	// FDC9266
	UPD765A(config, m_fdc, XTAL(8'000'000), true, true);

	// floppy drives
	FLOPPY_CONNECTOR(config, m_floppy[0], rc2014_floppies, "35hd", rc2014_floppy_formats);
	FLOPPY_CONNECTOR(config, m_floppy[1], rc2014_floppies, "35hd", rc2014_floppy_formats);
}

static INPUT_PORTS_START( rc2014_fdc9266_jumpers )
	PORT_START("SV1")
	PORT_CONFNAME( 0x7, 0x2, "Base Address" )
	PORT_CONFSETTING( 0x0, "0x00" )
	PORT_CONFSETTING( 0x1, "0x20" )
	PORT_CONFSETTING( 0x2, "0x40" )
	PORT_CONFSETTING( 0x3, "0x60" )
	PORT_CONFSETTING( 0x4, "0x80" )
	PORT_CONFSETTING( 0x5, "0xa0" )
	PORT_CONFSETTING( 0x6, "0xc0" )
	PORT_CONFSETTING( 0x7, "0xe0" )
	PORT_START("JP1")
	PORT_CONFNAME( 0x1, 0x1, "Two Side" )
	PORT_CONFSETTING( 0x0, "GND" )
	PORT_CONFSETTING( 0x1, "None" )
	PORT_START("JP2")
	PORT_CONFNAME( 0x1, 0x0, "/FAULT" )
	PORT_CONFSETTING( 0x0, "None" )
	PORT_CONFSETTING( 0x1, "+5V" )
	PORT_START("JP3")
	PORT_CONFNAME( 0x1, 0x1, "MINI" )
	PORT_CONFSETTING( 0x0, "GND" )
	PORT_CONFSETTING( 0x1, "+5V" )
	PORT_START("JP4")
	PORT_CONFNAME( 0x1, 0x4, "RDY" )
	PORT_CONFSETTING( 0x0, "GND" )
	PORT_CONFSETTING( 0x4, "DC/RDY" )
INPUT_PORTS_END

ioport_constructor rc2014_fdc9266_device::device_input_ports() const
{
	return INPUT_PORTS_NAME( rc2014_fdc9266_jumpers );
}

//**************************************************************************
//  RC2014 Floppy Disk Controller WD37C65
//  Module author: Dr. Scott M. Baker
//**************************************************************************

class rc2014_wd37c65_device : public device_t, public device_rc2014_card_interface
{
public:
	// construction/destruction
	rc2014_wd37c65_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock);

protected:
	// device-level overrides
	virtual void device_start() override;
	virtual void device_reset() override;
	virtual void device_add_mconfig(machine_config &config) override;
	virtual ioport_constructor device_input_ports() const override;

	// DACK confirmation is same as pulsing TC
	uint8_t dack_r(address_space &space, offs_t) { m_fdc->tc_w(true);  m_fdc->tc_w(false); return space.unmap(); }
private:
	required_ioport m_addr;
	required_ioport_array<2> m_jp;
	required_device<wd37c65c_device> m_fdc;
	required_device_array<floppy_connector, 2> m_floppy;
};

rc2014_wd37c65_device::rc2014_wd37c65_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
	: device_t(mconfig, RC2014_WD37C65, tag, owner, clock)
	, device_rc2014_card_interface(mconfig, *this)
	, m_addr(*this, "SV1")
	, m_jp(*this, "JP%u", 1U)
	, m_fdc(*this, "fdc")
	, m_floppy(*this, "fdc:%u", 0U)
{
}

void rc2014_wd37c65_device::device_start()
{
}

void rc2014_wd37c65_device::device_reset()
{
	uint8_t base = m_addr->read() << 5; // SV1
	// A15-A8 and A1 not connected
	m_bus->installer(AS_IO)->install_read_handler(base+0x10, base+0x10, 0, 0xff02, 0, read8smo_delegate(m_fdc, FUNC(wd37c65c_device::msr_r)));
	m_bus->installer(AS_IO)->install_readwrite_handler(base+0x11, base+0x11, 0, 0xff02, 0, read8smo_delegate(m_fdc, FUNC(wd37c65c_device::fifo_r)), write8smo_delegate(m_fdc, FUNC(wd37c65c_device::fifo_w)));

	// A15-A8 and A0 and A1 not connected
	m_bus->installer(AS_IO)->install_write_handler(base+0x08, base+0x08, 0, 0xff06, 0, write8smo_delegate(m_fdc, FUNC(wd37c65c_device::ccr_w)));
	m_bus->installer(AS_IO)->install_write_handler(base+0x18, base+0x18, 0, 0xff06, 0, write8smo_delegate(m_fdc, FUNC(wd37c65c_device::dor_w)));
	m_bus->installer(AS_IO)->install_read_handler(base+0x18, base+0x18, 0, 0xff06, 0, read8m_delegate(*this, FUNC(rc2014_wd37c65_device::dack_r)));
	// TODO: Use jumpers
}

void rc2014_wd37c65_device::device_add_mconfig(machine_config &config)
{
	WD37C65C(config, m_fdc, 16_MHz_XTAL);

	// floppy drives
	FLOPPY_CONNECTOR(config, m_floppy[0], rc2014_floppies, "35hd", rc2014_floppy_formats);
	FLOPPY_CONNECTOR(config, m_floppy[1], rc2014_floppies, "35hd", rc2014_floppy_formats);
}

static INPUT_PORTS_START( rc2014_wd37c65_jumpers )
	PORT_START("SV1")
	PORT_CONFNAME( 0x7, 0x2, "Base Address" )
	PORT_CONFSETTING( 0x0, "0x00" )
	PORT_CONFSETTING( 0x1, "0x20" )
	PORT_CONFSETTING( 0x2, "0x40" )
	PORT_CONFSETTING( 0x3, "0x60" )
	PORT_CONFSETTING( 0x4, "0x80" )
	PORT_CONFSETTING( 0x5, "0xa0" )
	PORT_CONFSETTING( 0x6, "0xc0" )
	PORT_CONFSETTING( 0x7, "0xe0" )
	PORT_START("JP1")
	PORT_CONFNAME( 0x1, 0x1, "DACK" )
	PORT_CONFSETTING( 0x0, "Share with DOR" )
	PORT_CONFSETTING( 0x1, "Use offset 0" )
	PORT_START("JP2")
	PORT_CONFNAME( 0x1, 0x0, "TC" )
	PORT_CONFSETTING( 0x0, "Port offset 4" )
	PORT_CONFSETTING( 0x1, "+5V" )
INPUT_PORTS_END

ioport_constructor rc2014_wd37c65_device::device_input_ports() const
{
	return INPUT_PORTS_NAME( rc2014_wd37c65_jumpers );
}

}
//**************************************************************************
//  DEVICE DEFINITIONS
//**************************************************************************

DEFINE_DEVICE_TYPE_PRIVATE(RC2014_FDC9266, device_rc2014_card_interface, rc2014_fdc9266_device, "rc2014_fdc9266", "RC2014 Floppy Disk Controller FDC9266")
DEFINE_DEVICE_TYPE_PRIVATE(RC2014_WD37C65, device_rc2014_card_interface, rc2014_wd37c65_device, "rc2014_wd37c65", "RC2014 Floppy Disk Controller WD37C65")