summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/sound/c140.h
blob: cdc84a38fd164a5c3146ea830a0007ce1b4a2218 (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
// license:BSD-3-Clause
// copyright-holders:R. Belmont
/* C140.h */

#ifndef MAME_SOUND_C140_H
#define MAME_SOUND_C140_H

#pragma once


//**************************************************************************
//  TYPE DEFINITIONS
//**************************************************************************


// ======================> c140_device

class c140_device : public device_t,
	public device_sound_interface,
	public device_rom_interface
{
public:
	enum class C140_TYPE
	{
		SYSTEM2,
		SYSTEM21,
		ASIC219
	};

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

	// configuration
	void set_bank_type(C140_TYPE bank) { m_banking_type = bank; }

	DECLARE_READ8_MEMBER( c140_r );
	DECLARE_WRITE8_MEMBER( c140_w );

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

	virtual void rom_bank_updated() override;

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

private:
	static constexpr unsigned MAX_VOICE = 24;

	struct C140_VOICE
	{
		C140_VOICE() { }

		int32_t    ptoffset     = 0;
		int32_t    pos          = 0;
		int32_t    key          = 0;
		//--work
		int32_t    lastdt       = 0;
		int32_t    prevdt       = 0;
		int32_t    dltdt        = 0;
		//--reg
		int32_t    rvol         = 0;
		int32_t    lvol         = 0;
		int32_t    frequency    = 0;
		int32_t    bank         = 0;
		int32_t    mode         = 0;

		int32_t    sample_start = 0;
		int32_t    sample_end   = 0;
		int32_t    sample_loop  = 0;
	};

	void init_voice( C140_VOICE *v );
	long find_sample(long adrs, long bank, int voice);

	int m_sample_rate;
	sound_stream *m_stream;
	C140_TYPE m_banking_type;
	/* internal buffers */
	std::unique_ptr<int16_t[]> m_mixer_buffer_left;
	std::unique_ptr<int16_t[]> m_mixer_buffer_right;

	int m_baserate;
	uint8_t m_REG[0x200];

	int16_t m_pcmtbl[8];        //2000.06.26 CAB

	C140_VOICE m_voi[MAX_VOICE];
};

DECLARE_DEVICE_TYPE(C140, c140_device)

#endif // MAME_SOUND_C140_H