summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/pc8801/pc8801_31.cpp
blob: 1250342bc9ad15ebf5c4e8476c07ee6bdc5d1637 (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
// license:BSD-3-Clause
// copyright-holders:Angelo Salese
/**************************************************************************************************

    NEC PC8801-31 CD-ROM I/F

    TODO:
    - Interface with PC8801-30 (the actual CD drive);
    - Make it a slot option for PC-8801MA (does it have same ROM as the internal MC version?)

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

#include "emu.h"
#include "pc8801_31.h"


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


// device type definition
DEFINE_DEVICE_TYPE(PC8801_31, pc8801_31_device, "pc8801_31", "NEC PC8801-31 CD-ROM I/F")


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


//-------------------------------------------------
//  pc8801_31_device - constructor
//-------------------------------------------------


pc8801_31_device::pc8801_31_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock)
	: device_t(mconfig, PC8801_31, tag, owner, clock)
	, m_scsibus(*this, "scsi")
	, m_rom_bank_cb(*this)
	, m_sel_off_timer(nullptr)
{
}


//-------------------------------------------------
//  device_add_mconfig - device-specific machine
//  configuration addiitons
//-------------------------------------------------

static void pc8801_scsi_devices(device_slot_interface &device)
{
	// TODO: PC8801-30
	device.option_add("cdrom", NSCSI_CDROM);
	// TODO: at very least HxC Floppy emulator option
}

void pc8801_31_device::device_add_mconfig(machine_config &config)
{
	NSCSI_BUS(config, m_scsibus);
	NSCSI_CONNECTOR(config, "scsi:0", pc8801_scsi_devices, "cdrom");
	NSCSI_CONNECTOR(config, "scsi:1", pc8801_scsi_devices, nullptr);
	NSCSI_CONNECTOR(config, "scsi:2", pc8801_scsi_devices, nullptr);
	NSCSI_CONNECTOR(config, "scsi:3", pc8801_scsi_devices, nullptr);
	NSCSI_CONNECTOR(config, "scsi:4", pc8801_scsi_devices, nullptr);
	NSCSI_CONNECTOR(config, "scsi:5", pc8801_scsi_devices, nullptr);
	NSCSI_CONNECTOR(config, "scsi:6", pc8801_scsi_devices, nullptr);
	NSCSI_CONNECTOR(config, "scsi:7", pc8801_scsi_devices, nullptr);

	SOFTWARE_LIST(config, "cd_list").set_original("pc8801_cdrom");
}


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

void pc8801_31_device::device_resolve_objects()
{
	m_rom_bank_cb.resolve();
}


void pc8801_31_device::device_start()
{
	m_sel_off_timer = timer_alloc(FUNC(pc8801_31_device::select_off), this);

	save_item(NAME(m_clock_hb));
	save_item(NAME(m_cddrive_enable));
}


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


void pc8801_31_device::device_reset()
{
	m_clock_hb = false;
	m_cddrive_enable = false;

	m_sel_off_timer->adjust(attotime::never);
}

TIMER_CALLBACK_MEMBER(pc8801_31_device::select_off)
{
	m_scsibus->ctrl_w(0, 0, nscsi_device::S_SEL);
}



//**************************************************************************
//  READ/WRITE HANDLERS
//**************************************************************************


void pc8801_31_device::amap(address_map &map)
{
	map(0x00, 0x00).rw(FUNC(pc8801_31_device::scsi_status_r), FUNC(pc8801_31_device::scsi_sel_w));
	map(0x01, 0x01).lrw8(
		NAME([this]() { return m_scsibus->data_r(); }),
		NAME([this](u8 data) { m_scsibus->data_w(0, data); })
	);
	map(0x04, 0x04).w(FUNC(pc8801_31_device::scsi_reset_w));
	map(0x08, 0x08).rw(FUNC(pc8801_31_device::clock_r), FUNC(pc8801_31_device::volume_control_w));
	map(0x09, 0x09).rw(FUNC(pc8801_31_device::id_r), FUNC(pc8801_31_device::rom_bank_w));
	map(0x0b, 0x0b).r(FUNC(pc8801_31_device::volume_meter_r));
	map(0x0d, 0x0d).r(FUNC(pc8801_31_device::volume_meter_r));
	map(0x0f, 0x0f).lw8(
		NAME([this](u8 data) { m_cddrive_enable = bool(BIT(data, 0)); })
	);
}

/*
 * I/O Port $90
 *
 * x--- ---- BSY
 * -x-- ---- REQ
 * --x- ---- MSG
 * ---x ---- CD
 * ---- x--- IO
 * ---- ---x CD-ROM drive status (from $9f)
 *
 * BIOS expects a bit 6 to go high then checks if (MSG | CD | IO) == CD.
 * It eventually moves on floppy/BASIC fallback if this check fails.
 *
 */
u8 pc8801_31_device::scsi_status_r()
{
	u32 ctrl = m_scsibus->ctrl_r();
	return (
		(ctrl & nscsi_device::S_BSY ? 0x80 : 0x00) |
		(ctrl & nscsi_device::S_REQ ? 0x40 : 0x00) |
		(ctrl & nscsi_device::S_MSG ? 0x20 : 0x00) |
		(ctrl & nscsi_device::S_CTL ? 0x10 : 0x00) |
		(ctrl & nscsi_device::S_INP ? 0x08 : 0x00) |
		m_cddrive_enable
	);
}

void pc8801_31_device::scsi_sel_w(u8 data)
{
	bool sel_on = bool(BIT(data, 0));
	m_scsibus->ctrl_w(
		0,
		sel_on ? nscsi_device::S_SEL : 0,
		nscsi_device::S_SEL
	);

	// TODO: timing
	if (sel_on)
		m_sel_off_timer->adjust(attotime::from_usec(10));
}

/*
 * I/O Port $98
 *
 * x--- ---- (r/o?) device clock heartbeat?
 * ---- -xxx (w/o?) CD-DA volume control (not unlike PCE)
 * ---- -00x enable
 * ---- -01x disable
 * ---- -100 fade-in short (100 msec)
 * ---- -101 fade-in long (1500 msec)
 * ---- -110 fade-out short (100 msec)
 * ---- -111 fade-out long (1500 msec)
 *
 */
u8 pc8801_31_device::clock_r()
{
	// Checked 11 times on POST before giving up, definitely some kind of timing-based CD-ROM or board identification.
	// If check passes the BIOS goes on with the "CD-System initialize\n[Space]->CD player" screen.
	// A similar PCE pattern is mapped as "CDDA data select".
	// There's no way to load floppies with this always on unless STOP key is held on boot (which doesn't look convenient).
	// TODO: identify source and verify how much fast this really is.
	m_clock_hb ^= 1;
	return m_clock_hb << 7;
}

void pc8801_31_device::volume_control_w(u8 data)
{
	logerror("%s: volume_w %02x\n", machine().describe_context(), data);
}

/*
 * I/O Port $94
 *
 * x--- ---- to SCSI RST
 *
 */
void pc8801_31_device::scsi_reset_w(u8 data)
{
	m_scsibus->ctrl_w(
		0,
		BIT(data, 7) ? nscsi_device::S_RST : 0,
		nscsi_device::S_RST
	);
}

u8 pc8801_31_device::id_r()
{
	// PC=A9AA CD-Player checks this against 0xcd, branches with $71 bit 0 set (N88 extended ROM bank)
	// Identifier for a 8801MC?
	logerror("%s: id_r\n", machine().describe_context());
	return 0xcd;
}

/*
 * I/O Port $99
 *
 * ---x ---- CD-ROM BIOS bank
 * ---- ---x CD-ROM E-ROM bank (?)
 *
 */
void pc8801_31_device::rom_bank_w(u8 data)
{
	m_rom_bank_cb(bool(BIT(data, 4)));

	if (data & 0xef)
		logerror("%s: rom_bank_w %02x\n", machine().describe_context(), data);
}

/*
 * I/O Port $9b / $9d CDDA Left/Right output meter
 *
 * ?xxx xx-- L/R metering
 *
 * M88 hardwires this as 0x3c, CD player shows arbitrary clamp with
 * timed flicker on ticks depending on the value read.
 * i.e. a value of 0x70 will make the uppermost tick to flicker more than 0x74,
 * while 0x7c won't flicker at all
 *
 */
// TODO: templatìze, measure via real HW tests
u8 pc8801_31_device::volume_meter_r()
{
	return 0;
}