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
|
// license:BSD-3-Clause
// copyright-holders:Dirk Best
/***************************************************************************
National Semiconductor MM5837
Digital Noise Source
***************************************************************************/
#include "emu.h"
#include "mm5837.h"
//**************************************************************************
// DEVICE DEFINITIONS
//**************************************************************************
DEFINE_DEVICE_TYPE(MM5837, mm5837_device, "mm5837", "MM5837 Digital Noise Source")
DEFINE_DEVICE_TYPE(MM5837_STREAM, mm5837_stream_device, "mm5837_stream", "MM5837 Digital Noise Stream")
//**************************************************************************
// MM5837 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_timer(nullptr),
m_vdd(-12)
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void mm5837_device::device_start()
{
// resolve callbacks
m_output_cb.resolve_safe();
// get timer
m_timer = timer_alloc(FUNC(mm5837_device::update_clock_output), this);
// register for save states
save_item(NAME(m_source.m_shift));
}
//-------------------------------------------------
// device_reset - device-specific reset
//-------------------------------------------------
void mm5837_device::device_reset()
{
m_source.reset();
if (m_vdd < 16)
m_timer->adjust(attotime::zero, 0, attotime::from_hz(mm5837_source::frequency(m_vdd)));
else
throw emu_fatalerror("%s: Invalid voltage: %d\n", tag(), m_vdd);
}
//-------------------------------------------------
// update_clock_output -
//-------------------------------------------------
TIMER_CALLBACK_MEMBER(mm5837_device::update_clock_output)
{
m_output_cb(m_source.clock());
}
//**************************************************************************
// MM5837 STREAM DEVICE
//**************************************************************************
//-------------------------------------------------
// mm5837_stream_device - constructor
//-------------------------------------------------
mm5837_stream_device::mm5837_stream_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
device_t(mconfig, MM5837_STREAM, tag, owner, clock),
device_sound_interface(mconfig, *this),
m_stream(nullptr),
m_vdd(-12)
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void mm5837_stream_device::device_start()
{
m_stream = stream_alloc(0, 1, mm5837_source::frequency(m_vdd));
save_item(NAME(m_source.m_shift));
}
//-------------------------------------------------
// sound_stream_update - fill the sound buffer
//-------------------------------------------------
void mm5837_stream_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
{
for (int sampindex = 0; sampindex < outputs[0].samples(); sampindex++)
outputs[0].put(sampindex, m_source.clock() ? 1.0 : 0.0);
}
|