summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/coco/dragon_fdc.cpp
blob: 9f644d088fb060d8fb4b44bf2166e4d9e7fb8052 (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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
// license:BSD-3-Clause
// copyright-holders:Nathan Woods
/*********************************************************************

    dragon_fdc.cpp

    Dragon Floppy Disk Controller

    The CoCo and Dragon both use the Western Digital floppy disk controllers.
    The CoCo uses either the WD1793 or the WD1773, the Dragon uses the WD2797,
    which mostly uses the same command set with some subtle differences, most
    notably the 2797 handles disk side select internally. The Dragon Alpha also
    uses the WD2797, however as this is a built in interface and not an external
    cartridge, it is dealt with in the main coco.cpp file.

    The wd's variables are mapped to $FF48-$FF4B on the CoCo and on $FF40-$FF43
    on the Dragon.  In addition, there is another register
    called DSKREG that controls the interface with the wd1793.  DSKREG is
    detailed below:  But they appear to be

    References:
    CoCo:   Disk Basic Unravelled
    Dragon: Inferences from the PC-Dragon source code
    DragonDos Controller, Disk and File Formats by Graham E Kinns

    ---------------------------------------------------------------------------

    DSKREG - the control register
    Dragon ($FF48)

    Bit
    7 not used
    6 not used
    5 NMI enable flag
    4 write precompensation
    3 single density enable
    2 drive motor activation
    1 drive select high bit
    0 drive select low bit

    ---------------------------------------------------------------------------

    2007-02-22, P.Harvey-Smith

    Began implementing the Dragon Delta Dos controller, this was actually the first
    Dragon disk controller to market, beating Dragon Data's by a couple of months,
    it is based around the WD2791 FDC, which is compatible with the WD1793/WD2797 used
    by the standard CoCo and Dragon disk controllers except that it used an inverted
    data bus, which is the reason the read/write handlers invert the data. This
    controller like, the DragonDos WD2797 is mapped at $FF40-$FF43, in the normal
    register order.

    The Delta cart also has a register (74LS174 hex flipflop) at $FF44 encoded as
    follows :-

    Bit
    7 not used
    6 not used
    5 not used
    4 Single (0) / Double (1) density select
    3 5.25"(0) / 8"(1) Clock select
    2 Side select
    1 Drive select ms bit
    0 Drive select ls bit

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

#include "emu.h"
#include "dragon_fdc.h"

#include "coco_fdc.h"
#include "imagedev/flopdrv.h"
#include "machine/wd_fdc.h"
#include "formats/dmk_dsk.h"
#include "formats/jvc_dsk.h"
#include "formats/vdk_dsk.h"
#include "formats/sdf_dsk.h"


/***************************************************************************
    PARAMETERS
***************************************************************************/

#define LOG_FDC                 0



/***************************************************************************
    TYPE DEFINITIONS
***************************************************************************/

namespace
{
	class dragon_fdc_device_base : public coco_family_fdc_device_base
	{
	protected:
		// construction/destruction
		dragon_fdc_device_base(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);

		// device-level overrides
		virtual DECLARE_READ8_MEMBER(scs_read) override;
		virtual DECLARE_WRITE8_MEMBER(scs_write) override;
		virtual void device_add_mconfig(machine_config &config) override;
		virtual void update_lines() override;

	private:
		// device references
		required_device<wd2797_device>              m_wd2797;
		required_device_array<floppy_connector, 4>  m_floppies;

		// methods
		void dskreg_w(uint8_t data);
	};

	class premier_fdc_device_base : public coco_family_fdc_device_base
	{
	protected:
		// construction/destruction
		premier_fdc_device_base(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);

		// device-level overrides
		virtual DECLARE_READ8_MEMBER(scs_read) override;
		virtual DECLARE_WRITE8_MEMBER(scs_write) override;
		virtual void device_add_mconfig(machine_config &config) override;
		virtual void update_lines() override;

	private:
		// device references
		required_device<wd2791_device>              m_wd2791;
		required_device_array<floppy_connector, 4>  m_floppies;

		// methods
		void dskreg_w(uint8_t data);
	};
}

/***************************************************************************
    LOCAL VARIABLES
***************************************************************************/

static void dragon_fdc_drives(device_slot_interface &device)
{
	device.option_add("qd", FLOPPY_525_QD);
}


void dragon_fdc_device_base::device_add_mconfig(machine_config &config)
{
	WD2797(config, m_wd2797, 4_MHz_XTAL / 4).set_force_ready(true);
	m_wd2797->intrq_wr_callback().set(FUNC(dragon_fdc_device_base::fdc_intrq_w));
	m_wd2797->drq_wr_callback().set(FUNC(dragon_fdc_device_base::fdc_drq_w));

	FLOPPY_CONNECTOR(config, m_floppies[0], dragon_fdc_drives, "qd", dragon_fdc_device_base::floppy_formats).enable_sound(true);
	FLOPPY_CONNECTOR(config, m_floppies[1], dragon_fdc_drives, "qd", dragon_fdc_device_base::floppy_formats).enable_sound(true);
	FLOPPY_CONNECTOR(config, m_floppies[2], dragon_fdc_drives, "", dragon_fdc_device_base::floppy_formats).enable_sound(true);
	FLOPPY_CONNECTOR(config, m_floppies[3], dragon_fdc_drives, "", dragon_fdc_device_base::floppy_formats).enable_sound(true);
}


void premier_fdc_device_base::device_add_mconfig(machine_config &config)
{
	WD2791(config, m_wd2791, 2_MHz_XTAL / 2).set_force_ready(true);

	FLOPPY_CONNECTOR(config, m_floppies[0], dragon_fdc_drives, "qd", dragon_fdc_device_base::floppy_formats).enable_sound(true);
	FLOPPY_CONNECTOR(config, m_floppies[1], dragon_fdc_drives, "qd", dragon_fdc_device_base::floppy_formats).enable_sound(true);
	FLOPPY_CONNECTOR(config, m_floppies[2], dragon_fdc_drives, "", dragon_fdc_device_base::floppy_formats).enable_sound(true);
	FLOPPY_CONNECTOR(config, m_floppies[3], dragon_fdc_drives, "", dragon_fdc_device_base::floppy_formats).enable_sound(true);
}


//**************************************************************************
//  IMPLEMENTATION
//**************************************************************************

//-------------------------------------------------
//  dragon_fdc_device_base - constructor
//-------------------------------------------------
dragon_fdc_device_base::dragon_fdc_device_base(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
	: coco_family_fdc_device_base(mconfig, type, tag, owner, clock)
	, m_wd2797(*this, "wd2797")
	, m_floppies(*this, "wd2797:%u", 0)
{
}


premier_fdc_device_base::premier_fdc_device_base(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
	: coco_family_fdc_device_base(mconfig, type, tag, owner, clock)
	, m_wd2791(*this, "wd2791")
	, m_floppies(*this, "wd2791:%u", 0)
{
}


//-------------------------------------------------
//  update_lines - Dragon specific disk
//  controller lines
//-------------------------------------------------

void dragon_fdc_device_base::update_lines()
{
	// set the NMI line
	set_line_value(line::NMI, intrq() && (dskreg() & 0x20));

	// set the CART line
	set_line_value(line::CART, drq());
}


void premier_fdc_device_base::update_lines()
{
}


//-------------------------------------------------
//  dskreg_w - function to write to
//  Dragon dskreg
//-------------------------------------------------

void dragon_fdc_device_base::dskreg_w(uint8_t data)
{
	if (LOG_FDC)
	{
		logerror("fdc_dragon_dskreg_w(): %c%c%c%c%c%c%c%c ($%02x)\n",
			BIT(data, 7) ? 'X' : 'x',
			BIT(data, 6) ? 'X' : 'x',
			BIT(data, 5) ? 'N' : 'n',
			BIT(data, 4) ? 'P' : 'p',
			BIT(data, 3) ? 'S' : 'D',
			BIT(data, 2) ? 'M' : 'm',
			BIT(data, 1) ? '1' : '0',
			BIT(data, 0) ? '1' : '0',
			data);
	}

	// update the motor on each floppy
	for (int i = 0; i < 4; i++)
	{
		floppy_image_device *floppy = m_floppies[i]->get_device();
		if (floppy)
			floppy->mon_w(BIT(data,2) && (i == (data & 0x03)) ? CLEAR_LINE : ASSERT_LINE);
	}

	// manipulate the WD2797
	m_wd2797->set_floppy(m_floppies[data & 0x03]->get_device());
	m_wd2797->dden_w(BIT(data, 3));

	set_dskreg(data);
}


void premier_fdc_device_base::dskreg_w(uint8_t data)
{
	if (LOG_FDC)
	{
		logerror("fdc_premier_dskreg_w(): %c%c%c%c%c%c%c%c ($%02x)\n",
			BIT(data, 7) ? 'X' : 'x',
			BIT(data, 6) ? 'X' : 'x',
			BIT(data, 5) ? 'X' : 'x',
			BIT(data, 4) ? 'D' : 'S',
			BIT(data, 3) ? '8' : '5',
			BIT(data, 2) ? '1' : '0',
			BIT(data, 1) ? '1' : '0',
			BIT(data, 0) ? '1' : '0',
			data);
	}
	floppy_image_device *floppy = nullptr;

	// update the motor on each floppy
	for (int i = 0; i < 4; i++)
	{
		floppy = m_floppies[i]->get_device();
		if (floppy)
			floppy->mon_w((i == (data & 0x03)) ? CLEAR_LINE : ASSERT_LINE );
	}
	floppy = m_floppies[data & 0x03]->get_device();

	// manipulate the WD2791
	m_wd2791->set_floppy(floppy);

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

	m_wd2791->dden_w(!BIT(data, 4));

	set_dskreg(data);
}


//-------------------------------------------------
//  scs_read
//-------------------------------------------------

READ8_MEMBER(dragon_fdc_device_base::scs_read)
{
	uint8_t result = 0;
	switch (offset & 0xef)
	{
	case 0:
	case 1:
	case 2:
	case 3:
		result = m_wd2797->read(space, offset & 0xef);
		break;
	}
	return result;
}


READ8_MEMBER(premier_fdc_device_base::scs_read)
{
	uint8_t result = 0;
	switch (offset)
	{
	case 0:
	case 1:
	case 2:
	case 3:
		result = m_wd2791->read(space, offset);
		break;
	}
	return result;
}


//-------------------------------------------------
//  scs_write
//-------------------------------------------------

WRITE8_MEMBER(dragon_fdc_device_base::scs_write)
{
	switch (offset & 0xef)
	{
	case 0:
	case 1:
	case 2:
	case 3:
		m_wd2797->write(space, offset & 0xef, data);
		break;
	case 8: case 9: case 10: case 11:
	case 12: case 13: case 14: case 15:
		dskreg_w(data);
		break;
	};
}


WRITE8_MEMBER(premier_fdc_device_base::scs_write)
{
	switch (offset)
	{
	case 0:
	case 1:
	case 2:
	case 3:
		m_wd2791->write(space, offset, data);
		break;
	case 4:
		dskreg_w(data);
		break;
	};
}


//**************************************************************************
//              DRAGON FDC
//**************************************************************************

ROM_START(dragon_fdc)
	ROM_REGION(0x4000, "eprom", ROMREGION_ERASE00)
	ROM_LOAD_OPTIONAL("ddos10.rom", 0x0000, 0x2000, CRC(b44536f6) SHA1(a8918c71d319237c1e3155bb38620acb114a80bc))
ROM_END

namespace
{
	class dragon_fdc_device : public dragon_fdc_device_base
	{
	public:
		// construction/destruction
		dragon_fdc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
			: dragon_fdc_device_base(mconfig, DRAGON_FDC, tag, owner, clock)
		{
		}

	protected:
		// optional information overrides
		virtual const tiny_rom_entry *device_rom_region() const override
		{
			return ROM_NAME(dragon_fdc);
		}
	};
}

DEFINE_DEVICE_TYPE_PRIVATE(DRAGON_FDC, device_cococart_interface, dragon_fdc_device, "dragon_fdc", "Dragon FDC")


//**************************************************************************
//              PREMIER FDC
//**************************************************************************

ROM_START(premier_fdc)
	ROM_REGION(0x4000, "eprom", ROMREGION_ERASE00)
	ROM_LOAD_OPTIONAL("deltados.rom", 0x0000, 0x2000, CRC(149eb4dd) SHA1(eb686ce6afe63e4d4011b333a882ca812c69307f))
ROM_END

namespace
{
	class premier_fdc_device : public premier_fdc_device_base
	{
	public:
		// construction/destruction
		premier_fdc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
			: premier_fdc_device_base(mconfig, PREMIER_FDC, tag, owner, clock)
		{
		}

	protected:
		// optional information overrides
		virtual const tiny_rom_entry *device_rom_region() const override
		{
			return ROM_NAME(premier_fdc);
		}
	};
};

DEFINE_DEVICE_TYPE_PRIVATE(PREMIER_FDC, device_cococart_interface, premier_fdc_device, "premier_fdc", "Premier FDC")


//**************************************************************************
//              SDTANDY FDC
//**************************************************************************

ROM_START(sdtandy_fdc)
	ROM_REGION(0x4000, "eprom", ROMREGION_ERASE00)
	ROM_LOAD_OPTIONAL("sdtandy.rom", 0x0000, 0x2000, CRC(5d7779b7) SHA1(ca03942118f2deab2f6c8a89b8a4f41f2d0b94f1))
ROM_END

namespace
{
	class sdtandy_fdc_device : public dragon_fdc_device_base
	{
	public:
		// construction/destruction
		sdtandy_fdc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
			: dragon_fdc_device_base(mconfig, SDTANDY_FDC, tag, owner, clock)
		{
		}

	protected:
		// optional information overrides
		virtual const tiny_rom_entry *device_rom_region() const override
		{
			return ROM_NAME(sdtandy_fdc);
		}
	};
}

DEFINE_DEVICE_TYPE_PRIVATE(SDTANDY_FDC, device_cococart_interface, sdtandy_fdc_device, "sdtandy_fdc", "SDTANDY FDC")