summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/bbc/1mhzbus/ide.cpp
blob: 103066ecc8142d3ff24b3218fe44e609b4f446e3 (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
// license:BSD-3-Clause
// copyright-holders:Nigel Barnes
/**********************************************************************

    RetroClinic BBC 8-bit IDE Interface

    http://www.retroclinic.com/acorn/bbcide/bbcide.htm
    http://www.retroclinic.com/acorn/kitide1mhz/kitide1mhz.htm

    Sprow BeebIDE 16-bit IDE Interface for the BBC series

    http://www.sprow.co.uk/bbc/beebide.htm

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


#include "emu.h"
#include "ide.h"


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

DEFINE_DEVICE_TYPE(BBC_IDE8, bbc_ide8_device, "bbc_ide8", "RetroClinic BBC 8-bit IDE Interface");
DEFINE_DEVICE_TYPE(BBC_BEEBIDE, bbc_beebide_device, "bbc_beebide", "Sprow BeebIDE 16-bit IDE Interface");


//-------------------------------------------------
//  INPUT_PORTS( beebide )
//-------------------------------------------------

INPUT_PORTS_START(beebide)
	PORT_START("LINKS")
	PORT_CONFNAME(0x01, 0x00, "Interrupt Enable")
	PORT_CONFSETTING(0x00, DEF_STR(No))
	PORT_CONFSETTING(0x01, DEF_STR(Yes))
	PORT_CONFNAME(0x10, 0x00, "Address Selection")
	PORT_CONFSETTING(0x00, "&FC40-&FC4F")
	PORT_CONFSETTING(0x10, "&FC50-&FC5F")
INPUT_PORTS_END


//-------------------------------------------------
//  input_ports - device-specific input ports
//-------------------------------------------------

ioport_constructor bbc_beebide_device::device_input_ports() const
{
	return INPUT_PORTS_NAME(beebide);
}

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

void bbc_ide8_device::device_add_mconfig(machine_config& config)
{
	ATA_INTERFACE(config, m_ide).options(ata_devices, "hdd", nullptr, false);
}

void bbc_beebide_device::device_add_mconfig(machine_config& config)
{
	ATA_INTERFACE(config, m_ide).options(ata_devices, "hdd", nullptr, false);
	m_ide->irq_handler().set(FUNC(bbc_beebide_device::irq_w));

	BBC_1MHZBUS_SLOT(config, m_1mhzbus, DERIVED_CLOCK(1, 1), bbc_1mhzbus_devices, nullptr);
	m_1mhzbus->irq_handler().set(DEVICE_SELF_OWNER, FUNC(bbc_1mhzbus_slot_device::irq_w));
	m_1mhzbus->nmi_handler().set(DEVICE_SELF_OWNER, FUNC(bbc_1mhzbus_slot_device::nmi_w));
}


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

//-------------------------------------------------
//  bbc_ide_device - constructor
//-------------------------------------------------

bbc_ide8_device::bbc_ide8_device(const machine_config& mconfig, const char* tag, device_t* owner, const XTAL &clock)
	: device_t(mconfig, BBC_IDE8, tag, owner, clock)
	, device_bbc_1mhzbus_interface(mconfig, *this)
	, m_ide(*this, "ide")
{
}

bbc_beebide_device::bbc_beebide_device(const machine_config& mconfig, const char* tag, device_t* owner, const XTAL &clock)
	: device_t(mconfig, BBC_BEEBIDE, tag, owner, clock)
	, device_bbc_1mhzbus_interface(mconfig, *this)
	, m_ide(*this, "ide")
	, m_1mhzbus(*this, "1mhzbus")
	, m_links(*this, "LINKS")
	, m_ide_data(0)
{
}


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

void bbc_beebide_device::device_start()
{
	save_item(NAME(m_ide_data));
}


//**************************************************************************
//  IMPLEMENTATION
//**************************************************************************

uint8_t bbc_ide8_device::fred_r(offs_t offset)
{
	uint8_t data = 0xff;

	switch (offset & 0xf8)
	{
	case 0x40:
		data = m_ide->cs0_r(offset & 0x07, 0xff);
		break;
	}

	return data;
}

void bbc_ide8_device::fred_w(offs_t offset, uint8_t data)
{
	switch (offset & 0xf8)
	{
	case 0x40:
		m_ide->cs0_w(offset & 0x07, data, 0xff);
		break;
	}
}


uint8_t bbc_beebide_device::fred_r(offs_t offset)
{
	uint8_t data = 0xff;

	if ((offset & 0x50) == ((m_links->read() & 0x10) | 0x40))
	{
		switch (offset & 0xe8)
		{
		case 0x40:
			if (offset & 0x07)
			{
				data = m_ide->cs0_r(offset & 0x07, 0xff);
			}
			else
			{
				m_ide_data = m_ide->cs0_r(offset & 0x07);
				data = m_ide_data & 0xff;
			}
			break;
		case 0x48:
			if (offset & 0x04)
			{
				data = m_ide->cs1_r(offset & 0x07, 0xff);
			}
			else
			{
				data = m_ide_data >> 8;
			}
			break;
		}
	}

	data &= m_1mhzbus->fred_r(offset);

	return data;
}

void bbc_beebide_device::fred_w(offs_t offset, uint8_t data)
{
	if ((offset & 0x50) == ((m_links->read() & 0x10) | 0x40))
	{
		switch (offset & 0xe8)
		{
		case 0x40:
			if (offset & 0x07)
			{
				m_ide->cs0_w(offset & 0x07, data, 0xff);
			}
			else
			{
				m_ide_data = (m_ide_data & 0xff00) | data;
				m_ide->cs0_w(offset & 0x07, m_ide_data);
			}
			break;
		case 0x48:
			if (offset & 0x04)
			{
				m_ide->cs1_w(offset & 0x07, data, 0xff);
			}
			else
			{
				m_ide_data = data << 8;
			}
			break;
		}
	}

	m_1mhzbus->fred_w(offset, data);
}

uint8_t bbc_beebide_device::jim_r(offs_t offset)
{
	return m_1mhzbus->jim_r(offset);
}

void bbc_beebide_device::jim_w(offs_t offset, uint8_t data)
{
	m_1mhzbus->jim_w(offset, data);
}

WRITE_LINE_MEMBER(bbc_beebide_device::irq_w)
{
	if (BIT(m_links->read(), 0))
	{
		m_slot->irq_w(state);
	}
}