summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/comx35/fdc.cpp
blob: 93f2b8452ef826bd5d7469d4203fe2b8fe743c72 (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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
// license:BSD-3-Clause
// copyright-holders:Curt Coder
/**********************************************************************

    COMX-35 Disk Controller Card emulation

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

/*

(c) 1984 Comx World Operations

PCB Layout
----------

F-001-FD-REV0

    |---------------|
    |      CN1      |
|---|               |---------------------------|
|                                               |
|   40174               4068    4072           -|
|           ROM                                ||
|   LS04                4072    4050    7438   C|
|8MHz                                          N|
|                       4049    4075    LS08   2|
|LD1        WD1770                             ||
|   40174               4503    4075    7438   -|
|LD2                                            |
|-----------------------------------------------|

Notes:
    All IC's shown.

    ROM     - "D.O.S. V1.2"
    WD1770  - Western Digital WD1770-xx Floppy Disc Controller @ 8MHz
    CN1     - COMX-35 bus PCB edge connector
    CN2     - 34 pin floppy connector
    LD1     - card selected LED
    LD2     - floppy motor on LED

*/

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



//**************************************************************************
//  MACROS/CONSTANTS
//**************************************************************************

#define WD1770_TAG          "wd1770"



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

const device_type COMX_FD = &device_creator<comx_fd_device>;


//-------------------------------------------------
//  ROM( comx_fd )
//-------------------------------------------------

ROM_START( comx_fd )
	ROM_REGION( 0x2000, "c000", 0 )
	ROM_LOAD( "d.o.s. v1.2.f4", 0x0000, 0x2000, CRC(cf4ecd2e) SHA1(290e19bdc89e3c8059e63d5ae3cca4daa194e1fe) )
ROM_END


//-------------------------------------------------
//  rom_region - device-specific ROM region
//-------------------------------------------------

const tiny_rom_entry *comx_fd_device::device_rom_region() const
{
	return ROM_NAME( comx_fd );
}


FLOPPY_FORMATS_MEMBER( comx_fd_device::floppy_formats )
	FLOPPY_COMX35_FORMAT
FLOPPY_FORMATS_END

static SLOT_INTERFACE_START( comx_fd_floppies )
	SLOT_INTERFACE( "525sd35t", FLOPPY_525_SD_35T )
	SLOT_INTERFACE( "525qd", FLOPPY_525_QD )
SLOT_INTERFACE_END


//-------------------------------------------------
//  MACHINE_CONFIG_FRAGMENT( comx_fd )
//-------------------------------------------------

static MACHINE_CONFIG_FRAGMENT( comx_fd )
	MCFG_WD1770_ADD(WD1770_TAG, XTAL_8MHz)

	MCFG_FLOPPY_DRIVE_ADD(WD1770_TAG":0", comx_fd_floppies, "525sd35t", comx_fd_device::floppy_formats)
	MCFG_FLOPPY_DRIVE_ADD(WD1770_TAG":1", comx_fd_floppies, nullptr,       comx_fd_device::floppy_formats)
MACHINE_CONFIG_END


//-------------------------------------------------
//  machine_config_additions - device-specific
//  machine configurations
//-------------------------------------------------

machine_config_constructor comx_fd_device::device_mconfig_additions() const
{
	return MACHINE_CONFIG_NAME( comx_fd );
}



//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

//-------------------------------------------------
//  comx_fd_device - constructor
//-------------------------------------------------

comx_fd_device::comx_fd_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, COMX_FD, "COMX FD", tag, owner, clock, "comx_fd", __FILE__),
	device_comx_expansion_card_interface(mconfig, *this),
	m_fdc(*this, WD1770_TAG),
	m_floppy0(*this, WD1770_TAG":0"),
	m_floppy1(*this, WD1770_TAG":1"),
	m_rom(*this, "c000"),
	m_q(0),
	m_addr(0),
	m_disb(1)
{
}


//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void comx_fd_device::device_start()
{
	// state saving
	save_item(NAME(m_ds));
	save_item(NAME(m_q));
	save_item(NAME(m_addr));
	save_item(NAME(m_disb));
}


//-------------------------------------------------
//  device_reset - device-specific reset
//-------------------------------------------------

void comx_fd_device::device_reset()
{
	m_fdc->reset();
	m_fdc->dden_w(1);
	m_fdc->set_floppy(nullptr);

	m_addr = 0;
	m_disb = 1;
}


//-------------------------------------------------
//  comx_ef4_r - external flag 4 read
//-------------------------------------------------

int comx_fd_device::comx_ef4_r()
{
	int state = CLEAR_LINE;

	if (m_ds && !m_disb)
	{
		state = !m_fdc->drq_r();
	}

	return state;
}


//-------------------------------------------------
//  comx_q_w - Q write
//-------------------------------------------------

void comx_fd_device::comx_q_w(int state)
{
	m_q = state;
}


//-------------------------------------------------
//  comx_mrd_r - memory read
//-------------------------------------------------

uint8_t comx_fd_device::comx_mrd_r(address_space &space, offs_t offset, int *extrom)
{
	uint8_t data = 0xff;

	if (offset >= 0x0dd0 && offset < 0x0de0)
	{
		data = m_rom->base()[offset & 0x1fff];
		*extrom = 0;
	}
	else if (offset >= 0xc000 && offset < 0xe000)
	{
		data = m_rom->base()[offset & 0x1fff];
	}

	return data;
}


//-------------------------------------------------
//  comx_io_r - I/O read
//-------------------------------------------------

uint8_t comx_fd_device::comx_io_r(address_space &space, offs_t offset)
{
	uint8_t data = 0xff;

	if (offset == 2)
	{
		if (m_q)
		{
			data = 0xfe | (m_fdc->intrq_r() ? 1 : 0);
		}
		else
		{
			data = m_fdc->gen_r(m_addr);
			if (m_addr==3) logerror("%s FDC read %u:%02x\n", machine().describe_context(), m_addr,data);
		}
	}

	return data;
}


//-------------------------------------------------
//  comx_io_w - I/O write
//-------------------------------------------------

void comx_fd_device::comx_io_w(address_space &space, offs_t offset, uint8_t data)
{
	if (offset == 2)
	{
		if (m_q)
		{
			/*

			    bit     description

			    0       FDC A0
			    1       FDC A1
			    2       DRIVE0
			    3       DRIVE1
			    4       F9 DISB
			    5       SIDE SELECT

			*/

			// latch data to F3
			m_addr = data & 0x03;

			// drive select
			floppy_image_device *floppy = nullptr;

			if (BIT(data, 2)) floppy = m_floppy0->get_device();
			if (BIT(data, 3)) floppy = m_floppy1->get_device();

			m_fdc->set_floppy(floppy);

			if (floppy) floppy->ss_w(BIT(data, 5));

			m_disb = !BIT(data, 4);
		}
		else
		{
			// write data to WD1770
			m_fdc->gen_w(m_addr, data);
		}
	}
}