summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/machine/mc1502_fdc.c
blob: 6fbf87681f7184ce691e72588f84050f726e7ee3 (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
// license:BSD-3-Clause
// copyright-holders:XXX
/**********************************************************************

    Electronika MC 1502 FDC device

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

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

#include "mc1502_fdc.h"

#include "cpu/i86/i86.h"
#include "formats/dsk_dsk.h"
#include "formats/pc_dsk.h"

#define VERBOSE_DBG 0

#define DBG_LOG(N,M,A) \
	do { \
		if(VERBOSE_DBG>=N) \
		{ \
			if( M ) \
				logerror("%11.6f: %-24s",machine().time().as_double(),(char*)M ); \
			logerror A; \
		} \
	} while (0)


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

const device_type MC1502_FDC = &device_creator<mc1502_fdc_device>;

static DECLARE_READ8_DEVICE_HANDLER(mc1502_FDC_r);
static DECLARE_WRITE8_DEVICE_HANDLER(mc1502_FDC_w);

FLOPPY_FORMATS_MEMBER( mc1502_fdc_device::floppy_formats )
	FLOPPY_PC_FORMAT,
	FLOPPY_DSK_FORMAT
FLOPPY_FORMATS_END

static SLOT_INTERFACE_START( mc1502_floppies )
	SLOT_INTERFACE( "525qd", FLOPPY_525_QD )
SLOT_INTERFACE_END

static MACHINE_CONFIG_FRAGMENT( mc1502_fdc )
	MCFG_FD1793x_ADD("fdc", XTAL_16MHz / 16)
	MCFG_FLOPPY_DRIVE_ADD("fdc:0", mc1502_floppies, "525qd", mc1502_fdc_device::floppy_formats)
	MCFG_FLOPPY_DRIVE_ADD("fdc:1", mc1502_floppies, "525qd", mc1502_fdc_device::floppy_formats)
MACHINE_CONFIG_END

//-------------------------------------------------
//  ROM( mc1502_fdc )
//-------------------------------------------------

ROM_START( mc1502_fdc )
ROM_END


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

machine_config_constructor mc1502_fdc_device::device_mconfig_additions() const
{
	return MACHINE_CONFIG_NAME( mc1502_fdc );
}

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

const rom_entry *mc1502_fdc_device::device_rom_region() const
{
	return ROM_NAME( mc1502_fdc );
}


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

TIMER_CALLBACK_MEMBER(mc1502_fdc_device::motor_callback)
{
	m_fdc->subdevice<floppy_connector>("0")->get_device()->mon_w(ASSERT_LINE);
	m_fdc->subdevice<floppy_connector>("1")->get_device()->mon_w(ASSERT_LINE);
	motor_on = 0;
}

UINT8 mc1502_fdc_device::mc1502_wd17xx_aux_r()
{
	UINT8 data;

	data = 0;

	return data;
}

void mc1502_fdc_device::mc1502_wd17xx_aux_w(UINT8 data)
{
	floppy_image_device *floppy0 = m_fdc->subdevice<floppy_connector>("0")->get_device();
	floppy_image_device *floppy1 = m_fdc->subdevice<floppy_connector>("1")->get_device();
	floppy_image_device *floppy = ((data & 0x10)?floppy1:floppy0);

	// master reset
	if((data & 1) == 0)
		m_fdc->reset();

	m_fdc->set_floppy(floppy);

	// SIDE ONE
	floppy->ss_w((data & 2)?1:0);

	// bits 2, 3 -- motor on (drive 0, 1)
	floppy0->mon_w(!(data & 4));
	floppy1->mon_w(!(data & 8));

	if (data & 12) {
		motor_timer->adjust(attotime::from_msec( 3000 ));
		motor_on = 1;
	}

}

/*
 * Accesses to this port block (halt the CPU until DRQ, INTRQ or MOTOR ON)
 */
UINT8 mc1502_fdc_device::mc1502_wd17xx_drq_r()
{
	cpu_device *maincpu = machine().device<cpu_device>("maincpu");

	if (!m_fdc->drq_r() && !m_fdc->intrq_r()) {
		// fake cpu wait by resetting PC one insn back
		maincpu->set_state_int(I8086_IP, maincpu->state_int(I8086_IP) - 1);
		maincpu->set_input_line(INPUT_LINE_HALT, ASSERT_LINE);
	}

	return m_fdc->drq_r();
}

UINT8 mc1502_fdc_device::mc1502_wd17xx_motor_r()
{
	return motor_on;
}

void mc1502_fdc_device::mc1502_fdc_irq_drq(bool state)
{
	cpu_device *maincpu = machine().device<cpu_device>("maincpu");

	if(state)
		maincpu->set_input_line(INPUT_LINE_HALT, CLEAR_LINE);
}

static READ8_DEVICE_HANDLER( mc1502_FDC_r )
{
	UINT8 data = 0xff;
	mc1502_fdc_device *fdc  = downcast<mc1502_fdc_device *>(device);

	switch( offset )
	{
		case 0: data = fdc->mc1502_wd17xx_aux_r();     break;
		case 8: data = fdc->mc1502_wd17xx_drq_r();     break;
		case 10: data = fdc->mc1502_wd17xx_motor_r();   break;
	}

	return data;
}

static WRITE8_DEVICE_HANDLER( mc1502_FDC_w )
{
	mc1502_fdc_device *fdc  = downcast<mc1502_fdc_device *>(device);

	switch( offset )
	{
		case 0: fdc->mc1502_wd17xx_aux_w(data);    break;
	}
}

//-------------------------------------------------
//  mc1502_fdc_device - constructor
//-------------------------------------------------

mc1502_fdc_device::mc1502_fdc_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
	device_t(mconfig, MC1502_FDC, "MC-1502 floppy", tag, owner, clock, "mc1502_fdc", __FILE__),
	device_isa8_card_interface( mconfig, *this ),
	m_fdc(*this, "fdc")
{
}

#if 0
	AM_RANGE(0x004c, 0x004c) AM_READWRITE(mc1502_wd17xx_aux_r, mc1502_wd17xx_aux_w)
	AM_RANGE(0x004d, 0x004d) AM_READ(mc1502_wd17xx_motor_r)
	AM_RANGE(0x004e, 0x004e) AM_READ(mc1502_wd17xx_drq_r)           // blocking read!
	AM_RANGE(0x0048, 0x004b) AM_DEVREADWRITE("vg93", fd1793_t, read, write)

	AM_RANGE(0x0100, 0x0100) AM_READWRITE(mc1502_wd17xx_aux_r, mc1502_wd17xx_aux_w)
	AM_RANGE(0x0108, 0x0108) AM_READ(mc1502_wd17xx_drq_r)           // blocking read!
	AM_RANGE(0x010a, 0x010a) AM_READ(mc1502_wd17xx_motor_r)
	AM_RANGE(0x010c, 0x010f) AM_DEVREADWRITE("vg93", fd1793_t, read, write)
#endif

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

void mc1502_fdc_device::device_start()
{
	set_isa_device();

	// BIOS 5.0, 5.2
	m_isa->install_device(0x010c, 0x010f, 0, 0,
		READ8_DEVICE_DELEGATE(m_fdc, fd1793_t, read),
		WRITE8_DEVICE_DELEGATE(m_fdc, fd1793_t, write) );
	m_isa->install_device(this, 0x0100, 0x010b, 0, 0, FUNC(mc1502_FDC_r), FUNC(mc1502_FDC_w) );
	// BIOS 5.31, 5.33
/*
    m_isa->install_device(0x010c, 0x010f, 0, 0,
        READ8_DEVICE_DELEGATE(m_fdc, fd1793_t, read),
        WRITE8_DEVICE_DELEGATE(m_fdc, fd1793_t, write) );
    m_isa->install_device(this, 0x0100, 0x010b, 0, 0, FUNC(mc1502_FDC_r), FUNC(mc1502_FDC_w) );
*/
	m_fdc->setup_drq_cb(fd1793_t::line_cb(FUNC(mc1502_fdc_device::mc1502_fdc_irq_drq), this));
	m_fdc->setup_intrq_cb(fd1793_t::line_cb(FUNC(mc1502_fdc_device::mc1502_fdc_irq_drq), this));

	motor_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mc1502_fdc_device::motor_callback),this));
	motor_on = 0;
}


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

void mc1502_fdc_device::device_reset()
{
}