summaryrefslogtreecommitdiffstats
path: root/src/devices/bus/msx_slot/disk.h
blob: d619cb1aa25c3745c1066dd974a62fe659bc9d97 (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
// license:BSD-3-Clause
// copyright-holders:Wilbert Pol
#ifndef MAME_BUS_MSX_SLOT_DISK_H
#define MAME_BUS_MSX_SLOT_DISK_H

#pragma once

#include "bus/msx_slot/slot.h"
#include "bus/msx_slot/rom.h"
#include "machine/wd_fdc.h"
#include "machine/upd765.h"
#include "imagedev/flopdrv.h"
#include "imagedev/floppy.h"


/* WD FDC accessed through 7ffx */
DECLARE_DEVICE_TYPE(MSX_SLOT_DISK1, msx_slot_disk1_device)
/* WD FDC accessed through 7fbx */
DECLARE_DEVICE_TYPE(MSX_SLOT_DISK2, msx_slot_disk2_device)
/* TC8566 accessed through 7ff8-7fff */
DECLARE_DEVICE_TYPE(MSX_SLOT_DISK3, msx_slot_disk3_device)
/* TC8566 accessed through 7ff0-7ff7 (used in Turob-R, untested) */
DECLARE_DEVICE_TYPE(MSX_SLOT_DISK4, msx_slot_disk4_device)
/* WD FDC accessed through i/o ports 0xd0-0xd4 */
DECLARE_DEVICE_TYPE(MSX_SLOT_DISK5, msx_slot_disk5_device)
/* WD FDC accessed through 7ff0-7ff? (used in Toshiba HX34) */
DECLARE_DEVICE_TYPE(MSX_SLOT_DISK6, msx_slot_disk6_device)


#define MCFG_MSX_SLOT_DISK1_ADD(_tag, _startpage, _numpages, _region, _offset, _fdc_tag, _floppy0_tag, _floppy1_tag) \
	MCFG_MSX_INTERNAL_SLOT_ADD(_tag, MSX_SLOT_DISK1, _startpage, _numpages) \
	downcast<msx_slot_rom_device &>(*device).set_rom_start(_region, _offset); \
	downcast<msx_slot_disk_device &>(*device).set_fdc_tag(_fdc_tag); \
	downcast<msx_slot_disk_device &>(*device).set_floppy0_tag(_floppy0_tag); \
	downcast<msx_slot_disk_device &>(*device).set_floppy1_tag(_floppy1_tag);

#define MCFG_MSX_SLOT_DISK2_ADD(_tag, _startpage, _numpages, _region, _offset, _fdc_tag, _floppy0_tag, _floppy1_tag) \
	MCFG_MSX_INTERNAL_SLOT_ADD(_tag, MSX_SLOT_DISK2, _startpage, _numpages) \
	downcast<msx_slot_rom_device &>(*device).set_rom_start(_region, _offset); \
	downcast<msx_slot_disk_device &>(*device).set_fdc_tag(_fdc_tag); \
	downcast<msx_slot_disk_device &>(*device).set_floppy0_tag(_floppy0_tag); \
	downcast<msx_slot_disk_device &>(*device).set_floppy1_tag(_floppy1_tag);

#define MCFG_MSX_SLOT_DISK3_ADD(_tag, _startpage, _numpages, _region, _offset, _fdc_tag, _floppy0_tag, _floppy1_tag) \
	MCFG_MSX_INTERNAL_SLOT_ADD(_tag, MSX_SLOT_DISK3, _startpage, _numpages) \
	downcast<msx_slot_rom_device &>(*device).set_rom_start(_region, _offset); \
	downcast<msx_slot_disk_device &>(*device).set_fdc_tag(_fdc_tag); \
	downcast<msx_slot_disk_device &>(*device).set_floppy0_tag(_floppy0_tag); \
	downcast<msx_slot_disk_device &>(*device).set_floppy1_tag(_floppy1_tag);

#define MCFG_MSX_SLOT_DISK4_ADD(_tag, _startpage, _numpages, _region, _offset, _fdc_tag, _floppy0_tag, _floppy1_tag) \
	MCFG_MSX_INTERNAL_SLOT_ADD(_tag, MSX_SLOT_DISK4, _startpage, _numpages) \
	downcast<msx_slot_rom_device &>(*device).set_rom_start(_region, _offset); \
	downcast<msx_slot_disk_device &>(*device).set_fdc_tag(_fdc_tag); \
	downcast<msx_slot_disk_device &>(*device).set_floppy0_tag(_floppy0_tag); \
	downcast<msx_slot_disk_device &>(*device).set_floppy1_tag(_floppy1_tag);

#define MCFG_MSX_SLOT_DISK5_ADD(_tag, _startpage, _numpages, _region, _offset, _fdc_tag, _floppy0_tag, _floppy1_tag, _floppy2_tag, _floppy3_tag) \
	MCFG_MSX_INTERNAL_SLOT_ADD(_tag, MSX_SLOT_DISK5, _startpage, _numpages) \
	downcast<msx_slot_rom_device &>(*device).set_rom_start(_region, _offset); \
	downcast<msx_slot_disk_device &>(*device).set_fdc_tag(_fdc_tag); \
	downcast<msx_slot_disk_device &>(*device).set_floppy0_tag(_floppy0_tag); \
	downcast<msx_slot_disk_device &>(*device).set_floppy1_tag(_floppy1_tag); \
	downcast<msx_slot_disk_device &>(*device).set_floppy2_tag(_floppy2_tag); \
	downcast<msx_slot_disk_device &>(*device).set_floppy3_tag(_floppy3_tag);

#define MCFG_MSX_SLOT_DISK6_ADD(_tag, _startpage, _numpages, _region, _offset, _fdc_tag, _floppy0_tag, _floppy1_tag) \
	MCFG_MSX_INTERNAL_SLOT_ADD(_tag, MSX_SLOT_DISK6, _startpage, _numpages) \
	downcast<msx_slot_rom_device &>(*device).set_rom_start(_region, _offset); \
	downcast<msx_slot_disk_device &>(*device).set_fdc_tag(_fdc_tag); \
	downcast<msx_slot_disk_device &>(*device).set_floppy0_tag(_floppy0_tag); \
	downcast<msx_slot_disk_device &>(*device).set_floppy1_tag(_floppy1_tag);


class msx_slot_disk_device : public msx_slot_rom_device
{
public:
	// configuration helpers
	void set_fdc_tag(const char *tag) { m_fdc_tag = tag; }
	void set_floppy0_tag(const char *tag) { m_floppy0_tag = tag; }
	void set_floppy1_tag(const char *tag) { m_floppy1_tag = tag; }
	void set_floppy2_tag(const char *tag) { m_floppy2_tag = tag; }
	void set_floppy3_tag(const char *tag) { m_floppy3_tag = tag; }

protected:
	msx_slot_disk_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);

	virtual void device_start() override;

	floppy_connector *m_floppy0;
	floppy_connector *m_floppy1;
	floppy_connector *m_floppy2;
	floppy_connector *m_floppy3;
	floppy_image_device *m_floppy;

	const char *m_fdc_tag;
	const char *m_floppy0_tag;
	const char *m_floppy1_tag;
	const char *m_floppy2_tag;
	const char *m_floppy3_tag;
};


class msx_slot_wd_disk_device : public msx_slot_disk_device
{
protected:
	msx_slot_wd_disk_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);

	virtual void device_start() override;

	wd_fdc_analog_device_base *m_fdc;
};


class msx_slot_tc8566_disk_device : public msx_slot_disk_device
{
protected:
	msx_slot_tc8566_disk_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);

	virtual void device_start() override;

	tc8566af_device *m_fdc;
};


class msx_slot_disk1_device : public msx_slot_wd_disk_device
{
public:
	msx_slot_disk1_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	virtual DECLARE_READ8_MEMBER(read) override;
	virtual DECLARE_WRITE8_MEMBER(write) override;

protected:
	virtual void device_start() override;
	virtual void device_reset() override;

	void post_load();

private:
	uint8_t m_side_control;
	uint8_t m_control;

	void set_control(uint8_t data);
	void set_side_control(uint8_t data);
};


class msx_slot_disk2_device : public msx_slot_wd_disk_device
{
public:
	msx_slot_disk2_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	virtual DECLARE_READ8_MEMBER(read) override;
	virtual DECLARE_WRITE8_MEMBER(write) override;

protected:
	virtual void device_start() override;
	virtual void device_reset() override;

	void post_load();

private:
	uint8_t m_control;

	void set_control(uint8_t data);
};


class msx_slot_disk3_device : public msx_slot_tc8566_disk_device
{
public:
	msx_slot_disk3_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	virtual DECLARE_READ8_MEMBER(read) override;
	virtual DECLARE_WRITE8_MEMBER(write) override;
};


class msx_slot_disk4_device : public msx_slot_tc8566_disk_device
{
public:
	msx_slot_disk4_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	virtual DECLARE_READ8_MEMBER(read) override;
	virtual DECLARE_WRITE8_MEMBER(write) override;
};


class msx_slot_disk5_device : public msx_slot_wd_disk_device
{
public:
	msx_slot_disk5_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	DECLARE_READ8_MEMBER(io_read);
	DECLARE_WRITE8_MEMBER(io_write);

protected:
	virtual void device_start() override;
	virtual void device_reset() override;

	void post_load();

private:
	uint8_t m_control;

	void set_control(uint8_t control);
};


class msx_slot_disk6_device : public msx_slot_wd_disk_device
{
public:
	msx_slot_disk6_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	virtual DECLARE_READ8_MEMBER(read) override;
	virtual DECLARE_WRITE8_MEMBER(write) override;

protected:
	virtual void device_start() override;
	virtual void device_reset() override;

	void post_load();

private:
	uint8_t m_side_motor;
	uint8_t m_drive_select0;
	uint8_t m_drive_select1;

	void set_side_motor();
	void select_drive();
};


#endif // MAME_BUS_MSX_SLOT_DISK_H