summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/sound/huc6230.h
blob: 27e67ce41a37d2c23af9b3d44263ecdda43a3fee (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
// license:BSD-3-Clause
// copyright-holders:cam900
#ifndef MAME_SOUND_HUC6230_H
#define MAME_SOUND_HUC6230_H

#pragma once

#include "sound/okiadpcm.h"
#include "sound/c6280.h"

class huc6230_device : public device_t, public device_sound_interface
{
public:
	static constexpr feature_type imperfect_features() { return feature::SOUND; } // Incorrect ADPCM

	huc6230_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	template <unsigned N> auto adpcm_update_cb() { return m_adpcm_update_cb[N].bind(); }
	auto vca_callback() { return m_vca_cb.bind(); }

	// write only
	void write(offs_t offset, uint8_t data);

protected:
	// device-level overrides
	virtual void device_add_mconfig(machine_config &config) override;
	virtual void device_start() override;
	virtual void device_clock_changed() override;

	// sound stream update overrides
	virtual void sound_stream_update_legacy(sound_stream &stream, stream_sample_t const * const *inputs, stream_sample_t * const *outputs, int samples) override;

private:
	struct adpcm_channel {
		oki_adpcm_state m_adpcm;
		uint8_t         m_lvol;
		uint8_t         m_rvol;
		uint8_t         m_interpolate;
		uint8_t         m_playing;
		int32_t         m_prev_sample;
		int32_t         m_curr_sample;
		int32_t         m_output;
		uint32_t        m_pos;
		uint8_t         m_input;
	};

	// internal state
	sound_stream *m_stream;
	emu_timer *m_adpcm_timer;
	required_device<c6280_device> m_psg;
	adpcm_channel m_adpcm_channel[2];
	uint32_t m_adpcm_freq;
	uint32_t m_pcm_lvol;
	uint32_t m_pcm_rvol;

	TIMER_CALLBACK_MEMBER(adpcm_timer);

	devcb_read8::array<2> m_adpcm_update_cb;
	devcb_write8 m_vca_cb;
};

DECLARE_DEVICE_TYPE(HuC6230, huc6230_device)

#endif // MAME_SOUND_HUC6230_H