summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/machine/compclr_flp.c
blob: 08067a53cefddcc7f35e87f9e64036527a765ac0 (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
// license:BSD-3-Clause
// copyright-holders:Curt Coder
/**********************************************************************

    Compucolor Floppy Disk Drive emulation

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

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

#include "compclr_flp.h"



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

const device_type COMPUCOLOR_FLOPPY_PORT = &device_creator<compucolor_floppy_port_device>;
const device_type COMPUCOLOR_FLOPPY = &device_creator<compucolor_floppy_device>;


//-------------------------------------------------
//  SLOT_INTERFACE( compucolor_floppy_port_devices )
//-------------------------------------------------

SLOT_INTERFACE_START( compucolor_floppy_port_devices )
	SLOT_INTERFACE("floppy", COMPUCOLOR_FLOPPY)
SLOT_INTERFACE_END


//-------------------------------------------------
//  FLOPPY_FORMATS( floppy_formats )
//-------------------------------------------------

FLOPPY_FORMATS_MEMBER( compucolor_floppy_device::floppy_formats )
	FLOPPY_CCVF_FORMAT
FLOPPY_FORMATS_END


//-------------------------------------------------
//  SLOT_INTERFACE( compucolor_floppies )
//-------------------------------------------------

static SLOT_INTERFACE_START( compucolor_floppies )
	SLOT_INTERFACE_INTERNAL( "525sssd", FLOPPY_525_SSSD )
SLOT_INTERFACE_END


//-------------------------------------------------
//  MACHINE_DRIVER( compucolor_floppy )
//-------------------------------------------------

static MACHINE_CONFIG_FRAGMENT( compucolor_floppy )
	MCFG_FLOPPY_DRIVE_ADD("floppy", compucolor_floppies, "525sssd", compucolor_floppy_device::floppy_formats)
MACHINE_CONFIG_END


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

machine_config_constructor compucolor_floppy_device::device_mconfig_additions() const
{
	return MACHINE_CONFIG_NAME( compucolor_floppy );
}



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

//-------------------------------------------------
//  device_compucolor_floppy_port_interface - constructor
//-------------------------------------------------

device_compucolor_floppy_port_interface::device_compucolor_floppy_port_interface(const machine_config &mconfig, device_t &device)
	: device_serial_port_interface(mconfig, device)
{
}


//-------------------------------------------------
//  compucolor_floppy_port_device - constructor
//-------------------------------------------------

compucolor_floppy_port_device::compucolor_floppy_port_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
	: serial_port_device(mconfig, COMPUCOLOR_FLOPPY_PORT, "Compucolor Floppy Port", tag, owner, clock, "rs232", __FILE__)
{
}


//-------------------------------------------------
//  compucolor_floppy_device - constructor
//-------------------------------------------------

compucolor_floppy_device::compucolor_floppy_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
	: device_t(mconfig, COMPUCOLOR_FLOPPY, "Compucolor floppy", tag, owner, clock, "compclr_flp", __FILE__),
		device_compucolor_floppy_port_interface(mconfig, *this),
		m_floppy(*this, "floppy:525sssd"),
		m_period(attotime::from_hz(9600*8))
{
	m_owner = dynamic_cast<compucolor_floppy_port_device *>(this->owner());
}


//-------------------------------------------------
//  device_config_complete - 
//-------------------------------------------------

void compucolor_floppy_port_device::device_config_complete()
{
	serial_port_device::device_config_complete();

	m_dev = dynamic_cast<device_compucolor_floppy_port_interface *>(get_card_device());
}


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

void compucolor_floppy_port_device::device_start()
{
	serial_port_device::device_start();
}


void compucolor_floppy_device::device_start()
{
	// allocate timer
	m_timer = timer_alloc();
	m_timer->adjust(attotime::from_hz(9600*8));

	// state saving
	save_item(NAME(m_stp));
	save_item(NAME(m_sel));
}


//-------------------------------------------------
//  device_timer - handle timer events
//-------------------------------------------------

void compucolor_floppy_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
	if (!m_sel && !m_rw)
	{
		m_owner->out_rx(read_bit());
	}
}


//-------------------------------------------------
//  tx_w -
//-------------------------------------------------

void compucolor_floppy_device::tx(UINT8 state)
{
	if (!m_sel && m_rw)
	{
		write_bit(state);
	}
}


//-------------------------------------------------
//  rw_w -
//-------------------------------------------------

void compucolor_floppy_device::rw_w(int state)
{
	m_rw = state;

	if (m_rw)
	{
		m_owner->out_rx(1);
	}
}


//-------------------------------------------------
//  stepper_w -
//-------------------------------------------------

void compucolor_floppy_device::stepper_w(UINT8 data)
{
	if (!m_sel)
	{
		if ((m_stp == 1 && data == 4) || (m_stp == 2 && data == 1) || (m_stp == 4 && data == 2))
		{
			// step in
			m_floppy->dir_w(1);
			m_floppy->stp_w(0);
			m_floppy->stp_w(1);
		}
		else if ((m_stp == 1 && data == 2) || (m_stp == 2 && data == 4) || (m_stp == 4 && data == 1))
		{
			// step out
			m_floppy->dir_w(0);
			m_floppy->stp_w(0);
			m_floppy->stp_w(1);
		}
	}

	m_stp = data;
}


//-------------------------------------------------
//  select_w -
//-------------------------------------------------

void compucolor_floppy_device::select_w(int state)
{
	m_floppy->mon_w(state);

	m_sel = state;

	if (m_sel)
	{
		m_owner->out_rx(1);
	}
}


//-------------------------------------------------
//  read_bit -
//-------------------------------------------------

bool compucolor_floppy_device::read_bit()
{
	attotime edge = m_floppy ? m_floppy->get_next_transition(machine().time()) : attotime::never;
	attotime next = m_ctime + m_period;

	if (edge.is_never() || edge >= next)
	{
		return 0;
	}

	return 1;
}


//-------------------------------------------------
//  write_bit -
//-------------------------------------------------

void compucolor_floppy_device::write_bit(bool bit)
{
	// TODO
}