summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/sound/es5503.h
blob: 941c56ef8c4cb4699084b2074311f156399c8c58 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// license:BSD-3-Clause
// copyright-holders:R. Belmont
#pragma once

#ifndef __ES5503_H__
#define __ES5503_H__

// channels must be a power of two

#define MCFG_ES5503_ADD(_tag, _clock)  \
	MCFG_DEVICE_ADD(_tag, ES5503, _clock)

#define MCFG_ES5503_OUTPUT_CHANNELS(_channels) \
	es5503_device::static_set_channels(*device, _channels);

#define MCFG_ES5503_IRQ_FUNC(_write) \
	devcb = &es5503_device::static_set_irqf(*device, DEVCB_##_write);

#define MCFG_ES5503_ADC_FUNC(_read) \
	devcb = &es5503_device::static_set_adcf(*device, DEVCB_##_read);

// ======================> es5503_device

class es5503_device : public device_t,
						public device_sound_interface,
						public device_memory_interface
{
public:
	// construction/destruction
	es5503_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);

	static void static_set_channels(device_t &device, int channels);

	template<class _Object> static devcb_base &static_set_irqf(device_t &device, _Object object) { return downcast<es5503_device &>(device).m_irq_func.set_callback(object); }
	template<class _Object> static devcb_base &static_set_adcf(device_t &device, _Object object) { return downcast<es5503_device &>(device).m_adc_func.set_callback(object); }

	DECLARE_READ8_MEMBER(read);
	DECLARE_WRITE8_MEMBER(write);

	UINT8 get_channel_strobe() { return m_channel_strobe; }

	sound_stream *m_stream;

protected:
	// device-level overrides
	virtual void device_start() override;
	virtual void device_reset() override;
	virtual void device_timer(emu_timer &timer, device_timer_id tid, int param, void *ptr) override;

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

	// device_memory_interface overrides
	virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const override;

	const address_space_config  m_space_config;

	devcb_write_line   m_irq_func;
	devcb_read8        m_adc_func;

	emu_timer *m_sync_timer;

private:
	enum
	{
		MODE_FREE = 0,
		MODE_ONESHOT = 1,
		MODE_SYNCAM = 2,
		MODE_SWAP = 3
	};

	struct ES5503Osc
	{
		UINT16 freq;
		UINT16 wtsize;
		UINT8  control;
		UINT8  vol;
		UINT8  data;
		UINT32 wavetblpointer;
		UINT8  wavetblsize;
		UINT8  resolution;

		UINT32 accumulator;
		UINT8  irqpend;
	};

	ES5503Osc oscillators[32];

	INT8  oscsenabled;      // # of oscillators enabled
	int   rege0;            // contents of register 0xe0

	UINT8 m_channel_strobe;

	int output_channels;
	UINT32 output_rate;

	emu_timer *m_timer;

	direct_read_data *m_direct;

	void halt_osc(int onum, int type, UINT32 *accumulator, int resshift);
};


// device type definition
extern const device_type ES5503;

#endif /* __ES5503_H__ */