summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/ti99/peb/spchsyn.cpp
blob: 0f10eea1f33f56eaa48328a5660b85b94f61606b (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
// license:LGPL-2.1+
// copyright-holders:Michael Zapf
/****************************************************************************

    TI-99 Speech synthesizer

    We emulate the Speech Synthesizer plugged onto a P-Box adapter. The original
    Speech Synthesizer device was provided as a box to be plugged into the
    right side of the console. In order to be used with Geneve and SGCPU, the
    speech synthesizer must be moved into the Peripheral Box.

    The Speech Synthesizer used for the TI was the CD2501E, AKA TMS5200,
    (internal name TMC0285), a predecessor of the TMS5220 which was used in
    other commercial products.

    Note that this adapter also contains the speech roms.

    Michael Zapf

    February 2012: Rewritten as class

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

#include "emu.h"
#include "spchsyn.h"

#include "machine/spchrom.h"
#include "speaker.h"

#define LOG_WARN        (1U<<1)    // Warnings
#define LOG_CONFIG      (1U<<2)
#define LOG_MEM         (1U<<3)
#define LOG_ADDR        (1U<<4)
#define LOG_READY       (1U<<5)

#define VERBOSE ( LOG_CONFIG | LOG_WARN )
#include "logmacro.h"

DEFINE_DEVICE_TYPE_NS(TI99_SPEECH, bus::ti99::peb, ti_speech_synthesizer_device, "ti99_speech", "TI-99 Speech synthesizer (on adapter card)")

namespace bus { namespace ti99 { namespace peb {

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

ti_speech_synthesizer_device::ti_speech_synthesizer_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, TI99_SPEECH, tag, owner, clock),
	device_ti99_peribox_card_interface(mconfig, *this),
	m_vsp(*this, "vsp"),
	m_reading(false),
	m_sbe(false)
{
}

/*
    Memory read
*/

READ8Z_MEMBER( ti_speech_synthesizer_device::readz )
{
	if (machine().side_effects_disabled()) return;

	if (m_sbe)
	{
		*value = m_vsp->status_r() & 0xff;
		LOGMASKED(LOG_MEM, "read value = %02x\n", *value);
		// We should clear the lines at this point. The TI-99/4A clears the
		// lines by setting the address bus to a different value, but the
		// Geneve may behave differently. This may not 100% reflect the real
		// situation, but it ensures a safe processing.
		m_vsp->combined_rsq_wsq_w(space, 0, ~0);
	}
}

/*
    Memory write
*/
WRITE8_MEMBER( ti_speech_synthesizer_device::write )
{
	if (machine().side_effects_disabled()) return;

	if (m_sbe)
	{
		LOGMASKED(LOG_MEM, "write value = %02x\n", data);
		m_vsp->data_w(data);
		// Note that we must NOT clear the lines here. Find the lines in the
		// READY callback below.
	}
}

SETADDRESS_DBIN_MEMBER( ti_speech_synthesizer_device::setaddress_dbin )
{
	// 1001 00xx xxxx xxx0   DBIN=1
	// 1001 01xx xxxx xxx0   DBIN=0
	// 1111 1000 0000 0001    mask
	m_space = &space;
	m_reading = (state==ASSERT_LINE);

	bool valid = (((offset & 0x0400)==0) == m_reading);
	m_sbe = ((offset & m_select_mask)==m_select_value) && valid;

	if (m_sbe)
	{
		LOGMASKED(LOG_ADDR, "set address = %04x, dbin = %d\n", offset, state);

		// Caution: In the current tms5220 emulation, care must be taken
		// to clear one line before asserting the other line, or otherwise
		// both RS* and WS* are active, which is illegal.
		// Alternatively, we'll use the combined settings method

		m_vsp->combined_rsq_wsq_w(space, 0, m_reading ? ~tms5220_device::RS : ~tms5220_device::WS);
	}
	else
		// If other address, turn off RS* and WS* (negative logic!)
		m_vsp->combined_rsq_wsq_w(space, 0, ~0);
}

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

WRITE_LINE_MEMBER( ti_speech_synthesizer_device::speech_ready )
{
	// The TMS5200 implementation uses true/false, not ASSERT/CLEAR semantics
	// and we have to adapt a /READY to a READY line.
	// The real synthesizer board uses a transistor for that purpose.
	m_slot->set_ready((state==0)? ASSERT_LINE : CLEAR_LINE);
	LOGMASKED(LOG_READY, "READY = %d\n", (state==0));

	if ((state==0) && !m_reading)
		// Clear the lines only when we are done with writing.
		m_vsp->combined_rsq_wsq_w(*m_space, 0, ~0);
}

void ti_speech_synthesizer_device::device_start()
{
	// We don't need to save m_space because the calling method
	// combined_rsq_wsq_w only needs the address space formally.
	save_item(NAME(m_reading));
	save_item(NAME(m_sbe));
}

void ti_speech_synthesizer_device::device_reset()
{
	if (m_genmod)
	{
		m_select_mask = 0x1ff801;
		m_select_value = 0x179000;
	}
	else
	{
		m_select_mask = 0x7f801;
		m_select_value = 0x79000;
	}

	m_reading = false;
	m_sbe = false;
}

ROM_START( ti99_speech )
	ROM_REGION(0x8000, "vsm", 0)
	ROM_LOAD("cd2325a.u2a", 0x0000, 0x4000, CRC(1f58b571) SHA1(0ef4f178716b575a1c0c970c56af8a8d97561ffe)) // at location u2, bottom of stack
	ROM_LOAD("cd2326a.u2b", 0x4000, 0x4000, CRC(65d00401) SHA1(a367242c2c96cebf0e2bf21862f3f6734b2b3020)) // at location u2, top of stack
ROM_END

void ti_speech_synthesizer_device::device_add_mconfig(machine_config& config)
{
	SPEECHROM(config, "vsm", 0).set_reverse_bit_order(true);
	SPEAKER(config, "speech_out").front_center();
	CD2501E(config, m_vsp, 640000L);
	m_vsp->set_speechrom_tag("vsm");
	m_vsp->ready_cb().set(FUNC(ti_speech_synthesizer_device::speech_ready));
	m_vsp->add_route(ALL_OUTPUTS, "speech_out", 0.50);

/*
    // FIXME: Make it work. Guess we need two VSM circuits @16K.
    TMS6100(config, "vsm", 640_kHz_XTAL/4);
    m_vsp->m0_cb().set("vsm", FUNC(tms6100_device::m0_w));
    m_vsp->m1_cb().set("vsm", FUNC(tms6100_device::m1_w));
    m_vsp->addr_cb().set("vsm", FUNC(tms6100_device::add_w));
    m_vsp->data_cb().set("vsm", FUNC(tms6100_device::data_line_r));
    m_vsp->romclk_cb().set("vsm", FUNC(tms6100_device::clk_w));
*/
}

const tiny_rom_entry *ti_speech_synthesizer_device::device_rom_region() const
{
	return ROM_NAME( ti99_speech );
}

} } } // end namespace bus::ti99::peb