summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/acorn/atom/mdcr.cpp
blob: ee69a7aaaeaaa9a03972b51448c80b5f9f9757ff (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
// license:BSD-3-Clause
// copyright-holders:Nigel Barnes
/**********************************************************************

    Acorn Atom MDCR

    https://site.acornatom.nl/hardware/storage/mdcr/

    Error messages:
      101 No cassette
      102 End of tape
      103 Nothing on tape
      104 No preamble
      105 Incorrect load
      106 Write protect
      107 File not found

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

#include "emu.h"
#include "mdcr.h"

#include "machine/mdcr.h"


namespace {

class atom_mdcr_device : public device_t, public device_acorn_bus_interface
{
public:
	static constexpr feature_type imperfect_features() { return feature::TAPE; }

	atom_mdcr_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
		: device_t(mconfig, ATOM_MDCR, tag, owner, clock)
		, device_acorn_bus_interface(mconfig, *this)
		, m_mdcr(*this, "mdcr")
	{
	}

protected:
	// device_t overrides
	virtual void device_start() override ATTR_COLD { }

	// optional information overrides
	virtual void device_add_mconfig(machine_config &config) override ATTR_COLD;

	virtual uint8_t pb_r() override;
	virtual void pb_w(uint8_t data) override;
	virtual void write_cb2(int state) override;

private:
	required_device<mdcr_device> m_mdcr;

	void cb1_w(int state);

	bool m_output_enable;
};


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

void atom_mdcr_device::device_add_mconfig(machine_config &config)
{
	MDCR(config, m_mdcr);
	m_mdcr->rdc_cb().set(FUNC(atom_mdcr_device::cb1_w));
}


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

uint8_t atom_mdcr_device::pb_r()
{
	uint8_t data = 0x00;

	data |= m_mdcr->rda() << 0;
	data |= m_mdcr->wen() << 1;
	data |= m_mdcr->bet() << 6;
	data |= m_mdcr->cip() << 7;

	return data;
}

void atom_mdcr_device::pb_w(uint8_t data)
{
	m_output_enable = !BIT(data, 4);

	if (m_output_enable)
	{
		m_mdcr->fwd(BIT(data, 2));
		m_mdcr->rev(BIT(data, 3));
		m_mdcr->wdc(BIT(data, 5));
	}
}

void atom_mdcr_device::write_cb2(int state)
{
	if (m_output_enable)
	{
		m_mdcr->wda(state);
	}
}

void atom_mdcr_device::cb1_w(int state)
{
	m_bus->cb1_w(state);
}

} // anonymous namespace


DEFINE_DEVICE_TYPE_PRIVATE(ATOM_MDCR, device_acorn_bus_interface, atom_mdcr_device, "atom_mdcr", "Atom MDCR")