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

    Acorn Cassette Interface

    Part No. 100,001

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


#include "emu.h"
#include "cass.h"


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

DEFINE_DEVICE_TYPE(ACORN_CASS, acorn_cass_device, "acorn_cass", "Acorn Cassette Interface")


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

MACHINE_CONFIG_START(acorn_cass_device::device_add_mconfig)
	/* sound hardware */
	SPEAKER(config, "mono").front_center();
	WAVE(config, "wave", "cassette").add_route(ALL_OUTPUTS, "mono", 0.25);

	CASSETTE(config, "cassette", 0);
	MCFG_TIMER_DRIVER_ADD_PERIODIC("cass_c", acorn_cass_device, cass_c, attotime::from_hz(4800))
	MCFG_TIMER_DRIVER_ADD_PERIODIC("cass_p", acorn_cass_device, cass_p, attotime::from_hz(40000))
MACHINE_CONFIG_END


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

//-------------------------------------------------
//  acorn_cass_device - constructor
//-------------------------------------------------

acorn_cass_device::acorn_cass_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, ACORN_CASS, tag, owner, clock)
	, device_acorn_bus_interface(mconfig, *this)
	, m_cass(*this, "cassette")
{
}


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

void acorn_cass_device::device_start()
{
}


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

WRITE_LINE_MEMBER(acorn_cass_device::cass_w)
{
	m_cass_state = state;
}

TIMER_DEVICE_CALLBACK_MEMBER(acorn_cass_device::cass_c)
{
	m_cass_data[3]++;

	if (m_cass_state != m_cassold)
	{
		m_cass_data[3] = 0;
		m_cassold = m_cass_state;
	}

	if (m_cass_state)
		m_cass->output(BIT(m_cass_data[3], 0) ? -1.0 : +1.0); // 2400Hz
	else
		m_cass->output(BIT(m_cass_data[3], 1) ? -1.0 : +1.0); // 1200Hz
}

TIMER_DEVICE_CALLBACK_MEMBER(acorn_cass_device::cass_p)
{
	/* cassette - turn 1200/2400Hz to a bit */
	m_cass_data[1]++;
	uint8_t cass_ws = (m_cass->input() > +0.03) ? 1 : 0;

	if (cass_ws != m_cass_data[0])
	{
		m_cass_data[0] = cass_ws;
		//m_bus->write_pb7(m_cass_data[1] < 12);
		m_cass_data[1] = 0;
	}
}