summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/svi3x8/expander/sv603.cpp
blob: fb0fd3428f97a242bf38eb54f1d4e3a7984076f5 (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
// license:GPL-2.0+
// copyright-holders:Dirk Best
/***************************************************************************

    SV-603 Coleco Game Adapter for SVI-318/328

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

#include "emu.h"
#include "sv603.h"
#include "softlist_dev.h"
#include "speaker.h"


//**************************************************************************
//  DEVICE DEFINITIONS
//**************************************************************************

DEFINE_DEVICE_TYPE(SV603, sv603_device, "sv603", "SV-603 Coleco Game Adapter")

//-------------------------------------------------
//  rom_region - device-specific ROM region
//-------------------------------------------------

ROM_START( sv603 )
	ROM_REGION(0x2000, "bios", 0)
	ROM_LOAD("sv603.ic10", 0x0000, 0x2000, CRC(19e91b82) SHA1(8a30abe5ffef810b0f99b86db38b1b3c9d259b78))
ROM_END

const tiny_rom_entry *sv603_device::device_rom_region() const
{
	return ROM_NAME( sv603 );
}

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

void sv603_device::device_add_mconfig(machine_config &config)
{
	SPEAKER(config, "mono").front_center();
	SN76489A(config, m_snd, XTAL(10'738'635) / 3).add_route(ALL_OUTPUTS, "mono", 1.00);

	// controller ports
	COLECOVISION_CONTROL_PORT(config, m_joy[0], colecovision_control_port_devices, "hand");
	m_joy[0]->irq().set(FUNC(sv603_device::joy_irq_w<0>));
	COLECOVISION_CONTROL_PORT(config, m_joy[1], colecovision_control_port_devices, nullptr);
	m_joy[1]->irq().set(FUNC(sv603_device::joy_irq_w<1>));

	// cartridge slot
	COLECOVISION_CARTRIDGE_SLOT(config, m_cart, colecovision_cartridges, nullptr);
	SOFTWARE_LIST(config, "cart_list").set_original("coleco");
}


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

//-------------------------------------------------
//  sv603_device - constructor
//-------------------------------------------------

sv603_device::sv603_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, SV603, tag, owner, clock),
	device_svi_expander_interface(mconfig, *this),
	m_bios(*this, "bios"),
	m_snd(*this, "snd"),
	m_joy{ {*this, "joy1"}, {*this, "joy2"} },
	m_cart(*this, COLECOVISION_CARTRIDGE_SLOT_TAG)
{
}

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

void sv603_device::device_start()
{
}

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

void sv603_device::device_reset()
{
	m_expander->ctrl1_w(0);
}


//**************************************************************************
//  IMPLEMENTATION
//**************************************************************************

template<int N>
WRITE_LINE_MEMBER( sv603_device::joy_irq_w )
{
	m_expander->int_w(state);
}

uint8_t sv603_device::mreq_r(offs_t offset)
{
	uint8_t data = 0xff;

	// ls138 (active low)
	int ccs1 = ((offset >> 13) == 0) ? 0 : 1;
	int ccs2 = ((offset >> 13) == 1) ? 0 : 1;
	int ccs3 = ((offset >> 13) == 2) ? 0 : 1;
	int ccs4 = ((offset >> 13) == 3) ? 0 : 1;
	int bios = ((offset >> 13) == 4) ? 0 : 1;
	// 5, 6, 7: not connected

	m_expander->romdis_w(0);
	m_expander->ramdis_w(bios);

	data &= m_cart->bd_r(offset, data, ccs1, ccs2, ccs3, ccs4);

	if (bios == 0)
		data &= m_bios->as_u8(offset & 0x1fff);

	return data;
}

void sv603_device::mreq_w(offs_t offset, uint8_t data)
{
	m_expander->romdis_w(0);
}

uint8_t sv603_device::iorq_r(offs_t offset)
{
	uint8_t data = 0xff;

	switch (offset & 0xe0)
	{
	case 0xa0:
		data = m_expander->excs_r(offset);
		break;

	case 0xe0:
		data = m_joy[BIT(offset, 1)]->read();
		break;
	}

	return data;
}

void sv603_device::iorq_w(offs_t offset, uint8_t data)
{
	switch (offset & 0xe0)
	{
	case 0x80:
		// keypad mode
		m_joy[0]->common0_w(1);
		m_joy[0]->common1_w(0);
		m_joy[1]->common0_w(1);
		m_joy[1]->common1_w(0);
		break;

	case 0xa0:
		m_expander->excs_w(offset, data);
		break;

	case 0xc0:
		// joystick mode
		m_joy[0]->common0_w(0);
		m_joy[0]->common1_w(1);
		m_joy[1]->common0_w(0);
		m_joy[1]->common1_w(1);
		break;

	case 0xe0:
		m_snd->write(data);
		break;
	}
}