summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/a2bus/corvfdc02.cpp
blob: 3367d18384ed3238500d2069a9295f07884143bf (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
// license:BSD-3-Clause
// copyright-holders:R. Belmont
/*********************************************************************

    corvfdc02.c

    Implemention of the Corvus Systems CORVUS02 floppy controller
    aka the "Buffered Floppy Controller"

    Boot PROM 0.8 says 8" SSDD or 5.25" DSDD; we stick with 5.25" here
    and let the FDC01 handle 8".

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

#include "emu.h"
#include "corvfdc02.h"
#include "formats/concept_dsk.h"

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

//**************************************************************************
//  GLOBAL VARIABLES
//**************************************************************************

DEFINE_DEVICE_TYPE(A2BUS_CORVFDC02, a2bus_corvfdc02_device, "crvfdc02", "Corvus Systems Buffered Floppy Controller")

#define FDC02_ROM_REGION    "fdc02_rom"
#define FDC02_FDC_TAG       "fdc02_fdc"

FLOPPY_FORMATS_MEMBER( a2bus_corvfdc02_device::corv_floppy_formats )
	FLOPPY_CONCEPT_525DSDD_FORMAT,
	FLOPPY_IMD_FORMAT
FLOPPY_FORMATS_END

static void corv_floppies(device_slot_interface &device)
{
	device.option_add("525dsqd", FLOPPY_525_QD);
}

ROM_START( fdc02 )
	ROM_REGION(0x20, FDC02_ROM_REGION, 0)
	ROM_LOAD( "bfc00.bin", 0x000000, 0x000020, CRC(98d1a765) SHA1(d27c3c6921e1bb3778a3f78decf106275bc0add1) )
ROM_END

/***************************************************************************
    FUNCTION PROTOTYPES
***************************************************************************/

//-------------------------------------------------
//  device_add_mconfig - add device configuration
//-------------------------------------------------

MACHINE_CONFIG_START(a2bus_corvfdc02_device::device_add_mconfig)
	MCFG_UPD765A_ADD(FDC02_FDC_TAG, true, false)
	MCFG_UPD765_INTRQ_CALLBACK(WRITELINE(a2bus_corvfdc02_device, intrq_w))
	MCFG_UPD765_DRQ_CALLBACK(WRITELINE(a2bus_corvfdc02_device, drq_w))
	MCFG_FLOPPY_DRIVE_ADD(FDC02_FDC_TAG":0", corv_floppies, "525dsqd", a2bus_corvfdc02_device::corv_floppy_formats)
	MCFG_FLOPPY_DRIVE_ADD(FDC02_FDC_TAG":1", corv_floppies, "525dsqd", a2bus_corvfdc02_device::corv_floppy_formats)
	MCFG_FLOPPY_DRIVE_ADD(FDC02_FDC_TAG":2", corv_floppies, "525dsqd", a2bus_corvfdc02_device::corv_floppy_formats)
	MCFG_FLOPPY_DRIVE_ADD(FDC02_FDC_TAG":3", corv_floppies, "525dsqd", a2bus_corvfdc02_device::corv_floppy_formats)
MACHINE_CONFIG_END

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

const tiny_rom_entry *a2bus_corvfdc02_device::device_rom_region() const
{
	return ROM_NAME( fdc02 );
}

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

a2bus_corvfdc02_device::a2bus_corvfdc02_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, type, tag, owner, clock),
	device_a2bus_card_interface(mconfig, *this),
	m_fdc(*this, FDC02_FDC_TAG),
	m_con1(*this, FDC02_FDC_TAG":0"),
	m_con2(*this, FDC02_FDC_TAG":1"),
	m_con3(*this, FDC02_FDC_TAG":2"),
	m_con4(*this, FDC02_FDC_TAG":3"), m_rom(nullptr), m_fdc_local_status(0), m_fdc_local_command(0), m_bufptr(0), m_curfloppy(nullptr), m_in_drq(false), m_timer(nullptr)
{
}

a2bus_corvfdc02_device::a2bus_corvfdc02_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	a2bus_corvfdc02_device(mconfig, A2BUS_CORVFDC02, tag, owner, clock)
{
}

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

void a2bus_corvfdc02_device::device_start()
{
	m_rom = device().machine().root_device().memregion(this->subtag(FDC02_ROM_REGION).c_str())->base();

	m_timer = timer_alloc(0);

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

void a2bus_corvfdc02_device::device_reset()
{
	m_fdc_local_status = 2;
	m_fdc_local_command = 0;
	m_curfloppy = nullptr;
	m_in_drq = false;
	m_timer->adjust(attotime::never);
}

void a2bus_corvfdc02_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
	m_fdc->tc_w(true);
	m_fdc->tc_w(false);
}

/*-------------------------------------------------
    read_c0nx - called for reads from this card's c0nx space
-------------------------------------------------*/

uint8_t a2bus_corvfdc02_device::read_c0nx(uint8_t offset)
{
	switch (offset)
	{
		case 0: // 765 FIFO
			return m_fdc->fifo_r();

		case 1: // 765 MSR
			return m_fdc->msr_r();

		case 2: // buffer address
			return (m_bufptr>>1) & 0xff;

		case 3:
//          printf("Read buffer @ %x = %02x\n", m_bufptr, m_buffer[m_bufptr]);
			return m_buffer[m_bufptr--];

		case 4: // local status
			if (m_curfloppy)
			{
				m_fdc_local_status &= ~(1 | 0x40);
				m_fdc_local_status |= m_curfloppy->dskchg_r() ? 1 : 0;
				m_fdc_local_status |= m_curfloppy->ready_r() ? 0x40 : 0;
			}
			return m_fdc_local_status;
			break;
	}

	return 0xff;
}


/*-------------------------------------------------
    write_c0nx - called for writes to this card's c0nx space
-------------------------------------------------*/

void a2bus_corvfdc02_device::write_c0nx(uint8_t offset, uint8_t data)
{
	floppy_image_device *floppy = nullptr;

	switch (offset)
	{
		case 0:    // FDC FIFO write
			m_fdc->fifo_w(data);
			break;

		case 1:    // FDC ???
			break;

		case 2: // buffer address
			m_bufptr = (data << 1) | (data & 1);
//          printf("%02x to buffer address yields %x\n", data, m_bufptr);
			break;

		case 3: // buffer write
//          printf("%02x to buffer[%x]\n", data, m_bufptr);
			m_buffer[m_bufptr--] = data;
			break;

		case 4:     // LOCAL COMMAND REG
			m_fdc_local_command = data;

			// drive select enabled?
			if (data & 4)
			{
				switch (data & 3)
				{
					case 0:
						floppy = m_con1 ? m_con1->get_device() : nullptr;
						break;
					case 1:
						floppy = m_con2 ? m_con2->get_device() : nullptr;
						break;
					case 2:
						floppy = m_con3 ? m_con3->get_device() : nullptr;
						break;
					case 3:
						floppy = m_con4 ? m_con4->get_device() : nullptr;
						break;
				}

				logerror("corvfdc02: selecting drive %d: %p\n", data & 3, (void *) floppy);

				if (floppy != m_curfloppy)
				{
					m_fdc->set_floppy(floppy);
					m_curfloppy = floppy;
				}
			}

			if (m_curfloppy != nullptr)
			{
				// motor control (active low)
				m_curfloppy->mon_w((data & 8) ? 1 : 0);
//              printf("Cur drive %p motor %s\n", m_curfloppy, (data & 8) ? "OFF" : "ON");
			}

			if (data & 0x80)
			{
//              printf("Reset NEC765\n");
				m_fdc->reset();
			}
			break;
	}
}

/*-------------------------------------------------
    read_cnxx - called for reads from this card's cnxx space
-------------------------------------------------*/

uint8_t a2bus_corvfdc02_device::read_cnxx(uint8_t offset)
{
	return m_rom[offset & 0x1f];
}

WRITE_LINE_MEMBER(a2bus_corvfdc02_device::intrq_w)
{
	if (state)
	{
		m_fdc_local_status &= ~2;   // indicate IRQ occurred
		if (m_fdc_local_command & 0x20)
		{
			raise_slot_irq();
		}
	}
	else
	{
		m_fdc_local_status |= 2;    // clear IRQ
		lower_slot_irq();
	}
}

WRITE_LINE_MEMBER(a2bus_corvfdc02_device::drq_w)
{
	if (state)
	{
		// pseudo-DMA direction?
		if (m_fdc_local_command & 0x40)
		{
			m_buffer[m_bufptr] = m_fdc->dma_r();
//          printf("DMA %02x to buffer[%x]\n", m_buffer[m_bufptr], m_bufptr);

			if (!m_bufptr)
			{
				m_timer->adjust(attotime::zero);
			}

			m_bufptr--;
			m_bufptr &= 0x1ff;
		}
		else
		{
			m_fdc->dma_w(m_buffer[m_bufptr++]);
			m_bufptr &= 0x1ff;
		}
	}
}