summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/sound/pcd3311.h
blob: f3e904b5116e1f4258b8d9a6284e7c4f6799d3d7 (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
// license:BSD-3-Clause
// copyright-holders:Curt Coder
/**********************************************************************

    PCD3311 DTMF/modem/musical tone generator emulation

**********************************************************************
                            _____   _____
                  OSCI   1 |*    \_/     | 16  Vdd
                  OSCO   2 |             | 15  Vss
                  MODE   3 |             | 14  D4
                    D5   4 |  PCD3311T   | 13  N/C
                   N/C   5 |             | 12  D3
                STROBE   6 |             | 11  D2
                  TONE   7 |             | 10  D1/SDA
                    A0   8 |_____________| 9   D0/SCL

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

#ifndef MAME_SOUND_PCD3311_H
#define MAME_SOUND_PCD3311_H

#pragma once


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

// ======================> pcd3311_device

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

	void write(uint8_t data) { m_data = data; }
	void strobe_w(int state);
	void mode_w(int state) { m_mode = state; }
	void a0_w(int state);

	void scl_w(int state);
	void sda_w(int state);
	int sda_r();

	// use in memory maps to avoid strobe logic.
	void write_direct(uint8_t data) { load_data(data); }

protected:
	// device_t overrides
	virtual void device_start() override ATTR_COLD;

	virtual void sound_stream_update(sound_stream &stream) override;

private:
	static constexpr uint8_t PCD3311_SLAVE_ADDRESS = 0x48;

	enum { STATE_IDLE, STATE_DEVSEL, STATE_DATAIN };

	void load_data(uint8_t data);

	int m_mode;
	int m_strobe;
	uint8_t m_data;

	int m_slave_address;
	int m_scl;
	int m_sdaw;
	int m_sdar;
	int m_state;
	int m_bits;
	int m_shift;
	int m_devsel;

	sound_stream *m_stream;               // stream number
	uint32_t m_freq[2];                   // current frequencies
	int32_t m_incr[2];                    // initial wave state
	sound_stream::sample_t m_signal[2];   // current signals
};


// device type definition
DECLARE_DEVICE_TYPE(PCD3311, pcd3311_device)

#endif // MAME_SOUND_PCD3311_H