summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/machine/concept_exp.c
blob: 5c9f506d38098bdf18d381f34db1fefa528352f6 (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
/**********************************************************************

 Corvus Concept expansion port emulation

 Copyright MESS Team.
 Visit http://mamedev.org for licensing and usage restrictions.


 FIXME: Concept expansion ports should just use the Apple II Bus device!
 The code below is outdated and inaccurate!

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

#include "machine/concept_exp.h"

// FDC controller
#include "imagedev/flopdrv.h"
#include "formats/basicdsk.h"

// HDC controller
#include "imagedev/harddriv.h"

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

// device type definition
const device_type CONCEPT_EXP_PORT = &device_creator<concept_exp_port_device>;


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

//-------------------------------------------------
//  concept_exp_port_device - constructor
//-------------------------------------------------

concept_exp_port_device::concept_exp_port_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
					device_t(mconfig, CONCEPT_EXP_PORT, "Corvus Concept expansion port", tag, owner, clock, "concept_exp_port", __FILE__),
					device_slot_interface(mconfig, *this)
{
}


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

void concept_exp_port_device::device_start()
{
	m_card = dynamic_cast<concept_exp_card_device *>(get_card_device());
}


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

void concept_exp_port_device::device_reset()
{
}


READ8_MEMBER( concept_exp_port_device::reg_r )
{
	if (m_card)
		return m_card->reg_r(space, offset);

	return 0;
}

WRITE8_MEMBER( concept_exp_port_device::reg_w )
{
	if (m_card != NULL)
		m_card->reg_w(space, offset, data);
}

READ8_MEMBER( concept_exp_port_device::rom_r )
{
	if (m_card)
		return m_card->reg_r(space, offset);

	return 0;
}

WRITE8_MEMBER( concept_exp_port_device::rom_w )
{
	if (m_card != NULL)
		m_card->reg_w(space, offset, data);
}


//**************************************************************************
//  CARD INTERFACE
//**************************************************************************

//-------------------------------------------------
//  concept_exp_card_device - constructor
//-------------------------------------------------

concept_exp_card_device::concept_exp_card_device(const machine_config &mconfig, device_t &device)
					: device_slot_card_interface(mconfig, device)
{
}


//**************************************************************************
//  STUB EMULATION OF CARD DEVICES
//**************************************************************************

// FIXME: clean these up and move them in separate sources if suitable...

const device_type CONCEPT_FDC = &device_creator<concept_fdc_device>;
const device_type CONCEPT_HDC = &device_creator<concept_hdc_device>;

concept_fdc_device::concept_fdc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
					: device_t(mconfig, CONCEPT_FDC, "Corvus Concept FDC controller", tag, owner, clock, "concept_fdc", __FILE__),
						concept_exp_card_device( mconfig, *this )
{
}

concept_hdc_device::concept_hdc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
					: device_t(mconfig, CONCEPT_HDC, "Corvus Concept HDC controller", tag, owner, clock, "concept_hdc", __FILE__),
						concept_exp_card_device( mconfig, *this ),
						m_hdc(*this, "hdc")
{
}


// FDC Controller

enum
{
	LS_DRQ_bit      = 0,    // DRQ
	LS_INT_bit      = 1,    // INT
	LS_SS_bit       = 4,    // 1 if single-sided (floppy or drive?)
	LS_8IN_bit      = 5,    // 1 if 8" floppy drive?
	LS_DSKCHG_bit   = 6,    // 0 if disk changed, 1 if not
	LS_SD_bit       = 7,    // 1 if single density

	LS_DRQ_mask     = (1 << LS_DRQ_bit),
	LS_INT_mask     = (1 << LS_INT_bit),
	LS_SS_mask      = (1 << LS_SS_bit),
	LS_8IN_mask     = (1 << LS_8IN_bit),
	LS_DSKCHG_mask  = (1 << LS_DSKCHG_bit),
	LS_SD_mask      = (1 << LS_SD_bit)
};

enum
{
	LC_FLPSD1_bit   = 0,    // 0 if side 0 , 1 if side 1
	LC_DE0_bit      = 1,    // drive select bit 0
	LC_DE1_bit      = 4,    // drive select bit 1
	LC_MOTOROF_bit  = 5,    // 1 if motor to be turned off
	LC_FLP8IN_bit   = 6,    // 1 to select 8", 0 for 5"1/4 (which I knew what it means)
	LC_FMMFM_bit    = 7,    // 1 to select single density, 0 for double

	LC_FLPSD1_mask  = (1 << LC_FLPSD1_bit),
	LC_DE0_mask     = (1 << LC_DE0_bit),
	LC_DE1_mask     = (1 << LC_DE1_bit),
	LC_MOTOROF_mask = (1 << LC_MOTOROF_bit),
	LC_FLP8IN_mask  = (1 << LC_FLP8IN_bit),
	LC_FMMFM_mask   = (1 << LC_FMMFM_bit)
};

void concept_fdc_device::device_start()
{
	m_wd179x = subdevice<fd1793_device>("wd179x");

	save_item(NAME(m_fdc_local_status));
	save_item(NAME(m_fdc_local_command));
}


void concept_fdc_device::device_reset()
{
	m_fdc_local_status = 0;
	m_fdc_local_command = 0;
}


WRITE_LINE_MEMBER(concept_fdc_device::intrq_w)
{
	if (state)
		m_fdc_local_status |= LS_INT_mask;
	else
		m_fdc_local_status &= ~LS_INT_mask;
}

WRITE_LINE_MEMBER(concept_fdc_device::drq_w)
{
	if (state)
		m_fdc_local_status |= LS_DRQ_mask;
	else
		m_fdc_local_status &= ~LS_DRQ_mask;
}

const wd17xx_interface concept_wd17xx_interface =
{
	DEVCB_NULL,
	DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, concept_fdc_device, intrq_w),
	DEVCB_DEVICE_LINE_MEMBER(DEVICE_SELF_OWNER, concept_fdc_device, drq_w),
	{FLOPPY_0, FLOPPY_1, FLOPPY_2, FLOPPY_3}
};

READ8_MEMBER(concept_fdc_device::reg_r)
{
	switch (offset)
	{
		case  0:    // LOCAL STATUS REG
			return m_fdc_local_status;

		case  8:    // FDC STATUS REG
			return m_wd179x->status_r(space, offset);

		case  9:    // FDC TRACK REG
			return m_wd179x->track_r(space, offset);

		case 10:    // FDC SECTOR REG
			return m_wd179x->sector_r(space, offset);

		case 11:    // FDC DATA REG
			return m_wd179x->data_r(space, offset);
	}

	return 0;
}

WRITE8_MEMBER(concept_fdc_device::reg_w)
{
	int current_drive;

	switch (offset)
	{
		case 0:     // LOCAL COMMAND REG
			m_fdc_local_command = data;

			m_wd179x->set_side((data & LC_FLPSD1_mask) != 0);
			current_drive = ((data >> LC_DE0_bit) & 1) | ((data >> (LC_DE1_bit-1)) & 2);
			m_wd179x->set_drive(current_drive);
			/*motor_on = (data & LC_MOTOROF_mask) == 0;*/
			// floppy_drive_set_motor_state(floppy_get_device(machine(),  current_drive), (data & LC_MOTOROF_mask) == 0 ? 1 : 0);
			/*flp_8in = (data & LC_FLP8IN_mask) != 0;*/
			m_wd179x->dden_w(BIT(data, 7));
			floppy_drive_set_ready_state(floppy_get_device(machine(), current_drive), 1, 0);
			break;

		case  8:    // FDC COMMAMD REG
			m_wd179x->command_w(space, offset, data);
			break;

		case  9:    // FDC TRACK REG
			m_wd179x->track_w(space, offset, data);
			break;

		case 10:    // FDC SECTOR REG
			m_wd179x->sector_w(space, offset, data);
			break;

		case 11:    // FDC DATA REG
			m_wd179x->data_w(space, offset, data);
			break;
	}
}

READ8_MEMBER(concept_fdc_device::rom_r)
{
	static const UINT8 data[] = "CORVUS01";
	return (offset < 8) ? data[offset] : 0;
}


static LEGACY_FLOPPY_OPTIONS_START(concept)
#if 1
/* SSSD 8" */
LEGACY_FLOPPY_OPTION(concept, "img", "Corvus Concept 8\" SSSD disk image", basicdsk_identify_default, basicdsk_construct_default, NULL,
						HEADS([1])
						TRACKS([77])
						SECTORS([26])
						SECTOR_LENGTH([128])
						FIRST_SECTOR_ID([1]))
#elif 0
/* SSDD 8" (according to ROMs) */
LEGACY_FLOPPY_OPTION(concept, "img", "Corvus Concept 8\" SSDD disk image", basicdsk_identify_default, basicdsk_construct_default, NULL,
						HEADS([1])
						TRACKS([77])
						SECTORS([26])
						SECTOR_LENGTH([256])
						FIRST_SECTOR_ID([1]))
#elif 0
/* Apple II DSDD 5"1/4 (according to ROMs) */
LEGACY_FLOPPY_OPTION(concept, "img", "Corvus Concept Apple II 5\"1/4 DSDD disk image", basicdsk_identify_default, basicdsk_construct_default, NULL,
						HEADS([2])
						TRACKS([35])
						SECTORS([16])
						SECTOR_LENGTH([256])
						FIRST_SECTOR_ID([1]))
#elif 0
/* actual formats found */
LEGACY_FLOPPY_OPTION(concept, "img", "Corvus Concept 5\"1/4 DSDD disk image (256-byte sectors)", basicdsk_identify_default, basicdsk_construct_default, NULL,
						HEADS([2])
						TRACKS([80])
						SECTORS([16])
						SECTOR_LENGTH([256])
						FIRST_SECTOR_ID([1]))
#else
LEGACY_FLOPPY_OPTION(concept, "img", "Corvus Concept 5\"1/4 DSDD disk image (512-byte sectors)", basicdsk_identify_default, basicdsk_construct_default, NULL,
						HEADS([2])
						TRACKS([80])
						SECTORS([9])
						SECTOR_LENGTH([512])
						FIRST_SECTOR_ID([1]))
#endif
LEGACY_FLOPPY_OPTIONS_END

static const floppy_interface concept_floppy_interface =
{
	DEVCB_NULL,
	DEVCB_NULL,
	DEVCB_NULL,
	DEVCB_NULL,
	DEVCB_NULL,
	FLOPPY_STANDARD_5_25_DSHD,
	LEGACY_FLOPPY_OPTIONS_NAME(concept),
	NULL,
	NULL
};


static MACHINE_CONFIG_FRAGMENT( fdc )
	MCFG_FD1793_ADD("wd179x", concept_wd17xx_interface )
	MCFG_LEGACY_FLOPPY_4_DRIVES_ADD(concept_floppy_interface)
MACHINE_CONFIG_END

machine_config_constructor concept_fdc_device::device_mconfig_additions() const
{
	return MACHINE_CONFIG_NAME(fdc);
}


// HDC Controller

void concept_hdc_device::device_start()
{
}


void concept_hdc_device::device_reset()
{
}


// Handle reads against the Hard Disk Controller's onboard registers
READ8_MEMBER(concept_hdc_device::reg_r)
{
	switch (offset)
	{
		case 0:     // HDC Data Register
			return m_hdc->read(space, offset);

		case 1:     // HDC Status Register
			return m_hdc->status_r(space, offset);
	}

	return 0;
}

// Handle writes against the Hard Disk Controller's onboard registers
WRITE8_MEMBER(concept_hdc_device::reg_w)
{
	switch (offset)
	{
		case 0:     // HDC Data Register
			m_hdc->write(space, offset, data);
			break;
	}
}

// Handle reads agsint the Hard Disk Controller's onboard ROM
READ8_MEMBER(concept_hdc_device::rom_r)
{
	static const UINT8 data[8] = { 0xa9, 0x20, 0xa9, 0x00, 0xa9, 0x03, 0xa9, 0x3c };            /* Same as Apple II */
	return (offset < 8) ? data[offset] : 0;
}



static MACHINE_CONFIG_FRAGMENT( hdc )
	MCFG_DEVICE_ADD("hdc", CORVUS_HDC, 0)
	MCFG_HARDDISK_ADD( "harddisk1" )
MACHINE_CONFIG_END

machine_config_constructor concept_hdc_device::device_mconfig_additions() const
{
	return MACHINE_CONFIG_NAME(hdc);
}