summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/audio/vc4000.cpp
blob: 79eee1b1b7120fe7a1f5d0ede8ec065aff1767b4 (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
// license:GPL-2.0+
// copyright-holders:Peter Trauner
/***************************************************************************

  PeT mess@utanet.at
  main part in video/

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

#include "emu.h"
#include "vc4000.h"


const device_type VC4000_SND = &device_creator<vc4000_sound_device>;

vc4000_sound_device::vc4000_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, VC4000_SND, "Intertion Electronic VC 4000 Audio Custom", tag, owner, clock, "vc4000_sound", __FILE__),
		device_sound_interface(mconfig, *this),
		m_channel(nullptr),
		m_size(0),
		m_pos(0),
		m_level(0)
{
	memset(m_reg, 0, sizeof(uint8_t)*1);
}


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

void vc4000_sound_device::device_start()
{
	m_channel = stream_alloc(0, 1, machine().sample_rate());
}


//-------------------------------------------------
//  sound_stream_update - handle a stream update
//-------------------------------------------------

void vc4000_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
	int i;
	stream_sample_t *buffer = outputs[0];

	for (i = 0; i < samples; i++, buffer++)
	{
		*buffer = 0;
		if (m_reg[0] && m_pos <= m_size / 2)
		{
			*buffer = 0x7fff;
		}
		if (m_pos <= m_size)
			m_pos++;
		if (m_pos > m_size)
			m_pos = 0;
	}
}


void vc4000_sound_device::soundport_w(int offset, int data)
{
	m_channel->update();
	m_reg[offset] = data;
	switch (offset)
	{
		case 0:
			m_pos = 0;
			m_level = true;
			// frequency 7874/(data+1)
			m_size = machine().sample_rate() * (data + 1) /7874;
			break;
	}
}