summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/sound/upd7752.cpp
blob: f49171588e7d847e9cb2462bc3d1549a389ca88a (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// license:BSD-3-Clause
// copyright-holders:Angelo Salese
/***************************************************************************

NEC uPD7752 Voice Synthesizing LSI

skeleton device

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

#include "emu.h"
#include "sound/upd7752.h"



/* status flags */
#define BSY 1<<7
#define REQ 1<<6
#define EXT 1<<5
#define ERR 1<<4


//**************************************************************************
//  GLOBAL VARIABLES
//**************************************************************************

// device type definition
DEFINE_DEVICE_TYPE(UPD7752, upd7752_device, "upd7752", "NEC uPD7752")


/* TODO: unknown exact size */
void upd7752_device::upd7752_ram(address_map &map)
{
//  AM_RANGE(0x0000, 0x7fff) AM_ROM
	map(0x0000, 0xffff).ram();
}

//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

//-------------------------------------------------
//  upd7752_device - constructor
//-------------------------------------------------

upd7752_device::upd7752_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, UPD7752, tag, owner, clock),
		device_sound_interface(mconfig, *this),
		device_memory_interface(mconfig, *this), m_stream(nullptr),
		m_space_config("ram", ENDIANNESS_LITTLE, 8, 16, 0, address_map_constructor(), address_map_constructor(FUNC(upd7752_device::upd7752_ram), this)), m_status(0), m_ram_addr(0), m_mode(0)
{
}


//-------------------------------------------------
//  memory_space_config - return a description of
//  any address spaces owned by this device
//-------------------------------------------------

device_memory_interface::space_config_vector upd7752_device::memory_space_config() const
{
	return space_config_vector {
		std::make_pair(0, &m_space_config)
	};
}


//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void upd7752_device::device_start()
{
	/* TODO: clock */
	m_stream = stream_alloc(0, 1, clock() / 64);

	m_status = 0;
}


//-------------------------------------------------
//  device_reset - device-specific reset
//-------------------------------------------------

void upd7752_device::device_reset()
{
}


//-------------------------------------------------
//  device_stop - device-specific stop
//-------------------------------------------------

void upd7752_device::device_stop()
{
}

//-------------------------------------------------
//  sound_stream_update - handle a stream update
//-------------------------------------------------

void upd7752_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
}

//**************************************************************************
//  INLINE HELPERS
//**************************************************************************

inline uint8_t upd7752_device::readbyte(offs_t address)
{
	return space().read_byte(address);
}

//-------------------------------------------------
//  writebyte - write a byte at the given address
//-------------------------------------------------

inline void upd7752_device::writebyte(offs_t address, uint8_t data)
{
	space().write_byte(address, data);
}

//**************************************************************************
//  READ/WRITE HANDLERS
//**************************************************************************

void upd7752_device::status_change(uint8_t flag,bool type)
{
	if(type == true)
		m_status |= flag;
	else
		m_status &= ~flag;
}

READ8_MEMBER( upd7752_device::read )
{
	switch(offset & 3)
	{
		//[0x00]: status register
		//x--- ---- BSY busy status (1) processing (0) stopped
		//-x-- ---- REQ audio parameter (1) input request (0) prohibited (???)
		//--x- ---- ~INT / EXT message data (1) Outside (0) Inside
		//---x ---- ERR error flag
		case 0x00: return m_status;
		//[0x02]: port 0xe2 latch?
		case 0x02: return 0xff;
		//[0x03]: port 0xe3 latch?
		case 0x03: return 0xff;
	}
	return 0xff;
}

WRITE8_MEMBER( upd7752_device::write )
{
	switch(offset & 3)
	{
		// [0x00]: audio parameter transfer
		case 0x00:
			if(m_status & EXT)
			{
				/*
				[0] xxxx x--- number of frames (times) to apply next table (N1)
				    ---- -x-- Quantized Magnification Data (QMAG)
				    ---- --x- Selective Interpolation Data (SI)
				    ---- ---x Voicing/Unvoicing Data (VU)
				[1] xxxx ---- amp Voice source amplitude
				    ---- x--- Fricative Voice data
				    ---- -xxx Pitch
				    (repeat for N1 times)
				if [0] & 0xf8 == 0 then command stop
				*/
				writebyte(m_ram_addr++,data);
			}
			//else
			// ...

		break;

		// [0x02]: mode set
		// ---- -x-- Frame periodic analysis (0) 10 ms / frame (1) 20 ms / frame
		// ---- --xx Utterance (tempo?) speed
		//        00 : NORMAL SPEED
		//        01 : SLOW SPEED
		//        10 : FAST SPEED
		//        11 : Setting prohibited

		case 0x02:
			m_mode = data & 7;
			break;

		case 0x03: //command set
			switch(data)
			{
				case 0xfe: // external message select cmd
					status_change(EXT,true);
					status_change(REQ,true);
					//TODO: BSY flag too
					m_ram_addr = 0;
					break;
			}

			break;

	}
}