summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/intv/ecs.cpp
blob: 6fd321af36b6f4139d36e7d856cceb31ccaa83a8 (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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
// license:BSD-3-Clause
// copyright-holders:Fabio Priuli
/***********************************************************************************************************


 Mattel Intellivision Entertainment Computer System expansion emulation

 TODO:
   - Make paged rom emulation more accurate (according to
   http://spatula-city.org/~im14u2c/intv/tech/ecs.html
   writes to $xa5y should be available for every x and every y, i.e. we shall
   have writes to every 4K chunk of the memory map, and there shall be 16 pages
   for each)
   Current emulation is instead tailored around the minimal usage necessary to
   make the main expansion and World Series Major League Baseball happy

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


#include "emu.h"
#include "ecs.h"
#include "speaker.h"


//-------------------------------------------------
//  intv_ecs_device - constructor
//-------------------------------------------------

DEFINE_DEVICE_TYPE(INTV_ROM_ECS, intv_ecs_device, "intv_ecs", "Intellivision ECS Expansion")

intv_ecs_device::intv_ecs_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: intv_rom_device(mconfig, INTV_ROM_ECS, tag, owner, clock),
	m_snd(*this, "ay8914"),
	m_subslot(*this, "subslot"),
	m_voice_enabled(false),
	m_ramd0_enabled(false),
	m_ram88_enabled(false)
{
}


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

void intv_ecs_device::device_start()
{
	// if the ECS is mounted directly in the system, use device rom and alloc RAM
	if (m_rom == nullptr)
	{
		std::string region_tag;
		m_rom = memregion(region_tag.assign(tag()).append(":ecs").c_str())->base();
	}
	if (m_ram.empty())
	{
		m_ram.resize(0x800);
	}

	save_item(NAME(m_bank_base));
}

void intv_ecs_device::device_reset()
{
	memset(m_bank_base, 0, sizeof(m_bank_base));
}

void intv_ecs_device::late_subslot_setup()
{
	switch (m_subslot->get_type())
	{
		case INTV_RAM:
			m_ramd0_enabled = true;
			break;
		case INTV_GFACT:
			m_ram88_enabled = true;
			break;
		case INTV_VOICE:
			m_voice_enabled = true;
			m_subslot->late_subslot_setup();
			break;
		case INTV_ECS:
			printf("WARNING: You cannot connect serially multiple ECS units.\n");
			printf("WARNING: Emulation will likely misbehave.\n");
			break;
		case INTV_KEYCOMP:
			printf("WARNING: You cannot connect the Keyboard component to the ECS unit.\n");
			printf("WARNING: Emulation will likely misbehave.\n");
			break;
	}
}

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


void intv_ecs_device::device_add_mconfig(machine_config &config)
{
	SPEAKER(config, "mono_ecs").front_center();

	AY8914(config, m_snd, XTAL(3'579'545)/2);
	m_snd->port_a_read_callback().set("ctrl_port", FUNC(intvecs_control_port_device::portA_r));
	m_snd->port_b_read_callback().set("ctrl_port", FUNC(intvecs_control_port_device::portB_r));
	m_snd->port_a_write_callback().set("ctrl_port", FUNC(intvecs_control_port_device::portA_w));
	m_snd->add_route(ALL_OUTPUTS, "mono_ecs", 0.33);

	INTVECS_CONTROL_PORT(config, "ctrl_port", intvecs_control_port_devices, "keybd");
	INTV_CART_SLOT(config, m_subslot, intv_cart, nullptr);
}


ROM_START( ecs )
	ROM_REGION( 0x20000, "ecs", ROMREGION_ERASEFF )
	ROM_LOAD16_WORD_SWAP( "ecs_rom.20", 0x04000, 0x2000, CRC(5f9d05e5) SHA1(083a3e7405b8f8b4b8a5003ca9c31b8d824b535c))
	ROM_LOAD16_WORD_SWAP( "ecs_rom.70", 0x0e000, 0x2000, CRC(46bb1f48) SHA1(eda44a8476fdada1ae90fba0d0287611e2efa074))
	ROM_LOAD16_WORD_SWAP( "ecs_rom.e0", 0x1c000, 0x2000, CRC(c2ebcd90) SHA1(b3c14955f56c57e6f0d8fbb695771946cfcf6582))
ROM_END

const tiny_rom_entry *intv_ecs_device::device_rom_region() const
{
	return ROM_NAME( ecs );
}


/*-------------------------------------------------
 Paged ROM handling
 -------------------------------------------------*/

uint16_t intv_ecs_device::read_rom20(offs_t offset)
{
	if (m_bank_base[2])
		return INTV_ROM16_READ(offset + 0x2000);
	else
		return 0xffff;
}

uint16_t intv_ecs_device::read_rom70(offs_t offset)
{
	if (m_bank_base[7])
		return 0xffff;
	else
		return INTV_ROM16_READ(offset + 0x7000);
}

uint16_t intv_ecs_device::read_rome0(offs_t offset)
{
	if (m_bank_base[14])
		return INTV_ROM16_READ(offset + 0xe000);
	else    // if WSMLB is loaded, it shall go here, otherwise 0xffff
		return m_subslot->read_rome0(offset);
}

uint16_t intv_ecs_device::read_romf0(offs_t offset)
{
	// only WSMLB should come here with bank_base = 1
	if (m_bank_base[15])
		return m_subslot->read_romf0(offset + 0x1000);
	else
		return m_subslot->read_romf0(offset);
}


/*-------------------------------------------------
 read_audio
 -------------------------------------------------*/

uint16_t intv_ecs_device::read_ay(offs_t offset)
{
	return 0xff00 | m_snd->read(offset);
}

/*-------------------------------------------------
 write_audio
 -------------------------------------------------*/

void intv_ecs_device::write_ay(offs_t offset, uint16_t data)
{
	return m_snd->write(offset, data & 0x00ff);
}


uint16_t intv_ecs_device::read_rom80(offs_t offset)
{
	if (m_ram88_enabled && offset >= 0x800)
		return m_subslot->read_ram(offset & 0x7ff);
	else
		return m_subslot->read_rom80(offset);
}


uint16_t intv_ecs_device::read_romd0(offs_t offset)
{
	if (m_ramd0_enabled && offset < 0x800)
		return m_subslot->read_ram(offset);
	else
		return m_subslot->read_romd0(offset);
}


void intv_ecs_device::write_rom20(offs_t offset, uint16_t data)
{
	if (offset == 0xfff)
	{
		if (data == 0x2a50)
			m_bank_base[2] = 0;
		else if (data == 0x2a51)
			m_bank_base[2] = 1;
	}
}

void intv_ecs_device::write_rom70(offs_t offset, uint16_t data)
{
	if (offset == 0xfff)
	{
		if (data == 0x7a50)
			m_bank_base[7] = 0;
		else if (data == 0x7a51)
			m_bank_base[7] = 1;
	}
}

void intv_ecs_device::write_rome0(offs_t offset, uint16_t data)
{
	if (offset == 0xfff)
	{
		if (data == 0xea50)
			m_bank_base[14] = 0;
		else if (data == 0xea51)
			m_bank_base[14] = 1;
	}
}

void intv_ecs_device::write_romf0(offs_t offset, uint16_t data)
{
	if (offset == 0xfff)
	{
		if (data == 0xfa50)
			m_bank_base[15] = 0;
		else if (data == 0xfa51)
			m_bank_base[15] = 1;
	}
}