summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/spectrum/beta.cpp
blob: 1fa6ab60bdffd83e2daa51bc5bd66604d5a37b3a (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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
// license:BSD-3-Clause
// copyright-holders:Nigel Barnes, David Haywood
/*********************************************************************

    Technology Research Beta Disk interface & clones
    these are designed for the 48k Spectrum models

    There are multiple versions of this

    'hand made' PCB with V2 ROM:
     - possible prototype / low production run
     - 4k ROM
     - FORMAT, COPY etc. must be loaded from a disk to be used
     - disks are password protected
     - uses FD1771 disk controller
     - disk format: FM, 7 or 10 256-byte sectors per track, 2 system sectors
     - supports up to 3 drives
       https://www.youtube.com/watch?v=gSJIuZjbFYs

    Original Beta Disk release with V3 ROM:
     - same features as above
     - uses a 1793 controller
     - disk format: MFM, 16 256-byte sectors per track, 9 system sectors
     - supports up to 4 drives

    Re-release dubbed "Beta Disk plus" with V4 ROM:
     - many operations moved into a larger capacity (8k) ROM rather
       than requiring a utility disk
     - uses a 1793 controller
     - adds 'magic button' to dump the running state of the machine
       to disk
     - disk password system removed

    Many clones exist, some specific to the various Spectrum clones.
    (not yet added)

    Original Beta Disk (V2) clones
     - Sandy FDD2 SP-DOS (match 2.0 ROM, only name text and checksum was changed)

    Original Beta Disk (V3) clones
     - AC DOS P.Z.APINA

    Beta Disk plus (V4) clones
     - CAS DOS Cheyenne Advanced System
     - CBI-95
     - SYNCHRON IDS91
     - SYNCHRON IDS2001ne
     - ARCADE AR-20
     - Vision Desktop Betadisk

    Some units also exist that allow population of both V3 and V4
    ROM types with a switch (unofficial, for compatibility?)

    ---

    NOTE:

    ROMs really need verifying, real dumps appear to be bitswapped
    on original boards, so we're using those ones where possible,
    however sizes are unconfirmed (some sources state that the data
    is duplicated across the 16k in ROM, others state it just mirrors
    in memory) and some might be modified or bad.

    beta128.cpp could be modified to expand on this, as it builds
    on the features of the betaplus, but for now I've kept them
    separate as the enable / disable mechanisms are different and
    remaining mappings of devices unconfirmed

    ---

    Based on older BDI schematics, it seems the logic is like:

    memory access 0x3CXX (any type of access: code or data, read or write) -> temporary use BDI ROM (NOT permanent latch/switch like in beta128)
    memory access <0x4000 area and BDI ROM_latch==true -> use BDI ROM

    IO write to port 0bxxxxxx00 -> D7 master_latch, 0=enable, 1=disable

    while master_latch is enabled access to regular Spectrum IO is blocked (output /IORQ forced to 1) but enabled BDI ports:

    IO write to port 0b1xxxx111 ->
      V2: D7 BDI ROM_latch (0=enable, 1=disble), D4 - FDC HLT, D3 - SIDE, D0-2 - floppy drive select (bitmask, active low).
      V3-V4: D7 BDI ROM_latch (0=enable, 1=disble), D6 - FDC DDEN, D4 - SIDE, D3 - FDC HLT, D2 - FDC /MR (reset), D0-1 - floppy drive select (binary value).
    IO read port 0b1xxxx111 <- D7 - FDC INTRQ, D6 - FDC DRQ
    IO read/write ports 0b0YYxx111 - access FDC ports YY

    So mostly the same as beta128, except for new BDI ROM_latch bit


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

#include "emu.h"
#include "beta.h"


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

DEFINE_DEVICE_TYPE(SPECTRUM_BETAV2,   spectrum_betav2_device, "spectrum_betav2", "TR Beta Disk Interface (older, FD1771 based)")
DEFINE_DEVICE_TYPE(SPECTRUM_BETAV3,   spectrum_betav3_device, "spectrum_betav3", "TR Beta Disk Interface (newer, FD1793 based)")
DEFINE_DEVICE_TYPE(SPECTRUM_BETAPLUS, spectrum_betaplus_device, "spectrum_betaplus", "TR Beta Disk Plus Interface")

//-------------------------------------------------
//  SLOT_INTERFACE( beta_floppies )
//-------------------------------------------------

static void beta_floppies(device_slot_interface &device)
{
	device.option_add("525qd", FLOPPY_525_QD);
}

//-------------------------------------------------
//  floppy_format_type floppy_formats
//-------------------------------------------------

FLOPPY_FORMATS_MEMBER(spectrum_betav2_device::floppy_formats)
	FLOPPY_TRD_FORMAT
FLOPPY_FORMATS_END

//-------------------------------------------------
//  ROM( beta )
//-------------------------------------------------

ROM_START(betav2)
	ROM_REGION(0x4000, "rom", 0)
	ROM_DEFAULT_BIOS("trd20")
	ROM_SYSTEM_BIOS(0, "trd20", "TR-DOS v2.0")
	ROMX_LOAD("trd20.bin", 0x0000, 0x1000, CRC(dd269fb2) SHA1(ab394a19461f314fffd592645a273b85e76fadec), ROM_BIOS(0))
	ROM_RELOAD(0x1000,0x1000)
	ROM_RELOAD(0x2000,0x1000)
	ROM_RELOAD(0x3000,0x1000)
ROM_END


// there is an alt set CRC(48f9149f) SHA1(52774757096fdc93ea94c55306481f6f41204e96) with differences at 30e, 3cd, 404, 7bd, it appears to be a bad dump
// 30c : call $2acd        call $6acd
// 3cc : ld hl, $5b00      ld hl, $5b01
// 402 : call $2acd        call $6bcd
// 7bd : ld ($5d02), hl    inc hl, ld (bc),a, ld e,l

// the Profisoft version appears to be different code, maybe based on a different revision or even modified hw?

ROM_START(betav3)
	ROM_REGION(0x4000, "rom", 0)
	ROM_DEFAULT_BIOS("trd30")
	ROM_SYSTEM_BIOS(0, "trd30", "TR-DOS v3.0 (set 1)")
	ROMX_LOAD("trd30.bin", 0x0000, 0x1000, CRC(c814179d) SHA1(b617ab59639beaa7b5d8e5b4e4a543a8eb0217c8), ROM_BIOS(0))
	ROM_RELOAD(0x1000,0x1000)
	ROM_RELOAD(0x2000,0x1000)
	ROM_RELOAD(0x3000,0x1000)
//  ROM_SYSTEM_BIOS(1, "trd30a", "TR-DOS v3.0 (set 2)")
//  ROMX_LOAD("trd30_alt.bin", 0x0000, 0x1000, CRC(48f9149f) SHA1(52774757096fdc93ea94c55306481f6f41204e96), ROM_BIOS(1))
//  ROM_RELOAD(0x1000,0x1000)
//  ROM_RELOAD(0x2000,0x1000)
//  ROM_RELOAD(0x3000,0x1000)
	ROM_SYSTEM_BIOS(1, "trd30p", "TR-DOS v3.0 (set 2, Profisoft)") // is this a clone device?
	ROMX_LOAD("trd30ps.bin", 0x0000, 0x1000, CRC(b0f175a3) SHA1(ac95bb4d89072224deef58a1655e8029f811a7fa), ROM_BIOS(1))
	ROM_RELOAD(0x1000,0x1000)
	ROM_RELOAD(0x2000,0x1000)
	ROM_RELOAD(0x3000,0x1000)
ROM_END

// some sources indicate these should be 16kb roms with both halves duplicated, others suggest the same but with the first byte being 0x00 instead (maybe an issue with the dumping)
// there are also some '412' unscrambled dumps with most of the data in the mirror regions as 0xff (maybe official, maybe from clone devices that should be treated separately?)
ROM_START(betaplus)
	ROM_REGION(0x4000, "rom", 0)
	ROM_DEFAULT_BIOS("trd409")
	ROM_SYSTEM_BIOS(0, "trd409", "TR-DOS v4.09")
	ROMX_LOAD("trd409.bin", 0x0000, 0x2000, CRC(18365bdc) SHA1(a0e7c80905423c54bd497575026ea8821061175a), ROM_BIOS(0))
	ROM_RELOAD(0x2000,0x2000)
	ROM_SYSTEM_BIOS(1, "trd411", "TR-DOS v4.11")
	ROMX_LOAD("trd411.bin", 0x0000, 0x2000, CRC(26902902) SHA1(cb90fc31bf62d5968730db23a600344338e31e7e), ROM_BIOS(1))
	ROM_RELOAD(0x2000,0x2000)
ROM_END


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

void spectrum_betav2_device::device_add_mconfig_base(machine_config& config)
{
	FLOPPY_CONNECTOR(config, "fdc:0", beta_floppies, "525qd", spectrum_betav2_device::floppy_formats).enable_sound(true);
	FLOPPY_CONNECTOR(config, "fdc:1", beta_floppies, "525qd", spectrum_betav2_device::floppy_formats).enable_sound(true);
	FLOPPY_CONNECTOR(config, "fdc:2", beta_floppies, nullptr, spectrum_betav2_device::floppy_formats).enable_sound(true);
	FLOPPY_CONNECTOR(config, "fdc:3", beta_floppies, nullptr, spectrum_betav2_device::floppy_formats).enable_sound(true);

	// passthru
	SPECTRUM_EXPANSION_SLOT(config, m_exp, spectrum_expansion_devices, nullptr);
	m_exp->irq_handler().set(DEVICE_SELF_OWNER, FUNC(spectrum_expansion_slot_device::irq_w));
	m_exp->nmi_handler().set(DEVICE_SELF_OWNER, FUNC(spectrum_expansion_slot_device::nmi_w));
}

void spectrum_betav2_device::device_add_mconfig(machine_config &config)
{
	FD1771(config, m_fdc, 4_MHz_XTAL / 4);
	m_fdc->hld_wr_callback().set(FUNC(spectrum_betav2_device::fdc_hld_w));

	device_add_mconfig_base(config);
}

void spectrum_betav3_device::device_add_mconfig(machine_config& config)
{
	FD1793(config, m_fdc, 4_MHz_XTAL / 4);
	m_fdc->hld_wr_callback().set(FUNC(spectrum_betav3_device::fdc_hld_w));

	device_add_mconfig_base(config);
}

const tiny_rom_entry *spectrum_betav2_device::device_rom_region() const
{
	return ROM_NAME(betav2);
}

const tiny_rom_entry *spectrum_betav3_device::device_rom_region() const
{
	return ROM_NAME(betav3);
}

const tiny_rom_entry *spectrum_betaplus_device::device_rom_region() const
{
	return ROM_NAME(betaplus);
}


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

//-------------------------------------------------
//  spectrum_betav2_device - constructor
//-------------------------------------------------

spectrum_betav2_device::spectrum_betav2_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, type, tag, owner, clock)
	, device_spectrum_expansion_interface(mconfig, *this)
	, m_rom(*this, "rom")
	, m_fdc(*this, "fdc")
	, m_floppy(*this, "fdc:%u", 0)
	, m_exp(*this, "exp")
	, m_control(0)
{
}

spectrum_betav2_device::spectrum_betav2_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: spectrum_betav2_device(mconfig, SPECTRUM_BETAV2, tag, owner, clock)
{
}

spectrum_betav3_device::spectrum_betav3_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
	: spectrum_betav2_device(mconfig, type, tag, owner, clock)
{
}

spectrum_betav3_device::spectrum_betav3_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: spectrum_betav3_device(mconfig, SPECTRUM_BETAV3, tag, owner, clock)
{
}

spectrum_betaplus_device::spectrum_betaplus_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
	: spectrum_betav3_device(mconfig, type, tag, owner, clock)
{
}

spectrum_betaplus_device::spectrum_betaplus_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: spectrum_betaplus_device(mconfig, SPECTRUM_BETAPLUS, tag, owner, clock)
{
}


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

void spectrum_betav2_device::device_start()
{
	save_item(NAME(m_romcs));
	save_item(NAME(m_control));
	save_item(NAME(m_motor_active));

#if 0 // we do this in realtime instead
	for (int i = 0; i < m_rom->bytes(); i++)
	{
		uint8_t* rom = m_rom->base();

		rom[i] = bitswap<8>(rom[i],0,6,5,4,3,2,1,7);
	}
#endif
}

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

void spectrum_betav2_device::device_reset()
{
	// always paged in on boot? (no mode switch like beta128)
	m_romcs = 1;
	m_control = 0;
	m_masterportdisable = 1;
}

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

READ_LINE_MEMBER(spectrum_betav2_device::romcs)
{
	return m_romcs | m_exp->romcs();
}

void spectrum_betav2_device::fetch(offs_t offset)
{
	if (!machine().side_effects_disabled())
	{
		if ((offset & 0xff00) == 0x3c00)
			m_romcs = 1;
		else
			m_romcs = 0;

		if (!(m_control & 0x80))
		{
			if (offset < 0x4000)
				m_romcs = 1;
		}
	}
}

void spectrum_betav2_device::pre_opcode_fetch(offs_t offset)
{
	m_exp->pre_opcode_fetch(offset);
	fetch(offset);
}

void spectrum_betav2_device::pre_data_fetch(offs_t offset)
{
	m_exp->pre_data_fetch(offset);
	fetch(offset);
}

uint8_t spectrum_betav2_device::iorq_r(offs_t offset)
{
	uint8_t data = 0xff;

	if (!m_masterportdisable)
	{
		switch (offset & 0xe7)
		{
		case 0x07: case 0x27: case 0x47: case 0x67:
			data = m_fdc->read((offset >> 5) & 0x03);
			break;

		case 0x87: case 0xa7 : case 0xc7 : case 0xe7 :
			data &= 0x3f; // actually open bus
			data |= m_fdc->drq_r() ? 0x40 : 0;
			data |= m_fdc->intrq_r() ? 0x80 : 0;
			break;
		}
	}
	else
		data = m_exp->iorq_r(offset);

	return data;
}

void spectrum_betav2_device::iorq_w(offs_t offset, uint8_t data)
{
	if ((offset & 3) == 0)
		m_masterportdisable = data & 0x80;

	if (!m_masterportdisable)
	{
		switch (offset & 0x87)
		{
		case 0x07:
			m_fdc->write((offset >> 5) & 0x03, data);
			break;

		case 0x87:
			m_control = data;

			floppy_image_device* floppy = nullptr;
			for (int i = 0; i < 3; i++)
				if (!(data & (1 << i)))
				{
					floppy = m_floppy[i]->get_device();
					break;
				}

			m_fdc->set_floppy(floppy);
			if (floppy)
				floppy->ss_w(BIT(data, 3) ? 0 : 1);

			m_fdc->hlt_w(BIT(data, 4));

			motors_control();
			break;
		}
	}
	else
		m_exp->iorq_w(offset, data);
}

void spectrum_betav3_device::iorq_w(offs_t offset, uint8_t data)
{
	if ((offset & 3) == 0)
		m_masterportdisable = data & 0x80;

	if (!m_masterportdisable)
	{
		switch (offset & 0x87)
		{
		case 0x07:
			m_fdc->write((offset >> 5) & 0x03, data);
			break;

		case 0x87:
			m_control = data;

			floppy_image_device* floppy = m_floppy[data & 3]->get_device();

			m_fdc->set_floppy(floppy);
			if (floppy)
				floppy->ss_w(BIT(data, 4) ? 0 : 1);
			m_fdc->dden_w(BIT(data, 6));

			m_fdc->hlt_w(BIT(data, 3));

			m_fdc->mr_w(BIT(data, 2));
			motors_control();
			break;
		}
	}
	else
		m_exp->iorq_w(offset, data);
}

uint8_t spectrum_betav2_device::mreq_r(offs_t offset)
{
	uint8_t data = 0xff;

	if (m_romcs)
	{
		data = m_rom->base()[offset & 0x3fff];
		data = bitswap<8>(data,0,6,5,4,3,2,1,7); // proper dumps have bits 0 and 7 swapped?
	}

	if (m_exp->romcs())
		data &= m_exp->mreq_r(offset);

	return data;
}

void spectrum_betav2_device::mreq_w(offs_t offset, uint8_t data)
{
	if (m_exp->romcs())
		m_exp->mreq_w(offset, data);
}

void spectrum_betav2_device::fdc_hld_w(int state)
{
	m_fdc->set_force_ready(state); // HLD connected to RDY pin
	m_motor_active = state;
	motors_control();
}

void spectrum_betav2_device::motors_control()
{
	for (int i = 0; i < 3; i++)
	{
		floppy_image_device* floppy = m_floppy[i]->get_device();
		if (!floppy)
			continue;
		if (m_motor_active && !(m_control & (1 << i)))
			floppy->mon_w(CLEAR_LINE);
		else
			floppy->mon_w(ASSERT_LINE);
	}
}

void spectrum_betav3_device::motors_control()
{
	for (int i = 0; i < 4; i++)
	{
		floppy_image_device* floppy = m_floppy[i]->get_device();
		if (!floppy)
			continue;
		if (m_motor_active && (m_control & 3) == i)
			floppy->mon_w(CLEAR_LINE);
		else
			floppy->mon_w(ASSERT_LINE);
	}
}

// Betaplus has a 'magic button' for dumping RAM

INPUT_PORTS_START(betaplus)
	PORT_START("BUTTON") // don't use F12, it clashes with the 'exit from debugger' button
	PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_BUTTON1) PORT_NAME("Magic Button") PORT_CODE(KEYCODE_MINUS_PAD) PORT_CHANGED_MEMBER(DEVICE_SELF, spectrum_betaplus_device, magic_button, 0)
INPUT_PORTS_END

ioport_constructor spectrum_betaplus_device::device_input_ports() const
{
	return INPUT_PORTS_NAME(betaplus);
}

INPUT_CHANGED_MEMBER(spectrum_betaplus_device::magic_button)
{
	if (newval && !oldval)
	{
		m_slot->nmi_w(ASSERT_LINE);
		m_romcs = 1;
		m_control &= ~0x80;
	}
	else
	{
		m_slot->nmi_w(CLEAR_LINE);
	}
}