summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/odyssey2/voice.cpp
blob: 3c2b5b0b6e36b014b17a6e677b7964804ee2067d (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
// license:BSD-3-Clause
// copyright-holders:Wilbert Pol, Fabio Priuli
/******************************************************************************

Magnavox The Voice emulation

Hardware notes:
- SP0256B-019 with 2KB internal ROM
- 16KB speech ROM, or 8*2KB on a daughterboard(same contents)
- passthrough cartridge slot, with support for extra speech ROM

Cartridge pins A,B,E,1,10,11 are repurposed for the extra speech ROM. This means
that (European) cartridges using extra I/O won't work on it.

TODO:
- bees sound at level complete "MORE MORE MORE CHK CHK CHK" should be more rapid

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

#include "emu.h"
#include "voice.h"
#include "speaker.h"

DEFINE_DEVICE_TYPE(O2_ROM_VOICE, o2_voice_device, "o2_voice", "Odyssey 2 The Voice Cartridge")

//-------------------------------------------------
//  o2_voice_device - constructor
//-------------------------------------------------

o2_voice_device::o2_voice_device(const machine_config &mconfig, const char *tag, device_t *owner, const XTAL &clock) :
	device_t(mconfig, O2_ROM_VOICE, tag, owner, clock),
	device_o2_cart_interface(mconfig, *this),
	m_speech(*this, "speech"),
	m_subslot(*this, "subslot")
{ }

void o2_voice_device::device_start()
{
	save_item(NAME(m_control));
}

void o2_voice_device::cart_init()
{
	u32 size = get_voice_size();
	if (size == 0)
		fatalerror("o2_voice_device: No voice region found\n");

	size = (size > 0x8000) ? 0x8000 : size;
	memcpy(memregion("speech")->base(), get_voice_base(), size);
}

void o2_voice_device::device_reset()
{
	if (m_subslot->exists() && m_subslot->cart() && m_subslot->cart()->get_voice_size())
	{
		// load additional speech data
		u32 size = m_subslot->cart()->get_voice_size();
		size = (size > 0x8000) ? 0x8000 : size;
		memcpy(memregion("speech")->base() + 0x8000, m_subslot->cart()->get_voice_base(), size);
	}
}


//-------------------------------------------------
//  device_add_mconfig - add device configuration
//-------------------------------------------------

void o2_voice_device::device_add_mconfig(machine_config &config)
{
	SPEAKER(config, "mono").front_center();

	SP0256(config, m_speech, 3.12_MHz_XTAL);
	// The Voice uses a speaker with its own volume control so the relative volumes to use are subjective, these sound good
	m_speech->add_route(ALL_OUTPUTS, "mono", 1.00);

	O2_CART_SLOT(config, m_subslot, o2_cart, nullptr);
}

ROM_START( o2voice )
	ROM_REGION( 0x10000, "speech", ROMREGION_ERASE00 )
ROM_END

const tiny_rom_entry *o2_voice_device::device_rom_region() const
{
	return ROM_NAME( o2voice );
}


//-------------------------------------------------
//  mapper specific handlers
//-------------------------------------------------

READ_LINE_MEMBER(o2_voice_device::t0_read)
{
	return m_speech->lrq_r() ? 0 : 1;
}

void o2_voice_device::io_write(offs_t offset, u8 data)
{
	if (offset & 0x80 && ~m_control & 0x10)
	{
		// A0-A6: SP0256B A1-A7 (A8 to GND)
		// D5: 7474 to SP0256B reset
		if (data & 0x20)
			m_speech->ald_w(offset & 0x7f);
		else
			m_speech->reset();
	}
}