summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/audio/lynx.h
blob: 0476a39f176e57f60b1b3649e91e2ad2319d2ab2 (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
// license:GPL-2.0+
// copyright-holders:Peter Trauner
#ifndef MAME_AUDIO_LYNX_H
#define MAME_AUDIO_LYNX_H

#pragma once


class lynx_sound_device : public device_t, public device_sound_interface
{
public:
	typedef device_delegate<void (void)> timer_delegate;

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

	DECLARE_READ8_MEMBER(read);
	DECLARE_WRITE8_MEMBER(write);
	void count_down(int nr);
	template<typename Object> void set_timer_delegate(Object &&cb) { m_timer_delegate = std::forward<Object>(cb); }

protected:
	struct LYNX_AUDIO {
		struct {
			int8_t volume;
			uint8_t feedback;
			int8_t output;
			uint8_t shifter;
			uint8_t bakup;
			uint8_t control1;
			uint8_t counter;
			uint8_t control2;
		} reg;
		uint8_t attenuation;
		uint16_t mask; // 12-bit
		uint16_t shifter; // 12-bit
		float ticks;
		int count;
	};

	lynx_sound_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);

	// device-level overrides
	virtual void device_start() override;

	virtual void device_reset() override;

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

	void reset_channel(LYNX_AUDIO *channel);
	void shift(int chan_nr);
	void execute(int chan_nr);
	void init();
	void register_save();

	sound_stream *m_mixer_channel;
	timer_delegate   m_timer_delegate;   // this calls lynx_timer_count_down from the driver state

	float m_usec_per_sample;
	std::unique_ptr<int[]> m_shift_mask;
	std::unique_ptr<int[]> m_shift_xor;
	uint8_t m_attenuation_enable;
	uint8_t m_master_enable;
	LYNX_AUDIO m_audio[4];
};


class lynx2_sound_device : public lynx_sound_device
{
public:
	lynx2_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

protected:
	// device-level overrides
	virtual void device_start() override;

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


DECLARE_DEVICE_TYPE(LYNX_SND,  lynx_sound_device)
DECLARE_DEVICE_TYPE(LYNX2_SND, lynx2_sound_device)


#define MCFG_LYNX_SND_SET_TIMER( _class, _method) \
	downcast<lynx_sound_device &>(*device).set_timer_delegate(lynx_sound_device::timer_delegate(&_class::_method, #_class "::" #_method, nullptr, (_class *)nullptr));


#endif // MAME_AUDIO_LYNX_H