summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/sound/mm5837.cpp
blob: ac48a5401946cf481c9f30dc4ed5a872e2784e62 (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
// license: GPL-2.0+
// copyright-holders: Dirk Best
/***************************************************************************

    National Semiconductor MM5837

    Digital Noise Source

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

#include "emu.h"
#include "mm5837.h"


//**************************************************************************
//  CONSTEXPR DEFINITIONS
//**************************************************************************

constexpr int mm5837_device::m_frequency[];


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

DEFINE_DEVICE_TYPE(MM5837, mm5837_device, "mm5837", "MM5837 Digital Noise Source")


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

//-------------------------------------------------
//  mm5837_device - constructor
//-------------------------------------------------

mm5837_device::mm5837_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, MM5837, tag, owner, clock),
	m_output_cb(*this),
	m_vdd(0),
	m_timer(nullptr),
	m_shift(0)
{
}

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

void mm5837_device::device_start()
{
	// resolve callbacks
	m_output_cb.resolve_safe();

	// get timer
	m_timer = timer_alloc(0);

	// register for save states
	save_item(NAME(m_shift));
}

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

void mm5837_device::device_reset()
{
	// initialize with something
	m_shift = 123456;

	if (m_vdd < 16)
		m_timer->adjust(attotime::zero, 0, attotime::from_hz(m_frequency[m_vdd]));
	else
		throw emu_fatalerror("%s: Invalid voltage: %d\n", tag(), m_vdd);
}

//-------------------------------------------------
//  device_timer - handle timer callbacks
//-------------------------------------------------

void mm5837_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
	int tap_14 = BIT(m_shift, 13);
	int tap_17 = BIT(m_shift, 16);
	int zero = (m_shift == 0) ? 1 : 0;

	m_shift <<= 1;
	m_shift |= tap_14 ^ tap_17 ^ zero;

	m_output_cb(BIT(m_shift, 16));
}